Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Wasm GC instructions for converting between anyref and externref #9435

Merged
merged 3 commits into from
Oct 10, 2024

Commits on Oct 9, 2024

  1. Implement the Wasm GC instructions for converting between anyref an…

    …d `externref`
    
    This commit implements two instructions:
    
    1. `any.convert_extern`
    2. `extern.convert_any`
    
    These instructions are used to convert between `anyref` and `externref`
    values. The `any.convert_extern` instruction takes an `anyref` value and
    converts it to an `externref` value. The `extern.convert_any` instruction takes
    an `externref` value and converts it to an `anyref` value.
    
    Rather than implementing wrapper objects -- for example an `struct
    AnyOfExtern(ExternRef)` type that is a subtype of `AnyRef` -- we instead reuse
    the same representation converted references as their unconverted reference. For
    example, `(any.convert_extern my_externref)` is identical to the original
    `my_externref` value. This means that we don't actually emit any clif
    instructions to implement these Wasm instructions; they are no-ops!
    
    Wasm code remains none-the-wiser because it cannot directly test for the
    difference between, for example, a `my_anyref` and the result of
    `(extern.convert_any my_anyref)` because they are in two different type
    hierarchies, so any direct `ref.test` would be invalid. The Wasm code would have
    to convert one into the other's type hierarchy, at which point it doesn't know
    whether wrapping/unwrapping took place.
    
    We did need some changes at the host API and host API implementation levels,
    however:
    
    * We needed to relax the requirement that a `wasmtime::AnyRef` only wraps a
      `VMGcRef` that points to an object that is a subtype of `anyref` and similar for
      `wasmtime::ExternRef`.
    
    * We needed to make the `wasmtime::ExternRef::data[_mut]` methods return an
      option of their associated host data, since any `externref` resulting from
      `(extern.convert_any ...)` does not have any associated host data. (This change
      would have been required either way, even if we used wrapper objects.)
    fitzgen committed Oct 9, 2024
    Configuration menu
    Copy the full SHA
    605c4f8 View commit details
    Browse the repository at this point in the history

Commits on Oct 10, 2024

  1. fix tests

    fitzgen committed Oct 10, 2024
    Configuration menu
    Copy the full SHA
    cf6223b View commit details
    Browse the repository at this point in the history
  2. fix wasmtime-environ tests

    fitzgen committed Oct 10, 2024
    Configuration menu
    Copy the full SHA
    78119f8 View commit details
    Browse the repository at this point in the history