From 9fa6ce1db1523b8c9d01cb32ff97a52d963371a9 Mon Sep 17 00:00:00 2001 From: Kevin Ransom Date: Thu, 25 Jul 2024 14:27:42 -0700 Subject: [PATCH] Fix #17447 --- .../Checking/AugmentWithHashCompare.fs | 15 ++++---- .../CCtorDUWithMember/CCtorDUWithMember.fs | 4 -- .../CompilerGeneratedAttributeOnAccessors.fs | 4 -- .../ComputationExpressions.fs | 38 ++++++++----------- .../GenericComparison/CrossAssembly.fs | 33 ++++++++++++++++ .../EmittedIL/Inlining/Inlining.fs | 4 -- .../ClassTypeInitialization.fs | 4 -- .../ClassTypeVisibility.fs | 4 -- .../ClassTypeVisibilityModuleRoot.fs | 4 -- .../ClassTypeVisibilityModuleRootWithFsi.fs | 4 -- .../ClassTypeVisibilityNamespaceRoot.fs | 4 -- ...ClassTypeVisibilityNamespaceRootWithFsi.fs | 4 -- .../ModuleInitialization.fs | 4 -- .../RealInternalSignature.fs | 4 -- tests/FSharp.Test.Utilities/Compiler.fs | 6 +++ 15 files changed, 62 insertions(+), 74 deletions(-) diff --git a/src/Compiler/Checking/AugmentWithHashCompare.fs b/src/Compiler/Checking/AugmentWithHashCompare.fs index 8d82a32ac4ef..31860d251ee2 100644 --- a/src/Compiler/Checking/AugmentWithHashCompare.fs +++ b/src/Compiler/Checking/AugmentWithHashCompare.fs @@ -1297,7 +1297,8 @@ let MakeValsForCompareAugmentation g (tcref: TyconRef) = let m = tcref.Range let _, ty = mkMinimalTy g tcref let tps = tcref.Typars m - let vis = tcref.TypeReprAccessibility + // CompareTo augments are always public + let vis = taccessPublic mkValSpec g tcref ty vis (Some(mkIComparableCompareToSlotSig g)) "CompareTo" (tps +-> (mkCompareObjTy g ty)) unaryArg false, mkValSpec g tcref ty vis (Some(mkGenericIComparableCompareToSlotSig g ty)) "CompareTo" (tps +-> (mkCompareTy g ty)) unaryArg false @@ -1306,7 +1307,8 @@ let MakeValsForCompareWithComparerAugmentation g (tcref: TyconRef) = let m = tcref.Range let _, ty = mkMinimalTy g tcref let tps = tcref.Typars m - let vis = tcref.TypeReprAccessibility + // CompareTo augments are always public + let vis = taccessPublic mkValSpec g @@ -1322,7 +1324,8 @@ let MakeValsForCompareWithComparerAugmentation g (tcref: TyconRef) = let MakeValsForEqualsAugmentation g (tcref: TyconRef) = let m = tcref.Range let _, ty = mkMinimalTy g tcref - let vis = tcref.TypeReprAccessibility + // Equals augments are always public + let vis = taccessPublic let tps = tcref.Typars m let objEqualsVal = @@ -1347,11 +1350,9 @@ let MakeValsForEqualsAugmentation g (tcref: TyconRef) = let MakeValsForEqualityWithComparerAugmentation g (tcref: TyconRef) = let _, ty = mkMinimalTy g tcref - let vis = - // Equality method for union types match the union type visibility rather than the TypeReprAccessibility - if tcref.IsUnionTycon then tcref.Accessibility - else tcref.TypeReprAccessibility let tps = tcref.Typars tcref.Range + // GetHashCode and Equals augments are always public + let vis = taccessPublic let objGetHashCodeVal = mkValSpec g tcref ty vis (Some(mkGetHashCodeSlotSig g)) "GetHashCode" (tps +-> (mkHashTy g ty)) unitArg false diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CCtorDUWithMember/CCtorDUWithMember.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CCtorDUWithMember/CCtorDUWithMember.fs index 248532a1638e..b6c46d001049 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CCtorDUWithMember/CCtorDUWithMember.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CCtorDUWithMember/CCtorDUWithMember.fs @@ -81,10 +81,6 @@ module CCtorDUWithMember = |> withAdditionalSourceFile (SourceFromPath (__SOURCE_DIRECTORY__ ++ "CCtorDUWithMember04.fs")) |> verifyCompilation - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompilerGeneratedAttributeOnAccessors.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompilerGeneratedAttributeOnAccessors.fs index 2d2f4fdede33..95d6a77c9608 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompilerGeneratedAttributeOnAccessors.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/CompilerGeneratedAttributeOnAccessors.fs @@ -185,10 +185,6 @@ module ``Auto-generated accessors have CompilerGenerated attribute`` = // Regression: https://github.com/dotnet/fsharp/issues/14652 module ``Let bindings in classes shoulnd't have DebuggerNonUserCodeAttribute`` = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpressions.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpressions.fs index 14a4a7e42707..4475a3cec159 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpressions.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpressions.fs @@ -7,18 +7,10 @@ open FSharp.Test.Compiler module ComputationExpressions = - let withRealInternalSignature compilation = - compilation - |> withOptions ["--realsig+"] - - let withoutRealInternalSignature compilation = - compilation - |> withOptions ["--realsig-"] - let computationExprLibrary = FsFromPath (Path.Combine(__SOURCE_DIRECTORY__, "ComputationExprLibrary.fs")) |> withName "ComputationExprLibrary" - |> withoutRealInternalSignature + |> withRealInternalSignatureOff let verifyCompilation compilation = compilation @@ -35,84 +27,84 @@ module ComputationExpressions = [] let ``ComputationExpr01_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr01_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> verifyCompilation [] let ``ComputationExpr02_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr02_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> verifyCompilation [] let ``ComputationExpr03_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr03_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> verifyCompilation [] let ``ComputationExpr04_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr04_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> verifyCompilation [] let ``ComputationExpr05_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr05_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> verifyCompilation [] let ``ComputationExpr06_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr06_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> verifyCompilation [] let ``ComputationExpr07_realsig=true`` compilation = compilation - |> withRealInternalSignature + |> withRealInternalSignatureOn |> verifyCompilation [] let ``ComputationExpr07_realsig=false`` compilation = compilation - |> withoutRealInternalSignature + |> withRealInternalSignatureOff |> withLangVersionPreview // TODO https://github.com/dotnet/fsharp/issues/16739: Remove this when LanguageFeature.LowerIntegralRangesToFastLoops is out of preview. |> verifyCompilation diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/CrossAssembly.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/CrossAssembly.fs index 8e2cd0853c01..130370c6ba48 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/CrossAssembly.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/CrossAssembly.fs @@ -91,3 +91,36 @@ Module1.Struct(1, 2) = Module1.Struct(2, 3) |> ignore""" IL_0031: ret } """ ] + + + [] // RealSig + [] // Regular + [] + let ``Another assembly with private type`` (realsig) = + let module1 = + FSharpWithFileName "Module1.fs" + """ +module Module1 + +type Value = + private { value: uint32 } + + static member Zero = { value = 0u } + static member Create(value: int) = { value = uint value } """ + |> withRealInternalSignature realsig + |> withOptimize + |> asLibrary + |> withName "module1" + + let module2 = + FSharpWithFileName "Program.fs" + """ +open Module1 + +Value.Zero = Value.Create 0 |> ignore""" + + module2 + |> withReferences [module1] + |> withOptimize + |> compileExeAndRun + |> shouldSucceed \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Inlining/Inlining.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Inlining/Inlining.fs index 391faa9067a8..49bbc723c788 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Inlining/Inlining.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Inlining/Inlining.fs @@ -16,10 +16,6 @@ module Inlining = |> ignoreWarnings |> verifyILBaseline - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - // SOURCE=Match01.fs SCFLAGS="-a --optimize+" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd Match01.dll" # Match01.fs [] let ``Match01_RealInternalSignatureOn_fs`` compilation = diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs index 19165b3fe8ca..5d841d6525e0 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeInitialization.fs @@ -8,10 +8,6 @@ open FSharp.Test.Compiler module ClassTypeInitialization = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibility.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibility.fs index acd800eb0a63..115db113b4a3 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibility.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibility.fs @@ -8,10 +8,6 @@ open FSharp.Test.Compiler module ClassTypeVisibilityModuleRoot = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs index 318a5f3a7cbe..c4b9afb30e72 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRoot.fs @@ -8,10 +8,6 @@ open FSharp.Test.Compiler module ClassTypeVisibilityModuleRoot = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRootWithFsi.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRootWithFsi.fs index 4d7d55c1e8e2..634919566398 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRootWithFsi.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityModuleRootWithFsi.fs @@ -7,10 +7,6 @@ open FSharp.Test.Compiler module ClassTypeVisibilityModuleRootWithFsi = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs index c12fe0c6829d..27d50c0bc5e2 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRoot.fs @@ -8,10 +8,6 @@ open FSharp.Test.Compiler module ClassTypeVisibilityNamespaceRoot = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs index 6f3b58e6f667..578abd5ec680 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ClassTypeVisibilityNamespaceRootWithFsi.fs @@ -7,10 +7,6 @@ open FSharp.Test.Compiler module ClassTypeVisibilityNamespaceRootWithFsi = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - [] // RealSig [] // Regular [] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ModuleInitialization.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ModuleInitialization.fs index 8666aaad2ac7..6d6fa0a0d71f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ModuleInitialization.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/ModuleInitialization.fs @@ -8,10 +8,6 @@ open FSharp.Test.Compiler module ModuleInitialization = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - let simplePublicModule = FSharp """ namespace MyLibraryNamespace diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/RealInternalSignature.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/RealInternalSignature.fs index b0b12e502d0a..7f508ef40a85 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/RealInternalSignature.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/RealInternalSignature/RealInternalSignature.fs @@ -8,10 +8,6 @@ open FSharp.Test.Compiler module RealInternalSignature = - let withRealInternalSignature realSig compilation = - compilation - |> withOptions [if realSig then "--realsig+" else "--realsig-" ] - let simplePublicModule = FSharp """ namespace MyLibraryNamespace diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 4a2d52ef4d44..9fb050b09df2 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -601,6 +601,12 @@ module rec Compiler = | FS fs -> FS { fs with Options = fs.Options @ ["--realsig+"] } | _ -> failwith "withRealInternalSignatureOn only supported by f#" + let withRealInternalSignature (realSig: bool) (cUnit: CompilationUnit) : CompilationUnit = + if realSig then + cUnit |> withRealInternalSignatureOn + else + cUnit |> withRealInternalSignatureOff + let asExe (cUnit: CompilationUnit) : CompilationUnit = withOutputType CompileOutput.Exe cUnit