Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Aug 21, 2023
1 parent 9bc3b0b commit bbbbd7e
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 18 deletions.
31 changes: 26 additions & 5 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,23 @@ let rec TypeRefForCompLoc cloc =
let mkILTyForCompLoc cloc =
mkILNonGenericBoxedTy (TypeRefForCompLoc cloc)

let ComputeMemberAccess hidden (accessibility: Accessibility option) realInternalSignature =
let ComputeMemberAccess hidden (accessibility: Accessibility option) (enclosingEntityCompilationPath: CompilationPath list option)realInternalSignature =
if hidden then
match accessibility with
| Some access when realInternalSignature ->
printfn $"ComputeMemberAccess: if: {access.ToString()}"
match access.AsILMemberAccess with
| ILMemberAccess.Public -> ILMemberAccess.Assembly
| access -> access
| _ -> ILMemberAccess.Assembly
else
match accessibility with
| Some access when realInternalSignature ->
printfn $"ComputeMemberAccess: else : {access.ToString()}"
access.AsILMemberAccess
| _ -> ILMemberAccess.Public

let _AmmendedComputeMemberAccess hidden (accessibility: Accessibility option) realInternalSignature =
if hidden then
match accessibility with
| Some access when realInternalSignature ->
Expand All @@ -514,7 +530,7 @@ let ComputeTypeAccess (tref: ILTypeRef) hidden (accessibility: Accessibility) re
ILTypeDefAccess.Private
else
ILTypeDefAccess.Public
| _ -> ILTypeDefAccess.Nested(ComputeMemberAccess hidden (Some accessibility) realInternalSignature)
| _ -> ILTypeDefAccess.Nested(ComputeMemberAccess hidden (Some accessibility) None realInternalSignature)

//--------------------------------------------------------------------------
// TypeReprEnv
Expand Down Expand Up @@ -6123,7 +6139,7 @@ and GenStructStateMachine cenv cgbuf eenvouter (res: LoweredStateMachine) sequel
) do
// Suppress the "ResumptionDynamicInfo" from generated state machines
if templateFld.LogicalName <> "ResumptionDynamicInfo" then
let access = ComputeMemberAccess false None cenv.g.realInternalSignature
let access = ComputeMemberAccess false None None cenv.g.realInternalSignature
let fty = GenType cenv m eenvinner.tyenv templateFld.FieldType

let fdef =
Expand All @@ -6144,7 +6160,7 @@ and GenStructStateMachine cenv cgbuf eenvouter (res: LoweredStateMachine) sequel

// Fields for captured variables
for ilCloFreeVar in ilCloFreeVars do
let access = ComputeMemberAccess false None cenv.g.realInternalSignature
let access = ComputeMemberAccess false None None cenv.g.realInternalSignature

