Skip to content

Validate global imports#8487

Merged
stevenfontanella merged 6 commits intomainfrom
global-validation
Mar 25, 2026
Merged

Validate global imports#8487
stevenfontanella merged 6 commits intomainfrom
global-validation

Conversation

@stevenfontanella
Copy link
Member

@stevenfontanella stevenfontanella commented Mar 18, 2026

  • Add a RuntimeGlobal class to wrap the global's runtime value as well as its definition so we can check its type + mutability for import validation
    • Global imports are invariant for mutable globals and covariant for immutable globals:
      image. Mutability must match as well.
  • Fix old_import.wast to account for instantiations which should correctly fail. This test is now mostly the same as test/spec/imports.wast, but there are small differences so I plan to keep it until the upstream testsuite imports.wast passes.

Example error message:

[trap Imported global Mref_ex.g-var-func with type: (mut (ref func)) isn't compatible with import declaration: (import "Mref_ex" "g-var-func" (global $gimport$0 (mut funcref)))
]

Part of #8261.

'imports.wast', # Requires fixing handling of mutation to imported globals
'proposals/threads/imports.wast', # Missing memory type validation on instantiation
'linking.wast', # Missing global type validation on instantiation
'linking.wast', # Incorrectly allows subtyping for table imports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the test is wrong or that our implementation is wrong?

Copy link
Member Author

@stevenfontanella stevenfontanella Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our implementation is wrong, table types should be invariant for imports but I implemented them as covariant (same mistake as Java): link. I'll address this in the next PR (#8489).

Image

@stevenfontanella stevenfontanella force-pushed the global-validation branch 2 times, most recently from 2591c89 to ba2c167 Compare March 18, 2026 19:43
@stevenfontanella stevenfontanella changed the title Validation for imported globals Validate global imports Mar 18, 2026
@stevenfontanella stevenfontanella marked this pull request as ready for review March 18, 2026 20:52
@stevenfontanella stevenfontanella requested a review from a team as a code owner March 23, 2026 19:58
@stevenfontanella stevenfontanella removed the request for review from a team March 23, 2026 19:59
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@stevenfontanella stevenfontanella enabled auto-merge (squash) March 25, 2026 20:16
@stevenfontanella stevenfontanella merged commit ddb7026 into main Mar 25, 2026
27 of 32 checks passed
@stevenfontanella stevenfontanella deleted the global-validation branch March 25, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants