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

[Misc] Refactored flattend_values() to avoid potential conflicts in flattened statements #6749

Merged
merged 8 commits into from
Dec 1, 2022

Conversation

jim19930609
Copy link
Contributor

@jim19930609 jim19930609 commented Nov 28, 2022

Issue: #5819

Overriding the flattened statement stmt of an Expression can cause conflicts, for example:

@ti.kernel
def test():
    x = ti.Vector([1, 2, 3, 4])
    tmp = x + x[0] # implicit broadcast

In x + x[0], the x on the lhs serves as rvalue whereas the x in the x[0] serves as a lvalue, so the result of flatten_rvalue() and flatten_lvalue() will override each other.

To avoid such conflicts, this PR refactored the flatten_values() functions:

  1. Flattened statement stmt of an Expression will only get modified by Expression::flatten(), any other overriding will be forbidden.
  2. flatten_rvalue() and flatten_lvalue() now returns the flattened statement as the result. External users such as irpass::lower_ast() will turn to use the returned statement.

@netlify
Copy link

netlify bot commented Nov 28, 2022

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit c3817e1
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/6387518a3cff260008604ef9
😎 Deploy Preview https://deploy-preview-6749--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.

Co-authored-by: Yi Xu <xy_xuyi@foxmail.com>
Copy link
Contributor Author

@jim19930609 jim19930609 left a comment

Choose a reason for hiding this comment

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

Code adjustment

@jim19930609 jim19930609 merged commit ef5655b into taichi-dev:master Dec 1, 2022
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
…lattened statements (taichi-dev#6749)

Issue: taichi-dev#5819

Overriding the flattened statement `stmt` of an `Expression` can cause
conflicts, for example:
```
@ti.kernel
def test():
    x = ti.Vector([1, 2, 3, 4])
    tmp = x + x[0] # implicit broadcast
```

In `x + x[0]`, the `x` on the lhs serves as rvalue whereas the `x` in
the `x[0]` serves as a lvalue, so the result of `flatten_rvalue()` and
`flatten_lvalue()` will override each other.

To avoid such conflicts, this PR refactored the `flatten_values()`
functions:
1. Flattened statement `stmt` of an `Expression` will only get modified
by `Expression::flatten()`, any other overriding will be forbidden.
2. `flatten_rvalue()` and `flatten_lvalue()` now returns the flattened
statement as the result. External users such as `irpass::lower_ast()`
will turn to use the returned statement.

Co-authored-by: Yi Xu <xy_xuyi@foxmail.com>
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.

2 participants