Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Oct 24, 2023
1 parent 5f6457e commit ca3f670
Showing 1 changed file with 31 additions and 56 deletions.
87 changes: 31 additions & 56 deletions src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -578,67 +578,42 @@ let private GetCSharpStyleIndexedExtensionMembersForTyconRef (amap: Import.Impor
let ty = generalizedTyconRef g tcrefOfStaticClass
let ty1 = metadataOfTy g ty

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

if extensionMethodsNotFound then [] else
let isApplicable =
canContainExtensionMethods &&
(IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass ||
g.langVersion.SupportsFeature(LanguageFeature.CSharpExtensionAttributeNotRequired) && tcrefOfStaticClass.IsLocalRef)

let pri = NextExtensionMethodPriority()
if not isApplicable then [] else

if g.langVersion.SupportsFeature(LanguageFeature.CSharpExtensionAttributeNotRequired) then
let csharpStyleExtensionMembers =
if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass || tcrefOfStaticClass.IsLocalRef then
protectAssemblyExploration [] (fun () ->
GetImmediateIntrinsicMethInfosOfType (None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty
|> List.filter (IsMethInfoPlainCSharpStyleExtensionMember g m true))
else
[]

if not csharpStyleExtensionMembers.IsEmpty then
[ for minfo in csharpStyleExtensionMembers do
let ilExtMem = ILExtMem (tcrefOfStaticClass, minfo, pri)
let pri = NextExtensionMethodPriority()

// The results are indexed by the TyconRef of the first 'this' argument, if any.
// So we need to go and crack the type of the 'this' argument.
//
// This is convoluted because we only need the ILTypeRef of the first argument, and we don't
// want to read any other metadata as it can trigger missing-assembly errors. It turns out ImportILTypeRef
// is less eager in reading metadata than GetParamTypes.
//
// We don't use the index for the IL extension method for tuple of F# function types (e.g. if extension
// methods for tuple occur in C# code)
let thisTyconRef = GetTyconRefForExtensionMembers minfo tcrefOfStaticClass.Deref amap m g
match thisTyconRef with
| None -> ()
| Some (Some tcref) -> yield Choice1Of2(tcref, ilExtMem)
| Some None -> yield Choice2Of2 ilExtMem ]
else
[]
else
if IsTyconRefUsedForCSharpStyleExtensionMembers g m tcrefOfStaticClass then
let minfos = GetImmediateIntrinsicMethInfosOfType (None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty

[ for minfo in minfos do
if IsMethInfoPlainCSharpStyleExtensionMember g m true minfo then
let ilExtMem = ILExtMem (tcrefOfStaticClass, minfo, pri)
// The results are indexed by the TyconRef of the first 'this' argument, if any.
// So we need to go and crack the type of the 'this' argument.
//
// This is convoluted because we only need the ILTypeRef of the first argument, and we don't
// want to read any other metadata as it can trigger missing-assembly errors. It turns out ImportILTypeRef
// is less eager in reading metadata than GetParamTypes.
//
// We don't use the index for the IL extension method for tuple of F# function types (e.g. if extension
// methods for tuple occur in C# code)
let thisTyconRef = GetTyconRefForExtensionMembers minfo tcrefOfStaticClass.Deref amap m g
match thisTyconRef with
| None -> ()
| Some (Some tcref) -> yield Choice1Of2(tcref, ilExtMem)
| Some None -> yield Choice2Of2 ilExtMem ]
else
[]
let methods =
protectAssemblyExploration []
(fun () -> GetImmediateIntrinsicMethInfosOfType (None, AccessorDomain.AccessibleFromSomeFSharpCode) g amap m ty)

[ for minfo in methods do
if IsMethInfoPlainCSharpStyleExtensionMember g m true minfo then
let ilExtMem = ILExtMem (tcrefOfStaticClass, minfo, pri)

// The results are indexed by the TyconRef of the first 'this' argument, if any.
// So we need to go and crack the type of the 'this' argument.
//
// This is convoluted because we only need the ILTypeRef of the first argument, and we don't
// want to read any other metadata as it can trigger missing-assembly errors. It turns out ImportILTypeRef
// is less eager in reading metadata than GetParamTypes.
//
// We don't use the index for the IL extension method for tuple of F# function types (e.g. if extension
// methods for tuple occur in C# code)
let thisTyconRef = GetTyconRefForExtensionMembers minfo tcrefOfStaticClass.Deref amap m g
match thisTyconRef with
| None -> ()
| Some (Some tcref) -> yield Choice1Of2(tcref, ilExtMem)
| Some None -> yield Choice2Of2 ilExtMem ]

/// Query the declared properties of a type (including inherited properties)
let IntrinsicPropInfosOfTypeInScope (infoReader: InfoReader) optFilter ad findFlag m ty =
Expand Down

0 comments on commit ca3f670

Please sign in to comment.