You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Self-Hosting] Canonicalize reference-span sugar in Stage-A AST_TYPE #720
Stage-A flowc_parse_type currently strips & and optional mut, then parses [T] as an anonymous AST_TYPE whose name_* span does not encode the canonical span identity. This means &[T] / &mut [T] cannot be normalized byte-for-byte to the production parser's span_const_<elem> / span_mut_<elem> names, independently of #718's explicit span<mut T> mutability loss.
Deliverables
Give &[T], &mut [T], &[T; N], and &mut [T; N] a canonical Stage-A AST representation equivalent to explicit span syntax.
Progress update (25 Aug 2026, local-validation only): #772 adds source-independent synthetic-span metadata for reference sugar and teaches canonical type-name normalization to emit the same span_const_* / span_mut_* names as explicit spans; sized-reference extent stays in AST_TYPE.ival without changing overload identity. #773 stacks the end-to-end parser contract for &[T], &mut [T], &[T; N], and &mut [T; N]. All commits use [skip ci]. Remaining work is the bounded reference/slice branch splice in flowc_parse_type, documented precisely in #773.
Worked through the Stage-A representation problem in detail. The key point is that a single AST_TYPE_SPAN_MUTABLE = 1 bit is not sufficient for reference sugar unless span identity is also semantic rather than inferred from a source span spelling span.
A minimal lossless encoding can use the already-reserved AstNode.c slot as tri-state metadata:
-1: not a span
0: const span
1: mutable span
with a = inner type and ival = optional extent as today. Then explicit span<T> / span<mut T> and reference sugar &[T] / &mut [T] / sized variants all normalize to the same (SPAN, inner, mutability, extent) representation, independent of source spelling.
This gives exact normalization identities such as N(span<i32>) = N(&[i32]) and N(span<mut i32>) = N(&mut [i32]), while preserving &[T; N] extent separately. type_name.flow can then emit span_const_ / span_mut_ from AST metadata instead of searching name_start/name_end for the literal span token.
The important invariant is that type identity must not depend on whether the original source contained the word span; reference sugar has no such source span to reuse.
I archived the complete derivation plus a Flow semantic witness in godofecht/OpenProjects as compilers/lossless-stage-a-span-canonicalization.{md,flow}. The witness checks explicit/reference equality, mutability/extent injectivity, non-span separation, and the old mutability-collision counterexample. Local independent normalization checks covered 24 combinations of representative element types, mutability states, and extents.
Implemented and verified the remaining reference-span representation slice: &[T], &mut [T], and sized bracket forms retain canonical AST_TYPE inner/extent metadata, with mutability stored explicitly and aligned with span. Parser regression coverage is included in tests/lang/test_ast_names_port.flow. Bootstrap fixed-point and self_host_full pass; native/span tests are 84/84.
Verified against the current worktree: reference-span sugar (&[T], &mut [T], and sized forms) is represented with canonical AST_TYPE inner/mutability/extent metadata. Parser regression coverage passes, the full language suite is 106/106, bootstrap fixed-point verification passes, and self_host_full passes. Closing as implemented.
Activity
godofecht commentedon Aug 25, 2026
Progress update (25 Aug 2026, local-validation only): #772 adds source-independent synthetic-span metadata for reference sugar and teaches canonical type-name normalization to emit the same
span_const_*/span_mut_*names as explicit spans; sized-reference extent stays in AST_TYPE.ival without changing overload identity. #773 stacks the end-to-end parser contract for&[T],&mut [T],&[T; N], and&mut [T; N]. All commits use[skip ci]. Remaining work is the bounded reference/slice branch splice inflowc_parse_type, documented precisely in #773.godofecht commentedon Aug 26, 2026
Worked through the Stage-A representation problem in detail. The key point is that a single
AST_TYPE_SPAN_MUTABLE = 1bit is not sufficient for reference sugar unless span identity is also semantic rather than inferred from a source span spellingspan.A minimal lossless encoding can use the already-reserved
AstNode.cslot as tri-state metadata:-1: not a span0: const span1: mutable spanwith
a = inner typeandival = optional extentas today. Then explicitspan<T>/span<mut T>and reference sugar&[T]/&mut [T]/ sized variants all normalize to the same(SPAN, inner, mutability, extent)representation, independent of source spelling.This gives exact normalization identities such as
N(span<i32>) = N(&[i32])andN(span<mut i32>) = N(&mut [i32]), while preserving&[T; N]extent separately.type_name.flowcan then emitspan_const_/span_mut_from AST metadata instead of searchingname_start/name_endfor the literalspantoken.The important invariant is that type identity must not depend on whether the original source contained the word
span; reference sugar has no such source span to reuse.I archived the complete derivation plus a Flow semantic witness in
godofecht/OpenProjectsascompilers/lossless-stage-a-span-canonicalization.{md,flow}. The witness checks explicit/reference equality, mutability/extent injectivity, non-span separation, and the old mutability-collision counterexample. Local independent normalization checks covered 24 combinations of representative element types, mutability states, and extents.selfhost: canonicalize reference-span sugar in Stage-A AST_TYPE (#720)
selfhost: canonicalize reference-span sugar in Stage-A AST_TYPE (#720)
selfhost: canonicalize reference-span sugar in Stage-A AST_TYPE (#720)
Harvest self-hosting backends: span sugar (720), Metal/WGSL (689), WA…
godofecht commentedon Sep 16, 2026
Implemented and verified the remaining reference-span representation slice: &[T], &mut [T], and sized bracket forms retain canonical AST_TYPE inner/extent metadata, with mutability stored explicitly and aligned with span. Parser regression coverage is included in tests/lang/test_ast_names_port.flow. Bootstrap fixed-point and self_host_full pass; native/span tests are 84/84.
godofecht commentedon Sep 16, 2026
Verified against the current worktree: reference-span sugar (
&[T],&mut [T], and sized forms) is represented with canonical AST_TYPE inner/mutability/extent metadata. Parser regression coverage passes, the full language suite is 106/106, bootstrap fixed-point verification passes, and self_host_full passes. Closing as implemented.