From a5f3c7ea2a40433a252206a086870986318041a8 Mon Sep 17 00:00:00 2001 From: Shun Kashiwa Date: Tue, 15 Oct 2024 16:04:27 -0700 Subject: [PATCH] this type checks but crashes at runtime :sob: --- chorus_lib/examples/cardgame.rs | 50 ++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/chorus_lib/examples/cardgame.rs b/chorus_lib/examples/cardgame.rs index c070a1c..b355b71 100644 --- a/chorus_lib/examples/cardgame.rs +++ b/chorus_lib/examples/cardgame.rs @@ -190,24 +190,40 @@ impl< Q: Member, { // TODO: enclave - let choice_at_q = op.locally(Q::new(), |un| *un.unwrap3(self.wants_next_card)); - let choice = op.broadcast(Q::new(), choice_at_q); - if choice { - let card2 = op.locally(Dealer, |_| { - println!("Player {:?} wants another card", Q::name()); - let mut input = String::new(); - std::io::stdin() - .read_line(&mut input) - .expect("Failed to read line"); - input.trim().parse::().expect("Failed to parse input") - }); - let card2 = op.comm(Dealer, Q::new(), &card2); - op.locally(Q::new(), |un| { - vec![*un.unwrap3(self.hand1), *un.unwrap(&card2)] - }) - } else { - op.locally(Q::new(), |un| vec![*un.unwrap3(self.hand1)]) + struct Enclave { + hand1: Located, + wants_next_card: Located, } + impl Choreography, Player>> for Enclave { + type L = LocationSet!(Dealer, Player); + + fn run(self, op: &impl ChoreoOp) -> Located, Player> { + let choice = op.broadcast(Player::new(), self.wants_next_card.clone()); + if choice { + let card2 = op.locally(Dealer, |_| { + println!("Player {:?} wants another card", Player::name()); + let mut input = String::new(); + std::io::stdin() + .read_line(&mut input) + .expect("Failed to read line"); + input.trim().parse::().expect("Failed to parse input") + }); + let card2 = op.comm(Dealer, Player::new(), &card2); + op.locally(Player::new(), |un| { + vec![*un.unwrap(&self.hand1), *un.unwrap(&card2)] + }) + } else { + op.locally(Player::new(), |un| vec![*un.unwrap(&self.hand1)]) + } + } + } + let hand1 = op.locally(Q::new(), |un| *un.unwrap3(self.hand1)); + let wants_next_card = op.locally(Q::new(), |un| *un.unwrap3(self.wants_next_card)); + op.enclave(Enclave:: { + hand1, + wants_next_card, + }) + .flatten() } } let hand2 = op.fanout(