diff --git a/NuGet.Config b/NuGet.Config
index 72f6d27ef5..f4c19635b0 100644
--- a/NuGet.Config
+++ b/NuGet.Config
@@ -1,4 +1,4 @@
-
+
@@ -10,4 +10,4 @@
-
+
\ No newline at end of file
diff --git a/PublishToBlob.proj b/PublishToBlob.proj
index c4b4991b9a..6d71be84df 100644
--- a/PublishToBlob.proj
+++ b/PublishToBlob.proj
@@ -10,7 +10,7 @@
Microsoft.DotNet.Build.Tasks.Feed
- 1.0.0-prerelease-02219-01
+ 2.1.0-prerelease-02419-02
diff --git a/fcs/.gitignore b/fcs/.gitignore
new file mode 100644
index 0000000000..176f453284
--- /dev/null
+++ b/fcs/.gitignore
@@ -0,0 +1,10 @@
+FSharp.Compiler.Service.netstandard/illex.fs
+FSharp.Compiler.Service.netstandard/ilpars.fs
+FSharp.Compiler.Service.netstandard/ilpars.fsi
+FSharp.Compiler.Service.netstandard/lex.fs
+FSharp.Compiler.Service.netstandard/pars.fs
+FSharp.Compiler.Service.netstandard/pars.fsi
+FSharp.Compiler.Service.netstandard/pplex.fs
+FSharp.Compiler.Service.netstandard/pppars.fs
+FSharp.Compiler.Service.netstandard/pppars.fsi
+
diff --git a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj
index 8d7f42d4ee..ce45abbc31 100644
--- a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj
+++ b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj
@@ -651,7 +651,7 @@
- $(FSharpSourcesRoot)\..\packages\System.ValueTuple.4.3.1\lib\netstandard1.0\System.ValueTuple.dll
+ $(FSharpSourcesRoot)\..\packages\System.ValueTuple.4.4.0\lib\netstandard1.0\System.ValueTuple.dll
diff --git a/fcs/README.md b/fcs/README.md
index d297185ee6..290012d34e 100644
--- a/fcs/README.md
+++ b/fcs/README.md
@@ -60,9 +60,9 @@ which does things like:
Yu can push the packages if you have permissions, either automatically using ``build Release`` or manually
set APIKEY=...
- .nuget\nuget.exe push release\fcs\FSharp.Compiler.Service.21.0.1.nupkg %APIKEY% -Source https://nuget.org
- .nuget\nuget.exe push release\fcs\FSharp.Compiler.Service.MSBuild.v12.21.0.1.nupkg %APIKEY% -Source https://nuget.org
- .nuget\nuget.exe push release\fcs\FSharp.Compiler.Service.ProjectCracker.21.0.1.nupkg %APIKEY% -Source https://nuget.org
+ .nuget\nuget.exe push release\fcs\FSharp.Compiler.Service.22.0.1.nupkg %APIKEY% -Source https://nuget.org
+ .nuget\nuget.exe push release\fcs\FSharp.Compiler.Service.MSBuild.v12.22.0.1.nupkg %APIKEY% -Source https://nuget.org
+ .nuget\nuget.exe push release\fcs\FSharp.Compiler.Service.ProjectCracker.22.0.1.nupkg %APIKEY% -Source https://nuget.org
### Use of Paket and FAKE
diff --git a/fcs/RELEASE_NOTES.md b/fcs/RELEASE_NOTES.md
index 4708e1f2b8..0d83971b13 100644
--- a/fcs/RELEASE_NOTES.md
+++ b/fcs/RELEASE_NOTES.md
@@ -1,3 +1,7 @@
+#### 22.0.1
+ * Integrate visualfsharp master
+ * Includes recent memory usage reduction work for ByteFile and ILAttributes
+
#### 21.0.1
* Use new .NET SDK project files
* FSharp.Compiler.Service nuget now uses net45 and netstandard2.0
diff --git a/fcs/build.fsx b/fcs/build.fsx
index 29ee4f111b..79c214683c 100644
--- a/fcs/build.fsx
+++ b/fcs/build.fsx
@@ -20,7 +20,8 @@ let isMono = true
let isMono = false
#endif
-let dotnetExePath = DotNetCli.InstallDotNetSDK "2.1.4"
+
+let dotnetExePath = DotNetCli.InstallDotNetSDK "2.1.102"
let runDotnet workingDir args =
let result =
diff --git a/fcs/fcs.props b/fcs/fcs.props
index c3e2198b38..646b8ccbf9 100644
--- a/fcs/fcs.props
+++ b/fcs/fcs.props
@@ -3,7 +3,7 @@
- 21.0.1
+ 22.0.1
$(FSharpSourcesRoot)\..\packages\FSharp.Compiler.Tools.4.1.27\tools
diff --git a/packages.config b/packages.config
index 01feddf7d5..7458826a65 100644
--- a/packages.config
+++ b/packages.config
@@ -13,6 +13,7 @@
+
@@ -27,13 +28,13 @@
-
+
-
+
diff --git a/src/absil/il.fs b/src/absil/il.fs
index 3316f156e6..ce8ee4065e 100644
--- a/src/absil/il.fs
+++ b/src/absil/il.fs
@@ -7,16 +7,19 @@ module Microsoft.FSharp.Compiler.AbstractIL.IL
#nowarn "346" // The struct, record or union type 'IlxExtensionType' has an explicit implementation of 'Object.Equals'. ...
-open Internal.Utilities
-open Microsoft.FSharp.Compiler.AbstractIL
-open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
-open Microsoft.FSharp.Compiler.AbstractIL.Internal
-open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
+open System
open System.Collections
open System.Collections.Generic
open System.Collections.Concurrent
open System.Runtime.CompilerServices
open System.Reflection
+
+open Microsoft.FSharp.Compiler.AbstractIL
+open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics
+open Microsoft.FSharp.Compiler.AbstractIL.Internal
+open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
+
+open Internal.Utilities
let logging = false
@@ -42,7 +45,7 @@ let _ = if logging then dprintn "* warning: Il.logging is on"
let int_order = LanguagePrimitives.FastGenericComparer
-let notlazy v = Lazy.CreateFromValue v
+let notlazy v = Lazy<_>.CreateFromValue v
/// A little ugly, but the idea is that if a data structure does not
/// contain lazy values then we don't add laziness. So if the thing to map
@@ -321,12 +324,12 @@ type PublicKey =
[]
type AssemblyRefData =
- { assemRefName: string;
- assemRefHash: byte[] option;
- assemRefPublicKeyInfo: PublicKey option;
- assemRefRetargetable: bool;
- assemRefVersion: ILVersionInfo option;
- assemRefLocale: Locale option; }
+ { assemRefName: string
+ assemRefHash: byte[] option
+ assemRefPublicKeyInfo: PublicKey option
+ assemRefRetargetable: bool
+ assemRefVersion: ILVersionInfo option
+ assemRefLocale: Locale option }
/// Global state: table of all assembly references keyed by AssemblyRefData.
let AssemblyRefUniqueStampGenerator = new UniqueStampGenerator()
@@ -721,11 +724,11 @@ let mkILCallSig (cc,args,ret) = { ArgTypes=args; CallingConv=cc; ReturnType=ret}
let mkILBoxedType (tspec:ILTypeSpec) = tspec.TypeRef.AsBoxedType tspec
type ILMethodRef =
- { mrefParent: ILTypeRef;
- mrefCallconv: ILCallingConv;
- mrefGenericArity: int;
- mrefName: string;
- mrefArgs: ILTypes;
+ { mrefParent: ILTypeRef
+ mrefCallconv: ILCallingConv
+ mrefGenericArity: int
+ mrefName: string
+ mrefArgs: ILTypes
mrefReturn: ILType }
member x.DeclaringTypeRef = x.mrefParent
member x.CallingConv = x.mrefCallconv
@@ -736,8 +739,10 @@ type ILMethodRef =
member x.ReturnType = x.mrefReturn
member x.CallingSignature = mkILCallSig (x.CallingConv,x.ArgTypes,x.ReturnType)
+
static member Create(a,b,c,d,e,f) =
{ mrefParent= a;mrefCallconv=b;mrefName=c;mrefGenericArity=d; mrefArgs=e;mrefReturn=f }
+
override x.ToString() = x.DeclaringTypeRef.ToString() + "::" + x.Name + "(...)"
@@ -750,9 +755,9 @@ type ILFieldRef =
[]
type ILMethodSpec =
- { mspecMethodRef: ILMethodRef;
- mspecDeclaringType: ILType;
- mspecMethodInst: ILGenericArgs; }
+ { mspecMethodRef: ILMethodRef
+ mspecDeclaringType: ILType
+ mspecMethodInst: ILGenericArgs }
static member Create(a,b,c) = { mspecDeclaringType=a; mspecMethodRef =b; mspecMethodInst=c }
member x.MethodRef = x.mspecMethodRef
member x.DeclaringType=x.mspecDeclaringType
@@ -764,16 +769,14 @@ type ILMethodSpec =
member x.FormalReturnType = x.MethodRef.ReturnType
override x.ToString() = x.MethodRef.ToString() + "(...)"
-
type ILFieldSpec =
- { FieldRef: ILFieldRef;
+ { FieldRef: ILFieldRef
DeclaringType: ILType }
member x.FormalType = x.FieldRef.Type
member x.Name = x.FieldRef.Name
member x.DeclaringTypeRef = x.FieldRef.DeclaringTypeRef
override x.ToString() = x.FieldRef.ToString()
-
// --------------------------------------------------------------------
// Debug info.
// --------------------------------------------------------------------
@@ -844,16 +847,34 @@ type ILAttribElem =
type ILAttributeNamedArg = (string * ILType * bool * ILAttribElem)
type ILAttribute =
- { Method: ILMethodSpec;
+ { Method: ILMethodSpec
Data: byte[]
Elements: ILAttribElem list}
-[]
-type ILAttributes(f: unit -> ILAttribute[]) =
- let mutable array = InlineDelayInit<_>(f)
- member x.AsArray = array.Value
+[]
+type ILAttributes(array : ILAttribute[]) =
+ member x.AsArray = array
member x.AsList = x.AsArray |> Array.toList
+[]
+type ILAttributesStored =
+ /// Computed by ilread.fs based on metadata index
+ | Reader of (int32 -> ILAttribute[])
+ /// Already computed
+ | Given of ILAttributes
+ member x.GetCustomAttrs metadataIndex =
+ match x with
+ | Reader f -> ILAttributes(f metadataIndex)
+ | Given attrs -> attrs
+
+let emptyILCustomAttrs = ILAttributes [| |]
+let mkILCustomAttrsFromArray (attrs: ILAttribute[]) = if attrs.Length = 0 then emptyILCustomAttrs else ILAttributes attrs
+let mkILCustomAttrs l = match l with [] -> emptyILCustomAttrs | _ -> mkILCustomAttrsFromArray (List.toArray l)
+
+let emptyILCustomAttrsStored = ILAttributesStored.Given emptyILCustomAttrs
+let storeILCustomAttrs (attrs: ILAttributes) = if attrs.AsArray.Length = 0 then emptyILCustomAttrsStored else ILAttributesStored.Given attrs
+let mkILCustomAttrsReader f = ILAttributesStored.Reader f
+
type ILCodeLabel = int
// --------------------------------------------------------------------
@@ -1233,14 +1254,31 @@ type
| DemandChoice
[]
-type ILPermission =
- | PermissionSet of ILSecurityAction * byte[]
+type ILSecurityDecl =
+ | ILSecurityDecl of ILSecurityAction * byte[]
+
+[]
+type ILSecurityDecls(array : ILSecurityDecl[]) =
+ member x.AsArray = array
+ member x.AsList = x.AsArray |> Array.toList
+
+[]
+type ILSecurityDeclsStored =
+ /// Computed by ilread.fs based on metadata index
+ | Reader of (int32 -> ILSecurityDecl[])
+ /// Already computed
+ | Given of ILSecurityDecls
+ member x.GetSecurityDecls metadataIndex =
+ match x with
+ | Reader f -> ILSecurityDecls(f metadataIndex)
+ | Given attrs -> attrs
+
+let emptyILSecurityDecls = ILSecurityDecls [| |]
+let emptyILSecurityDeclsStored = ILSecurityDeclsStored.Given emptyILSecurityDecls
+let mkILSecurityDecls l = match l with [] -> emptyILSecurityDecls | _ -> ILSecurityDecls (Array.ofList l)
+let storeILSecurityDecls (x: ILSecurityDecls) = if x.AsArray.Length = 0 then emptyILSecurityDeclsStored else ILSecurityDeclsStored.Given x
+let mkILSecurityDeclsReader f = ILSecurityDeclsStored.Reader f
-[]
-type ILPermissions =
- | SecurityDecls of ILPermission list
- | SecurityDeclsLazy of Lazy
- member x.AsList = match x with SecurityDecls m -> m | SecurityDeclsLazy m -> m.Force()
[]
type PInvokeCharBestFit =
@@ -1272,33 +1310,37 @@ type PInvokeCharEncoding =
[]
type PInvokeMethod =
- { Where: ILModuleRef;
- Name: string;
- CallingConv: PInvokeCallingConvention;
- CharEncoding: PInvokeCharEncoding;
- NoMangle: bool;
- LastError: bool;
- ThrowOnUnmappableChar: PInvokeThrowOnUnmappableChar;
+ { Where: ILModuleRef
+ Name: string
+ CallingConv: PInvokeCallingConvention
+ CharEncoding: PInvokeCharEncoding
+ NoMangle: bool
+ LastError: bool
+ ThrowOnUnmappableChar: PInvokeThrowOnUnmappableChar
CharBestFit: PInvokeCharBestFit }
[]
type ILParameter =
- { Name: string option;
- Type: ILType;
- Default: ILFieldInit option;
- Marshal: ILNativeType option;
- IsIn: bool;
- IsOut: bool;
- IsOptional: bool;
- CustomAttrs: ILAttributes }
+ { Name: string option
+ Type: ILType
+ Default: ILFieldInit option
+ Marshal: ILNativeType option
+ IsIn: bool
+ IsOut: bool
+ IsOptional: bool
+ CustomAttrsStored: ILAttributesStored
+ MetadataIndex: int32 }
+ member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex
type ILParameters = list
[]
type ILReturn =
- { Marshal: ILNativeType option;
- Type: ILType;
- CustomAttrs: ILAttributes }
+ { Marshal: ILNativeType option
+ Type: ILType
+ CustomAttrsStored: ILAttributesStored
+ MetadataIndex: int32 }
+ member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex
type ILOverridesSpec =
| OverridesSpec of ILMethodRef * ILType
@@ -1324,6 +1366,7 @@ type MethodBody =
| PInvoke of PInvokeMethod (* platform invoke to native *)
| Abstract
| Native
+ | NotAvailable
type ILLazyMethodBody =
| ILLazyMethodBody of Lazy
@@ -1335,7 +1378,7 @@ type MethodCodeKind =
| Native
| Runtime
-let mkMethBodyAux mb = ILLazyMethodBody (Lazy.CreateFromValue mb)
+let mkMethBodyAux mb = ILLazyMethodBody (notlazy mb)
let mkMethBodyLazyAux mb = ILLazyMethodBody mb
let typesOfILParams (ps:ILParameters) : ILTypes = ps |> List.map (fun p -> p.Type)
@@ -1347,14 +1390,16 @@ type ILGenericVariance =
| ContraVariant
type ILGenericParameterDef =
- { Name: string;
- Constraints: ILTypes;
- Variance: ILGenericVariance;
- HasReferenceTypeConstraint: bool;
- CustomAttrs : ILAttributes;
- HasNotNullableValueTypeConstraint: bool;
- HasDefaultConstructorConstraint: bool; }
-
+ { Name: string
+ Constraints: ILTypes
+ Variance: ILGenericVariance
+ HasReferenceTypeConstraint: bool
+ HasNotNullableValueTypeConstraint: bool
+ HasDefaultConstructorConstraint: bool
+ CustomAttrsStored : ILAttributesStored
+ MetadataIndex: int32 }
+
+ member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex
override x.ToString() = x.Name
type ILGenericParameterDefs = ILGenericParameterDef list
@@ -1380,29 +1425,58 @@ let convertMemberAccess (ilMemberAccess:ILMemberAccess) =
let inline conditionalAdd condition flagToAdd source = if condition then source ||| flagToAdd else source &&& ~~~flagToAdd
+let NoMetadataIdx = -1
+
[]
-type ILMethodDef =
- { Name: string;
- Attributes: MethodAttributes;
- ImplAttributes: MethodImplAttributes;
- CallingConv: ILCallingConv;
- Parameters: ILParameters;
- Return: ILReturn;
- mdBody: ILLazyMethodBody;
- SecurityDecls: ILPermissions;
- IsEntryPoint:bool;
- GenericParams: ILGenericParameterDefs;
- CustomAttrs: ILAttributes; }
+type ILMethodDef (name: string, attributes: MethodAttributes, implAttributes: MethodImplAttributes, callingConv: ILCallingConv,
+ parameters: ILParameters, ret: ILReturn, body: ILLazyMethodBody, isEntryPoint:bool, genericParams: ILGenericParameterDefs,
+ securityDeclsStored: ILSecurityDeclsStored, customAttrsStored: ILAttributesStored, metadataIndex: int32) =
+
+ new (name, attributes, implAttributes, callingConv, parameters, ret, body, isEntryPoint, genericParams, securityDecls, customAttrs) =
+ ILMethodDef(name, attributes, implAttributes, callingConv, parameters, ret, body, isEntryPoint, genericParams,
+ storeILSecurityDecls securityDecls, storeILCustomAttrs customAttrs, NoMetadataIdx)
+
+ // The captured data - remember the object will be as large as the data captured by these members
+ member __.Name = name
+ member __.Attributes = attributes
+ member __.ImplAttributes = implAttributes
+ member __.CallingConv = callingConv
+ member __.Parameters = parameters
+ member __.Return = ret
+ member __.Body = body
+ member __.SecurityDeclsStored = securityDeclsStored
+ member __.IsEntryPoint = isEntryPoint
+ member __.GenericParams = genericParams
+ member __.CustomAttrsStored = customAttrsStored
+ member __.MetadataIndex = metadataIndex
+
+ member x.With (?name: string, ?attributes: MethodAttributes, ?implAttributes: MethodImplAttributes, ?callingConv: ILCallingConv, ?parameters: ILParameters, ?ret: ILReturn, ?body: ILLazyMethodBody, ?securityDecls: ILSecurityDecls, ?isEntryPoint:bool, ?genericParams: ILGenericParameterDefs, ?customAttrs: ILAttributes) =
+ ILMethodDef (name = defaultArg name x.Name,
+ attributes = defaultArg attributes x.Attributes,
+ implAttributes = defaultArg implAttributes x.ImplAttributes,
+ callingConv = defaultArg callingConv x.CallingConv,
+ parameters = defaultArg parameters x.Parameters,
+ ret = defaultArg ret x.Return,
+ body = defaultArg body x.Body,
+ securityDecls = (match securityDecls with None -> x.SecurityDecls | Some attrs -> attrs),
+ isEntryPoint = defaultArg isEntryPoint x.IsEntryPoint,
+ genericParams = defaultArg genericParams x.GenericParams,
+ customAttrs=(match customAttrs with None -> x.CustomAttrs | Some attrs -> attrs))
+
+ member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs metadataIndex
+ member x.SecurityDecls = x.SecurityDeclsStored.GetSecurityDecls x.MetadataIndex
member x.ParameterTypes = typesOfILParams x.Parameters
- // Whidbey feature: SafeHandle finalizer must be run
+
member md.Code =
- match md.mdBody.Contents with
+ match md.Body.Contents with
| MethodBody.IL il-> Some il.Code
| _ -> None
- member x.IsIL = match x.mdBody.Contents with | MethodBody.IL _ -> true | _ -> false
- member x.Locals = match x.mdBody.Contents with | MethodBody.IL il -> il.Locals | _ -> []
- member x.MethodBody = match x.mdBody.Contents with MethodBody.IL il -> il | _ -> failwith "not IL"
+ member x.IsIL = match x.Body.Contents with | MethodBody.IL _ -> true | _ -> false
+
+ member x.Locals = match x.Body.Contents with | MethodBody.IL il -> il.Locals | _ -> []
+
+ member x.MethodBody = match x.Body.Contents with MethodBody.IL il -> il | _ -> failwith "not IL"
member x.SourceMarker = x.MethodBody.SourceMarker
member x.MaxStack = x.MethodBody.MaxStack
@@ -1436,24 +1510,23 @@ type ILMethodDef =
member x.IsAggressiveInline= x.ImplAttributes &&& MethodImplAttributes.AggressiveInlining <> enum 0
member x.IsMustRun = x.ImplAttributes &&& MethodImplAttributes.NoOptimization <> enum 0
- member x.WithSpecialName = { x with Attributes = x.Attributes ||| MethodAttributes.SpecialName }
+ member x.WithSpecialName = x.With(attributes = (x.Attributes ||| MethodAttributes.SpecialName))
member x.WithHideBySig() =
- { x with
- Attributes =
+ x.With(attributes = (
if x.IsVirtual then x.Attributes &&& ~~~MethodAttributes.CheckAccessOnOverride ||| MethodAttributes.HideBySig
- else failwith "WithHideBySig" }
- member x.WithHideBySig(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition MethodAttributes.HideBySig}
- member x.WithFinal(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition MethodAttributes.Final}
- member x.WithAbstract(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition MethodAttributes.Abstract}
- member x.WithAccess(access) = { x with Attributes = x.Attributes &&& ~~~MethodAttributes.MemberAccessMask ||| convertMemberAccess access }
- member x.WithNewSlot = { x with Attributes = x.Attributes ||| MethodAttributes.NewSlot }
- member x.WithSecurity(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition MethodAttributes.HasSecurity}
- member x.WithPInvoke(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition MethodAttributes.PinvokeImpl}
- member x.WithPreserveSig(condition) = { x with ImplAttributes = x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.PreserveSig}
- member x.WithSynchronized(condition) = { x with ImplAttributes = x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.Synchronized}
- member x.WithNoInlining(condition) = { x with ImplAttributes = x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.NoInlining}
- member x.WithAggressiveInlining(condition) = { x with ImplAttributes = x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.AggressiveInlining}
- member x.WithRuntime(condition) = { x with ImplAttributes = x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.Runtime}
+ else failwith "WithHideBySig"))
+ member x.WithHideBySig(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.HideBySig))
+ member x.WithFinal(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.Final))
+ member x.WithAbstract(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.Abstract))
+ member x.WithAccess(access) = x.With(attributes = (x.Attributes &&& ~~~MethodAttributes.MemberAccessMask ||| convertMemberAccess access))
+ member x.WithNewSlot = x.With(attributes = (x.Attributes ||| MethodAttributes.NewSlot))
+ member x.WithSecurity(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.HasSecurity))
+ member x.WithPInvoke(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.PinvokeImpl))
+ member x.WithPreserveSig(condition) = x.With(implAttributes = (x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.PreserveSig))
+ member x.WithSynchronized(condition) = x.With(implAttributes = (x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.Synchronized))
+ member x.WithNoInlining(condition) = x.With(implAttributes = (x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.NoInlining))
+ member x.WithAggressiveInlining(condition) = x.With(implAttributes = (x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.AggressiveInlining))
+ member x.WithRuntime(condition) = x.With(implAttributes = (x.ImplAttributes |> conditionalAdd condition MethodImplAttributes.Runtime))
/// Index table by name and arity.
type MethodDefMap = Map
@@ -1486,37 +1559,74 @@ type ILMethodDefs(f : (unit -> ILMethodDef[])) =
member x.FindByNameAndArity (nm,arity) = x.FindByName nm |> List.filter (fun x -> List.length x.Parameters = arity)
[]
-type ILEventDef =
- { Type: ILType option;
- Name: string;
- Attributes: EventAttributes
- AddMethod: ILMethodRef;
- RemoveMethod: ILMethodRef;
- FireMethod: ILMethodRef option;
- OtherMethods: ILMethodRef list;
- CustomAttrs: ILAttributes; }
+type ILEventDef(eventType: ILType option, name: string, attributes: EventAttributes, addMethod: ILMethodRef, removeMethod: ILMethodRef, fireMethod: ILMethodRef option, otherMethods: ILMethodRef list, customAttrsStored: ILAttributesStored, metadataIndex: int32) =
+
+ new (eventType, name, attributes, addMethod, removeMethod, fireMethod, otherMethods, customAttrs) =
+ ILEventDef(eventType, name, attributes, addMethod, removeMethod, fireMethod, otherMethods, storeILCustomAttrs customAttrs, NoMetadataIdx)
+
+ member __.EventType = eventType
+ member __.Name = name
+ member __.Attributes = attributes
+ member __.AddMethod = addMethod
+ member __.RemoveMethod = removeMethod
+ member __.FireMethod = fireMethod
+ member __.OtherMethods = otherMethods
+ member __.CustomAttrsStored = customAttrsStored
+ member __.MetadataIndex = metadataIndex
+ member x.CustomAttrs = customAttrsStored.GetCustomAttrs x.MetadataIndex
+
+ member x.With(?eventType, ?name, ?attributes, ?addMethod, ?removeMethod, ?fireMethod, ?otherMethods, ?customAttrs) =
+ ILEventDef(eventType= defaultArg eventType x.EventType,
+ name= defaultArg name x.Name,
+ attributes= defaultArg attributes x.Attributes,
+ addMethod=defaultArg addMethod x.AddMethod,
+ removeMethod=defaultArg removeMethod x.RemoveMethod,
+ fireMethod= defaultArg fireMethod x.FireMethod,
+ otherMethods= defaultArg otherMethods x.OtherMethods,
+ customAttrs=(match customAttrs with None -> x.CustomAttrs | Some attrs -> attrs))
+
member x.IsSpecialName = (x.Attributes &&& EventAttributes.SpecialName) <> enum<_>(0)
member x.IsRTSpecialName = (x.Attributes &&& EventAttributes.RTSpecialName) <> enum<_>(0)
+
override x.ToString() = "event " + x.Name
(* Index table by name. *)
[]
type ILEventDefs =
- | Events of LazyOrderedMultiMap
- member x.AsList = let (Events t) = x in t.Entries()
- member x.LookupByName s = let (Events t) = x in t.[s]
+ | ILEvents of LazyOrderedMultiMap
+ member x.AsList = let (ILEvents t) = x in t.Entries()
+ member x.LookupByName s = let (ILEvents t) = x in t.[s]
[]
-type ILPropertyDef =
- { Name: string;
- Attributes: PropertyAttributes;
- SetMethod: ILMethodRef option;
- GetMethod: ILMethodRef option;
- CallingConv: ILThisConvention;
- Type: ILType;
- Init: ILFieldInit option;
- Args: ILTypes;
- CustomAttrs: ILAttributes; }
+type ILPropertyDef(name: string, attributes: PropertyAttributes, setMethod: ILMethodRef option, getMethod: ILMethodRef option, callingConv: ILThisConvention, propertyType: ILType, init: ILFieldInit option, args: ILTypes, customAttrsStored: ILAttributesStored, metadataIndex: int32) =
+
+ new (name, attributes, setMethod, getMethod, callingConv, propertyType, init, args, customAttrs) =
+ ILPropertyDef(name, attributes, setMethod, getMethod, callingConv, propertyType, init, args, storeILCustomAttrs customAttrs, NoMetadataIdx)
+
+ member x.Name = name
+ member x.Attributes = attributes
+ member x.GetMethod = getMethod
+ member x.SetMethod = setMethod
+ member x.CallingConv = callingConv
+ member x.PropertyType = propertyType
+ member x.Init = init
+ member x.Args = args
+ member x.CustomAttrsStored = customAttrsStored
+ member x.CustomAttrs = customAttrsStored.GetCustomAttrs x.MetadataIndex
+ member x.MetadataIndex = metadataIndex
+
+ member x.With(?name, ?attributes, ?setMethod, ?getMethod, ?callingConv, ?propertyType, ?init, ?args, ?customAttrs) =
+ ILPropertyDef(name=defaultArg name x.Name,
+ attributes=defaultArg attributes x.Attributes,
+ setMethod=defaultArg setMethod x.SetMethod,
+ getMethod=defaultArg getMethod x.GetMethod,
+ callingConv=defaultArg callingConv x.CallingConv,
+ propertyType=defaultArg propertyType x.PropertyType,
+ init=defaultArg init x.Init,
+ args=defaultArg args x.Args,
+ customAttrs=(match customAttrs with None -> x.CustomAttrs | Some attrs -> attrs))
+
+
member x.IsSpecialName = (x.Attributes &&& PropertyAttributes.SpecialName) <> enum<_>(0)
member x.IsRTSpecialName = (x.Attributes &&& PropertyAttributes.RTSpecialName) <> enum<_>(0)
override x.ToString() = "property " + x.Name
@@ -1524,9 +1634,9 @@ type ILPropertyDef =
// Index table by name.
[]
type ILPropertyDefs =
- | Properties of LazyOrderedMultiMap
- member x.AsList = let (Properties t) = x in t.Entries()
- member x.LookupByName s = let (Properties t) = x in t.[s]
+ | ILProperties of LazyOrderedMultiMap
+ member x.AsList = let (ILProperties t) = x in t.Entries()
+ member x.LookupByName s = let (ILProperties t) = x in t.[s]
let convertFieldAccess (ilMemberAccess:ILMemberAccess) =
match ilMemberAccess with
@@ -1538,36 +1648,50 @@ let convertFieldAccess (ilMemberAccess:ILMemberAccess) =
| ILMemberAccess.Public -> FieldAttributes.Public
[]
-type ILFieldDef =
- { Name: string;
- Type: ILType;
- Attributes: FieldAttributes;
- Data: byte[] option;
- LiteralValue: ILFieldInit option;
- Offset: int32 option;
- Marshal: ILNativeType option;
- CustomAttrs: ILAttributes; }
+type ILFieldDef(name: string, fieldType: ILType, attributes: FieldAttributes, data: byte[] option, literalValue: ILFieldInit option, offset: int32 option, marshal: ILNativeType option, customAttrsStored: ILAttributesStored, metadataIndex: int32) =
+
+ new (name, fieldType, attributes, data, literalValue, offset, marshal, customAttrs) =
+ ILFieldDef(name, fieldType, attributes, data, literalValue, offset, marshal, storeILCustomAttrs customAttrs, NoMetadataIdx)
+ member __.Name=name
+ member __.FieldType = fieldType
+ member __.Attributes=attributes
+ member __.Data=data
+ member __.LiteralValue=literalValue
+ member __.Offset=offset
+ member __.Marshal=marshal
+ member x.CustomAttrsStored = customAttrsStored
+ member x.CustomAttrs = customAttrsStored.GetCustomAttrs x.MetadataIndex
+ member x.MetadataIndex = metadataIndex
+
+ member x.With(?name: string, ?fieldType: ILType, ?attributes: FieldAttributes, ?data: byte[] option, ?literalValue: ILFieldInit option, ?offset: int32 option, ?marshal: ILNativeType option, ?customAttrs: ILAttributes) =
+ ILFieldDef(name=defaultArg name x.Name,
+ fieldType=defaultArg fieldType x.FieldType,
+ attributes=defaultArg attributes x.Attributes,
+ data=defaultArg data x.Data,
+ literalValue=defaultArg literalValue x.LiteralValue,
+ offset=defaultArg offset x.Offset,
+ marshal=defaultArg marshal x.Marshal,
+ customAttrs=defaultArg customAttrs x.CustomAttrs)
member x.IsStatic = x.Attributes &&& FieldAttributes.Static <> enum 0
member x.IsSpecialName = x.Attributes &&& FieldAttributes.SpecialName <> enum 0
member x.IsLiteral = x.Attributes &&& FieldAttributes.Literal <> enum 0
member x.NotSerialized = x.Attributes &&& FieldAttributes.NotSerialized <> enum 0
member x.IsInitOnly = x.Attributes &&& FieldAttributes.InitOnly <> enum 0
member x.Access = memberAccessOfFlags (int x.Attributes)
- member x.WithAccess(access) = { x with Attributes = x.Attributes &&& ~~~FieldAttributes.FieldAccessMask ||| convertFieldAccess access }
- member x.WithInitOnly(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition FieldAttributes.InitOnly }
- member x.WithStatic(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition FieldAttributes.Static }
- member x.WithSpecialName(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition (FieldAttributes.SpecialName ||| FieldAttributes.RTSpecialName) }
- member x.WithNotSerialized(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition FieldAttributes.NotSerialized }
- member x.WithLiteral(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition FieldAttributes.Literal }
- member x.WithHasDefault(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition FieldAttributes.HasDefault }
- member x.WithHasFieldMarshal(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition FieldAttributes.HasFieldMarshal }
+ member x.WithAccess(access) = x.With(attributes = (x.Attributes &&& ~~~FieldAttributes.FieldAccessMask ||| convertFieldAccess access))
+ member x.WithInitOnly(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition FieldAttributes.InitOnly))
+ member x.WithStatic(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition FieldAttributes.Static))
+ member x.WithSpecialName(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition (FieldAttributes.SpecialName ||| FieldAttributes.RTSpecialName)))
+ member x.WithNotSerialized(condition) = x.With(attributes = (x.Attributes |> conditionalAdd condition FieldAttributes.NotSerialized))
+ member x.WithLiteralDefaultValue(literal) = x.With(literalValue = literal, attributes = (x.Attributes |> conditionalAdd literal.IsSome (FieldAttributes.Literal ||| FieldAttributes.HasDefault)))
+ member x.WithFieldMarshal(marshal) = x.With(marshal = marshal, attributes = (x.Attributes |> conditionalAdd marshal.IsSome FieldAttributes.HasFieldMarshal))
// Index table by name. Keep a canonical list to make sure field order is not disturbed for binary manipulation.
type ILFieldDefs =
- | Fields of LazyOrderedMultiMap
- member x.AsList = let (Fields t) = x in t.Entries()
- member x.LookupByName s = let (Fields t) = x in t.[s]
+ | ILFields of LazyOrderedMultiMap
+ member x.AsList = let (ILFields t) = x in t.Entries()
+ member x.LookupByName s = let (ILFields t) = x in t.[s]
type ILMethodImplDef =
{ Overrides: ILOverridesSpec;
@@ -1575,8 +1699,8 @@ type ILMethodImplDef =
// Index table by name and arity.
type ILMethodImplDefs =
- | MethodImpls of Lazy
- member x.AsList = let (MethodImpls ltab) = x in Map.foldBack (fun _x y r -> y@r) (ltab.Force()) []
+ | ILMethodImpls of Lazy
+ member x.AsList = let (ILMethodImpls ltab) = x in Map.foldBack (fun _x y r -> y@r) (ltab.Force()) []
and MethodImplsMap = Map
@@ -1694,21 +1818,48 @@ let convertInitSemantics (init:ILTypeInit) =
| ILTypeInit.OnAny -> enum 0
[]
-type ILTypeDef =
- { Name: string;
- Attributes: TypeAttributes;
- GenericParams: ILGenericParameterDefs; (* class is generic *)
- Layout: ILTypeDefLayout;
- NestedTypes: ILTypeDefs;
- Implements: ILTypes;
- Extends: ILType option;
- Methods: ILMethodDefs;
- SecurityDecls: ILPermissions;
- Fields: ILFieldDefs;
- MethodImpls: ILMethodImplDefs;
- Events: ILEventDefs;
- Properties: ILPropertyDefs;
- CustomAttrs: ILAttributes; }
+type ILTypeDef(name: string, attributes: TypeAttributes, layout: ILTypeDefLayout, implements: ILTypes, genericParams: ILGenericParameterDefs,
+ extends: ILType option, methods: ILMethodDefs, nestedTypes: ILTypeDefs, fields: ILFieldDefs, methodImpls: ILMethodImplDefs,
+ events: ILEventDefs, properties: ILPropertyDefs, securityDeclsStored: ILSecurityDeclsStored, customAttrsStored: ILAttributesStored, metadataIndex: int32) =
+
+ new (name, attributes, layout, implements, genericParams, extends, methods, nestedTypes, fields, methodImpls, events, properties, securityDecls, customAttrs) =
+ ILTypeDef (name, attributes, layout, implements, genericParams, extends, methods, nestedTypes, fields, methodImpls, events, properties, storeILSecurityDecls securityDecls, storeILCustomAttrs customAttrs, NoMetadataIdx)
+
+ member __.Name = name
+ member __.Attributes = attributes
+ member __.GenericParams = genericParams
+ member __.Layout = layout
+ member __.NestedTypes = nestedTypes
+ member __.Implements = implements
+ member __.Extends = extends
+ member __.Methods = methods
+ member __.SecurityDeclsStored = securityDeclsStored
+ member __.Fields = fields
+ member __.MethodImpls = methodImpls
+ member __.Events = events
+ member __.Properties = properties
+ member __.CustomAttrsStored = customAttrsStored
+ member __.MetadataIndex = metadataIndex
+
+ member x.With(?name, ?attributes, ?layout, ?implements, ?genericParams, ?extends, ?methods, ?nestedTypes, ?fields, ?methodImpls, ?events, ?properties, ?customAttrs, ?securityDecls) =
+ ILTypeDef(name=defaultArg name x.Name,
+ attributes=defaultArg attributes x.Attributes,
+ layout=defaultArg layout x.Layout,
+ genericParams = defaultArg genericParams x.GenericParams,
+ nestedTypes = defaultArg nestedTypes x.NestedTypes,
+ implements = defaultArg implements x.Implements,
+ extends = defaultArg extends x.Extends,
+ methods = defaultArg methods x.Methods,
+ securityDecls = defaultArg securityDecls x.SecurityDecls,
+ fields = defaultArg fields x.Fields,
+ methodImpls = defaultArg methodImpls x.MethodImpls,
+ events = defaultArg events x.Events,
+ properties = defaultArg properties x.Properties,
+ customAttrs = defaultArg customAttrs x.CustomAttrs)
+
+ member x.CustomAttrs = customAttrsStored.GetCustomAttrs x.MetadataIndex
+ member x.SecurityDecls = x.SecurityDeclsStored.GetSecurityDecls x.MetadataIndex
+
member x.IsClass = (typeKindOfFlags x.Name x.Methods x.Fields x.Extends (int x.Attributes)) = ILTypeDefKind.Class
member x.IsStruct = (typeKindOfFlags x.Name x.Methods x.Fields x.Extends (int x.Attributes)) = ILTypeDefKind.ValueType
member x.IsInterface = (typeKindOfFlags x.Name x.Methods x.Fields x.Extends (int x.Attributes)) = ILTypeDefKind.Interface
@@ -1723,51 +1874,81 @@ type ILTypeDef =
member x.HasSecurity = x.Attributes &&& TypeAttributes.HasSecurity <> enum 0
member x.Encoding = typeEncodingOfFlags (int x.Attributes)
member x.IsStructOrEnum = x.IsStruct || x.IsEnum
- member x.WithAccess(access) = { x with Attributes = x.Attributes &&& ~~~TypeAttributes.VisibilityMask ||| convertTypeAccessFlags access }
- member x.WithNestedAccess(access) = { x with Attributes = x.Attributes &&& ~~~TypeAttributes.VisibilityMask ||| convertToNestedTypeAccess access }
- member x.WithSealed(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition TypeAttributes.Sealed }
- member x.WithSerializable(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition TypeAttributes.Serializable }
- member x.WithAbstract(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition TypeAttributes.Abstract }
- member x.WithImport(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition TypeAttributes.Import }
- member x.WithHasSecurity(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition TypeAttributes.HasSecurity }
- member x.WithLayout(layout) = { x with Attributes = x.Attributes ||| convertLayout layout; Layout = layout }
- member x.WithKind(kind) = { x with Attributes = x.Attributes ||| convertTypeKind kind; Extends = match kind with ILTypeDefKind.Interface -> None | _ -> x.Extends }
- member x.WithEncoding(encoding) = { x with Attributes = x.Attributes &&& ~~~TypeAttributes.StringFormatMask ||| convertEncoding encoding }
- member x.WithSpecialName(condition) = { x with Attributes = x.Attributes |> conditionalAdd condition TypeAttributes.SpecialName}
- member x.WithInitSemantics(init) = { x with Attributes = x.Attributes ||| convertInitSemantics init }
-
-and [] ILTypeDefs(f : unit -> (string list * string * ILAttributes * Lazy)[]) =
+ member x.WithAccess(access) = x.With(attributes=(x.Attributes &&& ~~~TypeAttributes.VisibilityMask ||| convertTypeAccessFlags access))
+ member x.WithNestedAccess(access) = x.With(attributes=(x.Attributes &&& ~~~TypeAttributes.VisibilityMask ||| convertToNestedTypeAccess access))
+ member x.WithSealed(condition) = x.With(attributes=(x.Attributes |> conditionalAdd condition TypeAttributes.Sealed))
+ member x.WithSerializable(condition) = x.With(attributes=(x.Attributes |> conditionalAdd condition TypeAttributes.Serializable))
+ member x.WithAbstract(condition) = x.With(attributes=(x.Attributes |> conditionalAdd condition TypeAttributes.Abstract))
+ member x.WithImport(condition) = x.With(attributes=(x.Attributes |> conditionalAdd condition TypeAttributes.Import))
+ member x.WithHasSecurity(condition) = x.With(attributes=(x.Attributes |> conditionalAdd condition TypeAttributes.HasSecurity))
+ member x.WithLayout(layout) = x.With(attributes=(x.Attributes ||| convertLayout layout), layout = layout)
+ member x.WithKind(kind) = x.With(attributes=(x.Attributes ||| convertTypeKind kind), extends = match kind with ILTypeDefKind.Interface -> None | _ -> x.Extends)
+ member x.WithEncoding(encoding) = x.With(attributes=(x.Attributes &&& ~~~TypeAttributes.StringFormatMask ||| convertEncoding encoding))
+ member x.WithSpecialName(condition) = x.With(attributes=(x.Attributes |> conditionalAdd condition TypeAttributes.SpecialName))
+ member x.WithInitSemantics(init) = x.With(attributes=(x.Attributes ||| convertInitSemantics init))
+
+and [] ILTypeDefs(f : unit -> ILPreTypeDef[]) =
let mutable array = InlineDelayInit<_>(f)
let mutable dict = InlineDelayInit<_>(fun () ->
- let arr = array.Value
- let t = Dictionary<_,_>(HashIdentity.Structural)
- for (nsp, nm, _attr, ltd) in arr do
- let key = nsp, nm
- t.[key] <- ltd
- t)
+ let arr = array.Value
+ let t = Dictionary<_,_>(HashIdentity.Structural)
+ for pre in arr do
+ let key = pre.Namespace, pre.Name
+ t.[key] <- pre
+ t)
- member x.AsArray = [| for (_,_,_,ltd) in array.Value -> ltd.Force() |]
- member x.AsList = [ for (_,_,_,ltd) in array.Value -> ltd.Force() ]
+ member x.AsArray = [| for pre in array.Value -> pre.GetTypeDef() |]
+ member x.AsList = [ for pre in array.Value -> pre.GetTypeDef() ]
interface IEnumerable with
member x.GetEnumerator() = ((x :> IEnumerable).GetEnumerator() :> IEnumerator)
interface IEnumerable with
member x.GetEnumerator() =
- (seq { for (_,_,_,ltd) in array.Value -> ltd.Force() }).GetEnumerator()
+ (seq { for pre in array.Value -> pre.GetTypeDef() }).GetEnumerator()
- member x.AsArrayOfLazyTypeDefs = array.Value
+ member x.AsArrayOfPreTypeDefs = array.Value
member x.FindByName nm =
let ns,n = splitILTypeName nm
- dict.Value.[(ns,n)].Force()
+ dict.Value.[(ns,n)].GetTypeDef()
+
+/// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies.
+and [] ILPreTypeDef(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
+ let mutable store : ILTypeDef = Unchecked.defaultof<_>
+
+ member __.Namespace = nameSpace
+ member __.Name = name
+ member __.MetadataIndex = metadataIndex
+
+ member x.GetTypeDef() =
+ match box store with
+ | null ->
+ match storage with
+ | ILTypeDefStored.Given td ->
+ store <- td
+ td
+ | ILTypeDefStored.Computed f ->
+ System.Threading.LazyInitializer.EnsureInitialized(&store, System.Func<_>(fun () -> f()))
+ | ILTypeDefStored.Reader f ->
+ System.Threading.LazyInitializer.EnsureInitialized(&store, System.Func<_>(fun () -> f x.MetadataIndex))
+ | _ -> store
+
+and ILTypeDefStored =
+ | Given of ILTypeDef
+ | Reader of (int32 -> ILTypeDef)
+ | Computed of (unit -> ILTypeDef)
+
+let mkILTypeDefReader f = ILTypeDefStored.Reader f
type ILNestedExportedType =
- { Name: string;
- Access: ILMemberAccess;
- Nested: ILNestedExportedTypes;
- CustomAttrs: ILAttributes }
+ { Name: string
+ Access: ILMemberAccess
+ Nested: ILNestedExportedTypes
+ CustomAttrsStored: ILAttributesStored
+ MetadataIndex: int32 }
+ member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex
and ILNestedExportedTypes =
| ILNestedExportedTypes of Lazy