@@ -4265,20 +4265,74 @@ let compareILVersions (a1,a2,a3,a4) ((b1,b2,b3,b4) : ILVersionInfo) =
42654265 if c <> 0 then c else
42664266 0
42674267
4268+ let qunscope_scoref scoref_old =
4269+ match scoref_ old with
4270+ | ILScopeRef.Local -> None
4271+ | _ -> Some ILScopeRef.Local
4272+
4273+ let qunscope_tref ( x : ILTypeRef ) =
4274+ match qunscope_ scoref x.Scope with
4275+ | None -> None
4276+ | Some s -> Some ( ILTypeRef.Create( s, x.Enclosing, x.Name))
4277+
4278+ let unscopeILScopeRef y = match qunscope_ scoref y with Some x -> x | None -> y
4279+ let unscopeILTypeRef y = match qunscope_ tref y with Some x -> x | None -> y
4280+
4281+ let rec unscopeILTypeSpecQuick ( tspec : ILTypeSpec ) =
4282+ let tref = tspec.TypeRef
4283+ let tinst = tspec.GenericArgs
4284+ let qtref = qunscope_ tref tref
4285+ if ILList.isEmpty tinst && isNone qtref then
4286+ None (* avoid reallocation in the common case *)
4287+ else
4288+ match qtref with
4289+ | None -> Some ( ILTypeSpec.Create ( tref, unscopeILTypes tinst))
4290+ | Some tref -> Some ( ILTypeSpec.Create ( tref, unscopeILTypes tinst))
4291+
4292+ and unscopeILTypeSpec x y =
4293+ match rescopeILTypeSpecQuick x y with
4294+ | Some x -> x
4295+ | None -> y
4296+
4297+ and unscopeILType typ =
4298+ match typ with
4299+ | ILType.Ptr t -> ILType.Ptr ( unscopeILType t)
4300+ | ILType.FunctionPointer t -> ILType.FunctionPointer ( unscopeILCallSig t)
4301+ | ILType.Byref t -> ILType.Byref ( unscopeILType t)
4302+ | ILType.Boxed cr ->
4303+ match unscopeILTypeSpecQuick cr with
4304+ | Some res -> mkILBoxedType res
4305+ | None -> typ // avoid reallocation in the common case
4306+ | ILType.Array ( s, ty) -> ILType.Array ( s, unscopeILType ty)
4307+ | ILType.Value cr ->
4308+ match unscopeILTypeSpecQuick cr with
4309+ | Some res -> ILType.Value res
4310+ | None -> typ // avoid reallocation in the common case
4311+ | ILType.Modified( b, tref, ty) -> ILType.Modified( b, unscopeILTypeRef tref, unscopeILType ty)
4312+ | x -> x
4313+
4314+ and unscopeILTypes i =
4315+ if ILList.isEmpty i then i
4316+ else ILList.map unscopeILType i
4317+
4318+ and unscopeILCallSig csig =
4319+ mkILCallSigRaw ( csig.CallingConv, unscopeILTypes csig.ArgTypes, unscopeILType csig.ReturnType)
42684320
42694321let resolveILMethodRefWithRescope r td ( mref : ILMethodRef ) =
42704322 let args = mref.ArgTypes
42714323 let nargs = args.Length
42724324 let nm = mref.Name
42734325 let possibles = td.Methods.FindByNameAndArity ( nm, nargs)
42744326 if isNil possibles then failwith ( " no method named " + nm+ " found in type " + td.Name);
4327+ let argTypes = mref.ArgTypes |> List.map r
4328+ let retType : ILType = r mref.ReturnType
42754329 match
42764330 possibles |> List.filter ( fun md ->
42774331 mref.CallingConv = md.CallingConv &&
42784332 // REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
4279- ( md.Parameters, mref.ArgTypes ) ||> ILList.lengthsEqAndForall2 ( fun p1 p2 -> r p1.Type = p2) &&
4333+ ( md.Parameters, argTypes ) ||> ILList.lengthsEqAndForall2 ( fun p1 p2 -> r p1.Type = p2) &&
42804334 // REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
4281- r md.Return.Type = mref.ReturnType ) with
4335+ r md.Return.Type = retType ) with
42824336 | [] -> failwith ( " no method named " + nm+ " with appropriate argument types found in type " + td.Name)
42834337 | [ mdef] -> mdef
42844338 | _ -> failwith ( " multiple methods named " + nm+ " appear with identical argument types in type " + td.Name)
0 commit comments