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
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
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 21, 2026 17:52
5f64862 to
c2f62c4
Compare
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, numeric-enum 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, typedxls::Valuerestoration, sign conversion, active-payload validation, inactive placeholders, and internal formatting descriptors all consume that shared layout. Supplying the nominal sum type during raw-value restoration validates tags, payload widths, declared numeric-enum membership, and canonical inactive payloads; enum identity and signedness are reconstructed from the expected type. Untyped raw tuples remain ordinary tuples.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.Internal interpreter formatting and type-mismatch diagnostics preserve constructor names, declaration order, 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 supported bits-like and numeric-enum payloads; inactive empty-sum alternatives; canonical storage offsets and inactive placeholders; existing AST node-kind identifiers; mismatches between distinct nominal sum declarations; direct and nested semantic-sum IR-lowering rejection; explicit non-first zero-discriminant constructors; malformed typed raw values; source-backed binary protobuf round trips for unit, tuple, and struct constructors; malformed serialized metadata; and existing non-sum wire behavior.