diff --git a/src/runtime2/component/component_pdl.rs b/src/runtime2/component/component_pdl.rs index afa053bf3d65d24b3d13b14d3c8fcbc5921973cf..ed94ded96a5f9d0277ae3ffe542378e49cf3b5f3 100644 --- a/src/runtime2/component/component_pdl.rs +++ b/src/runtime2/component/component_pdl.rs @@ -580,9 +580,8 @@ impl CompPDL { let reservation = sched_ctx.runtime.start_create_pdl_component(); let mut created_ctx = CompCtx::new(&reservation); - let other_proc = &sched_ctx.runtime.protocol.heap[definition_id]; - let self_proc = &sched_ctx.runtime.protocol.heap[self.prompt.frames[0].definition]; - + // let other_proc = &sched_ctx.runtime.protocol.heap[definition_id]; + // let self_proc = &sched_ctx.runtime.protocol.heap[self.prompt.frames[0].definition]; // dbg_code!({ // sched_ctx.log(&format!( // "DEBUG: Comp '{}' (ID {:?}) is creating comp '{}' (ID {:?})", @@ -643,23 +642,24 @@ impl CompPDL { let created_port_info = created_ctx.get_port_mut(pair.created_handle); if created_port_info.peer_comp_id == creator_ctx.id { - // Port peer is owned by the creator as well + // Peer of the transferred port is the component that is + // creating the new component. let created_peer_port_index = opened_port_id_pairs .iter() .position(|v| v.creator_id == creator_port_info.peer_port_id); match created_peer_port_index { Some(created_peer_port_index) => { - // Peer port moved to the new component as well. So - // adjust IDs appropriately. + // Addendum to the above comment: but that port is also + // moving to the new component let peer_pair = &opened_port_id_pairs[created_peer_port_index]; created_port_info.peer_port_id = peer_pair.created_id; created_port_info.peer_comp_id = reservation.id(); - todo!("either add 'self peer', or remove that idea from Ctx altogether") + todo!("either add 'self peer', or remove that idea from Ctx altogether");` }, None => { // Peer port remains with creator component. created_port_info.peer_comp_id = creator_ctx.id; - created_ctx.add_peer(pair.created_handle, sched_ctx, creator_ctx.id, None); + created_ctx.change_port_peer(sched_ctx, pair.created_handle, Some(creator_ctx.id)); } } } else { @@ -667,7 +667,7 @@ impl CompPDL { // appropriate messages later let peer_handle = creator_ctx.get_peer_handle(created_port_info.peer_comp_id); let peer_info = creator_ctx.get_peer(peer_handle); - created_ctx.add_peer(pair.created_handle, sched_ctx, peer_info.id, Some(&peer_info.handle)); + created_ctx.change_port_peer(sched_ctx, pair.created_handle, Some(peer_info.id)); created_component_has_remote_peers = true; } } @@ -687,10 +687,8 @@ impl CompPDL { // potentially remove the peer component. for pair in opened_port_id_pairs.iter() { // Remove peer if appropriate - let creator_port_info = creator_ctx.get_port(pair.creator_handle); let creator_port_index = creator_ctx.get_port_index(pair.creator_handle); - let creator_peer_comp_id = creator_port_info.peer_comp_id; - creator_ctx.remove_peer(sched_ctx, pair.creator_handle, creator_peer_comp_id, false); + creator_ctx.change_port_peer(sched_ctx, pair.creator_handle, None); creator_ctx.remove_port(pair.creator_handle); // Transfer any messages @@ -712,15 +710,17 @@ impl CompPDL { } } - // Handle potential channel between creator and created component let created_port_info = component.ctx.get_port(pair.created_handle); - if created_port_info.peer_comp_id == creator_ctx.id { + // This handles the creation of a channel between the creator + // component and the newly created component. So if the creator + // had a `a -> b` channel, and `b` is moved to the new + // component, then `a` needs to set its peer component. let peer_port_handle = creator_ctx.get_port_handle(created_port_info.peer_port_id); let peer_port_info = creator_ctx.get_port_mut(peer_port_handle); peer_port_info.peer_comp_id = component.ctx.id; peer_port_info.peer_port_id = created_port_info.self_id; - creator_ctx.add_peer(peer_port_handle, sched_ctx, component.ctx.id, None); + creator_ctx.change_port_peer(sched_ctx, peer_port_handle, Some(component.ctx.id)); } }