Closed Bug 1819215 Opened 2 years ago Closed 2 years ago

Implement function subtyping

Categories

(Core :: JavaScript: WebAssembly, task, P3)

Firefox 112
task

Tracking

()

VERIFIED FIXED
114 Branch
Tracking Status
firefox114 --- fixed

People

(Reporter: mozilla, Assigned: jpages)

References

Details

Attachments

(2 files, 1 obsolete file)

Steps to reproduce:

Load https://flutterweb-wasm.web.app

Enable wasm_gc, wasm_function_references

Actual results:

App does not load. Dev console: Failed to fetch and instantiate wasm module: CompileError: wasm validation error: at offset 46036: incompatible super type

Expected results:

App runs like it does in Chrome.

Note from engineer on my team:

If the issue is what I think it is, it's probably that their supertype validation for functions needs to have covariant return types and contravariant arguments

And I'm guessing right now it's strict equality

Also: it seems like without JSPI, things won't work either. But if this helps get us closer, awesome!

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript: WebAssembly' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → JavaScript: WebAssembly
Product: Firefox → Core

Seems we are (in Kotlin-Wasm) facing similar issue with code optimised with Binaryen.
V8 works fine.
Supertype hierarchy looks ok but got "incompatible super type".

Sample wasm file:
https://drive.google.com/file/d/1NVIYKl5_wa3TYD82ryEPR5t1AwFsDUDO/view

The severity field is not set for this bug.
:rhunt, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(rhunt)
Severity: -- → S3
Flags: needinfo?(rhunt)
Priority: -- → P3
Blocks: wasm-gc

Yes, we currently have a limitation that func types must be strictly equal. This was arbitrary though and we should be able to relax it.

Summary: Wasm-gc: Flutter web + Wasm-GC demo not loading - incompatible super type → Implement function subtyping
Type: defect → task
Assignee: nobody → jpages
Depends on: 1827952

I have a patch in local which fixes this particular issue.
However, several other problems appear after that:

With this example https://flutterweb-wasm.web.app:
After fixing the subtyping issue, the error is now "CompileError: wasm validation error: at offset 1515444: unrecognized opcode: fb 41"

This opcode looks to be defined in some GC-proposal extensions, uses opcode that we are not supporting for now (0xfb41)
Reference is here https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#instructions-1

With the kotlin-wasm example, there was this subtyping issue "incompatible super type" which is fixable indeed.
After the fix, I had this error: wasm validation error: bad type 0x65

This opcode is not supported now but should be after this is implemented https://bugzilla.mozilla.org/show_bug.cgi?id=1827952

I could bypass that with the WIP patch but then I'm having an error: uncaught exception: [object WebAssembly.Exception]

See Also: → 1820163
See Also: → 1821061

Previously, function subtyping was only checking the invariance.
Now, return types are covariant and arguments are contravariant.

Depends on D175696

Attachment #9328921 - Attachment description: WIP: Bug 1819215 - wasm: Add new subtyping rules related to the none type. → Bug 1819215 - wasm: Add new subtyping rules related to the none type.
Attachment #9328920 - Attachment description: WIP: Bug 1819215 - wasm: Change subtyping rules for functions. → Bug 1819215 - wasm: Change subtyping rules for functions.
Attachment #9328921 - Attachment description: Bug 1819215 - wasm: Add new subtyping rules related to the none type. → Bug 1819215 - wasm: Change the validation of supertypes during parsing.
Attachment #9328921 - Attachment description: Bug 1819215 - wasm: Change the validation of supertypes during parsing. → Bug 1819215 - wasm: Change the validation of supertypes during parsing. r=rhunt,jseward

(In reply to Julien Pages [:jpages] from comment #7)

I have a patch in local which fixes this particular issue.
However, several other problems appear after that:

With this example https://flutterweb-wasm.web.app:
After fixing the subtyping issue, the error is now "CompileError: wasm validation error: at offset 1515444: unrecognized opcode: fb 41"

This opcode looks to be defined in some GC-proposal extensions, uses opcode that we are not supporting for now (0xfb41)
Reference is here https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#instructions-1

With the kotlin-wasm example, there was this subtyping issue "incompatible super type" which is fixable indeed.
After the fix, I had this error: wasm validation error: bad type 0x65

This opcode is not supported now but should be after this is implemented https://bugzilla.mozilla.org/show_bug.cgi?id=1827952

I could bypass that with the WIP patch but then I'm having an error: uncaught exception: [object WebAssembly.Exception]

FYI: we still use JSPI – I wonder if that's what you're hitting.

Attachment #9328920 - Attachment description: Bug 1819215 - wasm: Change subtyping rules for functions. → Bug 1819215 - wasm: Change subtyping rules for functions. r=rhunt,jseward
Pushed by jpages@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/acd6ebbf770c wasm: Change subtyping rules for functions. r=rhunt
Pushed by jpages@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c49f35eb0846 wasm: Change the validation of supertypes during parsing. r=rhunt,jseward
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 114 Branch

Many patches related to wasm-gc have landed recently, the original error "CompileError: wasm validation error: at offset 46036: incompatible super type" is now fixed.

However, this app https://flutterweb-wasm.web.app still doesn't load. It's not the same error but this is probably related to JSPI: "second argument must be a function". We are planning to implement JSPI in wasm in the future but for now it's not supported. Maybe try without JSPI if possible to see if it loads?

For the Kotlin-wasm issue, the original error is fixed but I'm still getting an uncaught Exception even with all the patches: uncaught exception: [object WebAssembly.Exception]

I'll follow up in this ticket for the exception problem: https://bugzilla.mozilla.org/show_bug.cgi?id=1820163

Confirming we (Flutter/Dart Wasm) are using JSPI. Working to remove now. Thanks for your work here!

FYI: https://flutterweb-wasm.web.app/ now works with Firefox nightly + flags. Thanks for your work here!

Status: RESOLVED → VERIFIED
Attachment #9328919 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: