-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change successor function in basic_block module #1212
Comments
I'm having doubts about the visitor pattern I introduced in #1200 as it doesn't seem versatile. Forcing the use of lamdas makes result handling inconvenient. For example if I attempt to apply it to pub(crate) fn display_block_with_successors(
function: &Function,
block_id: BasicBlockId,
f: &mut Formatter,
) -> Result {
display_block(function, block_id, f)?;
let basic_block = &function.dfg[block_id];
if basic_block.maybe_terminator().is_none() {
// If the terminator is assigned it is not safe to attempt to visit its successors.
return Ok(());
}
let mut ok_or_first_err = Ok(());
basic_block_visitors::visit_block_succs(basic_block, |succ_id| {
match display_block(function, succ_id, f) {
Err(err) => ok_or_first_err = Err(err),
_ => {}
}
});
ok_or_first_err
} Or probably better: let mut successor_ids = vec![];
basic_block_visitors::visit_block_succs(basic_block, |succ_id| successor_ids.push(succ_id));
for succ_id in successor_ids {
display_block_with_successors(function, succ_id, f)?
}
Ok(()) Either is feels bit clumsy. @jfecher would you be in favour of killing visitors? I was merely mimicking cranelift without a great deal of thought. Tangential point: I've also included handling of the terminator's optionality in the above snippet because I think there may be demons down the line. I'd in favour of having a separate factory struct. |
I generally do like having functions for traversing the data since it helps separate the traversal from the "business logic" of whatever operation is actually being done. That being said, they're just a tool so if they're hard to use then we should change them. It seems to me that |
How about? for successor in basic_block_views::successors_iter(&function.dfg[block_id]) {
display_block(function, successor, f)?;
} |
|
Yep, I see what you mean. I've done a PR nonetheless, but feel free to chuck it. |
Duplication removed in 52ce1fd |
Problem
Referencing https://github.com/noir-lang/noir/pull/1211/files#r1175710844
Proposed solution
Once #1200 has been merged, modify that function.
Alternatives considered
No response
Additional context
No response
Submission Checklist
The text was updated successfully, but these errors were encountered: