Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Jul 7, 2023
1 parent 42bc2ad commit dd8cd2d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
58 changes: 31 additions & 27 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -489,23 +489,25 @@ let rec TypeRefForCompLoc cloc =
let mkILTyForCompLoc cloc =
mkILNonGenericBoxedTy (TypeRefForCompLoc cloc)

let ComputeMemberAccess hidden =
let ComputeMemberAccess hidden (accessibility: Accessibility option) =
if hidden then
ILMemberAccess.Assembly
match accessibility with
| None -> ILMemberAccess.Assembly
| Some access -> access.AsILMemberAccess
else
ILMemberAccess.Public

// Under --publicasinternal change types from Public to Private (internal for types)
let ComputePublicTypeAccess () = ILTypeDefAccess.Public

let ComputeTypeAccess (tref: ILTypeRef) hidden =
let ComputeTypeAccess (tref: ILTypeRef) hidden (accessibility: Accessibility option) =
match tref.Enclosing with
| [] ->
if hidden then
ILTypeDefAccess.Private
match accessibility with
| None -> ILTypeDefAccess.Private
| Some access -> access.AsILTypeDefAccess
//ILTypeDefAccess.Private //@@@@@@@@@@@@@@@@@@@@@@@@
else
ComputePublicTypeAccess()
| _ -> ILTypeDefAccess.Nested(ComputeMemberAccess hidden)
ILTypeDefAccess.Public
| _ -> ILTypeDefAccess.Nested(ComputeMemberAccess hidden accessibility) //@@@@@@@@@@@@@@@@@@@@@@@@

//--------------------------------------------------------------------------
// TypeReprEnv
Expand Down Expand Up @@ -2245,7 +2247,7 @@ and AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbuf
let vtdef = mkRawDataValueTypeDef g.iltyp_ValueType (name, size, 0us)
let vtref = NestedTypeRefForCompLoc cloc vtdef.Name
let vtspec = mkILTySpec (vtref, [])
let vtdef = vtdef.WithAccess(ComputeTypeAccess vtref true)
let vtdef = vtdef.WithAccess(ComputeTypeAccess vtref true None) //@@@@@@@@@@@@@@@@@@@@
mgbuf.AddTypeDef(vtref, vtdef, false, true, None)
vtspec),
keyComparer = HashIdentity.Structural
Expand Down Expand Up @@ -6065,7 +6067,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
let access = ComputeMemberAccess false None //@@@@@@@@@@@@@@@@@@@@@@@@
let fty = GenType cenv m eenvinner.tyenv templateFld.FieldType

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

// Fields for captured variables
for ilCloFreeVar in ilCloFreeVars do
let access = ComputeMemberAccess false
let access = ComputeMemberAccess false None //@@@@@@@@@@@@@@@@@@@@@@@@

let fdef =
ILFieldDef(
Expand Down Expand Up @@ -6131,7 +6133,7 @@ and GenStructStateMachine cenv cgbuf eenvouter (res: LoweredStateMachine) sequel
)
.WithSealed(true)
.WithSpecialName(true)
.WithAccess(ComputeTypeAccess ilCloTypeRef true)
.WithAccess(ComputeTypeAccess ilCloTypeRef true None) //@@@@@@@@@@@@@@@@@@@
.WithLayout(ILTypeDefLayout.Auto)
.WithEncoding(ILDefaultPInvokeEncoding.Auto)
.WithInitSemantics(ILTypeInit.BeforeField)
Expand Down Expand Up @@ -6554,7 +6556,7 @@ and GenClosureTypeDefs
.WithSealed(true)
.WithSerializable(true)
.WithSpecialName(true)
.WithAccess(ComputeTypeAccess tref true)
.WithAccess(ComputeTypeAccess tref true None) //@@@@@@@@@@@@@@@@@@@@@@@@@
.WithLayout(ILTypeDefLayout.Auto)
.WithEncoding(ILDefaultPInvokeEncoding.Auto)
.WithInitSemantics(ILTypeInit.BeforeField)
Expand Down Expand Up @@ -8168,7 +8170,7 @@ and ComputeMethodAccessRestrictedBySig eenv vspec =
// Compiler generated members for class function 'let' bindings get assembly visibility
vspec.IsIncrClassGeneratedMember

