Skip to content

cst, sema: record spreads (F# 11's RecordSpreads) - #830

Merged
Smaug123 merged 1 commit into
mainfrom
claude/record-spreads
Nov 15, 2026
Merged

Smaug123 merged 1 commit into
mainfrom
claude/record-spreads

Conversation

@Smaug123

Copy link
Copy Markdown
Collaborator

PR 8 step 4a of docs/ast-versioning-plan.md: F# 11's record spreads (RecordSpreads, dotnet/fsharp#18927), parsed, gated and declined soundly.

Parser (borzoi-cst)

  • { ...e; F = x }, { x with ...e }, { inherit B(); ...e }, {| ...e; F = x |}, struct {| ...e |}, and type R = { ...T; F: int } (impl and signature files), as FCS's recdExprCore, recdBinding and recdFieldDecl read them.
  • FCS's error forms, each matching its tree:
    • a spread with no source ({ ... }, { ...r; ... }, {| ... |}: FS3899; type R = { ... }: FS3900);
    • { ...e with F = x } and {| ...e with … |}: FS3903, with e kept as the copy source;
    • ...e anywhere else ([ ...xs ], (...x), x, ...y, 1 + ...x, { ...; X = 1 }): FS3902. It parses as an ERROR node that stands for FCS's ArbitraryAfterError, so its slot reads as empty and its expression is unchecked, as in FCS.
  • New kinds: DOT_DOT_DOT_TOK, RECORD_SPREAD and RECORD_SPREAD_DECL.
  • The lex-filter part (... after with) came with fcs-dump: FCS 43.13.101, with a frozen legacy oracle below the support floor #813.
  • FCS's parser accepts a dotted field in an anonymous record's construction ({| ...r; Nested.B = 1 |}). parsInvalidAnonRecdExpr is no longer raised anywhere in FCS, so our parse error for it is gone. diff_ast_anon_recd_dotted_field is now FCS-graded.

Union and facades

  • RecordExpr::spreads(), AnonRecdExpr::spreads() and RecordRepr::spreads() each return (index, RecordSpread[Decl]): every spread with its position among the record's bindings, so fields() and spreads() interleave back into FCS's ordered list.
  • I tried an ordered item enum (RecordExprItem { Field, Spread }) first. astgen derives it into every frozen facade (its Field variant's node exists there) and fails on it as a "new variant". A wholly new enum is classified the same way, so that shape would have needed ACCEPTED_DIVERGENCES. The tuple shape adds no line to any published lock.
  • v4_6/v5/v8/v9/v10 locks, code and consumer fixtures are byte-identical. union, v11 and preview gain the two nodes and five accessors.

Gate

  • The RecordSpreads row is now Kind(RECORD_SPREAD)+Kind(RECORD_SPREAD_DECL), live: a parse-phase Legality gate at each spread's ...e / ...T.
  • sema's check_time_gates_report_what_fcs_checks_report holds it to FCS's check diagnostics, span and message, at 10.0 / 11.0 / preview, for nominal, generic, anonymous and struct spreads. Below 10.0 the legacy oracle predates spreads.
  • fcs_types_a_legality_gated_file_as_it_does_at_the_features_version has a fixture. The anonymous-record spread is left out of it because FCS's generated anonymous type name differs between 10.0 and 11.0; the check-time fixture covers that spread.
  • Fixtures in diagnostic_classes, facade_properties, and a control in parser_diff_feature_gates (from the support floor) show the tree is the same at every version.

Sema

Sema declines rather than guesses wherever it does not model spreads:

  • Resolution walks each spread's source in source order, with binders inside it interned. It resolves a record type's spread type. FCS-graded in resolve_diff's corpus.
  • The record-label table cannot answer past a spread. A record with a spread may carry any label, and a later spread can replace an explicit field. So every entry the record adds declines, and one more entry answers every label and shadows what it outranks. Without it, p.A after type R = { ...T } would commit to T.A, where FCS says R.A.
    • Systematic test: record_label_gen_diff's generator now spreads records, before or after their own fields. Its model of FCS's table (spread labels declared at the spread's type, and the shadowing rules) agrees with FCS on every probe. A new floor, "winners carrying a spread", is 37 at the default seed against a floor of 15.
    • Removing the wildcard makes the generator fail.
  • Inference reads no field of a record with a spread. infer_project_record_diff gains spread and spreadShadows rows across every placement and receiver context; in spreadShadows the spread replaces an explicit K: string with int. Re-enabling field reads makes that grid fail.
  • Record expressions were already unmodelled in inference.
  • Record fields are not bare-lookup binders, so binder completeness is unaffected. FCS reports the copied fields' definitions at the spread's type.

Manifest movement (every item is a record-spread corpus file)

  • parser_corpus_diff: the 31 spread files leave fcs-normaliser-unmodelled. 30 match FCS.
    • Expression_Anonymous_NestedUpdates.fs briefly read we-reject-fcs-accepts because of the dotted-field error above. It matches now.
    • The tuple-type-extension files and fslib-extra-pervasives.fs stay as they were, for 4b.
  • parser_corpus: the same 31 files leave errors.
  • accessor_coverage: +AnonRecdExpr::spreads, +RecordExpr::spreads, +RecordRepr::spreads, +RecordSpread::expr, +RecordSpreadDecl::ty.
  • version_dependence_census:
    • The spread files are now L (Legality only) at every version below 11.0.
    • RecordSpreads.fsx and the two CoercionsApplied files keep their existing R cells below 8.0, which come from retired features.
  • recovery_sweep: four newly sampled token deletions in spread files.
    • Three are exact or outside-damage.
    • Expression_Nominal_NoOverlap_Spread_Explicit.fs@102 is divergent. It deletes NoComparison from a type's attribute list, the same pre-existing attribute-recovery family as the pinned E_Clashing_Values_in_AbstractClass02.fs@229. It has nothing to do with spreads.
  • resolve_corpus_diff, infer_corpus_diff, attr_resolution_corpus, xml_doc_source_corpus: three spread files move from our-parse-errors to compared, with their attribute uses committed or recorded as assembly-gap, and their bindings agree-none.
  • infer_corpus_dump: the spread files' digests, now that they parse.

Checks

  • fmt, clippy, cargo test, doc with --document-private-items, and the featureless cst clippy/doc pair.
  • Every cst and sema corpus sweep in AGENTS.md's list, and the LSP's parser_corpus_sweep, xml_doc_shipped_sweep and xml_doc_source_diff::corpus.
  • The deep record-label sweep.
  • tools/ci/project-corpus-gate.sh.
  • codex review: no findings.

For PR 5 (publishing v11)

  • v11's surface now differs from v10's by RecordSpread/RecordSpreadDecl and the five accessors, so publishing it writes a distinct facade and consumer fixture, not an alias.
  • Step 4b (tuple-type extensions, preview) leaves v11 alone.

🤖 Generated with Claude Code

Parse `{ ...e; F = x }`, `{| ...e |}` and `type R = { ...T; F: int }`
as FCS does: new kinds `RECORD_SPREAD`, `RECORD_SPREAD_DECL` and the
`DOT_DOT_DOT_TOK` token, with FCS's error forms (a spread with no source,
FS3899/FS3900; `{ ...e with … }`, FS3903, keeping `e` as the copy source;
`...e` anywhere else, FS3902, as an `ERROR` node standing for its
`ArbitraryAfterError`). The `RecordSpreads` row goes live: a parse-phase
`Legality` gate at each spread, held to FCS's check at 10.0.

The union reads spreads through `spreads()` on `RecordExpr`,
`AnonRecdExpr` and `RecordRepr`, each spread with its index among the
bindings. An ordered item enum would put a new enum in every frozen
facade, which astgen blocks; this shape leaves every published lock
byte-identical.

Sema walks each spread's source, resolves a spread type, declines every
record-label answer past a record with a spread (whose labels it does not
read), and reads no field of such a record. The record-label generator
now spreads records, and the record inference grid and the resolution
corpus hold the declines to FCS.

FCS's parser accepts a dotted field in an anonymous record's
construction, so the parse error for one is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Smaug123
Smaug123 enabled auto-merge November 15, 2026 14:51
@Smaug123
Smaug123 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit e0dc0df Nov 15, 2026
19 checks passed
@Smaug123
Smaug123 deleted the claude/record-spreads branch November 15, 2026 15:51
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.

1 participant