-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
constant expressions evaluator should handle local let-expressions #4708
Comments
I believe I found some limitations in the "const-eval" module. I will create a PR to address them first. |
## Description This PR is necessary for #4708 It fixes some problems with `const_eval`, most importantly: 1 - It differentiates when an eval cannot be used inside const (there is a new error for that), and when expressions/statements just do not produce any value; 2 - It always cleans up `eval_codeblock` (it never shortcircuit with `?`); Another advantage of the explicit error is the exact span of the "offending" expression, which we can use in the future for better error messages. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Anton Trunov <anton.a.trunov@gmail.com>
@anton-trunov, I was unsure if changing the IR generation would be beneficial in this case. So I improved the Even if you think the IR generation is a must, I would merge #4780. Any thoughts? |
## Description Closes #4708. This PR does NOT change the IR generation for expressions. Instead, it implements constant folding for unary and binary operators. The idea is that IR generation will be kept simple and stable, and all optimizations are pushed onto the opt passes. To better test this, this PR also changes some implementation details on IR generation tests: 1 - `filecheck` directives are now collected and tested in groups. This allows a new "::check-ir-optimized::", that can be configured with the passes you want to test, or just fallback to "o1". 2 - `filechecker` explanations are now pretty-printed, and can be printed when `verbose=true`. This allows the test to be checked more easily. ![image](https://github.com/FuelLabs/sway/assets/83425/75d0f628-b271-458d-8c33-7d4d47af789a) ![image](https://github.com/FuelLabs/sway/assets/83425/9591a3d5-b0b4-4623-8a7c-1a34f5f96a99) `breaking` label because of this change: https://github.com/FuelLabs/sway/pull/4780/files#diff-b40fc3999876b0ff447de112b508250c7d0e7993f9023db29ddce8590d9b2286L5 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Anton Trunov <anton.a.trunov@gmail.com>
The optimizer pass solution is done. I will experiment with |
For instance,
currently produces the following IR:
but one would expect no
add
instructions for the script shown above.The text was updated successfully, but these errors were encountered: