Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Jun 21, 2024
1 parent 6a30813 commit b1bb412
Showing 1 changed file with 42 additions and 25 deletions.
67 changes: 42 additions & 25 deletions src/Compiler/AbstractIL/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,12 +2118,19 @@ and typeDefReader ctxtH : ILTypeDefStored =

let containsExtensionMethods =
let mutable containsExtensionMethods = false
let mutable readAttributeParentIndex = true
let searchedKey = TaggedIndex(hca_TypeDef, idx)

let attributesSearcher =
{ new ISeekReadIndexedRowReader<CustomAttributeRow, CustomAttributeRow, CustomAttributeRow> with
member _.GetRow(i, row) =
seekReadCustomAttributeRow ctxt mdv i &row
// optimized version of seekReadCustomAttributeRow ctxt mdv i &row
let mutable addr = ctxt.rowAddr TableNames.CustomAttribute idx

if readAttributeParentIndex then
row.parentIndex <- seekReadHasCustomAttributeIdx ctxt mdv &addr
else
row.typeIndex <- seekReadCustomAttributeTypeIdx ctxt mdv &addr

member _.GetKey(row) = row
member _.CompareKey(key) = hcaCompare searchedKey key.parentIndex
Expand All @@ -2136,34 +2143,44 @@ and typeDefReader ctxtH : ILTypeDefStored =
(isSorted ctxt TableNames.CustomAttribute)
attributesSearcher

let hasAttributes = attrsStartIdx > 0 && attrsEndIdx >= attrsStartIdx
let mutable attrIdx = attrsStartIdx

while hasAttributes && attrIdx <= attrsEndIdx && not containsExtensionMethods do
let mutable attr = Unchecked.defaultof<_>
attributesSearcher.GetRow(attrIdx, &attr)
let attrCtorIdx = attr.typeIndex.index

let name =
if attr.typeIndex.tag = cat_MethodDef then
let idx = seekMethodDefParent ctxt attrCtorIdx
let _, nameIdx, namespaceIdx, _, _, _ = seekReadTypeDefRow ctxt idx
readBlobHeapAsTypeName ctxt (nameIdx, namespaceIdx)
else
let mrpTag, _, _ = seekReadMemberRefRow ctxt mdv attrCtorIdx

if mrpTag.tag <> mrp_TypeRef then
""
else
let _, nameIdx, namespaceIdx = seekReadTypeRefRow ctxt mdv mrpTag.index
if attrsStartIdx <= 0 || attrsEndIdx < attrsStartIdx then
false
else
let mutable attrIdx = attrsStartIdx

// read attribute typeIndex only
readAttributeParentIndex <- false

while attrIdx <= attrsEndIdx && not containsExtensionMethods do
let mutable attr = Unchecked.defaultof<_>
attributesSearcher.GetRow(attrIdx, &attr)
let attrCtorIdx = attr.typeIndex.index

let name =
if attr.typeIndex.tag = cat_MethodDef then
let idx = seekMethodDefParent ctxt attrCtorIdx
let mutable addr = ctxt.rowAddr TableNames.TypeDef idx
let nameIdx = seekReadStringIdx ctxt mdv &addr
let namespaceIdx = seekReadStringIdx ctxt mdv &addr
readBlobHeapAsTypeName ctxt (nameIdx, namespaceIdx)
else
let mutable addr = ctxt.rowAddr TableNames.MemberRef attrCtorIdx
let mrpTag = seekReadMemberRefParentIdx ctxt mdv &addr

if mrpTag.tag <> mrp_TypeRef then
""
else
let mutable addr = ctxt.rowAddr TableNames.TypeRef mrpTag.index
let nameIdx = seekReadStringIdx ctxt mdv &addr
let namespaceIdx = seekReadStringIdx ctxt mdv &addr
readBlobHeapAsTypeName ctxt (nameIdx, namespaceIdx)

if name = "System.Runtime.CompilerServices.ExtensionAttribute" then
containsExtensionMethods <- true
if name = "System.Runtime.CompilerServices.ExtensionAttribute" then
containsExtensionMethods <- true

attrIdx <- attrIdx + 1
attrIdx <- attrIdx + 1

containsExtensionMethods
containsExtensionMethods

let additionalFlags =
if containsExtensionMethods then
Expand Down

0 comments on commit b1bb412

Please sign in to comment.