ComputeMemberAccess isHidden
ComputeMemberAccess isHidden None //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

and GenBindingAfterDebugPoint cenv cgbuf eenv bind isStateVar startMarkOpt =
let g = cenv.g
Expand Down Expand Up @@ -8354,7 +8356,7 @@ and GenBindingAfterDebugPoint cenv cgbuf eenv bind isStateVar startMarkOpt =
/// Generate a static field definition...
let ilFieldDefs =
let access =
ComputeMemberAccess(not hasLiteralAttr || IsHiddenVal eenv.sigToImplRemapInfo vspec)
ComputeMemberAccess(not hasLiteralAttr || IsHiddenVal eenv.sigToImplRemapInfo vspec) None //@@@@@@@@@@@@@@@@@@@@@@@@

let ilFieldDef = mkILStaticField (fspec.Name, fty, None, None, access)

Expand Down Expand Up @@ -9881,15 +9883,15 @@ and CreatePermissionSets cenv eenv (securityAttributes: Attrib list) =
//--------------------------------------------------------------------------

/// Generate a static class at the given cloc
and GenTypeDefForCompLoc (cenv, eenv, mgbuf: AssemblyBuilder, cloc, hidden, attribs, initTrigger, eliminateIfEmpty, addAtEnd) =
and GenTypeDefForCompLoc (cenv, eenv, mgbuf: AssemblyBuilder, cloc, hidden, _accessibility: Accessibility option, attribs, initTrigger, eliminateIfEmpty, addAtEnd) =
let g = cenv.g
let tref = TypeRefForCompLoc cloc

