Skip to content

The standard library takes fix-ceremony's rewrites; the tool no longer trusts code this target did not check; the compile-time evaluator stores into a field of a let (part of #3061) - #3601

Merged
ehartford merged 3 commits into
mainfrom
std-trait-ret
Nov 24, 2026

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3061 (and of #2519's first item). Both stay open.

Sweeping lib/std with with fix-ceremony found three defects. They are fixed here, before the sweep.

1. The tool trusted code this target never checked (a platform hazard)

The comptime transform keeps one arm of a comptime if / comptime match and Sema never sees the others. A fact of the form "nothing else uses this name" therefore did not cover them:

var x = 1
comptime if Target.os == .Windows:
    x = 5            // not checked on the Mac

was reported as "var is never rebound", the rewrite to let passed the Mac re-check, and Windows would have stopped compiling. The same for an index loop whose counter is used only in such an arm. The rewriter now finds the ranges a file's compile-time branches cover and withholds var → let when the name is written in one, and the index-loop rewrite when one lies inside the loop. src/ has no such branches, so the earlier sweeps of the compiler were not exposed; lib/std has many.

2. A var written through &raw mut was "never rebound"

var n = 0; fill(&raw mut n) lost its var. Sema now records the address-of as a write.

3. The compile-time evaluator refused what Sema accepts

let out = self; out.output = path runs, but evaluated at compile time it was "cannot assign to field of immutable value". The sweep turned such a var into let in lib/std/build.with, which build evaluation interprets, and 41 build-layer tests went red. let forbids rebinding the name, not a store into a field of its value (xs.push(…) on a let already evaluated). The evaluator re-derived Sema's answer and got it wrong; the refusal is removed (D65).

The sweep

Each of the 91 files outside the migrated engines as its own entry, --std --check-with src/main; none restored. 38 files change:

rewrite sites
var never rebound → let 199
widening as where the context widens 186
List.new() / HashMap.new() where the type is demanded or written → [] / [:] 148
&x at a &T parameter 49
a trait impl method's return type that restates the trait's 42
annotation that restates the initializer 15
index loop over one list 14
.clone() on a str, Some(x) under an Option demand 15

Four files do not check as their own entry and are untouched (builtins, result, string, traits).

Tests: test/internals_compiler/ceremony_fix_test.with gains a sample with a Windows-only assignment, a Windows-only counter use and a &raw mut write (one rewrite, not three); behav_comptime_field_store_into_let. Both fail on main.

Evidence at c2ba7a0

  • macOS: release build; :unit-return-review, :ceremony-census, :self-audit, :behavior-tests, :internals-compiler-tests green; battery green; :release-checks survey: all targets green.
  • linux-aarch64 (container leg): build, :behavior-tests, :internals-compiler-tests green.
  • windows-x86_64 (VM): :build green on this content.

Eric Hartford added 3 commits November 24, 2026 13:40
…t a name is unused, and a var written through &raw mut keeps its var (part of #3061)
…urn types, 199 vars never rebound, 186 widening casts, 148 empty constructors (part of #3061)
…un time does; it no longer re-derives Sema's answer
@ehartford

Copy link
Copy Markdown
Contributor Author

Windows (VM, at b6aaf32, which is this branch plus the emit-C link fix): :build, :release-checks (37 targets), :behavior-tests and :internals-compiler-tests all report survey: all targets green. VM shut off afterwards.

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