Repository navigation
Lowering behaviour, shared helpers, and Builder-built Rust - #21
Merged
Merged
Conversation
Lowering wrote Rust nodes as struct literals and kept five copies of a method-call constructor. It now builds them with the Builder the Rustler code generation already uses, and Builder.expr/1 accepts every node in the AST registry instead of a hand-kept list.
Each Elixir module's lowering implements RustQ.Meta.Lower.Stdlib.Lowering. Using it imports the helpers they share (lowered/2, type_of/2, closure/3, in_use?/2, and the rest), which call Lower and Typing directly instead of through a context of closures. Stdlib dispatches a call to the module named after its Elixir module when that module implements the behaviour, in place of a clause per module for lowering and another for typing.
Path calls, unary and binary operations, closures, tuples, Some/Ok/Err, matches, assignments, and named types now use Builder constructors too.
Merged
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.
Follow-up to #20, stacked on
ownership-pass.RustQ.Meta.Lower.Stdlib.Loweringbehaviour. Each Elixir module's lowering (Lower.Kernel,Enum,List,Map,MapSet,String,Tuple,Range) declareslower/2andsynth/2as callbacks.useimports the helpers they share:lowered/2,3,type_of/2,closure/3,4,operand/2,capture/2,in_use?/2,nonnegative_count/2and the rest. These callLowerandTypingdirectly; before, the lowering context was a struct of eleven closures.Stdlibsends a call to the module named after its Elixir module, but only when that Elixir module belongs to Elixir and the lowering implements the behaviour, so a user alias such asCollectionis never looked up. This replaces 18 dispatch clauses. Each answer is cached in:persistent_term, because an uncached lookup costs about 20 µs.Kernel's../inhand off toRangeinsideLower.Kernel.RustQ.Rust.AST.Builderthroughout lowering. Struct literals and five copies of a method-call constructor are nowA.method,A.path,A.ref,A.block_expr,A.closureand the other Builder constructors, so chains read as pipes.Builder.expr/1accepts every node in the AST registry instead of a hand-kept list.Lowered output is unchanged: Figler's 1.7 MB
generated.rsis byte-identical before and after.mix cipasses with 885 tests.