Skip to content

fix(validator): implement GC structural subtyping validation #147

@avrabe

Description

@avrabe

Problem

The validator lacks GC structural subtyping, causing:

  • 21 assert_invalid failures for "sub type" validation
  • 8 assert_invalid failures for "unknown type" in GC instructions
  • ~20 module validation failures (false positives) in type-subtyping.wast, type-equivalence.wast, type-rec.wast

What's needed

  1. Sub type validation: When a type uses (sub $parent ...), validate that:

    • The parent type index exists
    • The child type is structurally compatible with the parent
    • Function subtypes have contravariant params and covariant results
  2. Recursive type groups: (rec ...) groups define mutually recursive types. Type indices within a rec group can reference each other.

  3. Type equivalence for GC: Two types are equivalent if they have the same structure (iso-recursive interpretation). The validator must use structural comparison for type-indexed operations like call_indirect.

Impact

  • ~49 directly failing assertions
  • Additional cascading failures from false module validation rejections

Files

  • kiln-build-core/src/wast_validator.rs — needs new validate_subtypes() function
  • kiln-format/src/module.rs — may need sub/rec type information in Module struct
  • kiln-decoder/src/streaming_decoder.rs — may need to decode sub/rec type declarations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions