-
Notifications
You must be signed in to change notification settings - Fork 830
Typar name signature data #15003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Typar name signature data #15003
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
97f3d0a
Add failing unit test to illustrate problem.
nojaf 03085c3
Ensure that the signature file typar name is preserved.
nojaf 2e90785
Extract code to separate module.
nojaf d6b30e0
Pretty name typars after checking signature file.
nojaf f06db6c
Consider TypeCheckingMode.Graph to be deterministic for now.
nojaf ccf2fb0
FSharpGenericParameter has a name now.
nojaf 2d1c7aa
Update FSharp.Core Debug SurfaceArea.
nojaf b801f3c
Add surface from Ubuntu
nojaf 65b6cf9
Add extra unit test.
nojaf 89a8661
Update FSharp.Core surface area for netstandard2.0
nojaf 309111d
Update FSharp.Core surface area for netstandard2.0 DEBUG
nojaf 1fc852d
Merge branch 'main' into typar-name-signature-data
nojaf b84896b
Merge branch 'main' into typar-name-signature-data
nojaf 1e08652
Add space in unit test name.
nojaf abe7729
Merge branch 'typar-name-signature-data' of https://github.com/nojaf/…
nojaf 1c053b2
Merge branch 'main' into typar-name-signature-data
nojaf 7e91aa3
Merge branch 'main' into typar-name-signature-data
nojaf 7945f36
Merge branch 'main' into typar-name-signature-data
nojaf ad3fb61
Change order of functions.
nojaf c20267b
Merge branch 'main' into typar-name-signature-data
nojaf 23a0ef5
Merge branch 'main' into typar-name-signature-data
nojaf b2979a8
Merge branch 'main' into typar-name-signature-data
nojaf b2ba853
Merge branch 'main' into typar-name-signature-data
nojaf ae5fd7f
Merge branch 'main' into typar-name-signature-data
nojaf cbde066
Extract AssignPrettyTyparNames
nojaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /// The Typars of a Val in the signature data should also be pretty named. | ||
| /// This will happen for the implementation file contents, but not for the signature data. | ||
| /// In this module some helpers will traverse the ModuleOrNamespaceType and update all the typars of each found Val. | ||
| module internal FSharp.Compiler.UpdatePrettyTyparNames | ||
|
|
||
| open Internal.Utilities.Library | ||
| open FSharp.Compiler.TypedTree | ||
| open FSharp.Compiler.TypedTreeOps | ||
|
|
||
| let updateVal (v: Val) = | ||
| if not (List.isEmpty v.Typars) then | ||
| let nms = PrettyTypes.PrettyTyparNames (fun _ -> true) List.empty v.Typars | ||
| PrettyTypes.AssignPrettyTyparNames v.Typars nms | ||
|
|
||
| let rec updateEntity (entity: Entity) = | ||
| for e in entity.ModuleOrNamespaceType.AllEntities do | ||
| updateEntity e | ||
|
|
||
| for v in entity.ModuleOrNamespaceType.AllValsAndMembers do | ||
| updateVal v | ||
|
|
||
| let updateModuleOrNamespaceType (signatureData: ModuleOrNamespaceType) = | ||
| for e in signatureData.ModuleAndNamespaceDefinitions do | ||
| updateEntity e |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /// The Typars of a Val in the signature data should also be pretty named. | ||
| /// This will happen for the implementation file contents, but not for the signature data. | ||
| /// In this module some helpers will traverse the ModuleOrNamespaceType and update all the typars of each found Val. | ||
| module internal FSharp.Compiler.UpdatePrettyTyparNames | ||
|
|
||
| open FSharp.Compiler.TypedTree | ||
|
|
||
| val updateModuleOrNamespaceType: signatureData: ModuleOrNamespaceType -> unit |
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
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
142 changes: 142 additions & 0 deletions
142
tests/FSharp.Compiler.ComponentTests/TypeChecks/TyparNameTests.fs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| module FSharp.Compiler.ComponentTests.TypeChecks.TyparNameTests | ||
|
|
||
| open FSharp.Compiler.Symbols | ||
| open Xunit | ||
| open FSharp.Test | ||
| open FSharp.Test.Compiler | ||
|
|
||
| let private getGenericParametersNamesFor | ||
| (cUnit: CompilationUnit) | ||
| (entityDisplayName: string) | ||
| (valueDisplayName: string) | ||
| (additionalFile: SourceCodeFileKind) | ||
| : string array = | ||
| let typeCheckResult = | ||
| cUnit |> withAdditionalSourceFile additionalFile |> typecheckProject | ||
|
|
||
| assert (Array.isEmpty typeCheckResult.Diagnostics) | ||
|
|
||
| typeCheckResult.AssemblySignature.Entities | ||
| |> Seq.tryPick (fun (entity: FSharpEntity) -> | ||
| if entity.DisplayName <> entityDisplayName then | ||
| None | ||
| else | ||
| entity.MembersFunctionsAndValues | ||
| |> Seq.tryFind (fun mfv -> mfv.DisplayName = valueDisplayName) | ||
| |> Option.map (fun (mfv: FSharpMemberOrFunctionOrValue) -> | ||
| mfv.GenericParameters |> Seq.map (fun gp -> gp.DisplayName) |> Seq.toArray)) | ||
| |> Option.defaultValue Array.empty | ||
|
|
||
| [<Fact>] | ||
| let ``The call site of a generic function should have no influence on the name of the type parameters`` () = | ||
| let definitionFile = | ||
| Fs | ||
| """ | ||
| module A | ||
|
|
||
| let someGenericFunction _ = () | ||
| """ | ||
| |> withFileName "A.fs" | ||
|
|
||
| let usageFile = | ||
| (""" | ||
| module B | ||
|
|
||
| let otherGenericFunction _ _ _ = | ||
| A.someGenericFunction 1 | ||
| """ | ||
| |> FsSource) | ||
| .WithFileName("B.fs") | ||
|
|
||
| let namesForB = | ||
| getGenericParametersNamesFor definitionFile "A" "someGenericFunction" usageFile | ||
|
|
||
| let alternativeUsageFile = | ||
| (""" | ||
| module C | ||
|
|
||
| let alternateGenericFunction _ = | ||
| A.someGenericFunction 1 | ||
| """ | ||
| |> FsSource) | ||
| .WithFileName("C.fs") | ||
|
|
||
| let namesForC = | ||
| getGenericParametersNamesFor definitionFile "A" "someGenericFunction" alternativeUsageFile | ||
|
|
||
| Assert.Equal<string array>(namesForB, namesForC) | ||
|
|
||
| [<Fact>] | ||
| let ``Fixed typar name in signature file is still respected`` () = | ||
| let signatureFile = | ||
| Fsi | ||
| """ | ||
| module A | ||
|
|
||
| val someGenericFunction: 'x -> unit | ||
| """ | ||
| |> withFileName "A.fsi" | ||
|
|
||
| let implementationFile = | ||
| (""" | ||
| module A | ||
|
|
||
| let someGenericFunction _ = () | ||
| """ | ||
| |> FsSource) | ||
| .WithFileName("A.fs") | ||
|
|
||
| let names = | ||
| getGenericParametersNamesFor signatureFile "A" "someGenericFunction" implementationFile | ||
|
|
||
| Assert.Equal<string array>([| "x" |], names) | ||
|
|
||
| [<Fact>] | ||
| let ``Hash constraint typar in signature file gets pretty name`` () = | ||
| let signatureFile = | ||
| Fsi | ||
| """ | ||
| module A | ||
|
|
||
| val someGenericFunction: #exn list -> unit | ||
| """ | ||
| |> withFileName "A.fsi" | ||
|
|
||
| let implementationFile = | ||
| (""" | ||
| module A | ||
|
|
||
| let someGenericFunction (_ : #exn list) = () | ||
| """ | ||
| |> FsSource) | ||
| .WithFileName("A.fs") | ||
|
|
||
| let names = | ||
| getGenericParametersNamesFor signatureFile "A" "someGenericFunction" implementationFile | ||
|
|
||
| Assert.Equal<string array>([| "a" |], names) | ||
|
|
||
| [<Fact>] | ||
| let ``Hash constraint with generic type parameter should have pretty name`` () = | ||
| let signatureFile = | ||
| Fsi | ||
| """ | ||
| module A | ||
|
|
||
| val array2D: rows: seq<#seq<'T>> -> 'T[,] | ||
| """ | ||
| |> withFileName "A.fsi" | ||
|
|
||
| let implementationFile = | ||
| (""" | ||
| module A | ||
|
|
||
| let array2D (rows: seq<#seq<'T>>) : 'T[,] = failwith "todo" | ||
| """ | ||
| |> FsSource) | ||
| .WithFileName("A.fs") | ||
|
|
||
| let names = | ||
| getGenericParametersNamesFor signatureFile "A" "array2D" implementationFile | ||
|
|
||
| Assert.Equal<string array>([| "a"; "T" |], names) |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.