Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 74deefc

Browse files
committed
make get_entry_exit panic if the entry/exit nodes don't exist
1 parent 32ffe25 commit 74deefc

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/emit/func.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ impl<'c, H: HugrView> EmitFuncContext<'c, H> {
115115
/// Create a new basic block. When `before` is `Some` the block will be
116116
/// created immediately before that block, otherwise at the end of the
117117
/// function.
118-
///
119-
/// TODO I think this will be needed for emitting CFGs.
120118
pub(crate) fn new_basic_block(
121119
&mut self,
122120
name: impl AsRef<str>,

src/emit/ops/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'c, 'd, H: HugrView> CfgEmitter<'c, 'd, H> {
6060
}
6161
})
6262
.collect::<Result<HashMap<_, _>>>()?;
63-
let (entry_node, exit_node) = node.get_entry_exit().unwrap();
63+
let (entry_node, exit_node) = node.get_entry_exit();
6464
Ok(CfgEmitter {
6565
context,
6666
bbs,

src/fat.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,22 @@ impl<'c, OT, H: HugrView + ?Sized> FatNode<'c, OT, H> {
182182
}
183183

184184
impl<'c, H: HugrView> FatNode<'c, CFG, H> {
185-
/// TODO it would be reasonable to remove Option and panic on failure here
186-
pub fn get_entry_exit(
187-
&self,
188-
) -> Option<(FatNode<'c, DataflowBlock, H>, FatNode<'c, ExitBlock, H>)> {
185+
/// Returns the entry and exit nodes of a CFG.
186+
///
187+
/// These are guaranteed to exist the `Hugr` is valid. Panics if they do not
188+
/// exist.
189+
pub fn get_entry_exit(&self) -> (FatNode<'c, DataflowBlock, H>, FatNode<'c, ExitBlock, H>) {
189190
let [i, o] = self
190191
.hugr
191192
.children(self.node)
192193
.take(2)
193194
.collect_vec()
194195
.try_into()
195-
.ok()?;
196-
Some((
197-
FatNode::try_new(self.hugr, i)?,
198-
FatNode::try_new(self.hugr, o)?,
199-
))
196+
.unwrap();
197+
(
198+
FatNode::try_new(self.hugr, i).unwrap(),
199+
FatNode::try_new(self.hugr, o).unwrap(),
200+
)
200201
}
201202
}
202203

0 commit comments

Comments
 (0)