Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow method idx + 1 index #6425

Merged
merged 3 commits into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/absil/ilread.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,14 +2027,16 @@ and seekReadFields (ctxt: ILMetadataReader) (numtypars, hasLayout) fidx1 fidx2 =
mkILFieldsLazy
(lazy
let mdv = ctxt.mdfile.GetView()
[ for i = fidx1 to fidx2 - 1 do
yield seekReadField ctxt mdv (numtypars, hasLayout) i ])
[ if fidx1 > 0 then
for i = fidx1 to fidx2 - 1 do
yield seekReadField ctxt mdv (numtypars, hasLayout) i ])

and seekReadMethods (ctxt: ILMetadataReader) numtypars midx1 midx2 =
mkILMethodsComputed (fun () ->
let mdv = ctxt.mdfile.GetView()
[| for i = midx1 to midx2 - 1 do
yield seekReadMethod ctxt mdv numtypars i |])
[| if midx1 > 0 then
for i = midx1 to midx2 - 1 do
yield seekReadMethod ctxt mdv numtypars i |])

and sigptrGetTypeDefOrRefOrSpecIdx bytes sigptr =
let n, sigptr = sigptrGetZInt32 bytes sigptr
Expand Down Expand Up @@ -2506,8 +2508,9 @@ and seekReadEvents (ctxt: ILMetadataReader) numtypars tidx =
let (_, endEventIdx) = seekReadEventMapRow ctxt mdv (rowNum + 1)
endEventIdx

[ for i in beginEventIdx .. endEventIdx - 1 do
yield seekReadEvent ctxt mdv numtypars i ])
[ if beginEventIdx > 0 then
for i in beginEventIdx .. endEventIdx - 1 do
yield seekReadEvent ctxt mdv numtypars i ])

and seekReadProperty ctxt mdv numtypars idx =
let (flags, nameIdx, typIdx) = seekReadPropertyRow ctxt mdv idx
Expand Down Expand Up @@ -2548,8 +2551,9 @@ and seekReadProperties (ctxt: ILMetadataReader) numtypars tidx =
else
let (_, endPropIdx) = seekReadPropertyMapRow ctxt mdv (rowNum + 1)
endPropIdx
[ for i in beginPropIdx .. endPropIdx - 1 do
yield seekReadProperty ctxt mdv numtypars i ])
[ if beginPropIdx > 0 then
for i in beginPropIdx .. endPropIdx - 1 do
yield seekReadProperty ctxt mdv numtypars i ])


and customAttrsReader ctxtH tag: ILAttributesStored =
Expand Down
30 changes: 13 additions & 17 deletions src/absil/ilwrite.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ type ByteBuffer with
buf.EmitByte 0x0uy

// Emit compressed untagged integer
member buf.EmitZUntaggedIndex nm sz big idx =
member buf.EmitZUntaggedIndex big idx =
if big then buf.EmitInt32 idx
elif idx > 0xffff then
#if NETSTANDARD1_6
let trace = "no stack trace on.NET Standard 1.6"
#else
let trace = (new System.Diagnostics.StackTrace()).ToString()
#endif
failwithf "EmitZUntaggedIndex: index into table '%d' is too big for small address or simple index, idx = %d, big = %A, size of table = %d, stack = %s" nm idx big sz trace
else buf.EmitInt32AsUInt16 idx
else
// Note, we can have idx=0x10000 generated for method table idx + 1 for just beyond last index of method table.
// This indicates that a MethodList, FieldList, PropertyList or EventList has zero entries
// For this case, the EmitInt32AsUInt16 writes a 0 (null) into the field. Binary readers respect this as an empty
// list of methods/fields/properties/events.
if idx > 0x10000 then
System.Diagnostics.Debug.Assert (false, "EmitZUntaggedIndex: too big for small address or simple index")
buf.EmitInt32AsUInt16 idx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when an idx of 0x10000 is passed in, 0x0000 is written to buffer by this, which is identical to passing an idx of 0x0000. Is that actually what we want?


// Emit compressed tagged integer
member buf.EmitZTaggedIndex tag nbits big idx =
Expand Down Expand Up @@ -3203,10 +3203,8 @@ let writeILMetadataAndCode (generatePdb, desiredMetadataVersion, ilg, emitTailca

let codedTables =

let sizesTable = Array.map Array.length sortedTables
let bignessTable = Array.map (fun rows -> Array.length rows >= 0x10000) sortedTables
let bigness (tab: int32) = bignessTable.[tab]
let size (tab: int32) = sizesTable.[tab]

let codedBigness nbits tab =
(tableSize tab) >= (0x10000 >>> nbits)
Expand Down Expand Up @@ -3330,12 +3328,10 @@ let writeILMetadataAndCode (generatePdb, desiredMetadataVersion, ilg, emitTailca
| _ when t = RowElementTags.ULong -> tablesBuf.EmitInt32 n
| _ when t = RowElementTags.Data -> recordRequiredDataFixup requiredDataFixups tablesBuf (tablesStreamStart + tablesBuf.Position) (n, false)
| _ when t = RowElementTags.DataResources -> recordRequiredDataFixup requiredDataFixups tablesBuf (tablesStreamStart + tablesBuf.Position) (n, true)
| _ when t = RowElementTags.Guid -> tablesBuf.EmitZUntaggedIndex -3 guidsStreamPaddedSize guidsBig (guidAddress n)
| _ when t = RowElementTags.Blob -> tablesBuf.EmitZUntaggedIndex -2 blobsStreamPaddedSize blobsBig (blobAddress n)
| _ when t = RowElementTags.String -> tablesBuf.EmitZUntaggedIndex -1 stringsStreamPaddedSize stringsBig (stringAddress n)
| _ when t <= RowElementTags.SimpleIndexMax ->
let tnum = t - RowElementTags.SimpleIndexMin
tablesBuf.EmitZUntaggedIndex tnum (size tnum) (bigness tnum) n
| _ when t = RowElementTags.Guid -> tablesBuf.EmitZUntaggedIndex guidsBig (guidAddress n)
| _ when t = RowElementTags.Blob -> tablesBuf.EmitZUntaggedIndex blobsBig (blobAddress n)
| _ when t = RowElementTags.String -> tablesBuf.EmitZUntaggedIndex stringsBig (stringAddress n)
| _ when t <= RowElementTags.SimpleIndexMax -> tablesBuf.EmitZUntaggedIndex (bigness (t - RowElementTags.SimpleIndexMin)) n
| _ when t <= RowElementTags.TypeDefOrRefOrSpecMax -> tablesBuf.EmitZTaggedIndex (t - RowElementTags.TypeDefOrRefOrSpecMin) 2 tdorBigness n
| _ when t <= RowElementTags.TypeOrMethodDefMax -> tablesBuf.EmitZTaggedIndex (t - RowElementTags.TypeOrMethodDefMin) 1 tomdBigness n
| _ when t <= RowElementTags.HasConstantMax -> tablesBuf.EmitZTaggedIndex (t - RowElementTags.HasConstantMin) 2 hcBigness n
Expand Down