Skip to content
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

Mark backing fields as CompilerGenerated (fixes serialization of fields in FSI multiemit) #13494

Merged
merged 4 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion VisualFSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Test.Utilities", "tests\FSharp.Test.Utilities\FSharp.Test.Utilities.fsproj", "{60D275B0-B14A-41CB-A1B2-E815A7448FCB}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharpSuite.Tests", "tests\fsharp\FSharpSuite.Tests.fsproj", "{C163E892-5BF7-4B59-AA99-B0E8079C67C4}"
ProjectSection(ProjectDependencies) = postProject
{0973C362-585C-4838-9459-D7E45C6B784B} = {0973C362-585C-4838-9459-D7E45C6B784B}
{37EB3E54-ABC6-4CF5-8273-7CE4B61A42C1} = {37EB3E54-ABC6-4CF5-8273-7CE4B61A42C1}
{511C95D9-3BA6-451F-B6F8-F033F40878A5} = {511C95D9-3BA6-451F-B6F8-F033F40878A5}
{597D9896-4B90-4E9E-9C99-445C2CB9FF60} = {597D9896-4B90-4E9E-9C99-445C2CB9FF60}
{E54456F4-D51A-4334-B225-92EBBED92B40} = {E54456F4-D51A-4334-B225-92EBBED92B40}
{EB015235-1E07-4CDA-9CC6-3FBCC27910D1} = {EB015235-1E07-4CDA-9CC6-3FBCC27910D1}
EndProjectSection
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.UnitTests", "tests\FSharp.Compiler.UnitTests\FSharp.Compiler.UnitTests.fsproj", "{A8D9641A-9170-4CF4-8FE0-6DB8C134E1B5}"
EndProject
Expand Down Expand Up @@ -149,8 +157,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Service", "
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Compiler.Service.Tests", "tests\FSharp.Compiler.Service.Tests\FSharp.Compiler.Service.Tests.fsproj", "{14F3D3D6-5C8E-43C2-98A2-17EA704D4DEA}"
ProjectSection(ProjectDependencies) = postProject
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B} = {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}
{887630A3-4B1D-40EA-B8B3-2D842E9C40DB} = {887630A3-4B1D-40EA-B8B3-2D842E9C40DB}
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B} = {FF76BD3C-5E0A-4752-B6C3-044F6E15719B}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualFSharpDebug", "vsintegration\Vsix\VisualFSharpFull\VisualFSharpDebug.csproj", "{A422D673-8E3B-4924-821B-DD3174173426}"
Expand Down
8 changes: 5 additions & 3 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,15 +2073,16 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu
mkILFields
[
for _, fldName, fldTy in flds ->
// Don't hide fields when splitting to multiple assemblies.

let access =
if cenv.options.isInteractive && cenv.options.fsiMultiAssemblyEmit then
ILMemberAccess.Public
else
ILMemberAccess.Private

let fdef = mkILInstanceField (fldName, fldTy, None, access)
fdef.With(customAttrs = mkILCustomAttrs [ g.DebuggerBrowsableNeverAttribute ])
let attrs = [ g.CompilerGeneratedAttribute; g.DebuggerBrowsableNeverAttribute ]
fdef.With(customAttrs = mkILCustomAttrs attrs)
]

// Generate property definitions for the fields compiled as properties
Expand Down Expand Up @@ -10676,7 +10677,8 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =

let extraAttribs =
match tyconRepr with
| TFSharpRecdRepr _ when not useGenuineField -> [ g.DebuggerBrowsableNeverAttribute ] // hide fields in records in debug display
| TFSharpRecdRepr _ when not useGenuineField ->
[ g.CompilerGeneratedAttribute; g.DebuggerBrowsableNeverAttribute ]
| _ -> [] // don't hide fields in classes in debug display

let access = ComputeMemberAccess isFieldHidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field assembly int32 key1@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field assembly int32 key2@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_key1() cil managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field assembly int32 key1@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field assembly int32 key2@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_key1() cil managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field assembly int32 key1@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field assembly int32 key2@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_key1() cil managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field private !'<A>j__TPar' A@
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field private !'<B>j__TPar' B@
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [mscorlib]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [mscorlib]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public specialname rtspecialname
instance void .ctor(!'<A>j__TPar' A,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field assembly int32 x@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field assembly int32 y@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_x() cil managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field assembly int32 x@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field assembly int32 y@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_x() cil managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field public int32 x@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field public int32 y@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_x() cil managed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 02 00 00 00 00 00 )
.field public int32 x@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.field public int32 y@
.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.custom instance void [System.Runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [System.Runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 )
.method public hidebysig specialname
instance int32 get_x() cil managed
Expand Down
4 changes: 2 additions & 2 deletions tests/FSharp.Test.Utilities/TestFramework.fs
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ let diff normalize path1 path2 =
if x >= 0 then line.Substring(x+cwd.Length) else line
else line

let line1 = normalizePath lines1[i]
let line2 = normalizePath lines2[i]
let line1 = lines1[i] |> normalizePath
let line2 = lines2[i] |> normalizePath

if line1 <> line2 then
append <| sprintf "diff between [%s] and [%s]" path1 path2
Expand Down
53 changes: 53 additions & 0 deletions tests/fsharp/core/printing/output.1000.stdout.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -2764,4 +2764,57 @@ val ShortName: string = "hi"

> val list2: int list = [1]

module FSI_0317.
D27805741a339047ef3ed7a2ca8faae3c17e6ef2371984011e49a6c9c3286641

{"ImmutableField0":6}
type R1 =
{ ImmutableField0: int }
val it: unit = ()

> val it: R1 = { ImmutableField0 = 7 }

> {"MutableField1":8}
type R2 =
{ mutable MutableField1: int }
val it: unit = ()

> val it: R2 = { MutableField1 = 9 }

> {"AnonRecordField2":10}
val it: unit = ()

> val it: {| AnonRecordField2: int |} = { AnonRecordField2 = 11 }

module FSI_0324.Project.fsproj

type R3 =
{ ImmutableField3: int }
val test3a: string = "{"ImmutableField3":12}"

> val test3b: R3 = { ImmutableField3 = 12 }

> val test3c: string = "{"ImmutableField3":13}"

> val test3d: R3 = { ImmutableField3 = 13 }

> type R4 =
{ mutable MutableField4: int }
val test4a: string = "{"MutableField4":15}"

> val test4b: R4 = { MutableField4 = 15 }

> val test4c: string = "{"MutableField4":16}"

> val test4d: R4 = { MutableField4 = 16 }

> type R5 = {| AnonRecordField5: int |}
val test5a: string = "{"AnonRecordField5":17}"

> val test5b: R5 = { AnonRecordField5 = 17 }

> val test5c: string = "{"AnonRecordField5":18}"

> val test5d: R5 = { AnonRecordField5 = 18 }

> > >
53 changes: 53 additions & 0 deletions tests/fsharp/core/printing/output.200.stdout.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -2009,4 +2009,57 @@ val ShortName: string = "hi"

> val list2: int list = [1]

module FSI_0317.
D27805741a339047ef3ed7a2ca8faae3c17e6ef2371984011e49a6c9c3286641

{"ImmutableField0":6}
type R1 =
{ ImmutableField0: int }
val it: unit = ()

> val it: R1 = { ImmutableField0 = 7 }

> {"MutableField1":8}
type R2 =
{ mutable MutableField1: int }
val it: unit = ()

> val it: R2 = { MutableField1 = 9 }

> {"AnonRecordField2":10}
val it: unit = ()

> val it: {| AnonRecordField2: int |} = { AnonRecordField2 = 11 }

module FSI_0324.Project.fsproj

type R3 =
{ ImmutableField3: int }
val test3a: string = "{"ImmutableField3":12}"

> val test3b: R3 = { ImmutableField3 = 12 }

> val test3c: string = "{"ImmutableField3":13}"

> val test3d: R3 = { ImmutableField3 = 13 }

> type R4 =
{ mutable MutableField4: int }
val test4a: string = "{"MutableField4":15}"

> val test4b: R4 = { MutableField4 = 15 }

> val test4c: string = "{"MutableField4":16}"

> val test4d: R4 = { MutableField4 = 16 }

> type R5 = {| AnonRecordField5: int |}
val test5a: string = "{"AnonRecordField5":17}"

> val test5b: R5 = { AnonRecordField5 = 17 }

> val test5c: string = "{"AnonRecordField5":18}"

> val test5d: R5 = { AnonRecordField5 = 18 }

> > >
108 changes: 108 additions & 0 deletions tests/fsharp/core/printing/output.47.stderr.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,111 @@ stdin(838,6): error FS1210: Active pattern '|A|B|' has a result type containing

stdin(844,6): error FS1209: Active pattern '|A|B|' is not a function


#r "nuget:Newtonsoft.Json, 13.0.1"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(1117,1): error FS3302: The 'package management' feature requires language version 5.0 or above


JsonConvert.SerializeObject { ImmutableField0 = 7 }
^^^^^^^^^^^

stdin(1122,1): error FS0039: The value, namespace, type or module 'JsonConvert' is not defined.


JsonConvert.SerializeObject { MutableField1 = 8 } |> printfn "%s";;
^^^^^^^^^^^

stdin(1126,1): error FS0039: The value, namespace, type or module 'JsonConvert' is not defined.


JsonConvert.SerializeObject { MutableField1 = 9 }
^^^^^^^^^^^

stdin(1128,1): error FS0039: The value, namespace, type or module 'JsonConvert' is not defined.


JsonConvert.SerializeObject {| AnonRecordField2 = 10 |} |> printfn "%s";;
^^^^^^^^^^^

stdin(1131,1): error FS0039: The value, namespace, type or module 'JsonConvert' is not defined.


JsonConvert.SerializeObject {| AnonRecordField2 = 11 |}
^^^^^^^^^^^

stdin(1133,1): error FS0039: The value, namespace, type or module 'JsonConvert' is not defined.


#r "nuget: System.Text.Json"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(1136,1): error FS3302: The 'package management' feature requires language version 5.0 or above


let test3b = JsonSerializer.Deserialize<R3> test3a;;
-------------^^^^^^^^^^^^^^

stdin(1140,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test3c = JsonSerializer.Serialize { ImmutableField3 = 13 };;
-------------^^^^^^^^^^^^^^

stdin(1141,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test3d = JsonSerializer.Deserialize<R3> test3c;;
-------------^^^^^^^^^^^^^^

stdin(1142,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test4a = JsonSerializer.Serialize { MutableField4 = 15 };;
-------------^^^^^^^^^^^^^^

stdin(1145,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test4b = JsonSerializer.Deserialize<R4> test4a;;
-------------^^^^^^^^^^^^^^

stdin(1146,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test4c = JsonSerializer.Serialize { MutableField4 = 16 };;
-------------^^^^^^^^^^^^^^

stdin(1147,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test4d = JsonSerializer.Deserialize<R4> test4c;;
-------------^^^^^^^^^^^^^^

stdin(1148,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test5a = JsonSerializer.Serialize {| AnonRecordField5 = 17 |};;
-------------^^^^^^^^^^^^^^

stdin(1151,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test5b = JsonSerializer.Deserialize<R5> test5a;;
-------------^^^^^^^^^^^^^^

stdin(1152,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test5c = JsonSerializer.Serialize {| AnonRecordField5 = 18 |};;
-------------^^^^^^^^^^^^^^

stdin(1153,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.


let test5d = JsonSerializer.Deserialize<R5> test5c;;
-------------^^^^^^^^^^^^^^

stdin(1154,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined.

2 changes: 1 addition & 1 deletion tests/fsharp/core/printing/output.47.stdout.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -6309,4 +6309,4 @@ val ShortName: string = "hi"

> val list2: int list = [1]

> > >
> > > > > > > > > > > > > > > > > > > > >
Loading