Repository navigation
Comptime: a let annotation binds a collection constructor's instance (#2220 step 1) - #2259
Merged
Merged
Conversation
added 2 commits
October 7, 2026 11:46
…tructor's instance (#2220 step 1) Top-level folding runs before Sema, so typed_expr_types is empty for the nodes being folded and `Vec.new()` under `var v: Vec[i32] = Vec.new()` saw only the generic base `Vec`; eval_static_collection_new refused it with "requires a concrete generic type", in a comptime block and through any function called under comptime. The annotation was in the AST and never read. The evaluator now carries a demand stack (expected_types, Law 2's demand in the evaluator): eval_let_binding pushes the binding's annotation type around its initializer, and the static `new` path takes the demanded generic instance when the receiver gives only the base and the bases agree (Vec, HashMap). `v.push`, indexing, `len` and `for x in v` then run on the concrete instance. HashMap `new`/`insert` bind the same way; map iteration at comptime is a separate evaluator gap, noted on the issue. WITH_TRACE_COMPTIME=1 prints at each static constructor `[ct] static_new node=… recv='Vec' result='Vec[i32]' from=sema|demand|receiver`, so this class is one run; the route is in deep-debugging-tools.md. The refusal, when no demand exists, now says why and what to write. Fixture: test/behavior/behav_2220_comptime_vec_by_demand.w (through a call, len through a call, and a comptime block; fails on the installed compiler with the old refusal). Comptime behavior set: 42 files ok on stage1.
…step 1, second half)
eval_for refused a map ("comptime for requires an array, tuple, vec, or
range") and bound a tuple pattern as if it were a symbol. A map value's
entries sit in extra_values as key/value pairs, so each entry is a
(key, value) tuple over its pair (no copy), and a binding the parser
marked as a pattern (has_pattern_binding) goes through match_pattern.
D44's map traversal and tuple destructuring now hold at comptime.
Fixture: test/behavior/behav_2220_comptime_map_iteration.w (a map built
and summed in a function called under comptime; a Vec of tuples
destructured); fails on the installed compiler. Comptime behavior set:
41 files ok on stage1.
Contributor
Author
|
Battery GREEN on 409ae30 (tools/battery.w: gate 62s, uat 27s, battery-checks 782s; status.txt has no RED). |
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.
See the commit. The evaluator gains a demand stack; a let annotation is the demand; Vec.new()/HashMap.new() under an annotation evaluate through calls and in blocks. Trace line for the class; route in the tools doc. Gate and battery to follow.