Skip to content

Commit

Permalink
delete outdated document
Browse files Browse the repository at this point in the history
  • Loading branch information
shumbo committed Oct 17, 2024
1 parent df5c39b commit 4083a07
Showing 1 changed file with 1 addition and 63 deletions.
64 changes: 1 addition & 63 deletions chorus_book/src/guide-enclave.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,66 +112,4 @@ impl Choreography for MainChoreography {
}
```

## Returning Values from Enclave

Just like the `call` operator, the `enclave` operator can return a value. However, the type of the returned value must implement the `Superposition` trait. `Superposition` provides a way for ChoRus to construct a value on locations that are not specified in the `enclave` operator.

In general, `Superposition` is either a located value or a struct consisting only of located values. The `Located` struct implements the `Superposition` trait, so you can return located values without any code. If you wish to return a struct of located values, you need to derive the `Superposition` trait using the derive macro.

```rust
{{#include ./header.txt}}
# fn get_random_number() -> u32 {
# 42 // for presentation purpose
# }
#
#[derive(Superposition)]
struct BobCarolResult {
is_even_at_bob: Located<bool, Bob>,
is_even_at_carol: Located<bool, Carol>,
}

struct BobCarolChoreography {
x_at_bob: Located<u32, Bob>,
};

impl Choreography<BobCarolResult> for BobCarolChoreography {
type L = LocationSet!(Bob, Carol);
fn run(self, op: &impl ChoreoOp<Self::L>) -> BobCarolResult {
let is_even_at_bob: Located<bool, Bob> = op.locally(Bob, |un| {
let x = un.unwrap(&self.x_at_bob);
x % 2 == 0
});
let is_even: bool = op.broadcast(Bob, is_even_at_bob.clone());
if is_even {
let x_at_carol = op.comm(Bob, Carol, &self.x_at_bob);
op.locally(Carol, |un| {
let x = un.unwrap(&x_at_carol);
println!("x is even: {}", x);
});
}
BobCarolResult {
is_even_at_bob,
is_even_at_carol: op.locally(Carol, |_| is_even),
}
}
}

struct MainChoreography;

impl Choreography for MainChoreography {
type L = LocationSet!(Alice, Bob, Carol);
fn run(self, op: &impl ChoreoOp<Self::L>) {
let x_at_alice = op.locally(Alice, |_| {
get_random_number()
});
let x_at_bob = op.comm(Alice, Bob, &x_at_alice);
let BobCarolResult {
is_even_at_bob,
is_even_at_carol,
} = op.enclave(BobCarolChoreography {
x_at_bob,
});
// can access is_even_at_bob and is_even_at_carol using `locally` on Bob and Carol
}
}
```
<!-- TODO: document returning values from enclave and `flatten` -->

0 comments on commit 4083a07

Please sign in to comment.