diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-04-01 14:53:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-01 14:53:12 -0700 |
commit | 1f6c0f2c8622b2051b6c5977498db406abcff3e1 (patch) | |
tree | 6992003bb99d97534342f6684f5565e529bc36ce /src/wasm/wasm.cpp | |
parent | df6df2086992943cefed9184b8e4ebf24e3ed021 (diff) | |
download | binaryen-1f6c0f2c8622b2051b6c5977498db406abcff3e1.tar.gz binaryen-1f6c0f2c8622b2051b6c5977498db406abcff3e1.tar.bz2 binaryen-1f6c0f2c8622b2051b6c5977498db406abcff3e1.zip |
Fix type canonicalization bugs (#3761)
When canonical heap types were already present in the global store, for example
during the --roundtrip pass, type canonicalization was not working correctly.
The issue was that the GlobalCanonicalizer was replacing temporary HeapTypes
with their canonical equivalents one type at a time, but the act of replacing a
temporary HeapType use with a canonical HeapType use could change the shape of
later HeapTypes, preventing them from being correctly matched with their
canonical counterparts. This PR fixes that problem by computing all the
temporary-to-canonical heap type replacements before executing them.
To avoid a similar problem when canonicalizing Types, one solution would have
been to pre-calculate the replacements before executing them just like with the
HeapTypes, but that would have required either complex bookkeeping or moving
temporary Types into the global store when they are first canonicalized. That
would have been complicated because unlike for temporary HeapTypeInfos, the
unique_pointer to temporary TypeInfos is not readily available. This PR instead
switches back to using pointer-identity based equality and hashing for
TypeInfos, which works because we only ever canonicalize Types with canonical
children. This change should be a nice performance improvement as well.
Another bug this PR fixes is that shape hashing and equality considered
BasicKind HeapTypes to be different from their corresponding BasicHeapTypes,
which meant that canonicalization could produce different types for the same
type definition depending on whether the definition used a TypeBuilder or not.
The fix is to pre-canonicalize BasicHeapTypes (and Types that have them as
children) during shape hashing and equality. The same mechanism is also used to
simplify Store's canonicalization.
Fixes #3736.
Diffstat (limited to 'src/wasm/wasm.cpp')
0 files changed, 0 insertions, 0 deletions