MASM can produce type streams that are not topologically sorted. It can
even produce type streams with circular references, but those are not
common in practice.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
Do you need multiple scans? I wonder if you can keep type records that were not resolved in the first pass in a map or something and backfill them once we visit all type records.
Comment Actions
You can avoid the traversal if you copy the unresolved records to temporary storage and topologically sort them. You can't backpatch the type records because inserting them into the destination stream requires hashing them, and the hash includes the type index references we'd need to backpatch.
In general, if the type stream is badly unsorted, this algorithm is O(n^2). Topo sort is O(n), but it requires extra storage. It seemed better to optimize for the common case of a large, sorted type stream, and hope that unsorted streams are rare and/or small.