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

Wasmtime(gc): Add support for supertypes and finality #8595

Merged
merged 1 commit into from
May 13, 2024

Commits on May 13, 2024

  1. Wasmtime(gc): Add support for supertypes and finality

    This is the final type system change for Wasm GC: the ability to explicitly
    declare supertypes and finality. A final type may not be a supertype of another
    type. A concrete heap type matches another concrete heap type if its concrete
    type is a subtype (potentially transitively) of the other heap type's concrete
    type.
    
    Next, I'll begin support for allocating GC structs and arrays at runtime.
    
    I've also implemented `O(1)` subtype checking in the types registry:
    
    In a type system with single inheritance, the subtyping relationships between
    all types form a set of trees. The root of each tree is a type that has no
    supertype; each node's immediate children are the types that directly subtype
    that node.
    
    For example, consider these types:
    
        class Base {}
        class A subtypes Base {}
        class B subtypes Base {}
        class C subtypes A {}
        class D subtypes A {}
        class E subtypes C {}
    
    These types produce the following tree:
    
                   Base
                  /    \
                 A      B
                / \
               C   D
              /
             E
    
    Note the following properties:
    
    1. If `sub` is a subtype of `sup` (either directly or transitively) then
    `sup` *must* be on the path from `sub` up to the root of `sub`'s tree.
    
    2. Additionally, `sup` *must* be the `i`th node down from the root in that path,
    where `i` is the length of the path from `sup` to its tree's root.
    
    Therefore, if we maintain a vector containing the path to the root for each
    type, then we can simply check if `sup` is at index `supertypes(sup).len()`
    within `supertypes(sub)`.
    fitzgen committed May 13, 2024
    Configuration menu
    Copy the full SHA
    5db5a7a View commit details
    Browse the repository at this point in the history