WebAssembly / WebAssembly/shared-everything-threads

Unclear meaning of unshared `externref` and `anyref` in combination with JS API

Open
#97 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
97
Forks
6
PR merge metrics
No merged PRs in 30d

Description

My initial understanding of externref was "any unshared host value", especially as any.convert_extern would propagate that information to unshared anyref and all other abstract types have this notion of "not marked as shared == only unshared objects legal".

However, after starting with the implementation and considering the implications for the usage, I assume externref and anyref continue meaning "any host value independently of whether it is shared or unshared" because everything else would just be painful.

Considerations:

  1. A funcref can be stored in an externref and anyref via the JS API as well, even though it is not a subtype of anyref.
  2. externref is used by toolchains for "any host value", if it disallowed shared objects, that would probably create a decent amount of pain.
  3. For any engine having an externref in a signature and calling it from JS should be as cheap as possible. If we disallowed shared types there, the engine would need to check sharedness and then react accordingly. In a world where shared js structs exist, many JS values could be shared that are convertible to unshared variants (including Strings and Numbers) and therefore such a typecheck would need to consider these cases.

With externref containing shared struct and shared array, these propagate to unshared anyref then, however that only means that downcasts from anyref will need to check for non-sharedness then but these casts anyways aren't that cheap, so it probably is an acceptable cost.

WDYT? Does this make sense? Should we clarify this in the overview?
(It could very well be that some think that "obviously externref keeps the meaning of 'anything', that's how it is already spec'ed" but to me this wasn't very clear when starting with the implementation. 😄)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no file, test, or entry point. Start by reading the proposal overview and the sections covering externref, anyref, and the JavaScript API, then review the seven-comment discussion. Done means the sharedness semantics are decided and the overview is clarified if needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.