-
-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reimplement AST folding (#3669)
this commit reimplements AST folding. fundamentally, it changes AST folding from a mutating pass to be an annotation pass. this brings several benefits: - typechecking is easier, because folding does not have to reason at all about types. type checking happens on both the folded and unfolded nodes, so intermediate values are type-checked. - correctness in general is easier, because the AST is not mutated. there is also some incidental performance benefit, although that is not necessarily the focus here. - the vyper frontend is now nearly mutation-free. only the getter AST expansion pass remains. note that we cannot push folding past the typechecking stage entirely, because some type checking operations depend on having folded values (e.g., `range()` expressions, or type expressions with integer parameters). the approach taken in this commit is to change constant folding to be annotating, rather than mutating. this way, type-checking can operate on the original AST (and check for the folded values where needed). intermediate values are also type-checked, so expressions like `x: uint128 = 2**128 + 1 - 1` are caught by the typechecker. summary of changes: - `evaluate()` is renamed to `_try_fold()`. a new utility function called `get_folded_value()` caches folded values and is threaded through the codebase. - `pre_typecheck` is added, which extracts `constant` variables and runs `get_folded_value()` on all nodes. - a new `Modifiability` enum replaces the old (confusing) `is_constant` and `is_immutable` attributes on ExprInfo. - `ExprInfo.is_transient` is removed, and handled by adding `TRANSIENT` to the `DataLocation` enum. - the old `check_literal` and `check_kwargable` utility functions are replaced with a more general (and more correct) `check_modifiability` function - several utility functions (ex. `_validate_numeric_bounds()`) related to ad-hoc type-checking (which would happen during constant folding) are removed. - `CompilerData.vyper_module_folded` is renamed to `annotated_vyper_module` - the AST output options are now `ast` and `annotated_ast`. - `None` literals are now banned in AST validation instead of during analysis. --------- Co-authored-by: Charles Cooper <[email protected]>
- Loading branch information
1 parent
87db3c1
commit 56c4c9d
Showing
81 changed files
with
1,464 additions
and
1,230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.