mir(builder/loops): add in_loop()/depth() helpers; clean up Break lowering comment (no behavior change)

This commit is contained in:
Selfhosting Dev
2025-09-17 07:50:15 +09:00
parent ee4224d7d2
commit e47ee65a40
2 changed files with 12 additions and 9 deletions

View File

@ -26,3 +26,13 @@ pub(crate) fn current_header(builder: &super::MirBuilder) -> Option<BasicBlockId
pub(crate) fn current_exit(builder: &super::MirBuilder) -> Option<BasicBlockId> {
builder.loop_exit_stack.last().copied()
}
/// Returns true if the builder is currently inside at least one loop context.
pub(crate) fn in_loop(builder: &super::MirBuilder) -> bool {
!builder.loop_header_stack.is_empty()
}
/// Current loop nesting depth (0 means not in a loop).
pub(crate) fn depth(builder: &super::MirBuilder) -> usize {
builder.loop_header_stack.len()
}