From 190f703062aad184084e30b1259edd6e44a925f7 Mon Sep 17 00:00:00 2001 From: Don Syme Date: Tue, 19 Jan 2016 15:31:51 +0000 Subject: [PATCH] Integrate FCS API: Changes to src\absil --- src/absil/il.fs | 17 ++++++++++------- src/absil/il.fsi | 1 + src/absil/illib.fs | 10 ++++++++-- src/absil/ilreflect.fs | 5 +++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/absil/il.fs b/src/absil/il.fs index f1d827216..7131561ef 100644 --- a/src/absil/il.fs +++ b/src/absil/il.fs @@ -13,8 +13,9 @@ open Microsoft.FSharp.Compiler.AbstractIL open Microsoft.FSharp.Compiler.AbstractIL.Internal open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library open Microsoft.FSharp.Compiler.AbstractIL.Diagnostics -open System.Collections.Generic open System.Collections +open System.Collections.Generic +open System.Collections.Concurrent let logging = false @@ -75,10 +76,10 @@ let rec splitNamespaceAux (nm:string) = /// Global State. All namespace splits ever seen // ++GLOBAL MUTABLE STATE -let memoizeNamespaceTable = new Dictionary(10) +let memoizeNamespaceTable = new ConcurrentDictionary() // ++GLOBAL MUTABLE STATE -let memoizeNamespaceRightTable = new Dictionary(100) +let memoizeNamespaceRightTable = new ConcurrentDictionary() let splitNamespace nm = @@ -92,7 +93,7 @@ let splitNamespaceMemoized nm = splitNamespace nm // ++GLOBAL MUTABLE STATE let memoizeNamespaceArrayTable = - Dictionary(10) + Concurrent.ConcurrentDictionary() let splitNamespaceToArray nm = let mutable res = Unchecked.defaultof<_> @@ -5082,7 +5083,7 @@ let compareILVersions (a1,a2,a3,a4) ((b1,b2,b3,b4) : ILVersionInfo) = 0 -let resolveILMethodRef td (mref:ILMethodRef) = +let resolveILMethodRefWithRescope r td (mref:ILMethodRef) = let args = mref.ArgTypes let nargs = args.Length let nm = mref.Name @@ -5092,15 +5093,17 @@ let resolveILMethodRef td (mref:ILMethodRef) = possibles |> List.filter (fun md -> mref.CallingConv = md.CallingConv && // REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct - (md.Parameters,mref.ArgTypes) ||> ILList.lengthsEqAndForall2 (fun p1 p2 -> p1.Type = p2) && + (md.Parameters,mref.ArgTypes) ||> ILList.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2) && // REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct - md.Return.Type = mref.ReturnType) with + r md.Return.Type = mref.ReturnType) with | [] -> failwith ("no method named "+nm+" with appropriate argument types found in type "+td.Name); | [mdef] -> mdef | _ -> failwith ("multiple methods named "+nm+" appear with identical argument types in type "+td.Name) +let resolveILMethodRef td mref = resolveILMethodRefWithRescope id td mref + let mkRefToILModule m = ILModuleRef.Create(m.Name, true, None) diff --git a/src/absil/il.fsi b/src/absil/il.fsi index 66a1b4ef8..9c1224131 100644 --- a/src/absil/il.fsi +++ b/src/absil/il.fsi @@ -1622,6 +1622,7 @@ type ILModuleDef = /// or event. This is useful especially if your code is not using the Ilbind /// API to bind references. val resolveILMethodRef: ILTypeDef -> ILMethodRef -> ILMethodDef +val resolveILMethodRefWithRescope: (ILType -> ILType) -> ILTypeDef -> ILMethodRef -> ILMethodDef // ------------------------------------------------------------------ // Type Names diff --git a/src/absil/illib.fs b/src/absil/illib.fs index 27101792d..34e9ff578 100644 --- a/src/absil/illib.fs +++ b/src/absil/illib.fs @@ -151,6 +151,11 @@ module Option = | None -> dflt | Some x -> x + let orElse dflt opt = + match opt with + | None -> dflt() + | res -> res + // REVIEW: systematically eliminate foldMap/mapFold duplication let foldMap f z l = match l with @@ -961,6 +966,7 @@ module Shim = abstract AssemblyLoadFrom: fileName:string -> System.Reflection.Assembly abstract AssemblyLoad: assemblyName:System.Reflection.AssemblyName -> System.Reflection.Assembly + type DefaultFileSystem() = interface IFileSystem with member __.AssemblyLoadFrom(fileName:string) = @@ -1001,7 +1007,7 @@ module Shim = member __.FileDelete (fileName:string) = System.IO.File.Delete fileName type System.Text.Encoding with - static member GetEncodingShim(n:int) = - System.Text.Encoding.GetEncoding(n) + static member GetEncodingShim(n:int) = + System.Text.Encoding.GetEncoding(n) let mutable FileSystem = DefaultFileSystem() :> IFileSystem diff --git a/src/absil/ilreflect.fs b/src/absil/ilreflect.fs index e5cccbe85..7cca73512 100644 --- a/src/absil/ilreflect.fs +++ b/src/absil/ilreflect.fs @@ -1950,13 +1950,14 @@ let buildModuleFragment cenv emEnv (asmB : AssemblyBuilder) (modB : ModuleBuilde // test hook //---------------------------------------------------------------------------- -let mkDynamicAssemblyAndModule (assemblyName, optimize, debugInfo) = +let mkDynamicAssemblyAndModule (assemblyName, optimize, debugInfo, collectible) = let filename = assemblyName ^ ".dll" let currentDom = System.AppDomain.CurrentDomain let asmDir = "." let asmName = new AssemblyName() asmName.Name <- assemblyName; - let asmB = currentDom.DefineDynamicAssemblyAndLog(asmName,AssemblyBuilderAccess.RunAndSave,asmDir) + let asmAccess = if collectible then AssemblyBuilderAccess.RunAndCollect else AssemblyBuilderAccess.RunAndSave + let asmB = currentDom.DefineDynamicAssemblyAndLog(asmName,asmAccess,asmDir) if not optimize then let daType = typeof; let daCtor = daType.GetConstructor [| typeof |] -- GitLab