Repository navigation
Specification §9.1c: a global always holds a value, never moved out of (D52, blessed 2026-09-21) - #1245
Merged
Conversation
…f; a const is a value, not a place (D52, blessed 2026-09-21) Blessed wording, verbatim. The compiler enforces it on the #1242 branch; until that merges the implementation is non-compliant.
ehartford
added a commit
that referenced
this pull request
Sep 21, 2026
… rejected (#1242, D52) (#1247) * A global is never moved out of: transfer out of a non-const global is rejected (#1242) `let out = g; g = Vec.new(); out` double-freed (debug-alloc: DOUBLE FREE origin=Vec first_drop=__drop_struct_193 second_drop=__drop_struct_193). `--dump-mir` shows why: inside a function the global read lowered as `_1 = copy _2` — a byte copy of a non-Copy value with no blanking — so the reassignment's `drop(_2)` and the returned value freed one buffer (§2.3: transport never produces a second live value). In `main` the same spelling lowered as `move` + `_1 = const zst`, a blanked global every other function still sees as holding a value. The checker's MOVED mark on a global is not per function either: after `fn f(): let s = g`, every later body reported "use of moved value" for `g` (str/Vec x ret/swap/use matrix). Sema now records ident nodes that resolve to a non-`const` module global (`global_value_ident_nodes`, `const_global_syms`); the consume arm of mark_moved_if_consumed and the return walker (check_returned_field_move, which runs after the body scope popped) reject a transfer whose type needs drop: "cannot move out of global `g`: a global always holds a value; clone it (`.clone()`) instead". Reads, views, in-place mutation and reassignment stay legal; a `const` is a comptime value that every use materializes. Compiler sites that moved a str global: ClangBridge (with_str_clone_ref, no-prelude object), CImport reads g_migrate_raw_source in place and clones the two bail accessors, CiMigrate clones the defs prefix, build/compiler.w clones the sentinel; the embedded stdlib/runtime/clang-resource generators emit `const`. Tests: err_move_out_of_global_{binding,return,arg}, behav_global_observed_and_cloned. D52 in decisions.md proposes the §9.1c sentence for blessing. * Embedded data generators keep `let` and clone on return; D52 marked blessed Switching the generators to `const` un-escaped the embedded sources: comptime re-interprets escapes inside a raw string literal (#1246), so <embedded-std>/std/build.w lost its backslashes and every `use std.build` program failed to parse (35 behavior lanes red). Until #1246 is fixed the generated accessors return `EMBEDDED_X.clone()`; §9.1c landed as #1245. --------- Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 21, 2026
…t, the specification included (#1252) The D50 amendment to D49 kept three docs files in the identity because lanes read them (the specification, with-abi.sha256, with_for_ai.md). A spec-only merge (#1245) then left main with no published green and :install-user refused the reseed. Eric: "build measures software not documents." green_identity_inputs and ret_green_identity_inputs take the top-level listing alone; the docs ls-tree is gone from both; the test pins that a docs edit leaves the identity unchanged and a src edit does not. 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.
Blessed wording, verbatim. Docs-only: spec-inventory-check run. The enforcing compiler change is the #1242 branch (battery running); its D52 entry proposes this sentence and will be marked blessed when it merges.