Repository navigation
fix: Declared element section output is hash unstable - #308
logan-gatlin wants to merge 1 commit into
Conversation
|
Does this fix the long-standing issues we've had here, or is it new? |
|
Curious if there's a perf implication of this worth considering? In which case the benefit should be carefully justified? |
|
Yeah thats true. Will benchmark it. It would actually be better to do insertion order if that would be stable |
748e6fe to
febc90a
Compare
There was a problem hiding this comment.
This PR sorts the undeclared ref.func targets before ensure_func_declarations puts them into the synthesized Declared element segment. Until now that segment came out in IdHashSet iteration order, which depends on insertion order and table capacity (#330 had to avoid extend to keep the order). I'm guessing the aim is byte-identical output for wasm-bindgen builds. The fix itself is correct: id_arena::Id implements Ord, and all IDs come from the one function arena, so the result is a deterministic order by arena index. The arena index is not always the emitted function index, but the output is deterministic either way. Still missing: the NB comment from #330 above step 1 is now stale, there is no CHANGELOG.md entry, and no test pins the new ordering.
Not merge-ready:
- There is no
Fixedentry underUnreleasedinCHANGELOG.mdfor the now-deterministicDeclaredelement segment order. - No test pins the new order. For example, two modules whose
ref.funcs name the same undeclared functions in different orders should emit the same declared segment.
| .collect(); | ||
| // Sort to ensure we emit the Declared element segment deterministically, | ||
| // regardless of IdHashSet iteration order. | ||
| undeclared.sort_unstable(); |
There was a problem hiding this comment.
The NB comment above step 1 (lines 345–348) is now wrong.
It says the undeclared functions are listed in the set's iteration order, so the set must be built one insert at a time without extend. After this sort, neither is true. A maintainer who reads it will keep working around a constraint that no longer exists.
Drop the NB sentence. If you want to keep a note, say that the segment is sorted, so the order in which ref_funcs is built doesn't matter.
No description provided.