Introduce the astcompile pass - #649
Merged
Merged
Conversation
using e.g. @astnode("parsed") or @astnode("< redshifting"), etc.
This commit breaks the world, but test_simple[interp] passes.
…ler. TestBasic::test_assignexpr_basic[interp] passes
…ic::test_assignexpr_updates_cell[interp] passes
…read_local_cell[interp] passes
…gn_to_const_globals[interp] passes
…full pass in doppler
|
…s to the new Loc.colorize the astcompile can decide which nodes participate to colorization and which don't
antocuni
marked this pull request as ready for review
August 10, 2026 22:26
Merged
antocuni
added a commit
that referenced
this pull request
Aug 11, 2026
This should have belonged to #649 , but too late and too bad. The hard part is how to write readable tests, because comparing the generated AST is a pain. We ideally want to use the SPy backend to generated "astcompiled source code", but then all the nuances of NameLocalDirect, AssignLocal, etc, disappears. The solution was to introduce a new option for the SPy backend `ast_format="full"`, which annotates some selected nodes with extra info needed for tests. This is now exposed also from the `spy` cli. E.g.: ``` ❯ cat /tmp/x.spy def main() -> None: x = 1 print(x) ``` with the default "human-readable" format, we don't see any difference: ``` ❯ spy astcompile -f spy /tmp/x.spy def main() -> None: x = 1 print(x) ``` But with `--full-ast`, we do! ``` ❯ spy astcompile -f spy /tmp/x.spy --full-ast def main() -> None: AssignLocal(x := 1) ImportRef(print)(LocalDirect(x)) ``
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces a new pass
astcompilein the pipeline.astcompiletakes a "parsed" AST and produce a new AST which is more suited for execution.In particular, it handles:
ast.Namespecialization: depending on the symbol, it becomesast.NameLocalDirect,ast.NameOuterCell, etc.ast.Assignspecialization: similar to above, it becomesast.AssignLocal,ast.AssignOuter, etc.forloop desugaringPreviously, all these transformation were done at runtime by
ASTFrame, and then saved on the ugly dictsASTFrame._specialized_names, etc., so that they could be reused byDopplerFrame.Having a separate pass makes it easier to inspect the result and to add more desugaring when needed.
While we were at it, we also simplified the relationship between
ast.Assignandast.AssignExpr. Now all the logic is done by the variousAssignExprvariants, and the statement versions are just thin wrappers over them. This makes it possible to reduce code duplication and make the whole logic easier.For example, given:
Note that:
stageattribute which keeps track of which lowering we did so farAssignLocalandNameOuterDirectnodesWe can also use the
spybackend, useful for e.g. this: