Repository navigation
#3061 slice 1: with fix-ceremony; #3068: a global named like an imported enum's variant - #3067
Merged
Merged
Conversation
added 3 commits
November 7, 2026 03:13
…ary (slice 1) `with fix-ceremony --report|--apply [--std] [--exclude p] <entry.w>` (src/CeremonyFix.w): a `let x: T = e` whose initializer Sema typed as `T` without the annotation's demand loses `: T`; a `var` never assigned again and never passed to a `mut` parameter becomes `let`. Sema records the facts where it decides them (check_let_binding, check_assign, check_mut_param_arg); check_fstring records its expression type like every other expression. `--apply` re-checks the entry and restores every file if it no longer checks. A migrated corpus is never rewritten (D112); std only with --std. test/internals/ceremony_fix_test.w pins six rewrites over a sample and that the rewritten program checks.
…/AFTER collide with FnFlags members through an imported enum's bare variant names, filed separately)
…s the global MirLower's identifier lowering checked `variant_lookup` before the module-variable path, so `let AFTER = "…"` beside an import whose enum has an `AFTER` member was lowered as the enum's integer; Sema had typed the read as the global and recorded it (global_value_ident_nodes), and MirLower reads that fact now, as the place path already did. Pinned by behav_3068_global_named_like_imported_variant.w with lib/flags_mod_3068.w.
ehartford
marked this pull request as ready for review
November 7, 2026 12:14
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.
#3061, slice 1:
with fix-ceremony(Eric, 2026-11-07: "we need to make a sema based tool to automatically reduce bad ceremony"). The census counts; this rewrites, on facts Sema recorded while it checked the program, never on the text's shape.Passes in this slice.
let x: T = ewhere Sema typedeasTandeis typed without the annotation's demand (a read of a place, a string or f-string, a cast, a call of a non-generic function, operators over those):: Tgoes. A literal, a collection literal, a comprehension, a variant shorthand, anif/match, a closure or a generic call may take its type from the annotation (§4.3c, D93, D22), so those stay.varnever rebound: avarwhose binding is never assigned again (x = …,x += …) and never passed to amutparameter (§3.8a):let.Sema owns the facts (D65).
check_let_bindingrecords each local let's file, and, when annotated with an initializer, the annotation's type and type node and the initializer;check_assignandcheck_mut_param_argrecord the bindings they rebind.check_fstringnow records its expression type intyped_expr_typeslike every other expression (it was the one initializer kind the rewriter could not see).Proof.
test/internals/ceremony_fix_test.w: a sample with every shape the two passes decide yields exactly six rewrites, the rewritten text is the expected one, and the rewritten program checks.--applyre-checks the entry and restores every file if it no longer does.Found by the test and fixed: #3068. Its sample globals were
BEFOREandAFTER, and the compiler'sFnFlagsenum has members of those names: MirLower's identifier lowering checked "is this a bare variant name" (variant_lookup) before the module-variable path, so the program's ownstrglobal was lowered as the enum's integer (an f-string,assertandassert_eqall saw16384). Sema had typed the read as the global and recorded it (global_value_ident_nodes); MirLower now reads that fact and takes the variant path only when Sema did not resolve a global, as the place path already did. Pinned bybehav_3068_global_named_like_imported_variant.wwithlib/flags_mod_3068.w.Not yet (the issue's later items): widening casts,
List.new()→[], index loops,.clone()on str,&xat&T. Running the tool oversrc/is its own PR, after this one.