let fdef =
ILFieldDef(
Expand Down Expand Up @@ -8215,6 +8231,11 @@ and GenBinding cenv cgbuf eenv (bind: Binding) (isStateVar: bool) =
GenDebugPointForBind cenv cgbuf bind
GenBindingAfterDebugPoint cenv cgbuf eenv bind isStateVar None

and getApparentEnclosingEntityAccess (vspec: Val) =
match vspec.ApparentEnclosingEntity with
| Parent ref -> Some ref.Accessibility.CompilationPaths
| _ -> None

and ComputeMethodAccessRestrictedBySig eenv vspec =
let isHidden =
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Expand All @@ -8225,7 +8246,7 @@ and ComputeMethodAccessRestrictedBySig eenv vspec =
// Compiler generated members for class function 'let' bindings get assembly visibility
|| vspec.IsIncrClassGeneratedMember

ComputeMemberAccess isHidden (Some vspec.Accessibility) eenv.realInternalSignature
ComputeMemberAccess isHidden (Some vspec.Accessibility) (getApparentEnclosingEntityAccess vspec) eenv.realInternalSignature

and GenBindingAfterDebugPoint cenv cgbuf eenv bind isStateVar startMarkOpt =
let g = cenv.g
Expand Down
14 changes: 9 additions & 5 deletions src/Compiler/TypedTree/TypedTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,10 +2150,11 @@ let private isInternalCompPath x =

let private (|Public|Internal|RestrictedInternal|Private|) (TAccess p) =
match p with
| [] -> Public
| _ when isInternalCompPath (List.last p) && (List.length p) > 0-> RestrictedInternal
| _ when List.forall isInternalCompPath p -> Internal
| _ -> Private
| [] -> Public // Public
| _ when List.forall isInternalCompPath p -> Internal // Internal
// | _ when Option.isSome (List.tryFind isInternalCompPath p) -> RestrictedInternal // Internal + another scope restriction ... internal
| _ when p |> List.length > 1 -> RestrictedInternal // If not public, not internal and multiple scopes must be rendered internal compiler knows best here
| _ -> Private //

/// Represents the constraint on access for a construct
[<StructuralEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
Expand All @@ -2165,7 +2166,7 @@ type Accessibility =

member x.IsInternal = match x with Internal -> true | _ -> false

member x.IsRestrictedInternal = match x with Internal -> true | _ -> false
member x.IsRestrictedInternal = match x with RestrictedInternal -> true | _ -> false

member x.IsPrivate = match x with Private -> true | _ -> false

Expand All @@ -2184,6 +2185,9 @@ type Accessibility =
| Public -> ILTypeDefAccess.Public
| _ -> ILTypeDefAccess.Private

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
member x.CompilationPaths = match x with | TAccess compilationPaths -> compilationPaths

override x.ToString() =
match x with
| TAccess (paths) ->
Expand Down
4 changes: 3 additions & 1 deletion src/Compiler/TypedTree/TypedTree.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,9 @@ type Accessibility =

member AsILTypeDefAccess: ILTypeDefAccess

/// Readable rendering of Accessibility
member CompilationPaths: CompilationPath list

/// Readable rendering of Accessibility
override ToString: unit -> string

[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,173 @@ module internal PrintfImpl
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - public ctor`` (realSig, symbol) =
let ``Class Type visibility - public type - public ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
open System
open System.IO
[<AbstractClass>]
type FSharpSource () =
abstract FilePath: string
type FSharpSourceFromFile public (filePath: string) =
inherit FSharpSource()
override _.FilePath = filePath
type FSharpSource with
static member CreateFromFile (filePath: string) =
() //FSharpSourceFromFile(filePath) :> FSharpSource
module doit =
FSharpSource.CreateFromFile("Hello") |> ignore
printfn "Main program"
"""
|> withLangVersionPreview
|> withOptions [if realSig then yield "--test:RealInternalSignature"]
|> withOptions [if symbol then yield! ["-g"; "--debug:embedded"]]
|> compileExeAndRun
|> shouldSucceed
|> withStdOutContainsAllInOrder [
"Main program"
]


[<InlineData(true, true)>] // RealSig, Debug
[<InlineData(true, false)>] // RealSig, Release
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - public type - internal ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
open System
open System.IO
[<AbstractClass>]
type FSharpSource () =
abstract FilePath: string
type FSharpSourceFromFile internal (filePath: string) =
inherit FSharpSource()
override _.FilePath = filePath
type FSharpSource with
static member CreateFromFile(filePath: string) =
FSharpSourceFromFile(filePath) :> FSharpSource
module doit =
FSharpSource.CreateFromFile("Hello") |> ignore
printfn "Main program"
"""
|> withLangVersionPreview
|> withOptions [if realSig then yield "--test:RealInternalSignature"]
|> withOptions [if symbol then yield! ["-g"; "--debug:embedded"]]
|> compileExeAndRun
|> shouldSucceed
|> withStdOutContainsAllInOrder [
"Main program"
]


[<InlineData(true, true)>] // RealSig, Debug
[<InlineData(true, false)>] // RealSig, Release
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - public type - private ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
open System
open System.IO
[<AbstractClass>]
type FSharpSource () =
abstract FilePath: string
type FSharpSourceFromFile private (filePath: string) =
inherit FSharpSource()
override _.FilePath = filePath
type FSharpSource with
static member CreateFromFile (filePath: string) =
() //FSharpSourceFromFile(filePath) :> FSharpSource
module doit =
FSharpSource.CreateFromFile("Hello") |> ignore
printfn "Main program"
"""
|> withLangVersionPreview
|> withOptions [if realSig then yield "--test:RealInternalSignature"]
|> withOptions [if symbol then yield! ["-g"; "--debug:embedded"]]
|> compileExeAndRun
|> shouldSucceed
|> withStdOutContainsAllInOrder [
"Main program"
]

[<InlineData(true, true)>] // RealSig, Debug
[<InlineData(true, false)>] // RealSig, Release
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - public type - unspecified ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
open System
open System.IO
[<AbstractClass>]
type FSharpSource () =
abstract FilePath: string
type FSharpSourceFromFile (filePath: string) =
inherit FSharpSource()
override _.FilePath = filePath
type FSharpSource with
static member CreateFromFile (filePath: string) =
() //FSharpSourceFromFile(filePath) :> FSharpSource
module doit =
FSharpSource.CreateFromFile("Hello") |> ignore
printfn "Main program"
"""
|> withLangVersionPreview
|> withOptions [if realSig then yield "--test:RealInternalSignature"]
|> withOptions [if symbol then yield! ["-g"; "--debug:embedded"]]
|> compileExeAndRun
|> shouldSucceed
|> withStdOutContainsAllInOrder [
"Main program"
]

[<InlineData(true, true)>] // RealSig, Debug
[<InlineData(true, false)>] // RealSig, Release
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - private type - public ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
Expand Down Expand Up @@ -593,7 +759,7 @@ module doit =
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - internal ctor`` (realSig, symbol) =
let ``Class Type visibility - private type - internal ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
Expand Down Expand Up @@ -635,7 +801,7 @@ module doit =
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - private ctor`` (realSig, symbol) =
let ``Class Type visibility - private type - private ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
Expand All @@ -656,7 +822,7 @@ type private FSharpSourceFromFile private (filePath: string) =
type FSharpSource with
static member CreateFromFile (filePath: string) =
() //FSharpSourceFromFile(filePath) :> FSharpSource
()//FSharpSourceFromFile(filePath) :> FSharpSource
module doit =
FSharpSource.CreateFromFile("Hello") |> ignore
Expand All @@ -676,7 +842,7 @@ module doit =
[<InlineData(false,true)>] // Internal, Debug
[<InlineData(false,false)>] // Internal, Release
[<Theory>]
let ``Class Type visibility - unspecified ctor`` (realSig, symbol) =
let ``Class Type visibility - private type - unspecified ctor`` (realSig, symbol) =

FSharp """
namespace FSharp.Compiler.CodeAnalysis
Expand All @@ -697,7 +863,7 @@ type private FSharpSourceFromFile (filePath: string) =
type FSharpSource with
static member CreateFromFile (filePath: string) =
() //FSharpSourceFromFile(filePath) :> FSharpSource
FSharpSourceFromFile(filePath) :> FSharpSource
module doit =
FSharpSource.CreateFromFile("Hello") |> ignore
Expand All @@ -711,4 +877,3 @@ module doit =
|> withStdOutContainsAllInOrder [
"Main program"
]

0 comments on commit bbbbd7e

Please sign in to comment.