Skip to content

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
ehartford merged 11 commits into
mainfrom
fixes-2567
Oct 23, 2026

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Seven compiler fixes, one battery. Each is its own commit with its fixture.

Evidence: gate green; deep-debug-tool-tests and drop-audit green (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.

Eric Hartford 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).
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant