spectest: ensure compiled functions can outlive module #2105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tentative fix for #2039 for the
compiler
, notwazevo
.In
linking.wast
we have:A
that exports its memory and tableB
that imports bothmain
The test then verifies that initializing the memory and the table both succeeded before main failed. It does so by reading from the memory, and indirect calling the function in the table.
Both the memory and table are owned by
A
, so still exist. But the function, or rather the compiled code (andmmap
ed memory) for the function is/was owned byB
and can be GCed, because weSetFinalizer
on an object owned byB
.This change makes it so that the finalizer is set on the
compiledCode
rather than on thecompiledModule
. Since the resolved function import is afunction
, and that owns acompiledFunction
, which owns thecompiledCode
, this should fix the issue.