Repository navigation
Add a refactoring between reference and struct anonymous records - #20549
xperiandri wants to merge 17 commits into
Conversation
✅ Release notes checked
|
This comment has been minimized.
This comment has been minimized.
Covered casesConverts
Not offered
|
T-Gro
left a comment
There was a problem hiding this comment.
🤖 🕵️ AI review — verify independently.
| useSource | ||
| (List.item index exprs) | ||
| (SyntaxNode.SynExpr tuple :: SyntaxNode.SynExpr argument :: argumentPath) | ||
| | ValueSome(struct (argument, argumentPath)), ValueNone -> this.Retarget useSource argument argumentPath |
There was a problem hiding this comment.
🤖 🕵️ Converting a also converts the independent b argument, producing FS0001 against its explicit reference-record type.
module M
let identity<'T> (x: 'T) = x
let a = identity {| A = 1 |} // Invoke conversion on A = 1.
let b = identity<{| B: int |}> {| B = 2 |}There was a problem hiding this comment.
Fixed in 3021452: propagation stops at a parameter, result or value whose declared type involves a generic type parameter, so converting a leaves b alone. Test: Generic parameter stops the conversion.
There was a problem hiding this comment.
🤖🕵️ New alias forwarding bypasses the fixed generic boundary and converts independent b, producing FS0001.
let identity<'T> (x: 'T) = x
let alias = identity
let a = alias {| A = 1 |} // Convert this record to struct.
let b: {| B: int |} = alias {| B = 2 |}There was a problem hiding this comment.
Fixed in d623b91: isGenericParameter reads the parameter type from the alias's own function type when the alias has no parameter list (let alias = identity), so converting a leaves b alone. Test: this input as a row of Generic parameter stops the conversion; it failed with FS0001 before.
| match isStruct, toStruct with | ||
| | true, true | ||
| | false, false -> [] | ||
| | false, true -> [ TextChange(TextSpan((spanOf sourceText m).Start, 0), "struct ") ] |
There was a problem hiding this comment.
🤖 🕵️ Converting this valid adjacent application produces idstruct {| A = 1 |}, causing FS0039.
module M
let x = id{| A = 1 |} // Invoke conversion on A = 1.There was a problem hiding this comment.
Fixed in 3021452: struct inserted before {| gets a leading space after an identifier character (by the lexer's categories) or a closing bracket, using the helper shared with tuples. Test: Struct keyword is separated from a name the record follows (id{| A = 1 |} and a name ending in U+0301).
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Ctrl+. inside an anonymous record expression or annotated type converts
it between {| ... |} and struct {| ... |}, following the value through
the solution; the propagation engine is shared with the tuple
refactoring. From dotnet#20549 (release note left out:
18.vNext.md has local edits).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ents with their calls From dotnet#20548 and dotnet#20549. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…et#20549) up to their pull request heads Their calls to SymbolHelpers.getSymbolUses ask for RelatedSymbolUseKind.AllInCode, as the XML doc rename work on this branch requires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…annotated patterns The conversion now also follows a tuple through - a function in parentheses, `(sum) (1, 2)`; - a name bound to a lambda, its parameters and its result; - a function alias and a partial application, `let alias = make`; - a named argument, `M(p = pair)`; - an annotated tuple pattern, `((a, b): int * int)`, from the pattern, the annotation or the value; - a value whose binding head is in parentheses, `let (pair: int * int) = (1, 2)`. It is no longer offered where the result cannot compile or nothing would change: - on the annotation of a member's only argument, which is its parameter list; - on the argument of a union case whose only field is declared a tuple; - on the argument of a method in parentheses, `(c.Add) (1, 2)`; - on a tuple over several lines without parentheses, which cannot change in place. `struct` is kept apart from type arguments the parenthesis follows: `f<int> struct (1, 2)`. This is b7bc303 of dotnet#20548 as dotnet#20549 merged it (3abaa70) into the engine both kinds share: `StructConversion.fs` and `StructPropagation.fs` take what went into `TupleConversion.fs` and `TuplePropagation.fs` there. A member's parameter list is told by the kind, so the annotation of a member's only argument stays convertible for an anonymous record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port of the dotnet#20549 compaction (feature/anonymous-record-struct-refactoring 4c7066a..5be006c) to all-fixes. The range includes the pull request's merge of the compacted tuple refactoring (dotnet#20548), so this one commit covers both pull requests: all-fixes has the generalized engine of dotnet#20549 (StructPropagation.fs, TupleConversion.fs as a kind of that engine) and no TuplePropagation.fs, and the merge kept that layout. - dotnet#20548: Compact the tuple refactoring sources - dotnet#20548: Share the cross-file refactoring test setup - dotnet#20549: Compact the shared struct conversion sources - dotnet#20549: Share the cross-file test setup of the conversion tests StructPropagation.fs reads the related uses once now (ForEachUse) and keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs there. RefactorTestFramework.fs merges the pull request's helpers with those of the Extract suites that the earlier commits of this series put there. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
0fe03f4 to
f82e448
Compare
Ctrl+. inside an anonymous record expression or annotated type converts
it between {| ... |} and struct {| ... |}, following the value through
the solution; the propagation engine is shared with the tuple
refactoring. From dotnet#20549 (release note left out:
18.vNext.md has local edits).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ents with their calls From dotnet#20548 and dotnet#20549. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…et#20549) up to their pull request heads Their calls to SymbolHelpers.getSymbolUses ask for RelatedSymbolUseKind.AllInCode, as the XML doc rename work on this branch requires. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…annotated patterns The conversion now also follows a tuple through - a function in parentheses, `(sum) (1, 2)`; - a name bound to a lambda, its parameters and its result; - a function alias and a partial application, `let alias = make`; - a named argument, `M(p = pair)`; - an annotated tuple pattern, `((a, b): int * int)`, from the pattern, the annotation or the value; - a value whose binding head is in parentheses, `let (pair: int * int) = (1, 2)`. It is no longer offered where the result cannot compile or nothing would change: - on the annotation of a member's only argument, which is its parameter list; - on the argument of a union case whose only field is declared a tuple; - on the argument of a method in parentheses, `(c.Add) (1, 2)`; - on a tuple over several lines without parentheses, which cannot change in place. `struct` is kept apart from type arguments the parenthesis follows: `f<int> struct (1, 2)`. This is b7bc303 of dotnet#20548 as dotnet#20549 merged it (3abaa70) into the engine both kinds share: `StructConversion.fs` and `StructPropagation.fs` take what went into `TupleConversion.fs` and `TuplePropagation.fs` there. A member's parameter list is told by the kind, so the annotation of a member's only argument stays convertible for an anonymous record. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port of the dotnet#20549 compaction (feature/anonymous-record-struct-refactoring 4c7066a..5be006c) to all-fixes. The range includes the pull request's merge of the compacted tuple refactoring (dotnet#20548), so this one commit covers both pull requests: all-fixes has the generalized engine of dotnet#20549 (StructPropagation.fs, TupleConversion.fs as a kind of that engine) and no TuplePropagation.fs, and the merge kept that layout. - dotnet#20548: Compact the tuple refactoring sources - dotnet#20548: Share the cross-file refactoring test setup - dotnet#20549: Compact the shared struct conversion sources - dotnet#20549: Share the cross-file test setup of the conversion tests StructPropagation.fs reads the related uses once now (ForEachUse) and keeps the RelatedSymbolUseKind.AllInCode argument that all-fixes needs there. RefactorTestFramework.fs merges the pull request's helpers with those of the Extract suites that the earlier commits of this series put there. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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>
…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>
…e of its section Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…y and match aliases A parenthesized tuple applied to a method, a constructor or a union case of several fields is an argument list however the call is spaced. Results flow through try/finally and try/with, a match clause that names the value passes it on, and removing `struct` from a type keeps a comment before its parenthesis. `struct` is kept apart from a name ending in any identifier character the lexer accepts, combining marks included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…annotated patterns The conversion now also follows a tuple through - a function in parentheses, `(sum) (1, 2)`; - a name bound to a lambda, its parameters and its result; - a function alias and a partial application, `let alias = make`; - a named argument, `M(p = pair)`; - an annotated tuple pattern, `((a, b): int * int)`, from the pattern, the annotation or the value; - a value whose binding head is in parentheses, `let (pair: int * int) = (1, 2)`. It is no longer offered where the result cannot compile or nothing would change: - on the annotation of a member's only argument, which is its parameter list; - on the argument of a union case whose only field is declared a tuple; - on the argument of a method in parentheses, `(c.Add) (1, 2)`; - on a tuple over several lines without parentheses, which cannot change in place. `struct` is kept apart from type arguments the parenthesis follows: `f<int> struct (1, 2)`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Delete the comments the code says by itself and name what they described, share the edit code of tuple expressions and patterns, share the use scan of the propagation engine and keep every function at three nested levels or fewer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Move the test helpers into RefactorTestFramework, let them add the module M wrapper and run the two-file refactoring with its re-check as a new project, and assert both directions of a conversion in one helper. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replaying the branch onto main left some files short of the branch's own content; this restores it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A value bound by `(a, b) as alias` reaches the tuple pattern and the alias alike: the conversion now follows the value into both sides of the as pattern, from the value, from either side, and through a parameter, so neither side keeps the old tuple kind (FS0001). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
An annotation such as `Pair` for `type Pair = int * int` is a contract the conversion cannot rewrite, and converting around it gave FS0001. The checker resolves the annotation; when it abbreviates a tuple the conversion fails. The conversion now runs before the action is offered, so a failed conversion offers no action instead of one that changes nothing. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The tuple and anonymous record conversions now share one engine. The branch carried copies of the commits of the tuple branch and of several commits of main, so its history is rebuilt as this one commit on top of the tuple branch. It holds the refactoring, the shared engine with the review fixes, and the compaction made since they were first written.
The shared engine converts a record bound through `as` on both sides and withholds the conversion when the record passes an annotation that abbreviates an anonymous record, as it does for tuples. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`let alias = identity` has no parameter list of its own, so the generic boundary missed its `'T` parameter and converting one call of the alias converted every other, unrelated call (FS0001). The parameter type now comes from the alias's function type when it has no parameter list. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
In `p <- q` the value of `q` flows into `p`. Converting either side missed the assignment and left the other with the old kind (FS0001): the conversion now follows the assignment from the variable to the assigned value and back. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Converting `p: int * int` reaches an unparenthesized tuple over several lines that cannot be rewritten in place. The action used to be offered and then change nothing; since the conversion runs before the action is offered, no action is offered. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
f82e448 to
ede89e3
Compare
Stacked on #20548.
Offers
Ctrl+.to switch between{| … |}andstruct {| … |}, following the value the same way as the tuple refactoring. A copy-and-update{| r with … |}has its own form, so it converts independently ofr.🤖 Generated with Claude Code