wasm: avoid generation of types as defined in GC spec

This fixes passing tests in environments that either don't support or prohibit usage of GC spec
This commit is contained in:
Alexey Andreev 2024-08-18 17:51:29 +02:00
parent 8dd344412e
commit 8b52741e04
3 changed files with 16 additions and 4 deletions

View File

@ -407,6 +407,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|| expectedFunctionType != function.getType()) {
var functionType = typeMapper.getFunctionType(virtualTable.getClassName(), method, true);
functionType.getSupertypes().add(expectedFunctionType);
expectedFunctionType.setFinal(false);
var wrapperFunction = new WasmFunction(functionType);
module.functions.add(wrapperFunction);
var call = new WasmCall(function);

View File

@ -26,6 +26,7 @@ public class WasmFunctionType extends WasmCompositeType {
private Supplier<List<? extends WasmType>> parameterTypesSupplier;
private Supplier<WasmType> returnTypeSupplier;
private Set<WasmFunctionType> supertypes = new LinkedHashSet<>();
private boolean isFinal = true;
public WasmFunctionType(String name, WasmType returnType, List<? extends WasmType> parameterTypes) {
super(name);
@ -60,6 +61,14 @@ public class WasmFunctionType extends WasmCompositeType {
return supertypes;
}
public boolean isFinal() {
return isFinal;
}
public void setFinal(boolean aFinal) {
isFinal = aFinal;
}
@Override
public void acceptVisitor(WasmCompositeTypeVisitor visitor) {
visitor.visit(this);

View File

@ -57,11 +57,13 @@ public class WasmCompositeTypeBinaryRenderer implements WasmCompositeTypeVisitor
@Override
public void visit(WasmFunctionType type) {
if (!type.isFinal() || !type.getSupertypes().isEmpty()) {
section.writeByte(0x50);
section.writeLEB(type.getSupertypes().size());
for (var supertype : type.getSupertypes()) {
section.writeLEB(module.types.indexOf(supertype));
}
}
section.writeByte(0x60);
section.writeLEB(type.getParameterTypes().size());
for (var inputType : type.getParameterTypes()) {