Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Jul 29, 2025

Fixes a regression from #7763

This is pretty subtle, unfortunately. We cache the results of a struct.new
etc as we go, so that identity is preserved for precomputing RefEq etc.
The old code always computed structs in full before checking the cache.
#7763 removed that code as an optimization. But, it turns out,
that was load-bearing in that it, by pure luck, happened to avoid a bug.

The bug that was avoided, and which this PR fixes, is that when we
partially precompute, we modify a struct.new and see if we can
precompute that version. We were still using the same heap value
cache, so we could cache the value, then later end up using it for
the original (before, we'd still compute the struct.new again and
use those values). To fix that, do such speculative precomputations on a
side (throwaway) cache.

Fixes #7765

@kripken kripken requested a review from tlively July 29, 2025 17:55
@kripken kripken mentioned this pull request Jul 29, 2025
tlively
tlively approved these changes Jul 29, 2025
Comment on lines 732 to 733
usedHeapValues ? *usedHeapValues
: heapValues,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we simplify things by moving this logic to the very top of the function:

if (!usedHeapValues) {
  usedHeapValues = &heapValues;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@kripken kripken merged commit 97e0ecf into WebAssembly:main Jul 29, 2025
16 checks passed
@kripken kripken deleted the hc.bug branch July 29, 2025 20:44
kripken added a commit that referenced this pull request Aug 8, 2025
Precompute has two modes, one where we ignore effects. We were
caching the effectless results for where the normal mode (which cares
about effects) would reuse them, leading to bugs.

Fixes a regression from #7763, another after #7766. We were not using the
cache fully, before, and caches are bug-prone, sadly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Precompute bug

2 participants