Repository navigation
Ownership pass, fused Enum pipelines, std method types, and a restructured lowering - #20
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.
Lowering behaviour, shared helpers, and Builder-built Rust
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.
The lowering restructure discussed after rc.17. Behavior changes only where generated Rust gets more precise; Figler's generated crate is byte-identical except one
collect::<Vec<_>>()that now namesVec<Occurrence>.Ownership (
RustQ.Meta.Ownership). A backward liveness pass annotates every variable occurrence with what is still in use after it, following Elixir's scoping: sequence and argument order, alternative branches (case,if,cond,with), closures and comprehension bodies as repeated regions (what they capture stays live; their own variables follow the body), rebinding ending a value, and values built from another keeping it live while they may borrow (by type). Lowering asks one question, "is this the last use?", replacing the per-statement analysis, theotherslists threaded throughEnum/Map/MapSet, and the in-place update list inast.ex; parametermutnow comes from the lowered Rust. Fixes the sibling gap:{Map.put(scores, …), scores}clones.Fused pipelines. An
Enumcall over anotherEnumstage (map,filter,reject,flat_map,with_index,take_while,drop_while,zip_with,slice,take,drop,reverse,chunk_every) continues its iterator instead of collecting:.map(f).find(p),.filter(p).count().Std method types.
mix rustq.stdderives 179 return types from std's source for methods onstr,String,char,Vec, slices,HashMap,HashSet, andOptionwhose results don't depend on the receiver's type parameters;Typinguses them, soname.len()isusizeand predicates get|&len|.Desugaring (
RustQ.Meta.Desugar).Map.new,MapSet.new,Enum.intointo an empty collection,group_by,uniq, andwith_indexgenerators are rewritten into other Rusty-Elixir before ownership and lowering, leaving__rustq_items__/__rustq_owned__where lowering must decide by type or ownership. Lowering accepts multi-expression blocks as expressions, andTypingtypes comprehensions.Split
lower.ex(4,536 → 2,907 lines) along call-graph seams intoLower.Pattern,Lower.Comprehension,Lower.Paths, andLower.Mutability, which call back through a few documentedLowerfunctions.Checked:
mix ci(885 tests, every fixture cargo-checked); Figlermix ciandcargo clippy -D warningson this branch.