Repository navigation
Seven compiler fixes: literals at distinct demands (D153), element-place slices, variadic str, default-argument scope, comprehension iterables, resets after the move, Drop impl bounds (D154) - #2580
Merged
Conversation
added 11 commits
October 23, 2026 06:44
…istinct type (D153, #2567) `fn none() -> Id: 0` was refused ("return type mismatch"), and so were `let x: Id = 0`, `S { a: 5 }` and `f(3)` at `x: Id`, while `x != 0` typed its literal by the peer. The literal's context (untyped_literal_context_type) admitted only a numeric type; it now admits a distinct type whose representation is a number (Sema.distinct_over_numeric), the literal takes that type, and the fit check (numeric_literal_expected_type) and an untyped constant's fold (check_untyped_const_use) run at the underlying width. A float literal at a distinct float is the same (float_literal_expected_type). Codegen's exact-constant lowering lowers at the representation (exact_int_const_llvm; §4.5): the MIR constant carries Sema's type, the distinct one. §4.5 gains the sentence; D153 records the brief (delegated, D98). Fixtures: behav_2567 (return, binding, parameter, field, negation, float, constant), err_2567 (300 at `distinct i8` refused at the width).
… carries (#2578) `parts[0][..n]`, `arr[0][..2]`, `v[0][1..]`, `xs[0].rest()`, `xs[0].first()` and `for x in xs[0]` were invalid MIR ("slice base does not resolve to a concrete place type"): the lowering read "through a reference" whenever Sema's type of the base expression was a reference, and an element place is typed as a view (D27) while its MIR place already names the element, so a `str` place was dereferenced. The place's own type decides (MirLower.place_holds_reference, sequence_place_through_reference): a place holding a `&[T]` or `&T` is read through, an element place is read as it is. lower_slice_expr, lower_seq_method's three receivers and lower_sequence_place read it. Fixture behav_2578 covers the six shapes.
…2574) `printf(c"%s|%d".ptr, "compress", 7)` printed `compress|8`: a variadic slot has no parameter type, the fat `str` value was passed as is, and C read its length word as the next argument. record_c_promoted_args gives a `str` (or a view of one) in a slot without a parameter type the promoted type `*const c_char`, the type a `const char *` parameter would lend it across (§16.3c), and codegen's existing C-string lending passes the NUL-terminated pointer. Fixture behav_2574.
`use std.builtins.print_bool` beside the program's own `fn src()` failed inside embedded std: `panic(msg, loc: &str = src())`'s default was checked with the caller's module-level names in scope, so the program's `src` captured the builtin, and the checker reported a bogus argument error at the declaration's span. check_call_argument_expr copies the caller's module scope into a default's check only when the declaration is in the caller's module; and a runtime intrinsic's name (`src`, `embed_file`) that another module's declaration took stays the intrinsic where that declaration is not visible, instead of "symbol 'src' is not visible from this module". Fixture behav_2568.
…a literal there is typed by the binding's uses (#2569) `let m: BTreeMap[i32, i32] = [k: k * k for k in [4, 2, 3]]` was refused ("sequence literal cannot target a map"): the binding's map demand reached the clause's iterable literal, which is a sequence. The demand is the comprehension's (check_comprehension_clause_iterable checks the iterable in value context), and a list literal of untyped numbers there is typed by the clause binding's uses as a `for` loop's is (D128): the clause binding is registered against the literal (int_local_for_decls), a demand on the binding lands on the literal (literal_binding_lets_in_depth), and the body's second check types the literal at the decision. check_for's literal detection moves into untyped_list_literal_iterable, shared. Fixture behav_2569 (BTreeMap, BTreeSet and HashMap targets; the list case kept).
A cancellation unwind between a call's argument evaluations reset the
earlier argument temporaries, whose move into the call had not happened on
that path ("reset of _4 on a path where it was never moved", the ownership
audit): consume_moved_operand recorded the pending reset when the operand
was built, and every mid-statement exit (the cancel unwind, a `?`, a
`return` among a call's arguments or an aggregate's fields) flushed it. The
MIR body now records the operands a pushed statement or a set call
terminator reads (MirBody.emitted_operands), the pending reset carries its
move operand, and a flush skips a reset whose operand has not been emitted:
the local still owns its value, so a statement temporary whose drop the
move cancelled is dropped there and a local keeps its guarded scope drop.
Fixture behav_2570 runs the program and the audit.
A `Drop` impl demanding a bound the type's declaration does not (`type Holder[T]` with `impl[T: Clone] Drop for Holder[T]`) made the destructor conditional: an instantiation outside the bound ran no `drop` and leaked by silence (std's `BTreeMap` leaked every entry until its impl was made unbounded, which is the right form for a type declaring no bounds). collect_impl_decl refuses it (drop_impl_bounds_exceed_type): a destructor runs for every instantiation, so an impl's bounds are the type's own; an impl restating the type's bounds (`type Holder[T: Clone]`) is its destructor as an unbounded one is, and drop glue already runs it. §2.4 says so; D154 records the brief (delegated, D98). Fixtures behav_2571 (the bounded impl runs) and err_2571 (the stricter bound is refused).
…en-intrinsic rule alone fixes #2568
…ult is stated unwritten (#2570) The first cut tracked emitted operands by id and blanked a may-cancel call's result before the call so the unwind edge could drop it guarded: `drop(r)` consumes through a Drop statement on the place, a cast relabels through a `copy` of the consumed local, a consume may be recorded after its statement, and the guarded drop ran destructors over unwritten slots (da_916, da_1985, spec_ss14_11). Now a flush asks the body: since the statement frame opened, a statement reads or drops the entry's local, or a call terminator set on the frame's block or a later one passes it; the drops an unwind emitted for a not-yet-moved local are excluded. On the cancel edge nothing runs: MirLower states that the call's result local is unwritten at that return (MirBody.note_unwritten_at_return), and the ownership validator's leak rule reads the fact.
This was referenced Oct 23, 2026
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.
Seven compiler fixes, one battery. Each is its own commit with its fixture.
fn none() -> CiStmtId: 0is refused ("return type mismatch"), so the tree casts0 as CiStmtId690 times #2567 (D153, delegated): an unsuffixed numeric literal where a distinct type over a number is demanded takes the distinct type (fn none() -> Id: 0,let x: Id = 0,S { a: 5 },f(3),let m: Meters = 2.5), checked at the underlying width; codegen lowers the constant at the representation. §4.5 gains the sentence. 6900 as CiStmtIdcasts insrc/CImport.wcan now go (the sweep is a follow-up).parts[0][..n]) — "slice base does not resolve to a concrete place type" #2578: an element place (parts[0],arr[0],sl[0],v[0]) is read as itself for a slice,rest(),first()and afor: the lowering decided "through a reference" from Sema's view type of the expression instead of the place's own type, and dereferenced astrplace (an ICE).strpassed in a variadic C position is read as two words #2574: astrin a variadic C slot is lent as its NUL-terminated pointer, as a*const c_charparameter lends it; C read the fat value's length word as the next argument.fn srcno longer captures std'spanic(loc = src()), and a hidden intrinsic name stays the intrinsic.let m: BTreeMap[i32, i32] = [k: k * k for k in [4, 2, 3]]is refused ("sequence literal cannot target a map") #2569: a comprehension's iterable is checked without the collection demand, and a list literal there is typed by the clause binding's uses (D128), as aforloop's is.impl[K: Ord + Clone, V] Drop for BTreeMap[K, V]) is not taken as drop glue: locals are not dropped at scope end, an explicit drop() works #2571 (D154, delegated): aDropimpl's bounds are the type's own; an impl demanding a bound the type does not is refused ("a destructor runs for every instantiation"), closing the silent-leak class. §2.4 gains the sentence.Evidence: gate green;
deep-debug-tool-testsanddrop-auditgreen (MirLower changed); ceremony census diff clean; battery GREEN on the top commit (posted below).Battery GREEN on d6e4445 (624 s, seed-driven, this host). Gate, deep-debug-tool-tests and drop-audit green; ceremony census diff clean.