未验证 提交 027049ec 编写于 作者: E Eugene Auduchinok 提交者: GitHub

Infos: don't read parameter/return attributes unless really needed (#12996)

* Infos: don't read parameter/return attributes unless really needed

* Infos: reuse parameter/return attributes

* Update surface area

* Simplify

* Reduce diff
上级 9e491c2f
......@@ -865,6 +865,7 @@ type ILParameter =
IsOptional: bool
CustomAttrsStored: ILAttributesStored
MetadataIndex: int32 }
member CustomAttrs: ILAttributes
type ILParameters = ILParameter list
......
......@@ -347,24 +347,24 @@ let ImportILTypeFromMetadata amap m scoref tinst minst ilty =
ImportILType scoref amap m (tinst@minst) ilty
/// Read an Abstract IL type from metadata, including any attributes that may affect the type itself, and convert to an F# type.
let ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst ilty cattrs =
let ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst ilty getCattrs =
let ty = ImportILType scoref amap m (tinst@minst) ilty
// If the type is a byref and one of attributes from a return or parameter has IsReadOnly, then it's a inref.
if isByrefTy amap.g ty && TryFindILAttribute amap.g.attrib_IsReadOnlyAttribute cattrs then
if isByrefTy amap.g ty && TryFindILAttribute amap.g.attrib_IsReadOnlyAttribute (getCattrs ()) then
mkInByrefTy amap.g (destByrefTy amap.g ty)
else
ty
/// Get the parameter type of an IL method.
let ImportParameterTypeFromMetadata amap m ilty cattrs scoref tinst mist =
ImportILTypeFromMetadataWithAttributes amap m scoref tinst mist ilty cattrs
let ImportParameterTypeFromMetadata amap m ilty getCattrs scoref tinst mist =
ImportILTypeFromMetadataWithAttributes amap m scoref tinst mist ilty getCattrs
/// Get the return type of an IL method, taking into account instantiations for type, return attributes and method generic parameters, and
/// translating 'void' to 'None'.
let ImportReturnTypeFromMetadata amap m ilty cattrs scoref tinst minst =
let ImportReturnTypeFromMetadata amap m ilty getCattrs scoref tinst minst =
match ilty with
| ILType.Void -> None
| retTy -> Some(ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst retTy cattrs)
| retTy -> Some(ImportILTypeFromMetadataWithAttributes amap m scoref tinst minst retTy getCattrs)
/// Copy constraints. If the constraint comes from a type parameter associated
......@@ -597,8 +597,9 @@ type OptionalArgInfo =
match ilParam.Marshal with
| Some(ILNativeType.IUnknown | ILNativeType.IDispatch | ILNativeType.Interface) -> Constant ILFieldInit.Null
| _ ->
if TryFindILAttributeOpt g.attrib_IUnknownConstantAttribute ilParam.CustomAttrs then WrapperForIUnknown
elif TryFindILAttributeOpt g.attrib_IDispatchConstantAttribute ilParam.CustomAttrs then WrapperForIDispatch
let attrs = ilParam.CustomAttrs
if TryFindILAttributeOpt g.attrib_IUnknownConstantAttribute attrs then WrapperForIUnknown
elif TryFindILAttributeOpt g.attrib_IDispatchConstantAttribute attrs then WrapperForIDispatch
else MissingValue
else
DefaultValue
......@@ -877,19 +878,21 @@ type ILMethInfo =
/// Get the argument types of the the IL method. If this is an C#-style extension method
/// then drop the object argument.
member x.GetParamTypes(amap, m, minst) =
x.ParamMetadata |> List.map (fun p -> ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst)
x.ParamMetadata |> List.map (fun p -> ImportParameterTypeFromMetadata amap m p.Type (fun _ -> p.CustomAttrs) x.MetadataScope x.DeclaringTypeInst minst)
/// Get all the argument types of the IL method. Include the object argument even if this is
/// an C#-style extension method.
member x.GetRawArgTypes(amap, m, minst) =
x.RawMetadata.Parameters |> List.map (fun p -> ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst)
x.RawMetadata.Parameters |> List.map (fun p -> ImportParameterTypeFromMetadata amap m p.Type (fun _ -> p.CustomAttrs) x.MetadataScope x.DeclaringTypeInst minst)
/// Get info about the arguments of the IL method. If this is an C#-style extension method then
/// drop the object argument.
///
/// Any type parameters of the enclosing type are instantiated in the type returned.
member x.GetParamNamesAndTypes(amap, m, minst) =
x.ParamMetadata |> List.map (fun p -> ParamNameAndType(Option.map (mkSynId m) p.Name, ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst) )
let scope = x.MetadataScope
let tinst = x.DeclaringTypeInst
x.ParamMetadata |> List.map (fun p -> ParamNameAndType(Option.map (mkSynId m) p.Name, ImportParameterTypeFromMetadata amap m p.Type (fun _ -> p.CustomAttrs) scope tinst minst) )
/// Get a reference to the method (dropping all generic instantiations), as an Abstract IL ILMethodRef.
member x.ILMethodRef =
......@@ -918,7 +921,7 @@ type ILMethInfo =
// method instantiation.
if x.IsILExtensionMethod then
let p = x.RawMetadata.Parameters.Head
[ ImportParameterTypeFromMetadata amap m p.Type p.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst ]
[ ImportParameterTypeFromMetadata amap m p.Type (fun _ -> p.CustomAttrs) x.MetadataScope x.DeclaringTypeInst minst ]
else if x.IsInstance then
[ x.ApparentEnclosingType ]
else
......@@ -926,7 +929,7 @@ type ILMethInfo =
/// Get the compiled return type of the method, where 'void' is None.
member x.GetCompiledReturnTy (amap, m, minst) =
ImportReturnTypeFromMetadata amap m x.RawMetadata.Return.Type x.RawMetadata.Return.CustomAttrs x.MetadataScope x.DeclaringTypeInst minst
ImportReturnTypeFromMetadata amap m x.RawMetadata.Return.Type (fun _ -> x.RawMetadata.Return.CustomAttrs) x.MetadataScope x.DeclaringTypeInst minst
/// Get the F# view of the return type of the method, where 'void' is 'unit'.
member x.GetFSharpReturnTy (amap, m, minst) =
......@@ -1448,9 +1451,10 @@ type MethInfo =
match x with
| ILMeth(g, ilMethInfo, _) ->
[ [ for p in ilMethInfo.ParamMetadata do
let isParamArrayArg = TryFindILAttribute g.attrib_ParamArrayAttribute p.CustomAttrs
let attrs = p.CustomAttrs
let isParamArrayArg = TryFindILAttribute g.attrib_ParamArrayAttribute attrs
let reflArgInfo =
match TryDecodeILAttribute g.attrib_ReflectedDefinitionAttribute.TypeRef p.CustomAttrs with
match TryDecodeILAttribute g.attrib_ReflectedDefinitionAttribute.TypeRef attrs with
| Some ([ILAttribElem.Bool b ], _) -> ReflectedArgInfo.Quote b
| Some _ -> ReflectedArgInfo.Quote false
| _ -> ReflectedArgInfo.None
......@@ -1459,9 +1463,9 @@ type MethInfo =
// Note: we get default argument values from VB and other .NET language metadata
let optArgInfo = OptionalArgInfo.FromILParameter g amap m ilMethInfo.MetadataScope ilMethInfo.DeclaringTypeInst p
let isCallerLineNumberArg = TryFindILAttribute g.attrib_CallerLineNumberAttribute p.CustomAttrs
let isCallerFilePathArg = TryFindILAttribute g.attrib_CallerFilePathAttribute p.CustomAttrs
let isCallerMemberNameArg = TryFindILAttribute g.attrib_CallerMemberNameAttribute p.CustomAttrs
let isCallerLineNumberArg = TryFindILAttribute g.attrib_CallerLineNumberAttribute attrs
let isCallerFilePathArg = TryFindILAttribute g.attrib_CallerFilePathAttribute attrs
let isCallerMemberNameArg = TryFindILAttribute g.attrib_CallerMemberNameAttribute attrs
let callerInfo =
match isCallerLineNumberArg, isCallerFilePathArg, isCallerMemberNameArg with
......@@ -1603,10 +1607,10 @@ type MethInfo =
match x with
| ILMeth(_, ilminfo, _) ->
let ftinfo = ILTypeInfo.FromType g (TType_app(tcref, formalEnclosingTyparTys, g.knownWithoutNull))
let formalRetTy = ImportReturnTypeFromMetadata amap m ilminfo.RawMetadata.Return.Type ilminfo.RawMetadata.Return.CustomAttrs ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys
let formalRetTy = ImportReturnTypeFromMetadata amap m ilminfo.RawMetadata.Return.Type (fun _ -> ilminfo.RawMetadata.Return.CustomAttrs) ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys
let formalParams =
[ [ for p in ilminfo.RawMetadata.Parameters do
let paramType = ImportILTypeFromMetadataWithAttributes amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type p.CustomAttrs
let paramType = ImportILTypeFromMetadataWithAttributes amap m ftinfo.ILScopeRef ftinfo.TypeInstOfRawMetadata formalMethTyparTys p.Type (fun _ -> p.CustomAttrs)
yield TSlotParam(p.Name, paramType, p.IsIn, p.IsOut, p.IsOptional, []) ] ]
formalRetTy, formalParams
#if !NO_TYPEPROVIDERS
......
......@@ -81,14 +81,14 @@ val ExistsHeadTypeInEntireHierarchy: g:TcGlobals -> amap:ImportMap -> m:range ->
val ImportILTypeFromMetadata: amap:ImportMap -> m:range -> scoref:ILScopeRef -> tinst:TType list -> minst:TType list -> ilty:ILType -> TType
/// Read an Abstract IL type from metadata, including any attributes that may affect the type itself, and convert to an F# type.
val ImportILTypeFromMetadataWithAttributes: amap:ImportMap -> m:range -> scoref:ILScopeRef -> tinst:TType list -> minst:TType list -> ilty:ILType -> cattrs:ILAttributes -> TType
val ImportILTypeFromMetadataWithAttributes: amap:ImportMap -> m:range -> scoref:ILScopeRef -> tinst:TType list -> minst:TType list -> ilty:ILType -> getCattrs: (unit -> ILAttributes) -> TType
/// Get the parameter type of an IL method.
val ImportParameterTypeFromMetadata: amap:ImportMap -> m:range -> ilty:ILType -> cattrs:ILAttributes -> scoref:ILScopeRef -> tinst:TType list -> mist:TType list -> TType
val ImportParameterTypeFromMetadata: amap:ImportMap -> m:range -> ilty:ILType -> getCattrs: (unit -> ILAttributes) -> scoref:ILScopeRef -> tinst:TType list -> mist:TType list -> TType
/// Get the return type of an IL method, taking into account instantiations for type, return attributes and method generic parameters, and
/// translating 'void' to 'None'.
val ImportReturnTypeFromMetadata: amap:ImportMap -> m:range -> ilty:ILType -> cattrs:ILAttributes -> scoref:ILScopeRef -> tinst:TType list -> minst:TType list -> TType option
val ImportReturnTypeFromMetadata: amap:ImportMap -> m:range -> ilty:ILType -> getCattrs: (unit -> ILAttributes) -> scoref:ILScopeRef -> tinst:TType list -> minst:TType list -> TType option
/// Copy constraints. If the constraint comes from a type parameter associated
/// with a type constructor then we are simply renaming type variables. If it comes
......
......@@ -1153,7 +1153,7 @@ module FSharpExprConvert =
// is not sufficient to resolve to a symbol unambiguously in these cases.
let argtys = [ ilMethRef.ArgTypes |> List.map (ImportILTypeFromMetadata cenv.amap m scoref tinst1 tinst2) ]
let rty =
match ImportReturnTypeFromMetadata cenv.amap m ilMethRef.ReturnType emptyILCustomAttrs scoref tinst1 tinst2 with
match ImportReturnTypeFromMetadata cenv.amap m ilMethRef.ReturnType (fun _ -> emptyILCustomAttrs) scoref tinst1 tinst2 with
| None -> if isCtor then enclosingType else g.unit_ty
| Some ty -> ty
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册