Skip to content

Commit

Permalink
Choreographic Enclave (#26)
Browse files Browse the repository at this point in the history
* replace `colocally` with `enclave`

* bump version to 0.3.0

* bump dependencies
  • Loading branch information
shumbo authored Nov 15, 2023
1 parent 8010d56 commit 1dfce23
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["chorus_lib", "chorus_derive"]
resolver = "2"

[workspace.package]
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Shun Kashiwa <[email protected]>"]
homepage = "https://lsd-ucsc.github.io/ChoRus/"
Expand Down
2 changes: 1 addition & 1 deletion chorus_book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
- [Input and Output](./guide-input-and-output.md)
- [Higher-order Choreography](./guide-higher-order-choreography.md)
- [Location Polymorphism](./guide-location-polymorphism.md)
- [Colocally and Efficient Conditional](./guide-colocally.md)
- [Choreographic Enclave and Efficient Conditional](./guide-enclave.md)
- [Runner](./guide-runner.md)
- [Links](./links.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# colocally and Efficient Conditional
# Choreographic Enclave and Efficient Conditional

ChoRus supports the `colocally` operator to achieve efficient conditional execution.
ChoRus supports the `enclave` operator to achieve efficient conditional execution.

## Conditional with Broadcast

Expand Down Expand Up @@ -44,7 +44,7 @@ impl Choreography for DemoChoreography {

While this code correctly implements the protocol, it is inefficient. The `is_even` value is broadcasted to all locations, but Alice does not need to receive the value. Ideally, we want to send `is_even_at_bob` only to Carol and branch only on Bob and Carol.

In ChoRus, we can achieve this using the `colocally` operator. First, let us define a sub-choreography that describes the communication between Bob and Carol:
In ChoRus, we can achieve this using the `enclave` operator. First, let us define a sub-choreography that describes the communication between Bob and Carol:

```rust
{{#include ./header.txt}}
Expand All @@ -70,7 +70,7 @@ impl Choreography for BobCarolChoreography {
}
```

Notice that `BobCarolChoreography` only describes the behavior of Bob and Carol (see its location set `L`). `colocally` is an operator to execute a choreography only at locations that is included in the location set. In this case, if we invoke `BobCarolChoreography` with `colocally` in the main choreography, it will only be executed at Bob and Carol and not at Alice.
Notice that `BobCarolChoreography` only describes the behavior of Bob and Carol (see its location set `L`). `enclave` is an operator to execute a choreography only at locations that is included in the location set. In this case, if we invoke `BobCarolChoreography` with `enclave` in the main choreography, it will only be executed at Bob and Carol and not at Alice.

```rust
{{#include ./header.txt}}
Expand Down Expand Up @@ -105,16 +105,16 @@ impl Choreography for MainChoreography {
get_random_number()
});
let x_at_bob = op.comm(Alice, Bob, &x_at_alice);
op.colocally(BobCarolChoreography {
op.enclave(BobCarolChoreography {
x_at_bob,
});
}
}
```

## Returning Values from Colocally
## Returning Values from Enclave

Just like the `call` operator, the `colocally` 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 `colocally` operator.
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.

Expand Down Expand Up @@ -168,7 +168,7 @@ impl Choreography for MainChoreography {
let BobCarolResult {
is_even_at_bob,
is_even_at_carol,
} = op.colocally(BobCarolChoreography {
} = op.enclave(BobCarolChoreography {
x_at_bob,
});
// can access is_even_at_bob and is_even_at_carol using `locally` on Bob and Carol
Expand Down
2 changes: 1 addition & 1 deletion chorus_book/src/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ At high level, ChoRus provides the following features:
- Passing located arguments to / receiving located return values from choreographies.
- Location polymorphism.
- Higher-order choreographies.
- Efficient conditional with the `colocally` operator.
- Efficient conditional with choreographic enclaves.
- Performing end-point projection.
- Pluggable message transports.
- Two built-in transports: `Local` and `HTTP`.
Expand Down
2 changes: 1 addition & 1 deletion chorus_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords = ["choreography"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chorus_derive = { version = "0.2.0", path = "../chorus_derive" }
chorus_derive = { version = "0.3.0", path = "../chorus_derive" }
retry = "2.0.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.104"
Expand Down
4 changes: 2 additions & 2 deletions chorus_lib/examples/bookseller2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<D: Choreography<Located<bool, Buyer1>, L = LocationSet!(Buyer1, Buyer2)> +
return i32::MAX;
});
let price_at_buyer1 = op.comm(Seller, Buyer1, &price_at_seller);
let decision_at_buyer1 = op.colocally(D::new(price_at_buyer1));
let decision_at_buyer1 = op.enclave(D::new(price_at_buyer1));

struct GetDeliveryDateChoreography {
inventory: Located<Inventory, Seller>,
Expand All @@ -120,7 +120,7 @@ impl<D: Choreography<Located<bool, Buyer1>, L = LocationSet!(Buyer1, Buyer2)> +
}
}

return op.colocally(GetDeliveryDateChoreography {
return op.enclave(GetDeliveryDateChoreography {
inventory: self.inventory.clone(),
title_at_seller: title_at_seller.clone(),
decision_at_buyer1,
Expand Down
2 changes: 1 addition & 1 deletion chorus_lib/examples/loc-poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Choreography<Located<i32, Alice>> for MainChoreography {
data: v1,
});
let v2 = op.locally(Bob, |un| un.unwrap(&v2) + 10);
return op.colocally(CommAndPrint {
return op.enclave(CommAndPrint {
sender: Bob,
receiver: Alice,
data: v2,
Expand Down
2 changes: 1 addition & 1 deletion chorus_lib/examples/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Choreography for MainChoreography {
let BobCarolResult {
is_even_at_bob,
is_even_at_carol,
} = op.colocally(BobCarolChoreography { x_at_bob });
} = op.enclave(BobCarolChoreography { x_at_bob });
op.locally(Bob, |un| {
let is_even = un.unwrap(&is_even_at_bob);
assert!(is_even);
Expand Down
8 changes: 4 additions & 4 deletions chorus_lib/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub trait ChoreographyLocation: Copy {
pub trait Portable: Serialize + DeserializeOwned {}
impl<T: Serialize + DeserializeOwned> Portable for T {}

/// Represents a value that might *NOT* be located at a location. Values returned by `colocally` must satisfy this trait.
/// Represents a value that might *NOT* be located at a location. Values returned by `enclave` must satisfy this trait.
///
/// In most cases, you don't need to implement this trait manually. You can derive it using `#[derive(Superposition)]` as long as all the fields consist of located values.
pub trait Superposition {
Expand Down Expand Up @@ -282,7 +282,7 @@ pub trait ChoreoOp<L: LocationSet> {
M: LocationSet + Subset<L, Index>;

/// Calls a choreography on a subset of locations.
fn colocally<R: Superposition, S: LocationSet, C: Choreography<R, L = S>, Index>(
fn enclave<R: Superposition, S: LocationSet, C: Choreography<R, L = S>, Index>(
&self,
choreo: C,
) -> R
Expand Down Expand Up @@ -475,7 +475,7 @@ where
choreo.run(&op)
}

fn colocally<R: Superposition, S: LocationSet, C: Choreography<R, L = S>, Index>(
fn enclave<R: Superposition, S: LocationSet, C: Choreography<R, L = S>, Index>(
&self,
choreo: C,
) -> R {
Expand Down Expand Up @@ -584,7 +584,7 @@ impl<L: LocationSet> Runner<L> {
choreo.run(&op)
}

fn colocally<R: Superposition, S: LocationSet, C: Choreography<R, L = S>, Index>(
fn enclave<R: Superposition, S: LocationSet, C: Choreography<R, L = S>, Index>(
&self,
choreo: C,
) -> R {
Expand Down
3 changes: 1 addition & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"Choreo",
"choreographies",
"chrono",
"colocally",
"Condvar",
"Deque",
"Pluggable",
Expand All @@ -20,4 +19,4 @@
"unwrapper",
"ureq"
]
}
}

0 comments on commit 1dfce23

Please sign in to comment.