Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 59 additions & 10 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,22 @@ type LazyOrderedMultiMap<'Key, 'Data when 'Key: equality>(keyf: 'Data -> 'Key, l

t)

member self.Entries() = lazyItems.Force()
member _.Entries() = lazyItems.Force()

member self.Add y =
member _.Add y =
new LazyOrderedMultiMap<'Key, 'Data>(keyf, lazyItems |> lazyMap (fun x -> y :: x))

member self.Filter f =
member _.Filter f =
new LazyOrderedMultiMap<'Key, 'Data>(keyf, lazyItems |> lazyMap (List.filter f))

member self.Item
member _.Item
with get x =
match quickMap.Force().TryGetValue x with
| true, v -> v
| _ -> []

override _.ToString() = "<table>"

//---------------------------------------------------------------------
// SHA1 hash-signing algorithm. Used to get the public key token from
// the public key.
Expand Down Expand Up @@ -422,6 +424,8 @@ type AssemblyRefData =
assemRefLocale: Locale option
}

override x.ToString() = x.assemRefName

/// Global state: table of all assembly references keyed by AssemblyRefData.
let AssemblyRefUniqueStampGenerator = UniqueStampGenerator<AssemblyRefData>()

Expand Down Expand Up @@ -578,6 +582,8 @@ type ILModuleRef =

member x.Hash = x.hash

override x.ToString() = x.Name

[<StructuralEquality; StructuralComparison>]
[<RequireQualifiedAccess>]
type ILScopeRef =
Expand Down Expand Up @@ -667,6 +673,9 @@ type ILCallingConv =

static member Static = ILCallingConvStatics.Static

override x.ToString() =
if x.IsStatic then "static" else "instance"

/// Static storage to amortize the allocation of <c>ILCallingConv.Instance</c> and <c>ILCallingConv.Static</c>.
and ILCallingConvStatics() =

Expand Down Expand Up @@ -986,7 +995,8 @@ type ILMethodRef =

member x.ReturnType = x.mrefReturn

member x.CallingSignature = mkILCallSig (x.CallingConv, x.ArgTypes, x.ReturnType)
member x.GetCallingSignature() =
mkILCallSig (x.CallingConv, x.ArgTypes, x.ReturnType)

