Skip to content

Add typed nested pattern destructuring#37

Merged
beardedeagle merged 5 commits into
mainfrom
nested-typed-patterns
May 13, 2026
Merged

Add typed nested pattern destructuring#37
beardedeagle merged 5 commits into
mainfrom
nested-typed-patterns

Conversation

@beardedeagle
Copy link
Copy Markdown
Owner

@beardedeagle beardedeagle commented May 13, 2026

Summary

  • Add structural nested pattern destructuring across constructor payloads, records, list elements/rest, and map values/rest.
  • Accept fieldless nested enum constructor predicates such as Envelope(Assign(Ready)) as typed shape checks that introduce no bindings.
  • Apply nested destructuring consistently across step parameter patterns, whole-body message matches, state payload matches, source helper signatures, source helper match bodies, helper return-match expressions, and collection element/value positions.
  • Add checked typed projection paths and checked enum variant IDs so executable semantics after checking are typed structures rather than source-string selectors.
  • Lower checked enum IDs to Mantle enum variant IDs and keep Mantle artifact schema version 1 as the single admitted greenfield baseline while adding typed enum payload and enum variant templates.
  • Validate and admit nested template structures at the Strata checked-IR, Mantle artifact, and loaded-runtime boundaries.
  • Keep ProcessRef payload authority direct-only by rejecting nested or projected process reference payloads outside direct message payload bindings.
  • Add nested pattern docs, a runnable source-to-runtime example, acceptance coverage, regression tests, and fuzz seeds.

Semantics And Boundary

  • Strata source bindings remain immutable local values.
  • Collection rest bindings remain immutable whole-value projections, not mutable views.
  • Fieldless nested enum constructors are shape predicates only; they do not bind source values or lower as executable source strings.
  • Static map-key semantics remain bounded; dynamic map keys and collection iteration remain out of scope.
  • Strata owns syntax, diagnostics, semantic checking, checked IR, and source-visible meaning.
  • Lowering converts checked typed structures into Mantle artifact IDs and typed templates.
  • Mantle owns artifact admission, loaded runtime IDs, template evaluation, process state, mailbox behavior, and runtime observability.
  • Source names remain allowed only for syntax, diagnostics, traces, provenance, metadata, and literal values. Executable constructor/template semantics use checked IDs, artifact IDs, loaded IDs, and typed projection structures.

Tests And Verification

  • cargo +stable fmt --all --check
  • cargo +stable fmt --manifest-path fuzz/Cargo.toml --all --check
  • cargo +stable check --workspace --all-targets
  • cargo +stable test --workspace --all-targets
  • cargo +stable clippy --workspace --all-targets -- -D warnings
  • mdbook build docs
  • just source-to-runtime-gates
  • just performance-smoke
  • just ci-quality
  • git diff --check

The pre-commit hook also passed clippy and fmt checks, and the pre-push hook passed ci-native before the branch was uploaded.

Admit nested immutable constructor payload, record, list, and map patterns across step parameter patterns, whole-body message matches, state payload matches, source helper signatures, source helper match bodies, helper return-match expressions, and collection element/value pattern positions.

Represent nested destructuring structurally in the Strata AST and as checked typed projection paths in checked IR. Constructor payload matching now resolves to checked enum variant IDs, and lowering converts those IDs to Mantle enum variant IDs instead of using source names as executable selectors.

Add Mantle artifact schema v4 enum variant metadata plus typed enum payload and enum variant template structures. Artifact validation and loaded runtime admission validate enum variant IDs against type metadata, reject invalid programmatic templates at the correct boundary, and evaluate templates through admitted typed structures.

Preserve immutable Strata source semantics and the explicit Strata/Mantle boundary. Collection rest bindings remain immutable whole values, static map-key semantics remain bounded, and nested or projected process reference payloads are rejected unless they are direct message payload bindings.

