Refactoring between reference and struct anonymous records - #20549
Open
xperiandri wants to merge 8 commits into
Open
xperiandri wants to merge 8 commits into
xperiandri wants to merge 8 commits into
Conversation
Ctrl+. on a tuple expression, pattern or annotated tuple type converts it to the other kind and follows the value through the solution: annotations of values, parameters, record fields and function results it flows through, tuple patterns taking it apart, and the arguments and values flowing into it. Uses that cannot be followed (fst, snd, generic collections) are left for the compiler to report. CreateWithCodeAndDependency now tells FCS about both files, so the second file can be type-checked. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adding the second document to a single-file solution left Find All References unable to see either file, so a chain through a function's call sites stopped at the first file. The synthetic project gives both files to the checker the way AddReturnTypeTests and FindReferencesTests set up theirs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The synthetic project's checker reads the other file from disk, so checking the refactored document saw the old definition; a struct tuple pattern happens to accept a reference tuple, which hid that. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Ctrl+. inside an anonymous record expression or an annotated anonymous
record type converts it between {| ... |} and struct {| ... |}, following
the value through the solution like the tuple refactoring. A
copy-and-update has its own form and converts independently of its
source.
The propagation engine becomes independent of the kind of node:
StructConversion holds the shared caret search and the StructKind
description, TupleConversion and AnonymousRecordConversion are the two
kinds, and StructPropagation (was TuplePropagation) takes a kind and
registers the code action for both providers.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
…ents with their calls The only argument of a member or constructor is its parameter list, not a tuple, so it is no longer offered. A tuple that is a whole curried argument of a function or member now converts the matching argument at every call, and `struct` no longer runs into a name the parenthesis follows (`f(a, b)`). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ents with their calls The only argument of a member or constructor is its parameter list, not a tuple, so it is no longer offered. A tuple that is a whole curried argument of a function or member now converts the matching argument at every call, and `struct` no longer runs into a name the parenthesis follows (`f(a, b)`). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…s-record-struct-refactoring # Conflicts: # vsintegration/src/FSharp.Editor/Refactor/StructPropagation.fs # vsintegration/src/FSharp.Editor/Refactor/TupleConversion.fs
…e of its section Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 14, 2026
xperiandri
marked this pull request as ready for review
September 14, 2026 19:40
Contributor
|
🔍 Tooling Safety Check — Affects-Design-Time
|
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.
Description
Stacked on #20548: this branch contains its commits; the anonymous record commits on top of them (and the merge bringing #20548's latest changes) belong to this PR.
Adds an editor refactoring (
Ctrl+.inside an anonymous record expression or an annotated anonymous record type) that converts it between{| … |}andstruct {| … |}, following its value through the solution the same way #20548 does for tuples:⟷
What differs from tuples. Both forms differ only by
structin front of{|, so every change is an insertion or a removal of that keyword; there are no anonymous record patterns, and reading a field (r.Name) does not depend on the form. A copy-and-update{| r with … |}has its own form regardless ofr's (the checker does not carry it over), so it converts independently: convertingrleaves the copy alone, and converting the copy leavesralone.Engine. The propagation from #20548 is made independent of the kind of node:
StructConversion.fs— the shared caret search and aStructKindrecord describing how a kind is recognized in expressions, patterns and types and how its form changes;TupleConversion.fsandAnonymousRecordConversion.fs— the two kinds;StructPropagation.fs(wasTuplePropagation.fs) — the worklist over values, parameters, record fields and results, taking aStructKind, plusregisterConversion, which both providers now call.The tuple refactoring's behaviour and tests are unchanged.
Not offered inside quotations or in a file with a paired
.fsi.Covered cases
Converts
printfn "%A" {| A = 1 |}→printfn "%A" struct {| A = 1 |}; a type argumentlist<{| A: int |}>→list<struct {| A: int |}>; a multi-line{|…|}→struct {|…|}let person = {| Name = "Ada"; Age = 36 |}+let copy: {| Name: string; Age: int |} = person+person.Age→struct {| Name = "Ada"; Age = 36 |}+let copy: struct {| Name: string; Age: int |} = personlet greet (p: {| Name: string |})+let ada = {| Name = "Ada" |}+greet ada; greet {| Name = "Bob" |}→let greet (p: struct {| Name: string |})+let ada = struct {| Name = "Ada" |}+greet struct {| Name = "Bob" |}let origin () : {| X: int; Y: int |} = {| X = 0; Y = 0 |}+let start: {| X: int; Y: int |} = origin ()→struct {| X: int; Y: int |}in all three places{ Info: {| Age: int |}; Tags: {| Count: int |} }+{ Info = {| Age = 30 |}; Tags = {| Count = 0 |} }+let info: {| Age: int |} = person.Info→ onlyInfobecomesstruct {| Age: int |},struct {| Age = 30 |}andlet info: struct {| Age: int |};Tagsis not changedlet point = {| X = 1 |}givesstruct {| X = 1 |}and leaves{| point with Y = 2 |}alone; the caret onwithgivesstruct {| point with Y = 2 |}and leavespointalonelet name (p: {| Name: string |})+name A.personin moduleBalso rewriteslet person = {| Name = "Ada" |}inAtostruct {| Name = "Ada" |}; the result is checked as a new project and has no errorsConvert to struct anonymous recordandConvert to reference anonymous recordNot offered
let x = 1type Point = { X: int }+let point = { X = 1 }<@ {| A = 1 |} @>Checklist
🤖 Generated with Claude Code