[Lang] Support break in native for statement #8352
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: fix #8351
Brief Summary
🤖 Generated by Copilot at f484174
This pull request adds support for the break statement in for loops in Taichi. It modifies the IR, the LLVM code generator, and the AST lowering transform to handle the break statement correctly. It also adds a test case to
tests/python/test_for_break.py
to verify the functionality.Walkthrough
🤖 Generated by Copilot at f484174
WhileControlStmt
with a constant true condition and a mask (link)is_for_loop
to theWhileControlStmt
constructor to indicate whether it is a break statement in a for loop (link)WhileControlStmt
withis_for_loop
set to true by jumping to the after loop block of the current for loop (link, link, link)current_for_after_loop
to theTaskCodeGenLLVM
class to store the pointer to the after loop block of the current for loop (link)current_for_after_loop
pointer to null when initializing a new offloaded task to avoid using a stale pointer (link)test_for_break.py
to check the break statement in a for loop with a range iterator (link)