Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02dbf9e

Browse files
AviAvnidsyme
authored andcommitted
Reduce FCS memory footprint (dotnet#4272)
* reduce ILEventDef ILPropertyDef and ILFieldDef memory* Update IlxGen.fs* reduce ILMethodDef memory* reduce ILTypeDef memory* clean redundant functions
1 parent828fb11 commit02dbf9e

File tree

17 files changed

+603
-862
lines changed

17 files changed

+603
-862
lines changed

‎src/absil/il.fs‎

Lines changed: 256 additions & 199 deletions
Large diffs are not rendered by default.

‎src/absil/il.fsi‎

Lines changed: 94 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module public Microsoft.FSharp.Compiler.AbstractIL.IL
66

77
openInternal.Utilities
88
openSystem.Collections.Generic
9+
openSystem.Reflection
910

1011
[<RequireQualifiedAccess>]
1112
typePrimaryAssembly=
@@ -812,7 +813,6 @@ type ILMethodBody =
812813
[<RequireQualifiedAccess>]
813814
typeILMemberAccess=
814815
| Assembly
815-
| CompilerControlled
816816
| FamilyAndAssembly
817817
| FamilyOrAssembly
818818
| Family
@@ -1028,32 +1028,14 @@ type ILLazyMethodBody =
10281028
[<NoComparison; NoEquality>]
10291029
type ILMethodDef=
10301030
{ Name:string;
1031-
mdKind:MethodKind;
1031+
Attributes:MethodAttributes;
1032+
ImplAttributes:MethodImplAttributes;
10321033
CallingConv:ILCallingConv;
10331034
Parameters:ILParameters;
10341035
Return:ILReturn;
1035-
Access:ILMemberAccess;
10361036
mdBody:ILLazyMethodBody;
1037-
mdCodeKind:MethodCodeKind;
1038-
IsInternalCall:bool;
1039-
IsManaged:bool;
1040-
IsForwardRef:bool;
10411037
SecurityDecls:ILPermissions;
1042-
/// Some methods are marked "HasSecurity" even if there are no permissions attached, e.g. if they use SuppressUnmanagedCodeSecurityAttribute
1043-
HasSecurity:bool;
10441038
IsEntryPoint:bool;
1045-
IsReqSecObj:bool;
1046-
IsHideBySig:bool;
1047-
IsSpecialName:bool;
1048-
/// The method is exported to unmanaged code using COM interop.
1049-
IsUnmanagedExport:bool;
1050-
IsSynchronized:bool;
1051-
IsPreserveSig:bool;
1052-
/// .NET 2.0 feature: SafeHandle finalizer must be run.
1053-
IsMustRun:bool;
1054-
IsNoInline:bool;
1055-
IsAggressiveInline:bool;
1056-
10571039
GenericParams:ILGenericParameterDefs;
10581040
CustomAttrs:ILAttributes;}
10591041

@@ -1083,10 +1065,42 @@ type ILMethodDef =
10831065

10841066
memberIsFinal:bool
10851067
memberIsNewSlot:bool
1086-
memberIsCheckAccessOnOverride:bool
1068+
memberIsCheckAccessOnOverride:bool
10871069
memberIsAbstract:bool
1088-
memberMethodBody:ILMethodBody
1070+
memberMethodBody:ILMethodBody
10891071
memberCallingSignature:ILCallingSignature
1072+
memberAccess:ILMemberAccess
1073+
memberIsHideBySig:bool
1074+
memberIsSpecialName:bool
1075+
/// The method is exported to unmanaged code using COM interop.
1076+
memberIsUnmanagedExport:bool
1077+
memberIsReqSecObj:bool
1078+
/// Some methods are marked "HasSecurity" even if there are no permissions attached, e.g. if they use SuppressUnmanagedCodeSecurityAttribute
1079+
memberHasSecurity:bool
1080+
memberIsManaged:bool
1081+
memberIsForwardRef:bool
1082+
memberIsInternalCall:bool
1083+
memberIsPreserveSig:bool
1084+
memberIsSynchronized:bool
1085+
memberIsNoInline:bool
1086+
memberIsAggressiveInline:bool
1087+
/// .NET 2.0 feature: SafeHandle finalizer must be run.
1088+
memberIsMustRun:bool
1089+
1090+
memberWithSpecialName:ILMethodDef
1091+
memberWithHideBySig:unit->ILMethodDef
1092+
memberWithHideBySig:bool->ILMethodDef
1093+
memberWithFinal:bool->ILMethodDef
1094+
memberWithAbstract:bool->ILMethodDef
1095+
memberWithAccess:ILMemberAccess->ILMethodDef
1096+
memberWithNewSlot:ILMethodDef
1097+
memberWithSecurity:bool->ILMethodDef
1098+
memberWithPInvoke:bool->ILMethodDef
1099+
memberWithPreserveSig:bool->ILMethodDef
1100+
memberWithSynchronized:bool->ILMethodDef
1101+
memberWithNoInlining:bool->ILMethodDef
1102+
memberWithAggressiveInlining:bool->ILMethodDef
1103+
memberWithRuntime:bool->ILMethodDef
10901104

10911105
/// Tables of methods. Logically equivalent to a list of methods but
10921106
/// the table is kept in a form optimized for looking up methods by
@@ -1105,18 +1119,27 @@ type ILMethodDefs =
11051119
type ILFieldDef=
11061120
{ Name:string;
11071121
Type:ILType;
1108-
IsStatic:bool;
1109-
Access:ILMemberAccess;
1122+
Attributes:FieldAttributes;
11101123
Data:byte[] option;
11111124
LiteralValue:ILFieldInit option;
11121125
/// The explicit offset in bytes when explicit layout is used.
11131126
Offset:int32 option;
1114-
IsSpecialName:bool;
11151127
Marshal:ILNativeType option;
1116-
NotSerialized:bool;
1117-
IsLiteral:bool;
1118-
IsInitOnly:bool;
11191128
CustomAttrs:ILAttributes;}
1129+
memberIsStatic:bool
1130+
memberIsSpecialName:bool
1131+
memberIsLiteral:bool
1132+
memberNotSerialized:bool
1133+
memberIsInitOnly:bool
1134+
memberAccess:ILMemberAccess
1135+
memberWithAccess:ILMemberAccess->ILFieldDef
1136+
memberWithInitOnly:bool->ILFieldDef
1137+
memberWithStatic:bool->ILFieldDef
1138+
memberWithSpecialName:bool->ILFieldDef
1139+
memberWithNotSerialized:bool->ILFieldDef
1140+
memberWithLiteral:bool->ILFieldDef
1141+
memberWithHasDefault:bool->ILFieldDef
1142+
memberWithHasFieldMarshal:bool->ILFieldDef
11201143

11211144
/// Tables of fields. Logically equivalent to a list of fields but
11221145
/// the table is kept in a form optimized for looking up fields by
@@ -1129,15 +1152,16 @@ type ILFieldDefs =
11291152
/// Event definitions.
11301153
[<NoComparison; NoEquality>]
11311154
type ILEventDef=
1132-
{ Type:ILType option;
1155+
{ Type:ILType option;
11331156
Name:string;
1134-
IsRTSpecialName:bool;
1135-
IsSpecialName:bool;
1157+
Attributes:EventAttributes
11361158
AddMethod:ILMethodRef;
11371159
RemoveMethod:ILMethodRef;
11381160
FireMethod:ILMethodRef option;
11391161
OtherMethods:ILMethodRef list;
11401162
CustomAttrs:ILAttributes;}
1163+
memberIsSpecialName:bool
1164+
memberIsRTSpecialName:bool
11411165

11421166
/// Table of those events in a type definition.
11431167
[<NoEquality; NoComparison; Sealed>]
@@ -1149,15 +1173,16 @@ type ILEventDefs =
11491173
[<NoComparison; NoEquality>]
11501174
type ILPropertyDef=
11511175
{ Name:string;
1152-
IsRTSpecialName:bool;
1153-
IsSpecialName:bool;
1176+
Attributes:PropertyAttributes;
11541177
SetMethod:ILMethodRef option;
11551178
GetMethod:ILMethodRef option;
11561179
CallingConv:ILThisConvention;
11571180
Type:ILType;
11581181
Init:ILFieldInit option;
11591182
Args:ILTypes;
11601183
CustomAttrs:ILAttributes;}
1184+
memberIsSpecialName:bool
1185+
memberIsRTSpecialName:bool
11611186

11621187
/// Table of those properties in a type definition.
11631188
[<NoEquality; NoComparison>]
@@ -1263,37 +1288,49 @@ type ILTypeDefs =
12631288
/// have a very specific form.
12641289
and [<NoComparison; NoEquality>]
12651290
ILTypeDef=
1266-
{tdKind:ILTypeDefKind;
1267-
Name:string;
1291+
{Name:string;
1292+
Attributes:TypeAttributes;
12681293
GenericParams:ILGenericParameterDefs;
1269-
Access:ILTypeDefAccess;
1270-
IsAbstract:bool;
1271-
IsSealed:bool;
1272-
IsSerializable:bool;
1273-
/// Class or interface generated for COM interop.
1274-
IsComInterop:bool;
12751294
Layout:ILTypeDefLayout;
1276-
IsSpecialName:bool;
1277-
Encoding:ILDefaultPInvokeEncoding;
12781295
NestedTypes:ILTypeDefs;
12791296
Implements:ILTypes;
12801297
Extends:ILType option;
12811298
Methods:ILMethodDefs;
12821299
SecurityDecls:ILPermissions;
1283-
/// Some classes are marked "HasSecurity" even if there are no permissions attached,
1284-
/// e.g. if they use SuppressUnmanagedCodeSecurityAttribute
1285-
HasSecurity:bool;
12861300
Fields:ILFieldDefs;
12871301
MethodImpls:ILMethodImplDefs;
1288-
InitSemantics:ILTypeInit;
12891302
Events:ILEventDefs;
12901303
Properties:ILPropertyDefs;
12911304
CustomAttrs:ILAttributes;}
12921305
memberIsClass:bool;
1306+
memberIsStruct:bool;
12931307
memberIsInterface:bool;
12941308
memberIsEnum:bool;
12951309
memberIsDelegate:bool;
12961310
memberIsStructOrEnum:bool
1311+
memberAccess:ILTypeDefAccess
1312+
memberIsAbstract:bool
1313+
memberIsSealed:bool
1314+
memberIsSerializable:bool
1315+
/// Class or interface generated for COM interop.
1316+
memberIsComInterop:bool
1317+
memberIsSpecialName:bool
1318+
/// Some classes are marked "HasSecurity" even if there are no permissions attached,
1319+
/// e.g. if they use SuppressUnmanagedCodeSecurityAttribute
1320+
memberHasSecurity:bool
1321+
memberEncoding:ILDefaultPInvokeEncoding;
1322+
memberWithAccess:ILTypeDefAccess->ILTypeDef
1323+
memberWithNestedAccess:ILMemberAccess->ILTypeDef
1324+
memberWithSealed:bool->ILTypeDef
1325+
memberWithSerializable:bool->ILTypeDef
1326+
memberWithAbstract:bool->ILTypeDef
1327+
memberWithImport:bool->ILTypeDef
1328+
memberWithHasSecurity:bool->ILTypeDef
1329+
memberWithLayout:ILTypeDefLayout->ILTypeDef
1330+
memberWithKind:ILTypeDefKind->ILTypeDef
1331+
memberWithEncoding:ILDefaultPInvokeEncoding->ILTypeDef
1332+
memberWithSpecialName:bool->ILTypeDef
1333+
memberWithInitSemantics:ILTypeInit->ILTypeDef
12971334

12981335
[<NoEquality; NoComparison>]
12991336
[<Sealed>]
@@ -1339,10 +1376,11 @@ type ILExportedTypeOrForwarder =
13391376
{ ScopeRef:ILScopeRef;
13401377
/// [Namespace.]Name
13411378
Name:string;
1342-
IsForwarder:bool;
1343-
Access:ILTypeDefAccess;
1379+
Attributes:TypeAttributes
13441380
Nested:ILNestedExportedTypes;
1345-
CustomAttrs:ILAttributes}
1381+
CustomAttrs:ILAttributes}
1382+
memberAccess:ILTypeDefAccess
1383+
memberIsForwarder:bool
13461384

13471385
[<NoEquality; NoComparison>]
13481386
[<Sealed>]
@@ -1685,10 +1723,10 @@ val mkILClassCtor: MethodBody -> ILMethodDef
16851723
val mkILNonGenericEmptyCtor: ILSourceMarker option-> ILType-> ILMethodDef
16861724
val mkILStaticMethod: ILGenericParameterDefs* string* ILMemberAccess* ILParameter list* ILReturn* MethodBody-> ILMethodDef
16871725
val mkILNonGenericStaticMethod: string* ILMemberAccess* ILParameter list* ILReturn* MethodBody-> ILMethodDef
1688-
val mkILGenericVirtualMethod: string* ILMemberAccess* ILGenericParameterDefs* ILParameter list* ILReturn* MethodBody-> ILMethodDef
1689-
val mkILGenericNonVirtualMethod: string* ILMemberAccess* ILGenericParameterDefs* ILParameter list* ILReturn* MethodBody-> ILMethodDef
1726+
val mkILGenericVirtualMethod: string* ILMemberAccess* ILGenericParameterDefs* ILParameter list* ILReturn* MethodBody-> ILMethodDef
1727+
val mkILGenericNonVirtualMethod: string* ILMemberAccess* ILGenericParameterDefs* ILParameter list* ILReturn* MethodBody-> ILMethodDef
16901728
val mkILNonGenericVirtualMethod: string* ILMemberAccess* ILParameter list* ILReturn* MethodBody-> ILMethodDef
1691-
val mkILNonGenericInstanceMethod: string* ILMemberAccess* ILParameter list* ILReturn* MethodBody-> ILMethodDef
1729+
val mkILNonGenericInstanceMethod: string* ILMemberAccess* ILParameter list* ILReturn* MethodBody-> ILMethodDef
16921730

16931731

16941732
/// Make field definitions.
@@ -1727,7 +1765,7 @@ val mkILStorageCtor: ILSourceMarker option * ILInstr list * ILType * (string * I
17271765
val mkILSimpleStorageCtor: ILSourceMarker option* ILTypeSpec option* ILType* ILParameter list*(string* ILType) list* ILMemberAccess-> ILMethodDef
17281766
val mkILSimpleStorageCtorWithParamNames: ILSourceMarker option* ILTypeSpec option* ILType* ILParameter list*(string* string* ILType) list* ILMemberAccess-> ILMethodDef
17291767

1730-
val mkILDelegateMethods: ILGlobals-> ILType* ILType-> ILParameter list* ILReturn-> ILMethodDef list
1768+
val mkILDelegateMethods:ILMemberAccess->ILGlobals-> ILType* ILType-> ILParameter list* ILReturn-> ILMethodDef list
17311769

17321770
/// Given a delegate type definition which lies in a particular scope,
17331771
/// make a reference to its constructor.
@@ -1785,6 +1823,7 @@ val emptyILTypeDefs: ILTypeDefs
17851823
val mkILTypeDefsComputed:(unit->(string list* string* ILAttributes* Lazy<ILTypeDef>) array)-> ILTypeDefs
17861824
val addILTypeDef: ILTypeDef-> ILTypeDefs-> ILTypeDefs
17871825

1826+
val mkTypeForwarder: ILScopeRef-> string-> ILNestedExportedTypes-> ILAttributes-> ILTypeDefAccess-> ILExportedTypeOrForwarder
17881827
val mkILNestedExportedTypes: ILNestedExportedType list-> ILNestedExportedTypes
17891828
val mkILNestedExportedTypesLazy: Lazy<ILNestedExportedType list>-> ILNestedExportedTypes
17901829

‎src/absil/ilprint.fs‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ open Microsoft.FSharp.Compiler.AbstractIL.IL
1313

1414
openSystem.Text
1515
openSystem.IO
16+
openSystem.Reflection
1617

1718
#if DEBUG
1819
letpretty()=true
@@ -396,7 +397,6 @@ let output_member_access os access =
396397
(match accesswith
397398
| ILMemberAccess.Public->"public"
398399
| ILMemberAccess.Private->"private"
399-
| ILMemberAccess.CompilerControlled->"privatescope"
400400
| ILMemberAccess.Family->"family"
401401
| ILMemberAccess.FamilyAndAssembly->"famandassem"
402402
| ILMemberAccess.FamilyOrAssembly->"famorassem"
@@ -770,10 +770,9 @@ let goutput_ilmbody env os (il: ILMethodBody) =
770770

771771

772772
letgoutput_mbody is_entrypoint env os md=
773-
match md.mdCodeKindwith
774-
| MethodCodeKind.Native-> output_string os"native"
775-
| MethodCodeKind.IL-> output_string os"cil"
776-
| MethodCodeKind.Runtime-> output_string os"runtime"
773+
if md.ImplAttributes&&& MethodImplAttributes.Native<>enum0then output_string os"native"
774+
elif md.ImplAttributes&&& MethodImplAttributes.IL<>enum0then output_string os"cil"
775+
else output_string os"runtime"
777776

778777
output_string os(if md.IsInternalCallthen"internalcall"else"");
779778
output_string os(if md.IsManagedthen"managed"else"");
@@ -788,19 +787,18 @@ let goutput_mbody is_entrypoint env os md =
788787
output_string os"\n";
789788
output_string os"}\n"
790789

791-
letgoutput_mdef env osmd=
790+
letgoutput_mdef env os(md:ILMethodDef)=
792791
letattrs=
793-
match md.mdKindwith
794-
| MethodKind.Virtual vinfo->
792+
if md.IsVirtualthen
795793
"virtual"^
796-
(ifvinfo.IsFinalthen"final"else"")^
797-
(ifvinfo.IsNewSlotthen"newslot"else"")^
798-
(ifvinfo.IsCheckAccessOnOverridethen" strict"else"")^
799-
(ifvinfo.IsAbstractthen" abstract"else"")^
794+
(ifmd.IsFinalthen"final"else"")^
795+
(ifmd.IsNewSlotthen"newslot"else"")^
796+
(ifmd.IsCheckAccessOnOverridethen" strict"else"")^
797+
(ifmd.IsAbstractthen" abstract"else"")^
800798
""
801-
| MethodKind.NonVirtual->""
802-
| MethodKind.Ctor->"rtspecialname"
803-
| MethodKind.Static->
799+
elif md.IsNonVirtualInstancethen""
800+
elif md.IsConstructorthen"rtspecialname"
801+
elif md.IsStaticthen
804802
"static"^
805803
(match md.mdBody.Contentswith
806804
MethodBody.PInvoke(attr)->
@@ -824,7 +822,8 @@ let goutput_mdef env os md =
824822
")"
825823
|_->
826824
"")
827-
| MethodKind.Cctor->"specialname rtspecialname static"
825+
elif md.IsClassInitializerthen"specialname rtspecialname static"
826+
else""
828827
letis_entrypoint= md.IsEntryPoint
829828
letmenv= ppenv_enter_method(List.length md.GenericParams) env
830829
output_string os" .method";
@@ -904,10 +903,9 @@ let rec goutput_tdef (enc) env contents os cd =
904903
goutput_pdefs env os cd.Properties;
905904
else
906905
output_string os"\n";
907-
match cd.tdKindwith
908-
| ILTypeDefKind.Class| ILTypeDefKind.Enum| ILTypeDefKind.Delegate| ILTypeDefKind.ValueType-> output_string os".class"
909-
| ILTypeDefKind.Interface-> output_string os".class interface"
910-
output_init_semantics os cd.InitSemantics;
906+
if cd.IsInterfacethen output_string os".class interface"
907+
else output_string os".class"
908+
output_init_semantics os cd.Attributes;
911909
output_string os"";
912910
output_type_access os cd.Access;
913911
output_string os"";
@@ -937,9 +935,7 @@ let rec goutput_tdef (enc) env contents os cd =
937935
output_string os"\n}";
938936

939937
andoutput_init_semantics os f=
940-
match fwith
941-
ILTypeInit.BeforeField-> output_string os"beforefieldinit";
942-
| ILTypeInit.OnAny->()
938+
if f&&& TypeAttributes.BeforeFieldInit<>enum0then output_string os"beforefieldinit"
943939

944940
andgoutput_lambdas env os lambdas=
945941
match lambdaswith

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp