dslx: support semantic-sum types, values, and type information - #4777
Open
dank-openai wants to merge 1 commit into
Open
dslx: support semantic-sum types, values, and type information#4777dank-openai wants to merge 1 commit into
dank-openai wants to merge 1 commit into
Conversation
dank-openai
force-pushed
the
dank/upstream/semantic-sum-values
branch
from
August 14, 2026 15:25
256e5e9 to
1a7dcc5
Compare
richmckeever
self-requested a review
August 14, 2026 15:27
Adds Phase 1 semantic sum value representation and encoding support, including diagnostics and tests for sum type mismatch formatting.
dank-openai
force-pushed
the
dank/upstream/semantic-sum-values
branch
from
August 17, 2026 18:21
1a7dcc5 to
5f64862
Compare
dank-openai
marked this pull request as ready for review
August 17, 2026 18:59
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.
Summary
Why This Change
Parsed semantic-sum declarations need a concrete nominal type before DSLX support code can reason about constructor identity, payload shape, value layout, zero values, diagnostics, and serialized type information. Those consumers must agree on constructor order without independently reconstructing storage offsets or duplicating source-owned declaration metadata.
For example, consider a parsed declaration whose concrete types and source discriminants are available:
MakeZeroValueselectsIdle(u16:0)becauseIdlehas source discriminant zero. Its interpreter representation is(u1:1, (u8:0, u16:0)): storage tag1identifies the second declared constructor, theu8slot is an inactive canonical placeholder, and theu16slot contains the active zero payload. The source discriminant and dense storage tag are distinct even when their numerical values happen to coincide elsewhere.Type And Value Representation
SumTypeowns the nominal source definition and its declaration-orderedSumTypeVariantvalues. Shape-specific variant factories preserve the distinction between unit, tuple, and struct constructors, including empty payloads. Type equality, cloning, bit sizing, enum/token detection, visitor dispatch, and type-mismatch traversal use that same typed representation.Phase1SumTypeEncodingderives the internal dense tag and flattened payload layout from the canonical type. Value construction, rawxls::Valuerestoration, sign conversion, active-payload validation, inactive placeholders, and formatting descriptors all consume that shared layout. Nested construction and restoration avoid repeated recursive validation. Invalid tags, malformed aggregates, mismatched payload types, incorrect enum identity or signedness, and noncanonical inactive payloads fail with explicit statuses.MakeZeroValueselects the first constructor for implicit discriminants or the constructor whose explicit source discriminant is zero, then recursively zeroes its active payload. Sums without a valid zero constructor are rejected; zero-length arrays do not require an inhabitant of their element type.MakeAllOnesValuerejects semantic sums.Direct interpreter formatting and type-mismatch diagnostics preserve constructor names, declaration order, nested payloads, struct field names, and the distinct spellings of unit, empty-tuple, and empty-struct constructors. Format macros reject sums, including sums nested inside aggregates, during type validation. IR type lowering likewise reports that semantic sums are unsupported rather than exposing an accidental representation contract.
Serialized Type Information
The source AST owns constructor names, declaration order, payload shape, struct field names, and visibility. Serialized type information stores only the source span and concrete member types that cannot be recovered from the declaration:
TypeProto.sum_typeuses field number 13. Althoughsum_def_spanuses protobuf'soptionalsyntax, it is required by the reader. Decoding resolves the source declaration and rejects missing spans, constructor-count mismatches, incorrect declaration-ordered payload counts, meta-type payloads, and concrete payload types that disagree with available type information.No deployed serialized semantic-sum values impose an existing sum-wire compatibility contract. Existing non-sum
TypeInfoProtoencodings, optional legacy enum-member data, and published AST-node-kind values remain compatible.Source-level constructor typechecking, pattern execution, full constructor evaluation, and IR lowering remain separate implementation work. Explicit source discriminants participate in zero selection when their evaluated values are available; they are not used as storage tags.
Validation
Coverage includes deeply nested sums; active and inactive enum, token, proc, and uninhabited payloads; signed-enum restoration; canonical storage offsets; the production type-to-descriptor-to-value formatting path; nested mismatch diagnostics; explicit non-first zero-discriminant constructors; empty arrays; malformed raw values; source-backed binary protobuf round trips for unit, tuple, and struct constructors; malformed serialized metadata; and existing enum wire behavior.