Extend source-to-runtime gates, docs, examples, fuzz seeds, and focused positive and negative regressions for accepted nested forms, malformed syntax, duplicate bindings, type mismatches, missing fields, capacity violations, rest-pattern limits, enum metadata limits, and process-reference boundary enforcement.
Copilot AI review requested due to automatic review settings May 13, 2026 12:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Strata’s pattern system to support typed nested destructuring (constructor payloads, records, lists, maps) throughout step dispatch, state/message matches, and source helper patterns, while also migrating executable enum handling away from source-string selectors to checked IDs and Mantle artifact enum-variant metadata (schema v4).

Changes:

  • Add nested pattern destructuring support across the parser, checker, checked IR, and lowering.
  • Introduce checked enum variant IDs and emit Mantle artifact schema v4 with enum-variant metadata plus typed enum payload/variant templates.
  • Add an end-to-end example (examples/nested_patterns.str) plus regression/acceptance/fuzz seed coverage for nested patterns and v4 artifacts.

Reviewed changes

Copilot reviewed 66 out of 66 changed files in this pull request and generated no comments.

Show a summary per file
File Description
README.md Documents nested pattern destructuring and clarifies projection/rest semantics.
Justfile Adds nested pattern example to source-to-runtime gate recipes.
fuzz/seeds/strata_parse_check_lower/nested_patterns.str New fuzz seed covering nested pattern parsing/checking/lowering.
fuzz/seeds/mantle_runtime_from_source/nested_patterns.str New fuzz seed for runtime-from-source path with nested patterns.
fuzz/seeds/mantle_artifact_decode/collection_state.mta Updates decode seed to schema v4 and new template/type encodings.
examples/nested_patterns.str New runnable example demonstrating nested destructuring end-to-end.
docs/src/syntax-reference.md Updates grammar to include nested constructor patterns and nested collection bindings.
docs/src/runtime-traces.md Updates trace example to schema_version=4.
docs/src/language-reference.md Expands prose/spec and examples to cover nested patterns and typed templates/IDs.
docs/src/file-types.md Updates admitted artifact schema baseline to v4.
docs/src/examples.md Adds “Nested Patterns” example entry and run instructions.
crates/strata/src/language/tests/support.rs Updates test imports for new Mantle enum-variant limits/IDs.
crates/strata/src/language/tests/step_dispatch_validation.rs Updates parse-time diagnostic text for new destructuring categories.
crates/strata/src/language/tests/state_payload_values.rs Switches assertions to checked enum variant IDs.
crates/strata/src/language/tests/state_match_success.rs Switches assertions to checked/artifact enum variant IDs and minor refactor.
crates/strata/src/language/tests/source_function_core.rs Asserts lowering emits variant_id (not variant label strings).
crates/strata/src/language/tests/source_function_collection_patterns/map_rest_patterns.rs Updates enum variant assertions to EnumVariantId.
crates/strata/src/language/tests/source_function_collection_patterns/list_rest_patterns.rs Updates enum variant assertions to EnumVariantId.
crates/strata/src/language/tests/nested_pattern_destructuring.rs New regression suite for nested pattern destructuring and rejections.
crates/strata/src/language/tests/mod.rs Registers the new nested pattern test module.
crates/strata/src/language/tests/limits.rs Adds enum-variant-count limit test wired to artifact limit.
crates/strata/src/language/parser.rs Parses nested constructor patterns and nested collection binding patterns.
crates/strata/src/language/lowering.rs Lowers checked enum IDs and enum-payload templates into Mantle typed templates/IDs.
crates/strata/src/language/checker/steps/transition.rs Adjusts send payload representation and passes module/index for typed projection resolution.
crates/strata/src/language/checker/steps/discovery.rs Threads module/index into payload binding discovery for typed paths.
crates/strata/src/language/checker/steps/clauses.rs Uses module-aware type interning and module/index-aware payload binding resolution.
crates/strata/src/language/checker/static_validation/tests/support.rs Adds test helpers for enum value types, state values, and enum variant IDs.
crates/strata/src/language/checker/static_validation/tests/process_ref_templates.rs Expands coverage for rejecting nested/projected process-ref templates (including enum-payload projections).
crates/strata/src/language/checker/static_validation/tests/next_state_templates.rs Updates enum template tests to use enum-aware checked types and variant IDs.
crates/strata/src/language/checker/static_validation/templates.rs Validates new EnumPayload template shape and enforces process-ref “direct-only” constraints across projections.
crates/strata/src/language/checker/static_validation/runtime_order.rs Adds runtime-order evaluation for checked EnumPayload templates.
crates/strata/src/language/checker/static_validation/process_refs.rs Updates checked type-kind matching for new Value { enum_variants }.
crates/strata/src/language/checker/static_validation.rs Adapts send payload handling to boxed templates.
crates/strata/src/language/checker/state_space/tests.rs Updates CheckedTypeInterner construction to be module-aware.
crates/strata/src/language/checker/state_space/templates.rs Converts binding paths into typed projection segments and supports enum-payload projection templates.
crates/strata/src/language/checker/source_functions/value_resolution.rs Enables nested constructor patterns in source helper signature destructuring (with concrete-value matching).
crates/strata/src/language/checker/source_functions/record_patterns.rs Emits typed projection segments for record field bindings.
crates/strata/src/language/checker/source_functions/collection_patterns.rs Adds nested patterns in list/map element/value positions and supports nested substitutions.
crates/strata/src/language/checker/message_cases.rs Threads module/index through payload binding discovery to support typed projection paths.
crates/strata/src/language/checker.rs Introduces typed projection path segments, enum variant IDs, nested pattern binding checking, and enum variant count validation.
crates/strata/src/language/checked.rs Adds CheckedEnumVariantId, enum-variant metadata on checked value types, and EnumPayload checked templates.
crates/strata/src/language/ast.rs Adds nested CollectionPatternBinding::Pattern variant to represent nested collection patterns in the AST.
crates/strata-mantle-acceptance/tests/source_to_runtime_gates.rs Adds acceptance gate for examples/nested_patterns.str and updates enum template assertions to EnumVariantId.
crates/mantle-runtime/src/tests.rs Updates runtime tests for typed enum variants and enum type metadata.
crates/mantle-runtime/src/run/tests/support.rs Updates test artifacts to use enum_value metadata for enum types.
crates/mantle-runtime/src/run/tests/state_message_admission.rs Adds admission test for invalid enum payload projection variant IDs.
crates/mantle-runtime/src/run/templates.rs Evaluates EnumPayload projections and formats EnumVariant values via variant IDs.
crates/mantle-runtime/src/program/values.rs Adds loaded EnumPayload template and switches EnumVariant template to EnumVariantId.
crates/mantle-runtime/src/program/templates.rs Admits EnumPayload templates and validates enum variant IDs against type metadata.
crates/mantle-runtime/src/program.rs Adds enum variant label lookup and validates enum variant metadata in the loaded type table.
crates/mantle-artifact/src/validation.rs Accounts for enum variant metadata and new template fields in encoded size calculation.
crates/mantle-artifact/src/tests/support.rs Updates canonical valid artifact to declare enum variant metadata for enum types.
crates/mantle-artifact/src/tests/state_transitions.rs Updates enum template tests to use EnumVariantId.
crates/mantle-artifact/src/tests/process_ref_payloads.rs Updates enum template tests to use EnumVariantId.
crates/mantle-artifact/src/tests/identity_and_labels.rs Adds validation tests for enum variant metadata limits and EnumPayload invalid variant IDs.
crates/mantle-artifact/src/tests/codec.rs Adds round-trip coverage for large enum variant metadata and updates encoding expectations.
crates/mantle-artifact/src/lib.rs Re-exports EnumVariantId.
crates/mantle-artifact/src/ids.rs Introduces EnumVariantId as a first-class artifact ID type.
crates/mantle-artifact/src/fields.rs Adds decoding support for bounded EnumVariantId fields.
crates/mantle-artifact/src/constants.rs Bumps ARTIFACT_SCHEMA_VERSION to 4 and introduces MAX_ENUM_VARIANTS_PER_TYPE.
crates/mantle-artifact/src/artifact/value_template/value.rs Adds enum payload projection on ArtifactValue.
crates/mantle-artifact/src/artifact/value_template/template.rs Adds EnumPayload templates, moves enum variant representation to EnumVariantId, and validates variant IDs via type metadata.
crates/mantle-artifact/src/artifact/value_template/model.rs Adds EnumPayload template and switches EnumVariant template variant to EnumVariantId.
crates/mantle-artifact/src/artifact/process_validation.rs Ensures process-ref template validation traverses EnumPayload templates.
crates/mantle-artifact/src/artifact/codec.rs Encodes/decodes schema v4 type enum-variant metadata and enum template variant_id fields.
crates/mantle-artifact/src/artifact.rs Adds artifact enum variant label lookup, validates enum variant metadata per type, and updates template evaluation to use type entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The CLI tests that verify check and build fail before writing artifacts used a 256-process by 1024-state-value source to exceed the Mantle artifact byte limit. That fixture spent CI time in broad process and state-space checking before reaching the artifact-size boundary.

Replace the source with a single immutable process that reaches the same Mantle artifact-size admission boundary through bounded output literals and emit actions. The fixture remains below the Strata source byte limit and still proves both CLI paths surface the artifact encoding error before build writes an output artifact.

Verification:

- cargo +stable test -p strata strata_check_rejects_source_that_cannot_lower_to_artifact -- --nocapture

- cargo +stable test -p strata strata_build_rejects_lowering_failure_before_writing_output -- --nocapture

- cargo +stable test -p strata cli::tests -- --test-threads=1 --nocapture

- cargo +stable fmt --all --check

- just ci-rust

- just ci-quality

- git diff --check
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 67 out of 67 changed files in this pull request and generated 1 comment.

Comment thread docs/src/syntax-reference.md
Update the syntax reference so nested collection bindings are listed before plain identifier bindings and document the parser lookahead that distinguishes nested patterns from immutable binding names.

This resolves the review finding without changing Strata syntax, checker behavior, lowering, Mantle artifacts, or runtime semantics.

Verification:

- mdbook build docs

- git diff --check
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 67 out of 67 changed files in this pull request and generated no new comments.

Keep the current greenfield Mantle Target Artifact encoding as schema version 1 instead of advancing an artificial version counter for newly admitted fields.

Update the artifact constant, committed decode seed, and public docs/runtime-trace examples to use the single admitted schema baseline. The change does not add compatibility handling, migration branches, or source/runtime semantic changes.

