Skip to content

Specification §9.1c: a global always holds a value, never moved out of (D52, blessed 2026-09-21) - #1245

Merged
ehartford merged 1 commit into
mainfrom
spec-9-1c-globals
Sep 21, 2026
Merged

ehartford merged 1 commit into
mainfrom
spec-9-1c-globals

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

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.

…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
ehartford merged commit 06cb8cb into main Sep 21, 2026
5 checks passed
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]>
@ehartford
ehartford deleted the spec-9-1c-globals branch September 24, 2026 16:57
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