Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Jul 25, 2024
1 parent db4ad94 commit 9fa6ce1
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 74 deletions.
15 changes: 8 additions & 7 deletions src/Compiler/Checking/AugmentWithHashCompare.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 =
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,84 +27,84 @@ module ComputationExpressions =
[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr01.fs"|])>]
let ``ComputationExpr01_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr01.fs"|])>]
let ``ComputationExpr01_realsig=false`` compilation =
compilation
|> withoutRealInternalSignature
|> withRealInternalSignatureOff
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr02.fs"|])>]
let ``ComputationExpr02_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr02.fs"|])>]
let ``ComputationExpr02_realsig=false`` compilation =
compilation
|> withoutRealInternalSignature
|> withRealInternalSignatureOff
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr03.fs"|])>]
let ``ComputationExpr03_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr03.fs"|])>]
let ``ComputationExpr03_realsig=false`` compilation =
compilation
|> withoutRealInternalSignature
|> withRealInternalSignatureOff
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr04.fs"|])>]
let ``ComputationExpr04_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr04.fs"|])>]
let ``ComputationExpr04_realsig=false`` compilation =
compilation
|> withoutRealInternalSignature
|> withRealInternalSignatureOff
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr05.fs"|])>]
let ``ComputationExpr05_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr05.fs"|])>]
let ``ComputationExpr05_realsig=false`` compilation =
compilation
|> withoutRealInternalSignature
|> withRealInternalSignatureOff
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr06.fs"|])>]
let ``ComputationExpr06_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr06.fs"|])>]
let ``ComputationExpr06_realsig=false`` compilation =
compilation
|> withoutRealInternalSignature
|> withRealInternalSignatureOff
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOn", Includes=[|"ComputationExpr07.fs"|])>]
let ``ComputationExpr07_realsig=true`` compilation =
compilation
|> withRealInternalSignature
|> withRealInternalSignatureOn
|> verifyCompilation

[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[|"ComputationExpr07.fs"|])>]
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,36 @@ Module1.Struct(1, 2) = Module1.Struct(2, 3) |> ignore"""
IL_0031: ret
}
""" ]


[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"Match01_RealInternalSignatureOn.fs"|])>]
let ``Match01_RealInternalSignatureOn_fs`` compilation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ open FSharp.Test.Compiler

module ClassTypeInitialization =

let withRealInternalSignature realSig compilation =
compilation
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ open FSharp.Test.Compiler

module ClassTypeVisibilityModuleRoot =

let withRealInternalSignature realSig compilation =
compilation
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ open FSharp.Test.Compiler

module ClassTypeVisibilityModuleRoot =

let withRealInternalSignature realSig compilation =
compilation
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ open FSharp.Test.Compiler

module ClassTypeVisibilityModuleRootWithFsi =

let withRealInternalSignature realSig compilation =
compilation
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ open FSharp.Test.Compiler

module ClassTypeVisibilityNamespaceRoot =

let withRealInternalSignature realSig compilation =
compilation
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ open FSharp.Test.Compiler

module ClassTypeVisibilityNamespaceRootWithFsi =

let withRealInternalSignature realSig compilation =
compilation
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]

[<InlineData(true)>] // RealSig
[<InlineData(false)>] // Regular
[<Theory>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/FSharp.Test.Utilities/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9fa6ce1

Please sign in to comment.