Skip to content
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

[Error] [lang] Add error when breaking/continuing a static for inside non-static if #5755

Merged
merged 7 commits into from
Aug 31, 2022

Conversation

lin-hitonami
Copy link
Contributor

@lin-hitonami lin-hitonami commented Aug 12, 2022

Related issue = fixes #5729
Added nearest_non_static_if to the loop attribute. The NonStaticIfGuard maintains the nearest_non_static_if of the current loop.

For this kernel:

import taichi as ti

@ti.kernel
def test_static_loop():
    for i in ti.static(range(5)):
        x = 0.1
        if x == 0.0:
            print("consition statement")
            break
        print("after condition")

ti.init(arch=ti.cuda)

test_static_loop()

The error is like:

[Taichi] version 1.1.1, llvm 10.0.0, commit 6f9f5549, linux, python 3.10.4
[Taichi] Starting on arch=cuda
Traceback (most recent call last):
  File "/home/hitonami/test/test.py", line 14, in <module>
    test_static_loop()
  File "/home/hitonami/taichi/python/taichi/lang/kernel_impl.py", line 924, in wrapped
    raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiSyntaxError: 
On line 9 of file "/home/hitonami/test/test.py", in test_static_loop:
            break
            ^^^^^
On line 7 of file "/home/hitonami/test/test.py", in test_static_loop:
        if x == 0.0:
           ^^^^^^^^
You are trying to `break` a static `for` loop, but the `break` statement is inside a non-static `if`. 

@lin-hitonami lin-hitonami marked this pull request as draft August 12, 2022 10:07
@netlify
Copy link

netlify bot commented Aug 12, 2022

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit f9d31d1
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/630db59f4da13f0008517aa5
😎 Deploy Preview https://deploy-preview-5755--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@lin-hitonami lin-hitonami changed the title [lang] Add warning when breaking/continuing a static for inside non-static if [Error] [lang] Add warning when breaking/continuing a static for inside non-static if Aug 12, 2022
@lin-hitonami lin-hitonami changed the title [Error] [lang] Add warning when breaking/continuing a static for inside non-static if [Error] [lang] Add error when breaking/continuing a static for inside non-static if Aug 30, 2022
@lin-hitonami
Copy link
Contributor Author

lin-hitonami commented Aug 30, 2022

I don't think there are any cases anyone should break/continue a static for loop inside non-static if, so I made it an error.
Is this error message OK?

@lin-hitonami lin-hitonami marked this pull request as ready for review August 30, 2022 07:21
Copy link
Contributor

@ailzhang ailzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ailzhang ailzhang merged commit fce6377 into taichi-dev:master Aug 31, 2022
@lin-hitonami lin-hitonami deleted the for_break branch August 31, 2022 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

condition statements in static loop fail silently
2 participants