Skip to content

Commit b9685e8

Browse files
authored
Refactor TcGlobals (#15497)
1 parent 9c8b419 commit b9685e8

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

src/Compiler/TypedTree/TcGlobals.fs

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -878,26 +878,19 @@ type TcGlobals(
878878
let tref_CompilerGeneratedAttribute = findSysILTypeRef tname_CompilerGeneratedAttribute
879879
let tref_InternalsVisibleToAttribute = findSysILTypeRef tname_InternalsVisibleToAttribute
880880

881-
let mutable generatedAttribsCache = []
882-
let mutable debuggerBrowsableNeverAttributeCache = None
883-
let mkDebuggerNonUserCodeAttribute() = mkILCustomAttribute (findSysILTypeRef tname_DebuggerNonUserCodeAttribute, [], [], [])
884-
let mkCompilerGeneratedAttribute () = mkILCustomAttribute (tref_CompilerGeneratedAttribute, [], [], [])
881+
let debuggerNonUserCodeAttribute = mkILCustomAttribute (findSysILTypeRef tname_DebuggerNonUserCodeAttribute, [], [], [])
882+
let compilerGeneratedAttribute = mkILCustomAttribute (tref_CompilerGeneratedAttribute, [], [], [])
883+
let generatedAttributes = if noDebugAttributes then [||] else [| compilerGeneratedAttribute; debuggerNonUserCodeAttribute |]
885884
let compilerGlobalState = CompilerGlobalState()
886885

887886
// Requests attributes to be added to compiler generated methods.
888887
let addGeneratedAttrs (attrs: ILAttributes) =
889-
let attribs =
890-
match generatedAttribsCache with
891-
| [] ->
892-
let res = [
893-
if not noDebugAttributes then
894-
mkCompilerGeneratedAttribute()
895-
mkDebuggerNonUserCodeAttribute()
896-
]
897-
generatedAttribsCache <- res
898-
res
899-
| res -> res
900-
mkILCustomAttrs (attrs.AsList() @ attribs)
888+
if Array.isEmpty generatedAttributes then
889+
attrs
890+
else
891+
match attrs.AsArray() with
892+
| [||] -> mkILCustomAttrsFromArray generatedAttributes
893+
| attrs -> mkILCustomAttrsFromArray (Array.append attrs generatedAttributes)
901894

902895
let addMethodGeneratedAttrs (mdef:ILMethodDef) = mdef.With(customAttrs = addGeneratedAttrs mdef.CustomAttrs)
903896

@@ -911,15 +904,9 @@ type TcGlobals(
911904
ILType.Value (mkILNonGenericTySpec tref)
912905
mkILCustomAttribute (findSysILTypeRef tname_DebuggerBrowsableAttribute, [typ_DebuggerBrowsableState], [ILAttribElem.Int32 n], [])
913906

914-
let mkDebuggerBrowsableNeverAttribute() =
915-
match debuggerBrowsableNeverAttributeCache with
916-
| None ->
917-
let res = tref_DebuggerBrowsableAttribute 0
918-
debuggerBrowsableNeverAttributeCache <- Some res
919-
res
920-
| Some res -> res
907+
let debuggerBrowsableNeverAttribute = tref_DebuggerBrowsableAttribute 0
921908

922-
let addNeverAttrs (attrs: ILAttributes) = mkILCustomAttrs (attrs.AsList() @ [mkDebuggerBrowsableNeverAttribute()])
909+
let addNeverAttrs (attrs: ILAttributes) = mkILCustomAttrsFromArray (Array.append (attrs.AsArray()) [| debuggerBrowsableNeverAttribute |])
923910

924911
let addPropertyNeverAttrs (pdef:ILPropertyDef) = pdef.With(customAttrs = addNeverAttrs pdef.CustomAttrs)
925912

@@ -1837,13 +1824,7 @@ type TcGlobals(
18371824

18381825
member _.mkDebuggerDisplayAttribute s = mkILCustomAttribute (findSysILTypeRef tname_DebuggerDisplayAttribute, [ilg.typ_String], [ILAttribElem.String (Some s)], [])
18391826

1840-
member _.DebuggerBrowsableNeverAttribute = mkDebuggerBrowsableNeverAttribute()
1841-
1842-
member _.mkDebuggerStepThroughAttribute() =
1843-
mkILCustomAttribute (findSysILTypeRef tname_DebuggerStepThroughAttribute, [], [], [])
1844-
1845-
member _.mkDebuggableAttribute jitOptimizerDisabled =
1846-
mkILCustomAttribute (tref_DebuggableAttribute, [ilg.typ_Bool; ilg.typ_Bool], [ILAttribElem.Bool false; ILAttribElem.Bool jitOptimizerDisabled], [])
1827+
member _.DebuggerBrowsableNeverAttribute = debuggerBrowsableNeverAttribute
18471828

18481829
member _.mkDebuggableAttributeV2(jitTracking, jitOptimizerDisabled, enableEnC) =
18491830
let debuggingMode =
@@ -1858,9 +1839,9 @@ type TcGlobals(
18581839

18591840
member internal _.CompilerGlobalState = Some compilerGlobalState
18601841

1861-
member _.CompilerGeneratedAttribute = mkCompilerGeneratedAttribute ()
1842+
member _.CompilerGeneratedAttribute = compilerGeneratedAttribute
18621843

1863-
member _.DebuggerNonUserCodeAttribute = mkDebuggerNonUserCodeAttribute ()
1844+
member _.DebuggerNonUserCodeAttribute = debuggerNonUserCodeAttribute
18641845

18651846
member _.MakeInternalsVisibleToAttribute(simpleAssemName) =
18661847
mkILCustomAttribute (tref_InternalsVisibleToAttribute, [ilg.typ_String], [ILAttribElem.String (Some simpleAssemName)], [])

0 commit comments

Comments
 (0)