From d0fe080bba47128f3f1dd56605bfe08c33baae5d Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Jul 2022 22:03:45 +0100 Subject: [PATCH 1/4] mark backing fields as compiler generated --- VisualFSharp.sln | 10 +- src/Compiler/CodeGen/IlxGen.fs | 15 ++- src/Compiler/Interactive/fsi.fs | 12 +- tests/FSharp.Test.Utilities/TestFramework.fs | 4 +- .../core/printing/output.1000.stdout.bsl | 53 +++++++++ .../core/printing/output.200.stdout.bsl | 53 +++++++++ .../fsharp/core/printing/output.47.stderr.bsl | 108 ++++++++++++++++++ .../fsharp/core/printing/output.47.stdout.bsl | 2 +- .../core/printing/output.multiemit.stdout.bsl | 53 +++++++++ .../core/printing/output.off.stdout.bsl | 53 +++++++++ .../core/printing/output.quiet.stdout.bsl | 3 + tests/fsharp/core/printing/output.stdout.bsl | 53 +++++++++ tests/fsharp/core/printing/test.fsx | 40 +++++++ tests/fsharp/tests.fs | 11 +- 14 files changed, 453 insertions(+), 17 deletions(-) diff --git a/VisualFSharp.sln b/VisualFSharp.sln index c99c08c29c5..fa4c376c818 100644 --- a/VisualFSharp.sln +++ b/VisualFSharp.sln @@ -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 @@ -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}" diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index c39508fc595..6362c3f7b09 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -2073,7 +2073,7 @@ 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 @@ -2081,7 +2081,12 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu 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 @@ -10676,7 +10681,11 @@ 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 diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index 936343a7036..ad84394be1c 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -367,12 +367,12 @@ type ILMultiInMemoryAssemblyEmitEnv( emEnv.AddTypeDef asm ilScopeRef (enc@[tdef]) ntdef // Record the internal things to give warnings for internal access across fragment boundaries - for fdef in tdef.Fields.AsList() do - match fdef.Access with - | ILMemberAccess.Public -> () - | _ -> - let lfref = mkRefForILField ILScopeRef.Local (enc, tdef) fdef - internalFields.Add(lfref) |> ignore + //for fdef in tdef.Fields.AsList() do + // match fdef.Access with + // | ILMemberAccess.Public -> () + // | _ -> + // let lfref = mkRefForILField ILScopeRef.Local (enc, tdef) fdef + // internalFields.Add(lfref) |> ignore for mdef in tdef.Methods.AsArray() do match mdef.Access with diff --git a/tests/FSharp.Test.Utilities/TestFramework.fs b/tests/FSharp.Test.Utilities/TestFramework.fs index f2d93c0513c..60aac52400a 100644 --- a/tests/FSharp.Test.Utilities/TestFramework.fs +++ b/tests/FSharp.Test.Utilities/TestFramework.fs @@ -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 diff --git a/tests/fsharp/core/printing/output.1000.stdout.bsl b/tests/fsharp/core/printing/output.1000.stdout.bsl index cc3eaef035e..cdf91519c8d 100644 --- a/tests/fsharp/core/printing/output.1000.stdout.bsl +++ b/tests/fsharp/core/printing/output.1000.stdout.bsl @@ -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 } + > > > diff --git a/tests/fsharp/core/printing/output.200.stdout.bsl b/tests/fsharp/core/printing/output.200.stdout.bsl index 6d1b4c6dfc9..cb22322c94a 100644 --- a/tests/fsharp/core/printing/output.200.stdout.bsl +++ b/tests/fsharp/core/printing/output.200.stdout.bsl @@ -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 } + > > > diff --git a/tests/fsharp/core/printing/output.47.stderr.bsl b/tests/fsharp/core/printing/output.47.stderr.bsl index 4d3209ca246..3e98bca2fc4 100644 --- a/tests/fsharp/core/printing/output.47.stderr.bsl +++ b/tests/fsharp/core/printing/output.47.stderr.bsl @@ -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 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 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 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 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 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 test5c;; + -------------^^^^^^^^^^^^^^ + +stdin(1154,14): error FS0039: The value, namespace, type or module 'JsonSerializer' is not defined. + diff --git a/tests/fsharp/core/printing/output.47.stdout.bsl b/tests/fsharp/core/printing/output.47.stdout.bsl index af2d597eaad..b6f38074b36 100644 --- a/tests/fsharp/core/printing/output.47.stdout.bsl +++ b/tests/fsharp/core/printing/output.47.stdout.bsl @@ -6309,4 +6309,4 @@ val ShortName: string = "hi" > val list2: int list = [1] -> > > +> > > > > > > > > > > > > > > > > > > > > diff --git a/tests/fsharp/core/printing/output.multiemit.stdout.bsl b/tests/fsharp/core/printing/output.multiemit.stdout.bsl index acdcf6c63d8..9183285f872 100644 --- a/tests/fsharp/core/printing/output.multiemit.stdout.bsl +++ b/tests/fsharp/core/printing/output.multiemit.stdout.bsl @@ -6311,4 +6311,57 @@ val ShortName: string = "hi" > val list2: int list = [1] +module FSI_0316. + 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_0323.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 } + > > > diff --git a/tests/fsharp/core/printing/output.off.stdout.bsl b/tests/fsharp/core/printing/output.off.stdout.bsl index 2bd43f77f8f..586d7a58860 100644 --- a/tests/fsharp/core/printing/output.off.stdout.bsl +++ b/tests/fsharp/core/printing/output.off.stdout.bsl @@ -1778,4 +1778,57 @@ val ShortName: string = "hi" > val list2: int list +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 + +> val test3b: R3 + +> val test3c: string + +> val test3d: R3 + +> type R4 = + { mutable MutableField4: int } +val test4a: string + +> val test4b: R4 + +> val test4c: string + +> val test4d: R4 + +> type R5 = {| AnonRecordField5: int |} +val test5a: string + +> val test5b: R5 + +> val test5c: string + +> val test5d: R5 + > > > diff --git a/tests/fsharp/core/printing/output.quiet.stdout.bsl b/tests/fsharp/core/printing/output.quiet.stdout.bsl index 26683b52103..d8d778aca70 100644 --- a/tests/fsharp/core/printing/output.quiet.stdout.bsl +++ b/tests/fsharp/core/printing/output.quiet.stdout.bsl @@ -11,3 +11,6 @@ [Building 5 3...done] Expect ABC = ABC Expect ABC = ABC +{"ImmutableField0":6} +{"MutableField1":8} +{"AnonRecordField2":10} diff --git a/tests/fsharp/core/printing/output.stdout.bsl b/tests/fsharp/core/printing/output.stdout.bsl index acdcf6c63d8..9183285f872 100644 --- a/tests/fsharp/core/printing/output.stdout.bsl +++ b/tests/fsharp/core/printing/output.stdout.bsl @@ -6311,4 +6311,57 @@ val ShortName: string = "hi" > val list2: int list = [1] +module FSI_0316. + 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_0323.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 } + > > > diff --git a/tests/fsharp/core/printing/test.fsx b/tests/fsharp/core/printing/test.fsx index 1bd15e348f8..c0943540b49 100644 --- a/tests/fsharp/core/printing/test.fsx +++ b/tests/fsharp/core/printing/test.fsx @@ -1114,6 +1114,46 @@ let list = [{ A = 1; B = "a" }];; let list2 = [ for x in list do x.A ];; +#r "nuget:Newtonsoft.Json, 13.0.1" +type R1 = { ImmutableField0: int } +open Newtonsoft.Json +JsonConvert.SerializeObject { ImmutableField0 = 6 } |> printfn "%s";; + +JsonConvert.SerializeObject { ImmutableField0 = 7 } +|> JsonConvert.DeserializeObject;; + +type R2 = { mutable MutableField1: int } +JsonConvert.SerializeObject { MutableField1 = 8 } |> printfn "%s";; + +JsonConvert.SerializeObject { MutableField1 = 9 } +|> JsonConvert.DeserializeObject;; + +JsonConvert.SerializeObject {| AnonRecordField2 = 10 |} |> printfn "%s";; + +JsonConvert.SerializeObject {| AnonRecordField2 = 11 |} +|> JsonConvert.DeserializeObject<{| AnonRecordField2 :int |}>;; + +#r "nuget: System.Text.Json" +open System.Text.Json +type R3 = { ImmutableField3: int } +let test3a = JsonSerializer.Serialize { ImmutableField3 = 12 };; +let test3b = JsonSerializer.Deserialize test3a;; +let test3c = JsonSerializer.Serialize { ImmutableField3 = 13 };; +let test3d = JsonSerializer.Deserialize test3c;; + +type R4 = { mutable MutableField4: int } +let test4a = JsonSerializer.Serialize { MutableField4 = 15 };; +let test4b = JsonSerializer.Deserialize test4a;; +let test4c = JsonSerializer.Serialize { MutableField4 = 16 };; +let test4d = JsonSerializer.Deserialize test4c;; + +type R5 = {| AnonRecordField5: int |} +let test5a = JsonSerializer.Serialize {| AnonRecordField5 = 17 |};; +let test5b = JsonSerializer.Deserialize test5a;; +let test5c = JsonSerializer.Serialize {| AnonRecordField5 = 18 |};; +let test5d = JsonSerializer.Deserialize test5c;; + + ;; (* ;; needed, to isolate error regressions *) ;;exit 0;; (* piped in to enable error regressions *) \ No newline at end of file diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index d8c4bd79cc2..d4da2adaf94 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -1060,10 +1060,13 @@ module CoreTests = let rawFileErr = tryCreateTemporaryFileName () ``fsi b 2>c`` "%s --nologo --preferreduilang:en-US %s" fsc_flags_errors_ok flag ("test.fsx", rawFileOut, rawFileErr) - // REM REVIEW: want to normalise CWD paths, not suppress them. - let ``findstr /v`` text = Seq.filter (fun (s: string) -> not <| s.Contains(text)) - let removeCDandHelp from' to' = - File.ReadLines from' |> (``findstr /v`` cfg.Directory) |> (``findstr /v`` "--help' for options") |> (fun lines -> File.WriteAllLines(getfullpath cfg to', lines)) + let removeCDandHelp fromFile toFile = + File.ReadAllLines fromFile + |> Array.filter (fun s -> not (s.Contains(cfg.Directory))) + |> Array.filter (fun s -> not (s.Contains("--help' for options"))) + |> Array.filter (fun s -> not (s.Contains("[Loading"))) + |> Array.filter (fun s -> not (s.Contains("Binding session"))) + |> (fun lines -> File.WriteAllLines(getfullpath cfg toFile, lines)) removeCDandHelp rawFileOut diffFileOut removeCDandHelp rawFileErr diffFileErr From 4306dea1bf83b1d20a7a879d4938f4b6cfb0121c Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Jul 2022 22:10:34 +0100 Subject: [PATCH 2/4] update tests --- .../EmittedIL/GenericComparison/Compare06.fsx.il.bsl | 2 ++ .../EmittedIL/GenericComparison/Equals05.fsx.il.bsl | 2 ++ .../EmittedIL/GenericComparison/Hash08.fsx.il.bsl | 2 ++ .../EmittedIL/Misc/AnonRecd.fs.il.bsl | 2 ++ .../EmittedIL/TestFunctions/TestFunction17.fs.il.debug.bsl | 2 ++ .../EmittedIL/TestFunctions/TestFunction17.fs.il.release.bsl | 2 ++ .../EmittedIL/TestFunctions/TestFunction24.fs.il.debug.bsl | 2 ++ .../EmittedIL/TestFunctions/TestFunction24.fs.il.release.bsl | 2 ++ 8 files changed, 16 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare06.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare06.fsx.il.bsl index 30f333f36c8..b7aea842a83 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare06.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare06.fsx.il.bsl @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals05.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals05.fsx.il.bsl index 78d4df8f587..34ab1b1e85c 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals05.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals05.fsx.il.bsl @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash08.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash08.fsx.il.bsl index b23967fe77b..c94a00b3427 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash08.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash08.fsx.il.bsl @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/AnonRecd.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/AnonRecd.fs.il.bsl index 0b4d87cf293..31112ecefe0 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/AnonRecd.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/AnonRecd.fs.il.bsl @@ -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 !'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 !'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(!'j__TPar' A, diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.debug.bsl index ded94e51adc..de3a5062203 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.debug.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.debug.bsl @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.release.bsl index d34dc778f67..17ff542c4ed 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction17.fs.il.release.bsl @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.debug.bsl index 1139c1cdb0d..6047356613b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.debug.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.debug.bsl @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.release.bsl index 51afb9c71dd..97404f6bb4a 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.release.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/TestFunctions/TestFunction24.fs.il.release.bsl @@ -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 From d018d91a2e49bb29beb771a374266cbddd322fc3 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Jul 2022 22:17:49 +0100 Subject: [PATCH 3/4] mark backing fields as compiler generated --- src/Compiler/Interactive/fsi.fs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Interactive/fsi.fs b/src/Compiler/Interactive/fsi.fs index ad84394be1c..936343a7036 100644 --- a/src/Compiler/Interactive/fsi.fs +++ b/src/Compiler/Interactive/fsi.fs @@ -367,12 +367,12 @@ type ILMultiInMemoryAssemblyEmitEnv( emEnv.AddTypeDef asm ilScopeRef (enc@[tdef]) ntdef // Record the internal things to give warnings for internal access across fragment boundaries - //for fdef in tdef.Fields.AsList() do - // match fdef.Access with - // | ILMemberAccess.Public -> () - // | _ -> - // let lfref = mkRefForILField ILScopeRef.Local (enc, tdef) fdef - // internalFields.Add(lfref) |> ignore + for fdef in tdef.Fields.AsList() do + match fdef.Access with + | ILMemberAccess.Public -> () + | _ -> + let lfref = mkRefForILField ILScopeRef.Local (enc, tdef) fdef + internalFields.Add(lfref) |> ignore for mdef in tdef.Methods.AsArray() do match mdef.Access with From d07d5ecbf8d8cb1f14d13d5be3315bb816f7fae8 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Mon, 11 Jul 2022 22:29:12 +0100 Subject: [PATCH 4/4] format code --- src/Compiler/CodeGen/IlxGen.fs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 6362c3f7b09..773ec63bb8a 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -2081,11 +2081,7 @@ type AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbu ILMemberAccess.Private let fdef = mkILInstanceField (fldName, fldTy, None, access) - let attrs = - [ - g.CompilerGeneratedAttribute - g.DebuggerBrowsableNeverAttribute - ] + let attrs = [ g.CompilerGeneratedAttribute; g.DebuggerBrowsableNeverAttribute ] fdef.With(customAttrs = mkILCustomAttrs attrs) ] @@ -10682,10 +10678,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) = let extraAttribs = match tyconRepr with | TFSharpRecdRepr _ when not useGenuineField -> - [ - g.CompilerGeneratedAttribute - g.DebuggerBrowsableNeverAttribute - ] + [ g.CompilerGeneratedAttribute; g.DebuggerBrowsableNeverAttribute ] | _ -> [] // don't hide fields in classes in debug display let access = ComputeMemberAccess isFieldHidden