static member Create(enclosingTypeRef, callingConv, name, genericArity, argTypes, returnType) =
{
Expand Down Expand Up @@ -1115,6 +1125,8 @@ type ILSourceDocument =

member x.File = x.sourceFile

override x.ToString() = x.File

[<StructuralEquality; StructuralComparison; StructuredFormatDisplay("{DebugText}")>]
type ILDebugPoint =
{
Expand Down Expand Up @@ -1451,6 +1463,9 @@ type ILLocalDebugInfo =
DebugMappings: ILLocalDebugMapping list
}

override x.ToString() =
(fst x.Range).ToString() + "-" + (snd x.Range).ToString()

[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILCode =
{
Expand All @@ -1460,6 +1475,8 @@ type ILCode =
Locals: ILLocalDebugInfo list
}

override x.ToString() = "<code>"

[<RequireQualifiedAccess; NoComparison; NoEquality>]
type ILLocal =
{
Expand All @@ -1468,6 +1485,8 @@ type ILLocal =
DebugInfo: (string * int * int) option
}

override x.ToString() = "<local>"

type ILLocals = ILLocal list

[<RequireQualifiedAccess; NoEquality; NoComparison>]
Expand All @@ -1484,6 +1503,8 @@ type ILDebugImports =
Imports: ILDebugImport[]
}

override x.ToString() = "<imports>"

[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILMethodBody =
{
Expand All @@ -1497,6 +1518,8 @@ type ILMethodBody =
DebugImports: ILDebugImports option
}

override x.ToString() = "<method body>"

[<RequireQualifiedAccess>]
type ILMemberAccess =
| Assembly
Expand Down Expand Up @@ -1737,6 +1760,8 @@ type PInvokeMethod =
CharBestFit: PInvokeCharBestFit
}

override x.ToString() = x.Name

[<RequireQualifiedAccess; NoEquality; NoComparison>]
type ILParameter =
{
Expand All @@ -1753,6 +1778,9 @@ type ILParameter =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

override x.ToString() =
x.Name |> Option.defaultValue "<no name>"

type ILParameters = ILParameter list

[<RequireQualifiedAccess; NoEquality; NoComparison>]
Expand All @@ -1764,6 +1792,8 @@ type ILReturn =
MetadataIndex: int32
}

override x.ToString() = "<return>"

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

member x.WithCustomAttrs(customAttrs) =
Expand All @@ -1778,6 +1808,9 @@ type ILOverridesSpec =

member x.DeclaringType = let (OverridesSpec (_mr, ty)) = x in ty

override x.ToString() =
"overrides " + x.DeclaringType.ToString() + "::" + x.MethodRef.ToString()

type ILMethodVirtualInfo =
{
IsFinal: bool
Expand All @@ -1800,7 +1833,7 @@ type MethodCodeKind =
| Native
| Runtime

let typesOfILParams (ps: ILParameters) : ILTypes = ps |> List.map (fun p -> p.Type)
let typesOfILParams (ps: ILParameters) = ps |> List.map (fun p -> p.Type)

[<StructuralEquality; StructuralComparison>]
type ILGenericVariance =
Expand Down Expand Up @@ -1985,7 +2018,7 @@ type ILMethodDef

member x.IsZeroInit = x.MethodBody.IsZeroInit

member md.CallingSignature =
member md.GetCallingSignature() =
mkILCallSig (md.CallingConv, md.ParameterTypes, md.Return.Type)

member x.IsClassInitializer = x.Name = ".cctor"
Expand Down Expand Up @@ -2149,7 +2182,7 @@ type ILMethodDefs(f: unit -> ILMethodDef[]) =

member x.TryFindInstanceByNameAndCallingSignature(nm, callingSig) =
x.FindByName nm
|> List.tryFind (fun x -> not x.IsStatic && x.CallingSignature = callingSig)
|> List.tryFind (fun x -> not x.IsStatic && x.GetCallingSignature() = callingSig)

[<NoComparison; NoEquality; StructuredFormatDisplay("{DebugText}")>]
type ILEventDef
Expand Down Expand Up @@ -2232,6 +2265,8 @@ type ILEventDefs =

member x.LookupByName s = let (ILEvents t) = x in t[s]

override x.ToString() = "<events>"

[<NoComparison; NoEquality; StructuredFormatDisplay("{DebugText}")>]
type ILPropertyDef
(
Expand Down Expand Up @@ -2310,6 +2345,8 @@ type ILPropertyDefs =

member x.LookupByName s = let (ILProperties t) = x in t[s]

override x.ToString() = "<properties>"

let convertFieldAccess (ilMemberAccess: ILMemberAccess) =
match ilMemberAccess with
| ILMemberAccess.Assembly -> FieldAttributes.Assembly
Expand Down Expand Up @@ -2424,6 +2461,8 @@ type ILFieldDefs =

member x.LookupByName s = let (ILFields t) = x in t[s]

override x.ToString() = "<fields>"

type ILMethodImplDef =
{
Overrides: ILOverridesSpec
Expand Down Expand Up @@ -2804,10 +2843,10 @@ and [<Sealed>] ILTypeDefs(f: unit -> ILPreTypeDef[]) =

ReadOnlyDictionary t)

member x.AsArray() =
member _.AsArray() =
[| for pre in array.Value -> pre.GetTypeDef() |]

member x.AsList() =
member _.AsList() =
[ for pre in array.Value -> pre.GetTypeDef() ]

interface IEnumerable with
Expand Down Expand Up @@ -2870,6 +2909,8 @@ type ILNestedExportedType =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

override x.ToString() = "exported type " + x.Name

and ILNestedExportedTypes =
| ILNestedExportedTypes of Lazy<Map<string, ILNestedExportedType>>

Expand All @@ -2892,6 +2933,8 @@ and [<NoComparison; NoEquality>] ILExportedTypeOrForwarder =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

override x.ToString() = "exported type " + x.Name

and ILExportedTypesAndForwarders =
| ILExportedTypesAndForwarders of Lazy<Map<string, ILExportedTypeOrForwarder>>

Expand Down Expand Up @@ -2930,6 +2973,8 @@ type ILResource =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

override x.ToString() = "resource " + x.Name

type ILResources =
| ILResources of ILResource list

Expand Down Expand Up @@ -2977,6 +3022,8 @@ type ILAssemblyManifest =

member x.SecurityDecls = x.SecurityDeclsStored.GetSecurityDecls x.MetadataIndex

override x.ToString() = "assembly manifest " + x.Name

[<RequireQualifiedAccess>]
type ILNativeResource =
| In of fileName: string * linkedResourceBase: int * linkedResourceStart: int * linkedResourceLength: int
Expand Down Expand Up @@ -3020,6 +3067,8 @@ type ILModuleDef =

member x.CustomAttrs = x.CustomAttrsStored.GetCustomAttrs x.MetadataIndex

override x.ToString() = "assembly " + x.Name

// --------------------------------------------------------------------
// Add fields and types to tables, with decent error messages
// when clashes occur...
Expand Down
Loading