Verification:

- rg schema_version=4/schema v4 references outside ignored docs/book

- cargo +stable test --workspace --all-targets

- just ci-quality

- just fuzz-smoke

- mdbook build docs

- git diff --check
Parse bare nested constructor payload identifiers as structural fieldless enum constructor patterns, allowing forms such as Envelope(Assign(Ready)) in the nested pattern slice.

Carry the accepted form through Strata checking as typed payload guards for step patterns, match bodies, state matches, and source helper signature/body/return-match resolution. Guard evaluation is checker-time typed structure over resolved enum variants and concrete payload values; it does not lower source strings as executable semantics.

Keep shape-only nested collection patterns rejected, preserve immutable binding semantics, and leave the Mantle artifact schema baseline at version 1. Mantle lowering continues to receive checked typed templates and metadata only.

Add focused positive and negative tests for fieldless nested enum constructor predicates, mismatch diagnostics, helper contexts, and rejected shape-only collection nesting. Update the language and syntax references to document the accepted fieldless constructor predicate form.
Copilot AI review requested due to automatic review settings May 13, 2026 16:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 70 out of 70 changed files in this pull request and generated no new comments.

@beardedeagle beardedeagle merged commit 156fcd5 into main May 13, 2026
13 checks passed
@beardedeagle beardedeagle deleted the nested-typed-patterns branch May 13, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants