Repository navigation
Sema cluster A: #1344 #1472 #1493 #1494 #1303 #1477 #1503 #1502 #1517 #1565 #1533 #1220 #1478 (13 parser/Sema/MIR fixes) - #1721
Merged
Merged
Conversation
added 14 commits
September 26, 2026 02:46
…ecl registered both silently and E.A took one meaning Fixes #1344
…ontextual Copy); check_bool_condition compared the exact ref type to bool and rejected `if v[i]:` Fixes #1472
… tail; types_compatible is one-sided on Never so check_fn_body_with_sig_at let it reach the MIR validator Fixes #1493
…on another is a missing return (§4.10, D43); infer_unannotated_function_return_type substituted T.default() Fixes #1494
…tin (§18.2); check_method_call_parts matched the builtin by name before user methods Fixes #1303
…tee's type, and the view materializes as its pointee before the builtin widens; check_binary typed `&i64 + 1` at i32 and contextualize narrowed the view to the peer Fixes #1477
…ted missing-return rule skips them; an early `return 1` with a fall-off is the exit-status idiom (examples/c-interop) Refs #1494
…10.3); optional_chain_result_type used the struct-only field lookup and lower_optional_chain_field projected a struct field by symbol Fixes #1503
…d widens it (§4.4a, §4); lower_cast emitted one enum→float RK_CAST the validator rejected after Sema accepted it Fixes #1502
…d_access projected a `len` field place that no slice layout names, and the read yielded 0 Fixes #1517
…d a spec'd hole still needs a default display (§15.4.6, §15.4.8); FMT_BUF_WRITE_FMT treated every non-numeric value as a str header and Sema skipped the display check when a spec was present Fixes #1565
…coverage (§9.7); exh_class treated it as open so every slice-pattern match demanded a `_` arm, and the witness now names the uncovered length Fixes #1533
…ng is spelled `as`); types_compatible had an int←float arm and builtin_arg_type_compatible accepted it through the operator-promotion arm, so codegen failed with no location Fixes #1220
…ad of building one copy; the fill desugar read only an integer literal and fell back to fill_count = 1, so a typed binding read uninitialized tail elements Refs #1478
Contributor
Author
|
Battery on 9f330e5: build and :fixpoint green; :test red on 2/1318 behavior tests: behav_unannotated_value_return_fallthrough_default.w pins the pre-#1494 defaulting (non-conforming per §4.10/§9.1, becomes an err_ test) and behav_zip_reads_info_zip.w:145 ( |
added 2 commits
September 26, 2026 05:18
Contributor
Author
|
Seed-driven battery green on 1c07e10 (host darwin-aarch64, seed per seed.lock): |
ehartford
marked this pull request as ready for review
September 26, 2026 11:25
ehartford
pushed a commit
that referenced
this pull request
Sep 28, 2026
…— a `let` is a runtime value, a local `const` is a const §4.3a: "Length N must be a compile-time constant (integer literal or `const`)". §9.1b: a const expression is integer literals, arithmetic, unary negate, `not` and references to other `const`s; "`let` bindings are runtime values (even if initialized from a constant)". #1478's array_fill_count asked the comptime evaluator for the count's value, and the evaluator reads an immutable module `let` (eval_ident's find_module_let_decl), so `let N: i64 = 4; [7; N]` compiled — the program err_1478_array_fill_const_count (from #1721) pins as refused. The count must now be a const expression (expr_is_const_expr: literals, grouping, casts, unary and binary operators over those, and names of `const`s) before it is evaluated; otherwise "the count is not a compile-time constant … a `let` is a runtime value (§9.1b)". The test keeps its program and now expects that message (it pinned the interim "needs an integer literal count" refusal "until the fill is evaluated by Sema"). A local `const` was not a const to either check: the parser's parse_const_binding did not mark its binding (only a module `const` was), and the evaluator could not see it. The parser marks it (mark_const_decl); the evaluator reads a live local `const`'s initializer (Sema drops a name's decl when its scope ends, and a local `let` is never read). Evidence: the fix-lang battery's native compile-error tests, and `with-stage1 test` on err_1478_array_fill_const_count before this commit: failed (the program built and printed 4). After: refused with the §9.1b message; `const M = 5; [1; M]` and `[2; (N + M) * 2 - 5]` build 5 and 13 elements (behav_1478_array_fill_const_count); a function-local `let` count is still refused. Refs #1478
ehartford
pushed a commit
that referenced
this pull request
Sep 28, 2026
…— a `let` is a runtime value, a local `const` is a const §4.3a: "Length N must be a compile-time constant (integer literal or `const`)". §9.1b: a const expression is integer literals, arithmetic, unary negate, `not` and references to other `const`s; "`let` bindings are runtime values (even if initialized from a constant)". #1478's array_fill_count asked the comptime evaluator for the count's value, and the evaluator reads an immutable module `let` (eval_ident's find_module_let_decl), so `let N: i64 = 4; [7; N]` compiled — the program err_1478_array_fill_const_count (from #1721) pins as refused. The count must now be a const expression (expr_is_const_expr: literals, grouping, casts, unary and binary operators over those, and names of `const`s) before it is evaluated; otherwise "the count is not a compile-time constant … a `let` is a runtime value (§9.1b)". The test keeps its program and now expects that message (it pinned the interim "needs an integer literal count" refusal "until the fill is evaluated by Sema"). A local `const` was not a const to either check: the parser's parse_const_binding did not mark its binding (only a module `const` was), and the evaluator could not see it. The parser marks it (mark_const_decl); the evaluator reads a live local `const`'s initializer (Sema drops a name's decl when its scope ends, and a local `let` is never read). Evidence: the fix-lang battery's native compile-error tests, and `with-stage1 test` on err_1478_array_fill_const_count before this commit: failed (the program built and printed 4). After: refused with the §9.1b message; `const M = 5; [1; M]` and `[2; (N + M) * 2 - 5]` build 5 and 13 elements (behav_1478_array_fill_const_count); a function-local `let` count is still refused. Refs #1478
ehartford
pushed a commit
that referenced
this pull request
Sep 28, 2026
…— a `let` is a runtime value, a local `const` is a const §4.3a: "Length N must be a compile-time constant (integer literal or `const`)". §9.1b: a const expression is integer literals, arithmetic, unary negate, `not` and references to other `const`s; "`let` bindings are runtime values (even if initialized from a constant)". #1478's array_fill_count asked the comptime evaluator for the count's value, and the evaluator reads an immutable module `let` (eval_ident's find_module_let_decl), so `let N: i64 = 4; [7; N]` compiled — the program err_1478_array_fill_const_count (from #1721) pins as refused. The count must now be a const expression (expr_is_const_expr: literals, grouping, casts, unary and binary operators over those, and names of `const`s) before it is evaluated; otherwise "the count is not a compile-time constant … a `let` is a runtime value (§9.1b)". The test keeps its program and now expects that message (it pinned the interim "needs an integer literal count" refusal "until the fill is evaluated by Sema"). A local `const` was not a const to either check: the parser's parse_const_binding did not mark its binding (only a module `const` was), and the evaluator could not see it. The parser marks it (mark_const_decl); the evaluator reads a live local `const`'s initializer (Sema drops a name's decl when its scope ends, and a local `let` is never read). Evidence: the fix-lang battery's native compile-error tests, and `with-stage1 test` on err_1478_array_fill_const_count before this commit: failed (the program built and printed 4). After: refused with the §9.1b message; `const M = 5; [1; M]` and `[2; (N + M) * 2 - 5]` build 5 and 13 elements (behav_1478_array_fill_const_count); a function-local `let` count is still refused. Refs #1478
ehartford
added a commit
that referenced
this pull request
Sep 28, 2026
… refs, const array fills, str range views (#1786 #1781 #1782 #1478 #1587) (#1812) * MirLower/Sema: a discarded call result is a statement temp, and an entry point's tail is a statement — both dropped, never leaked §2.5.1 / §9.1: a statement's value is discarded and dropped. Two owners were missing one: 1. MirLower.lower_intrinsic_call (and lower_intrinsic_call_with_receiver_ operand, the dyn-dispatch path in lower_method_call) never registered its result temp as a statement temp; lower_call does (register_stmt_temp). A discarded `v.pop()` (VEC_POP) therefore had no drop: the popped `Some(payload)` leaked. Now every call result goes through call_result_operand: consumed by a binding or an argument it is cancelled, discarded it is dropped at the statement's end. 2. Sema.discard_body_tail discarded only an assignment tail. §9.1: `main`, `@[entry]` and `test_*` do not infer; their tail is statement position. A tail `mk()` in `main` was lowered as the body's value and moved into the unit return slot, never dropped. The verdict now covers any tail of an entry point (body_tail_is_statement), and a discarded statement tail keeps its own type: overwriting it with Unit sized an intrinsic's result temp as Unit — an undropped unit slot and a SIGTRAP for a tail `v.pop()`. Evidence: `with run --debug-alloc` on the issue's program reported `LEAK addr=... size=16 origin=unknown, leak count=1`; --dump-mir showed `call sym(pop)(copy _1) -> [return: _11]` with no `drop(_11)` while the free-call result `_7` had `drop(_7) @ scope-exit`, and --dump-drop-plan listed no site for _11. A nine-cell matrix (free fn / method / generic method / intrinsic × statement / tail / `let _`) leaks 0 after; before, every discarded result in tail position and every intrinsic leaked. Fixes #1786 * Parser: a block's statements share its column; a line indented to no enclosing block's level is an error, never the outer block's next statement §29.13 Form 2: the body is the indented block; it ends when indentation returns to or below the introducing construct's level. parse_indented_block took any line at a column >= its own as its next statement, so a dedent to a level no enclosing block has (an `if` body at 12, its next line at 8, `main`'s body at 4) ended the `if` body and silently joined `main`'s body: the line ran with the `if` false, reading a binding from the arm that never ran (base stage1 printed `inner 1`; with one-statement-body scoping it became `undefined variable`, still with no word about the layout). The same check names a line indented deeper than the statement before it with no ':' opening a body. Evidence: `with check` on the issue's program reported only `undefined variable` at the print; parse_indented_block's loop had `if next_col < block_col: break` and no case for `next_col > block_col`. Now: "unexpected indentation: this line is indented to column 8, which is no enclosing block's indentation (the block here starts at column 4)" at the line, with a §29.13 help. The #1391 indentation tests are unchanged. Fixes #1781 * MirLower: a cast through a reference reads what it names, through a distinct wrapper too — `r as str` on `r: &Name` reads the string, not the pointer §3.7 / §4.5: a distinct type is a zero-cost wrapper, and a cast through a reference reads what the reference names. lower_cast read through a `&T` source only when the target was a slice and the pointee was itself a str, array or slice (`r as []u8` on `r: &str`, #1719). `r as str` with `r: &Name` (`Name = distinct str`) took the other path: the reference VALUE, a pointer, was cast to the string header and `print` showed a garbage byte. The read-through now resolves both the pointee and the target through their distinct wrappers (unwrap_builtin_arg_distinct) and applies to str, array and slice targets. Evidence: --dump-mir on the issue's program lowered the cast as `_6 = cast(copy _1 as ty16)` with `_1: &Name` (a pointer local), no deref projection; the main tree's stage1 prints `\n0\n\n` for the new test, the fixed one prints `abc / 3 / xyz`. The test uses literals on purpose: the ownership of a non-Copy value cast into or out of a distinct wrapper is a separate, pre-existing defect (the allocator reports the same DOUBLE FREE on the base stage1 for an owned `n as str`; a `Name` drop is a no-op and `s as Name` leaves the buffer with `s`), filed separately. Fixes #1782 * Parser/Sema/MirLower: `[value; N]` with a `const` count builds N copies — the count is a node Sema evaluates, never a silent one-copy fallback §4.3a: "`[value; N]`: array of N copies of value. Length N must be a compile-time constant (integer literal or `const`)." The parser desugared the fill at parse time and could read only an integer literal; any other count fell back to ONE copy with no diagnostic (later: a loud refusal). Now a non-literal count stays on the literal as its d2 with the value held once; Sema evaluates it (array_fill_count, comptime_try_eval_expr) and records it (array_fill_counts) for MirLower (array and Vec targets) and the comptime evaluator (a top-level `const A = [v; N]` evaluates the count itself, its literal being checked after it). A runtime count is refused by name. The AST cost the issue notes stays for literal counts (#1358's dump shape is kept); a const count is now one node. Also: an annotated `[K]T` binding required no agreement with the literal's length, so `let b: [4]i32 = [7; N]` (one copy) compiled and read uninitialized tail elements (`4 0`); a length mismatch is now an error. Evidence: the issue's program printed `1` and `4 0` on the base; after, `4` and `4 7`. Tests: behav_1478_array_fill_const_count (const, const expression, `2 + 2`, `N * 2`, Vec targets, a comptime const array), err_1478_array_fill_non_const_count, err_1478_array_len_mismatch. Fixes #1478 * Sema/MirLower/Codegen: a str range `s[a..b]` is a `&str` view of its bytes (D71 §4.8a); out of range or inside a UTF-8 character panics D71 / §4.8a: "A range index on a `str` or `&str` — `s[a..b]`, `s[a..]`, `s[..b]`, `s[..]` — is a `&str` view of the bytes from a to b, with the origin and ephemerality of any view. Offsets are byte offsets. An offset past the end, or one that falls inside a UTF-8 character, panics." - Sema.check_slice types a str range `&str` with the base's origins (the invalidation rules follow: `s = …` while the view lives is refused; an owned demand `let t: str = s[1..]` materializes under D22). It used to refuse the spelling by name (before that: a valueless expression that failed generic inference and tripped "invalid MIR before codegen"). - MirLower.lower_slice_expr: a `&str` points at a string header, so the range's {ptr, len} is built into a hidden str local of the frame that owns nothing, and the view is a reference to it. A range through a reference slices what it names (§3.7): the base is dereferenced — `a[1..]` on `a: &[4]i32` failed codegen ("slice base has no bounds metadata"), and `r[1..]` on `r: &str` read `len(_2.*)` off the pointer local's type as 0 (RK_LEN now uses the projected place type). - Codegen: a str range is checked in every build — "string slice out of range", "string slice inside a UTF-8 character" (a `10xxxxxx` byte at the offset) — instead of the debug-only slice check. - Not the ruling yet: returning a str range view. Its header lives in the callee's frame, so the view carries the sentinel origin syms.str_range_view and a return of it (directly or through a binding) is refused by name: "a string slice cannot be returned yet (#1587)". Making that valid needs `&str` to carry its own {ptr, len} — the `&str → {ptr,len}` campaign — which touches every `&str` producer and consumer (FnAbi, c_import marshalling, element views, pattern bindings, the runtime's `str_data`), beyond this fix. Evidence: --dump-mir now `_2 = slice(_1, 0, 5); _3 = ref(shared, _2)` with `_2: str` undropped; --validate-all ok; --debug-alloc leak count=0 on the test; the test fails before ("a range of a str has no view type yet"). err_str_range_no_view_type pinned the old refusal and is removed. Fixes #1587 * Parser: only a statement that begins its line has an indentation — the one after `a; b` starts mid-line (#1781 follow-up) The #1781 check (a line indented to no enclosing block's level is an error) measured the column of every next statement, and skip_separators steps over `;` as well as newlines, so the second statement of `sum = sum + i; i = i + 1` sat at column 23 of an 8-column block and was refused (behav_semicolons.w, red on the #1813 stack battery). The check now applies when the token begins its line (column == line_indent_of). Verified on stage1: behav_semicolons prints ok; err_1781_dedent_matches_no_block and err_1781_over_indented_statement still report "unexpected indentation". * test/parser: four AST tests set their exit code with exit_code(), because main's tail is statement position (#1786, functions.md) Spec (docs/spec/functions.md): "main, @[entry] functions and test_* functions do not infer: their return contract is fixed and their tail is statement position." #1786 made the compiler conform, so ast_basic_decls, ast_char_literals, ast_expr_forms and ast_labeled_control — which read `expect-exit: N` from a bare tail value — exited 0 (parser-tests red on the #1813 stack battery). They were relying on the non-conforming tail; the observation now goes through std.process exit_code. Verified on stage1: exit codes 12, 107, 11, 5. * Sema: a `[v; N]` count is a compile-time constant expression (§9.1b) — a `let` is a runtime value, a local `const` is a const §4.3a: "Length N must be a compile-time constant (integer literal or `const`)". §9.1b: a const expression is integer literals, arithmetic, unary negate, `not` and references to other `const`s; "`let` bindings are runtime values (even if initialized from a constant)". #1478's array_fill_count asked the comptime evaluator for the count's value, and the evaluator reads an immutable module `let` (eval_ident's find_module_let_decl), so `let N: i64 = 4; [7; N]` compiled — the program err_1478_array_fill_const_count (from #1721) pins as refused. The count must now be a const expression (expr_is_const_expr: literals, grouping, casts, unary and binary operators over those, and names of `const`s) before it is evaluated; otherwise "the count is not a compile-time constant … a `let` is a runtime value (§9.1b)". The test keeps its program and now expects that message (it pinned the interim "needs an integer literal count" refusal "until the fill is evaluated by Sema"). A local `const` was not a const to either check: the parser's parse_const_binding did not mark its binding (only a module `const` was), and the evaluator could not see it. The parser marks it (mark_const_decl); the evaluator reads a live local `const`'s initializer (Sema drops a name's decl when its scope ends, and a local `let` is never read). Evidence: the fix-lang battery's native compile-error tests, and `with-stage1 test` on err_1478_array_fill_const_count before this commit: failed (the program built and printed 4). After: refused with the §9.1b message; `const M = 5; [1; M]` and `[2; (N + M) * 2 - 5]` build 5 and 13 elements (behav_1478_array_fill_const_count); a function-local `let` count is still refused. Refs #1478 --------- Co-authored-by: Eric Hartford <[email protected]>
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.
Thirteen separate commits, one per issue, each with a pinning test (
test/behavior/behav_*.wortest/compile_errors/err_*.w). Verified on a stage1 built from this branch (:dev, dev rc=0);examples/andbuild/release_uat_fixtures/allcheckgreen on it. No battery run yet.Root causes:
SemaDecl.collect_type_declregistered a repeated variant name twice, silently; nowduplicate variant \A` in `E`(enum, disc enum anderror E = | A | A`).if v[i]:over a Vec[bool] element is rejected: 'if condition must be bool' (D22 contextual Copy not applied to conditions) #1472check_bool_conditioncompared the exact&boolview type tobool; a condition is an owned-value demand, so it now records the D22 contextual-Copy adjustment (if v[i]:,if d.flags[i]:,while).types_compatibleis one-sided on Never, sofn f -> Never: 5passed the tail check and failed the MIR validator; Sema now reportsreturn type mismatch: a \-> Never` function must not produce a value`.infer_unannotated_function_return_typedefaulted a value-return-plus-fall-off body toT.default(); it ismissing return(§4.10, D43) except formain/@[entry]/test_*, which do not infer (§4.10;if failed: return 1infn main:stays green — examples/c-interop uses it).spawnis reported at the call site ("only available inside scope") instead of at the declaration #1303check_method_call_partsmatched thespawnscope builtin by name before the receiver's own methods; the builtin now applies only when no user method resolves (§18.2).check_binarytyped an unsuffixed literal beside a&i64view as i32 (numeric_operand_typedoes not see through a view), andcontextualize_builtin_binary_operandsthen materialized the view to the peer's i32 (a silent narrowing). The literal now takes the pointee's type and a numeric Copy view materializes as its own pointee before the builtin widens. Also fixesp * 2,p > 1,print(p + 1).optional_chain_result_typeused the struct-onlystruct_field_type, andlower_optional_chain_fieldprojected by field symbol; both now use the tuple-aware lookup / tuple-index projection, soo?.1 : Option[i32]andf"{o?.1}"lower. (A separate pre-existing bug found here: a secondo?.fieldon the same Option reads a reset value — filed as Optional chain resets its receiver: a secondo?.fieldon the same Option reads Some(<empty>) (struct and tuple payloads) #1710.)lower_castemitted a single enum→floatRK_CASTthe validator rejects; the cast is now the discriminant extraction (repr int) followed by the int→float widening (§4.4a + §4).lower_field_accessprojected alenfield on a slice, which no layout names, soarr.lenread 0; it now emitsRK_LEN(copying the view out first, assequence_len_rvalue's callers do). Spec spellsdata.lenon a slice (§16).FMT_BUF_WRITE_FMTtreated every non-numeric value as a str header (bool printed1, enum garbage); a spec'd bool/enum hole is now formatted to its display text and padded as a str. Sema also runs the §15.4.8 display check on a spec'd hole without?, so{point:>8}is rejected like{point}.exh_classclassified a dynamic slice /Veccolumn as Open; aSliceclass decides it by length coverage (exact pattern = one length, rest pattern = every length from its fixed count up), with the uncovered length as the witness (\[_, _]` is not covered`).types_compatiblehad an int←float arm, andbuiltin_arg_type_compatiblealso accepted f64→i32 through its operator-promotion arm (arithmetic_result_type(i32, f64) = f64); both closed, so the call site reportswrong argument type … expects i32instead of codegen's location-less failure.src/needed no sweep.fill_count = 1; a non-literal count is now a loud parse error naming the fix. Aconstcount still needs the fill to become a node Sema evaluates (the issue's proposed design; also removes the 16M-extras cost) — left open.Skipped: #1508 (closure
-> Tannotation dropped): the spec has no text on whether closures may declare a return type, so whether it becomes a checked annotation or a parse error is a ruling.Filed during the work: #1710 (optional chain resets its receiver).