Hello,
I was wondering how are 2 different modules compiled to WASM, originally written in 2 different languages, going to cooperate if both support generics - because GC doesn't intend to support generic types if I am not mistaken. What is the plan there?
I think if you have a language with strict generics like C# then the compiled code must check it self at runtime. If you have a language with only compile time generics like Java then there are no checks at runtime.
The answer has two parts:
To support approach (3) more efficiently I assume that will add type parameters to Wasm in a later step. But for the GC MVP you'll have to work around that with downcasts.
If multiple compilers or languages want to be able to interoperate, then they are of course free to define a common ABI on top of Wasm. That would be great! But Wasm itself doesn't need to prescribe it, no more than a CPU architecture does.
To add to what @rossberg says. For (1) static specialization, the language implementation may choose to fully specialize to language-level types (C++ template expansion) or specialize only up to representations (like Scala mini-boxing or levity polymorphism). At the wasm engine level, the only thing that really should be necessary is specializing to representations. This is why imported types in wasm have (or should have--I haven't checked the current state of the proposal, but discussed offline with @rossberg) an expected representation, perhaps restricted to anyref at the moment.
In short, the engine only needs to know representations of types in order to generate code. If code is not properly type-parametric (i.e. does not have the "parametricity" property), then any operator which depends on types has to be properly parametrized (and we have more work to do here).
Most helpful comment
The answer has two parts:
To support approach (3) more efficiently I assume that will add type parameters to Wasm in a later step. But for the GC MVP you'll have to work around that with downcasts.
If multiple compilers or languages want to be able to interoperate, then they are of course free to define a common ABI on top of Wasm. That would be great! But Wasm itself doesn't need to prescribe it, no more than a CPU architecture does.