@@ -15,6 +15,7 @@ open Microsoft.FSharp.Compiler.AbstractIL.Internal.Library
1515open System.Collections
1616open System.Collections .Generic
1717open System.Collections .Concurrent
18+ open System.Runtime .CompilerServices
1819
1920let logging = false
2021
@@ -2132,60 +2133,61 @@ let isILDoubleTy ty = isILValuePrimaryAssemblyTy ty tname_Double
21322133// Rescoping
21332134// --------------------------------------------------------------------
21342135
2135- let qrescope_scoref scoref scoref_old =
2136- match scoref, scoref_ oldwith
2137- | _, ILScopeRef.Local-> Some scoref
2138- | ILScopeRef.Local,_ -> None
2139- | _, ILScopeRef.Module_ -> Some scoref
2140- | ILScopeRef.Module_,_ -> None
2141- | _ -> None
2142- let qrescope_tref scoref ( x : ILTypeRef ) =
2143- match qrescope_ scoref scoref x.Scopewith
2144- | None-> None
2145- | Some s-> Some( ILTypeRef.Create( s, x.Enclosing, x.Name))
2146-
2147- let rescopeILScopeRef x y = match qrescope_ scoref x ywith Some x-> x| None-> y
2148- let rescopeILTypeRef x y = match qrescope_ tref x ywith Some x-> x| None-> y
2136+ let rescopeILScopeRef scoref scoref1 =
2137+ match scoref, scoref1with
2138+ | _, ILScopeRef.Local-> scoref
2139+ | ILScopeRef.Local,_ -> scoref1
2140+ | _, ILScopeRef.Module_ -> scoref
2141+ | ILScopeRef.Module_,_ -> scoref1
2142+ | _ -> scoref1
2143+
2144+ let rescopeILTypeRef scoref ( tref1 : ILTypeRef ) =
2145+ let scoref1 = tref1.Scope
2146+ let scoref2 = rescopeILScopeRef scoref scoref1
2147+ if scoref1=== scoref2then tref1
2148+ else ILTypeRef.Create( scoref2, tref1.Enclosing, tref1.Name)
21492149
21502150// ORIGINAL IMPLEMENTATION (too many allocations
21512151// { tspecTypeRef=rescopeILTypeRef scoref tref;
21522152// tspecInst=rescopeILTypes scoref tinst }
2153- let rec rescopeILTypeSpecQuick scoref ( tspec : ILTypeSpec ) =
2154- let tref = tspec.TypeRef
2155- let tinst = tspec.GenericArgs
2156- let qtref = qrescope_ tref scoref tref
2157- if isNil tinst&& Option.isNone qtrefthen
2158- None(* avoid reallocation in the common case*)
2153+ let rec rescopeILTypeSpec scoref ( tspec1 : ILTypeSpec ) =
2154+ let tref1 = tspec1.TypeRef
2155+ let tinst1 = tspec1.GenericArgs
2156+ let tref2 = rescopeILTypeRef scoref tref1
2157+
2158+ // avoid reallocation in the common case
2159+ if tref1=== tref2then
2160+ if isNil tinst1then tspec1else
2161+ let tinst2 = rescopeILTypes scoref tinst1
2162+ if tinst1=== tinst2then tspec1else
2163+ ILTypeSpec.Create( tref2, tinst2)
21592164else
2160- match qtrefwith
2161- | None-> Some( ILTypeSpec.Create( tref, rescopeILTypes scoref tinst))
2162- | Some tref-> Some( ILTypeSpec.Create( tref, rescopeILTypes scoref tinst))
2163-
2164- and rescopeILTypeSpec x y =
2165- match rescopeILTypeSpecQuick x ywith
2166- | Some x-> x
2167- | None-> y
2165+ let tinst2 = rescopeILTypes scoref tinst1
2166+ ILTypeSpec.Create( tref2, tinst2)
21682167
21692168and rescopeILType scoref typ =
21702169match typwith
21712170| ILType.Ptr t-> ILType.Ptr( rescopeILType scoref t)
21722171| ILType.FunctionPointer t-> ILType.FunctionPointer( rescopeILCallSig scoref t)
21732172| ILType.Byref t-> ILType.Byref( rescopeILType scoref t)
2174- | ILType.Boxed cr->
2175- match rescopeILTypeSpecQuick scoref crwith
2176- | Some res-> mkILBoxedType res
2177- | None-> typ// avoid reallocation in the common case
2178- | ILType.Array( s, ty) -> ILType.Array( s, rescopeILType scoref ty)
2179- | ILType.Value cr->
2180- match rescopeILTypeSpecQuick scoref crwith
2181- | Some res-> ILType.Value res
2182- | None-> typ// avoid reallocation in the common case
2173+ | ILType.Boxed cr1->
2174+ let cr2 = rescopeILTypeSpec scoref cr1
2175+ if cr1=== cr2then typelse
2176+ mkILBoxedType cr2
2177+ | ILType.Array( s, ety1) ->
2178+ let ety2 = rescopeILType scoref ety1
2179+ if ety1=== ety2then typelse
2180+ ILType.Array( s, ety2)
2181+ | ILType.Value cr1->
2182+ let cr2 = rescopeILTypeSpec scoref cr1
2183+ if cr1=== cr2then typelse
2184+ ILType.Value cr2
21832185| ILType.Modified( b, tref, ty) -> ILType.Modified( b, rescopeILTypeRef scoref tref, rescopeILType scoref ty)
21842186| x-> x
21852187
21862188and rescopeILTypes scoref i =
21872189if isNil ithen i
2188- else List.map ( rescopeILType scoref) i
2190+ else List.mapq ( rescopeILType scoref) i
21892191
21902192and rescopeILCallSig scoref csig =
21912193 mkILCallSig( csig.CallingConv, rescopeILTypes scoref csig.ArgTypes, rescopeILType scoref csig.ReturnType)