let tdef =
mkILSimpleClass
g.ilg
(tref.Name,
ComputeTypeAccess tref hidden,
ComputeTypeAccess tref hidden None, //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
emptyILMethods,
emptyILFields,
emptyILTypeDefs,
Expand Down Expand Up @@ -10028,6 +10030,7 @@ and GenModuleBinding cenv (cgbuf: CodeGenBuffer) (qname: QualifiedNameOfFile) la
cgbuf.mgbuf,
eenvinner.cloc,
hidden,
None, //@@@@@@@@@@@@@@@@@@@@@@@@
mspec.Attribs,
staticClassTrigger,
false (* atEnd= *) ,
Expand Down Expand Up @@ -10097,7 +10100,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: Checke
// Create the class to hold the initialization code and static fields for this file.
// internal static class $<StartupCode...> {}
// Put it at the end since that gives an approximation of dependency order (to aid FSI.EXE's code generator - see FSharp 1.0 5548)
GenTypeDefForCompLoc(cenv, eenv, mgbuf, initClassCompLoc, useHiddenInitCode, [], initClassTrigger, false, true)
GenTypeDefForCompLoc(cenv, eenv, mgbuf, initClassCompLoc, useHiddenInitCode,None, [], initClassTrigger, false, true) //@@@@@@@@@@@@@@@@@@@@@@@@

// lazyInitInfo is an accumulator of functions which add the forced initialization of the storage module to
// - mutable fields in public modules
Expand Down Expand Up @@ -10219,7 +10222,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: Checke
let initFieldName = CompilerGeneratedName "init"

let ilFieldDef =
mkILStaticField (initFieldName, g.ilg.typ_Int32, None, None, ComputeMemberAccess true)
mkILStaticField (initFieldName, g.ilg.typ_Int32, None, None, ComputeMemberAccess true None) //@@@@@@@@@@@@@@@@@@@@@@@@
|> g.AddFieldNeverAttributes
|> g.AddFieldGeneratedAttributes

Expand Down Expand Up @@ -10519,7 +10522,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =

let hidden = IsHiddenTycon eenv.sigToImplRemapInfo tycon
let hiddenRepr = hidden || IsHiddenTyconRepr eenv.sigToImplRemapInfo tycon
let access = ComputeTypeAccess tref hidden
let access = ComputeTypeAccess tref hidden None//tycon.Accessibility //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

// The implicit augmentation doesn't actually create CompareTo(object) or Object.Equals
// So we do it here.
Expand Down Expand Up @@ -10621,7 +10624,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =

let tyconRepr = tycon.TypeReprInfo

let reprAccess = ComputeMemberAccess hiddenRepr
let reprAccess = ComputeMemberAccess hiddenRepr None //@@@@@@@@@@@@@@@@@@@@@@@@

// DebugDisplayAttribute gets copied to the subtypes generated as part of DU compilation
let debugDisplayAttrs, normalAttrs =
Expand Down Expand Up @@ -10783,7 +10786,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =
[ g.CompilerGeneratedAttribute; g.DebuggerBrowsableNeverAttribute ]
| _ -> [] // don't hide fields in classes in debug display

let access = ComputeMemberAccess isFieldHidden
let access = ComputeMemberAccess isFieldHidden None //@@@@@@@@@@@@@@@@@@@@@@@@

let literalValue = Option.map (GenFieldInit m) fspec.LiteralValue

Expand Down Expand Up @@ -10853,7 +10856,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =
if not useGenuineField then
let ilPropName = fspec.LogicalName
let ilMethName = "get_" + ilPropName
let access = ComputeMemberAccess isPropHidden
let access = ComputeMemberAccess isPropHidden None //@@@@@@@@@@@@@@@@@@@@@@@@
let isStruct = isStructTyconRef tcref

let attrs =
Expand All @@ -10876,7 +10879,7 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =
let ilMethName = "set_" + ilPropName
let ilParams = [ mkILParamNamed ("value", ilPropType) ]
let ilReturn = mkILReturn ILType.Void
let iLAccess = ComputeMemberAccess isPropHidden
let iLAccess = ComputeMemberAccess isPropHidden None //@@@@@@@@@@@@@@@@@@@@@@@@

let ilMethodDef =
if isStatic then
Expand Down Expand Up @@ -11387,8 +11390,8 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) =
let ilThisTy = GenExnType cenv m eenv.tyenv exncref
let tref = ilThisTy.TypeRef
let isHidden = IsHiddenTycon eenv.sigToImplRemapInfo exnc
let access = ComputeTypeAccess tref isHidden
let reprAccess = ComputeMemberAccess isHidden
let access = ComputeTypeAccess tref isHidden None //@@@@@@@@@@@@@@@@@@@@@@@@
let reprAccess = ComputeMemberAccess isHidden None //@@@@@@@@@@@@@@@@@@@@@@@@
let fspecs = exnc.TrueInstanceFieldsAsList

let ilMethodDefsForProperties, ilFieldDefs, ilPropertyDefs, fieldNamesAndTypes =
Expand Down Expand Up @@ -11663,6 +11666,7 @@ let GenerateCode (cenv, anonTypeTable, eenv, CheckedAssemblyAfterOptimization im
mgbuf,
CompLocForPrivateImplementationDetails eenv.cloc,
useHiddenInitCode,
None, //@@@@@@@@@@@@@@@@@@@@@@@@
[],
ILTypeInit.BeforeField,
true (* atEnd= *) ,
Expand Down
12 changes: 12 additions & 0 deletions src/Compiler/TypedTree/TypedTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,17 @@ type Accessibility =
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

member x.AsILMemberAccess =
match x with
| Public -> ILMemberAccess.Public
| Internal -> ILMemberAccess.Assembly
| Private -> ILMemberAccess.Private

member x.AsILTypeDefAccess =
match x with
| Public -> ILTypeDefAccess.Public
| _ -> ILTypeDefAccess.Private

override x.ToString() =
match x with
| TAccess (paths) ->
Expand All @@ -2164,6 +2175,7 @@ type Accessibility =
else
$"{scopename} {paths}"


/// Represents less-frequently-required data about a type parameter of type inference variable
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
type TyparOptionalData =
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/TypedTree/TypedTree.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,10 @@ type Accessibility =
/// Indicates whether the Accessability is private
member IsPrivate: bool

member AsILMemberAccess: ILMemberAccess

member AsILTypeDefAccess: ILTypeDefAccess

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

Expand Down

0 comments on commit dd8cd2d

Please sign in to comment.