Conversation
Ms2ger
reviewed
Oct 2, 2026
Ms2ger
left a comment
Collaborator
There was a problem hiding this comment.
This seems plausible, but should have tests.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ToWebAssemblyValue's host-value-cache hit returns early and skips the type check every other path through this algorithm goes through, so a value cached once under a broad type can later be reused for a narrower, incompatible type without ever being rejected.This is
ToWebAssemblyValue'sref null heaptypecase as it stands today:Every other way this algorithm can produce an
r(including the cache-miss) falls through to the sharedref_type/match_valtypecheck a few steps below before ever returning, which is what makes converting a value to, say,eqrefreject an object that isn't actually eq-castable.The cache-hit branch is the one exception: it returns
ref.host |hostaddr|immediately, so once a value has been successfully converted once (under whatever type that was), every later conversion of that same value — even to a completely different, narrower type — short-circuits past the type check and returns the same cachedref.host, regardless of whether it's actually valid for the new target type.Concrete example
fis an exported function that takes two arguments with different types: one withanyrefand one witheqref. Callinginstance.exports.f(v, v)in JS goes throughcall an Exported Functionalgorithm, which converts each argument viaToWebAssemblyValueagainst the function's declared parameter type.Converting
vfor the first (anyref) parameter succeeds: it doesn't match any of the earlier cases, so it falls to the finalElsebranch, gets wrapped as a freshref.host, and is cached.anyrefaccepts anything, so the type check passes.Converting that same
vfor the second (eqref) parameter should throw aTypeErrorsince a bare host reference doesn't satisfyeq— and it would, if this were the first timevwas converted. But the cache already has an entry forvfrom the first argument, so this second conversion hits the cache-hit branch, returns the cachedref.hostimmediately, and never reaches thematch_valtypecheck that would otherwise reject it.Fix
Reword the cache-hit branch's
ReturntoLet |r| be ...,and wrap the cache-miss branch's three steps in an
Else,,so exactly one of the two branches runs and both join the shared tail: