Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Dec 11, 2023
1 parent f503ae9 commit 2505717
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Compiler/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,7 @@ type ILTypeDef
events: ILEventDefs,
properties: ILPropertyDefs,
isKnownToBeAttribute: bool,
canContainExtensionMethods: bool,
securityDeclsStored: ILSecurityDeclsStored,
customAttrsStored: ILAttributesStored,
metadataIndex: int32
Expand Down Expand Up @@ -2657,6 +2658,7 @@ type ILTypeDef
events,
properties,
isKnownToBeAttribute,
false,
storeILSecurityDecls securityDecls,
storeILCustomAttrs customAttrs,
NoMetadataIdx
Expand Down Expand Up @@ -2690,6 +2692,8 @@ type ILTypeDef

member _.IsKnownToBeAttribute = isKnownToBeAttribute

member _.CanContainExtensionMethods = canContainExtensionMethods

member _.CustomAttrsStored = customAttrsStored

member _.MetadataIndex = metadataIndex
Expand Down
10 changes: 9 additions & 1 deletion src/Compiler/AbstractIL/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,13 @@ type ILAttributes =

/// Represents the efficiency-oriented storage of ILAttributes in another item.
[<NoEquality; NoComparison>]
type ILAttributesStored
type ILAttributesStored =
/// Computed by ilread.fs based on metadata index
| Reader of (int32 -> ILAttribute[])
/// Already computed
| Given of ILAttributes

member GetCustomAttrs: metadataIndex: int32 -> ILAttributes

/// Method parameters and return values.
[<RequireQualifiedAccess; NoEquality; NoComparison>]
Expand Down Expand Up @@ -1500,6 +1506,7 @@ type ILTypeDef =
events: ILEventDefs *
properties: ILPropertyDefs *
isKnownToBeAttribute: bool *
canContainExtensionMethods: bool *
securityDeclsStored: ILSecurityDeclsStored *
customAttrsStored: ILAttributesStored *
metadataIndex: int32 ->
Expand Down Expand Up @@ -1556,6 +1563,7 @@ type ILTypeDef =
member HasSecurity: bool
member Encoding: ILDefaultPInvokeEncoding
member IsKnownToBeAttribute: bool
member CanContainExtensionMethods: bool

member internal WithAccess: ILTypeDefAccess -> ILTypeDef
member internal WithNestedAccess: ILMemberAccess -> ILTypeDef
Expand Down
7 changes: 7 additions & 0 deletions src/Compiler/AbstractIL/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,12 @@ and typeDefReader ctxtH : ILTypeDefStored =
| ILTypeDefLayout.Explicit _ -> true
| _ -> false)

let canContainExtensionMethods =
seq { for i in methodsIdx .. endMethodsIdx -> i }
|> Seq.map(fun x -> ctxt.customAttrsReader_MethodDef.GetCustomAttrs(x).AsArray())
|> Seq.concat
|> Seq.tryFind(fun attr -> attr.Method.DeclaringType.TypeSpec.Name = "System.Runtime.CompilerServices.ExtensionAttribute")

let mdefs = seekReadMethods ctxt numTypars methodsIdx endMethodsIdx
let fdefs = seekReadFields ctxt (numTypars, hasLayout) fieldsIdx endFieldsIdx
let nested = seekReadNestedTypeDefs ctxt idx
Expand All @@ -2164,6 +2170,7 @@ and typeDefReader ctxtH : ILTypeDefStored =
events = events,
properties = props,
isKnownToBeAttribute = false,
canContainExtensionMethods = canContainExtensionMethods.IsSome,
customAttrsStored = ctxt.customAttrsReader_TypeDef,
metadataIndex = idx
))
Expand Down
14 changes: 11 additions & 3 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,22 @@ let GetTyconRefForExtensionMembers minfo (deref: Entity) amap m g =
/// Get the info for all the .NET-style extension members listed as static members in the type.
let private GetCSharpStyleIndexedExtensionMembersForTyconRef (amap: Import.ImportMap) m (tcrefOfStaticClass: TyconRef) =
let g = amap.g
let ty = generalizedTyconRef g tcrefOfStaticClass
let ty1 = metadataOfTy g ty

let extensionMethodsNotFound =
match ty1 with
| ILTypeMetadata(TILObjectReprData(_, _, ilTypeDef)) -> not ilTypeDef.CanContainExtensionMethods
| _ -> false

if extensionMethodsNotFound then [] else

let pri = NextExtensionMethodPriority()

if g.langVersion.SupportsFeature(LanguageFeature.CSharpExtensionAttributeNotRequired) then
let csharpStyleExtensionMembers =
if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass || (tcrefOfStaticClass.IsLocalRef && not tcrefOfStaticClass.IsTypeAbbrev) then
protectAssemblyExploration [] (fun () ->
let ty = generalizedTyconRef g tcrefOfStaticClass
GetImmediateIntrinsicMethInfosOfType (None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty
|> List.filter (IsMethInfoPlainCSharpStyleExtensionMember g m true))
else
Expand Down Expand Up @@ -609,7 +618,6 @@ let private GetCSharpStyleIndexedExtensionMembersForTyconRef (amap: Import.Impor
[]
else
if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass then
let ty = generalizedTyconRef g tcrefOfStaticClass
let minfos = GetImmediateIntrinsicMethInfosOfType (None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty

[ for minfo in minfos do
Expand Down

0 comments on commit 2505717

Please sign in to comment.