Repository navigation
t27b: a module var of an optional type that starts as null (agents runtime registry.t27) #7910
Description
Part of #6063 (t27b coverage), item C10 of #6488.
What registry.t27 needs
specs/port/browseros/trios/agent-server/apps/server/src/lib/agents/runtime/registry.t27 passes the reference (9 of 9 tests). t27b refuses it first with VarDecl(module, pointer/slice):
var global_registry: ?AgentRuntimeRegistry = null;
The same refusal then cascades into ExprLiteral(null). #7470 lowered module vars that hold a string or start undefined. An optional-typed var still falls through to the pointer/slice refusal.
What the reference does
gen-zig prints the var as written: a container-level var whose initial value is null. Its payload is never read before a write. t27c test-report runs each test in a fresh process, so every test starts from null.
t27b lays out a ?T as the payload and then a flag byte, which is 0 for null. So the initial image of such a var is zero bytes, even when the payload holds a string. No address has to be written at load time, unlike #7470's string vars. Reads, writes, == null, .? and &g.? on an optional place already lower for locals.
Plan
- Accept a module var of an optional type whose initializer is
null. Its image is zeros. - Any other initial value of an optional var stays refused.
- A conformance spec:
specs/tri/t27b/conformance/optional_module_var.t27. It covers a?u32and a?structholding a str, create-on-first-use through&g.?, reset to null, and a fresh null at the start of every test.
With this change, registry.t27 stops only at reg1 == reg2, which is pointer equality and is #7742's (PR #7831). With both changes it passes. Measured on the t27c lab, with that assert replaced by reg1.len == reg2.len: 9/9 under both t27b and the reference.
Acceptance criteria
t27b test --blockerson registry.t27 names noVarDecl(module, pointer/slice)and noExprLiteral(null).- The conformance spec passes under
t27c test-reportwith 0 vacuous tests, and the same tests pass under t27b. - The lab corpus receipt compare gives IMPROVED_ONLY, EQUIVALENT or NEUTRAL.
User Scenarios
- Given a module-level variable declared with an optional type and initialized to
null(e.g.,var global_registry: ?AgentRuntimeRegistry = null;), when compiling with t27b, then the compiler accepts the declaration and emits a zero-initialized image for the variable without reportingVarDecl(module, pointer/slice)orExprLiteral(null)blockers.
Requirements
- FR-001: The compiler MUST accept a module-scope variable of optional type (
?T) whose initializer is exactlynulland MUST lay it out as zero bytes (payload zeroed, flag byte 0). - FR-002: The compiler MUST continue to refuse any module-scope optional variable whose initializer is not
null. - FR-003: A conformance spec at
specs/tri/t27b/conformance/optional_module_var.t27MUST be added covering?u32and?structholding a string, create-on-first-use via&g.?, reset to null, and fresh null at start of each test. - FR-004: After the change,
t27b test --blockersonspecs/port/browseros/trios/agent-server/apps/server/src/lib/agents/runtime/registry.t27MUST report zeroVarDecl(module, pointer/slice)and zeroExprLiteral(null)blockers.
Boundary
- specs/port/browseros/trios/agent-server/apps/server/src/lib/agents/runtime/registry.t27
- specs/tri/t27b/conformance/optional_module_var.t27
- compiler/codegen/zig/runtime.t27
Activity
Merge master e87e790 into t27b-optional-module-var-7910 (Closes #7910)
Merge master 430c522 into t27b-optional-module-var-7910 (Closes #7910)
Merge master 408d740 into t27b-optional-module-var-7910 (Closes #7910)
Merge master e66473f into t27b-optional-module-var-7910 (Closes #7910)
Merge master 4270760 into t27b-optional-module-var-7910 (Closes #7910)
Merge master 2dfe978 into t27b-optional-module-var-7910 (Closes #7910)
Merge master 6b6386e into t27b-optional-module-var-7910 (Closes #7910)
Merge master 09ffc2f into t27b-optional-module-var-7910 (Closes #7910)
Merge master 12ee225 into t27b-optional-module-var-7910 (Closes #7910)
Merge master 6cd8fba into t27b-optional-module-var-7910 (Closes #7910)
t27b: a module var of an optional type that starts as null (Closes #7910
Merge master 35e6996 into t27b-repeat-local-7909 (Closes #7909)
Merge master 35e6996 into t27b-int-cast-index-7902 (Closes #7902)