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()) { || expectedFunctionType != function.getType()) {
var functionType = typeMapper.getFunctionType(virtualTable.getClassName(), method, true); var functionType = typeMapper.getFunctionType(virtualTable.getClassName(), method, true);
functionType.getSupertypes().add(expectedFunctionType); functionType.getSupertypes().add(expectedFunctionType);
expectedFunctionType.setFinal(false);
var wrapperFunction = new WasmFunction(functionType); var wrapperFunction = new WasmFunction(functionType);
module.functions.add(wrapperFunction); module.functions.add(wrapperFunction);
var call = new WasmCall(function); var call = new WasmCall(function);

View File

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

View File

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