Skip to content

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

@Liedtke

Description

@Liedtke

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. 😄)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions