Skip to content

[Self-Hosting] Canonicalize reference-span sugar in Stage-A AST_TYPE #720

Closed

Description

@godofecht

Problem

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.
  • Preserve mutability and optional extent.
  • Keep formatter/codegen behavior compatible.
  • Add parser/AST tests proving reference syntax and explicit span syntax normalize identically.
  • Extend compiler/src/type_name.flow once the representation is lossless.

Related

#674 #677 #718 #717

Activity

  1. added
    self-hosting
    P1-high
    on Aug 22, 2026
  2. godofecht commented on Aug 25, 2026

    @godofecht
    ContributorAuthor

    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.

  3. godofecht commented on Aug 26, 2026

    @godofecht
    ContributorAuthor

    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.

  4. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    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.

  5. godofecht commented on Sep 16, 2026

    @godofecht
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highcompilerself-hosting

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions