wasm gc: don't generate emulated casts in non-strict mode

This commit is contained in:
Alexey Andreev 2024-09-19 20:40:45 +02:00
parent 29339f3fbc
commit 6613d379ec
5 changed files with 20 additions and 9 deletions

View File

@ -178,7 +178,8 @@ public class WasmGCTarget implements TeaVMTarget, TeaVMWasmGCHost {
customGenerators,
intrinsics,
customTypeMapperFactories,
controller::isVirtual
controller::isVirtual,
strict
);
declarationsGenerator.setFriendlyToDebugger(controller.isFriendlyToDebugger());
var moduleGenerator = new WasmGCModuleGenerator(declarationsGenerator);

View File

@ -57,7 +57,8 @@ public class WasmGCDeclarationsGenerator {
WasmGCCustomGeneratorProvider customGenerators,
WasmGCIntrinsicProvider intrinsics,
List<WasmGCCustomTypeMapperFactory> customTypeMapperFactories,
Predicate<MethodReference> isVirtual
Predicate<MethodReference> isVirtual,
boolean strict
) {
this.module = module;
hierarchy = new ClassHierarchy(classes);
@ -75,7 +76,8 @@ public class WasmGCDeclarationsGenerator {
names,
diagnostics,
customGenerators,
intrinsics
intrinsics,
strict
);
var tags = new TagRegistry(classes, hierarchy);
var metadataRequirements = new ClassMetadataRequirements(dependencyInfo);

View File

@ -32,7 +32,6 @@ import org.teavm.backend.wasm.generate.gc.classes.WasmGCSupertypeFunctionProvide
import org.teavm.backend.wasm.generate.gc.classes.WasmGCTypeMapper;
import org.teavm.backend.wasm.generate.gc.strings.WasmGCStringProvider;
import org.teavm.backend.wasm.model.WasmFunction;
import org.teavm.backend.wasm.model.WasmGlobal;
import org.teavm.backend.wasm.model.WasmModule;
import org.teavm.backend.wasm.model.WasmTag;
import org.teavm.backend.wasm.runtime.WasmGCSupport;
@ -60,10 +59,10 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
private WasmFunction npeMethod;
private WasmFunction aaiobeMethod;
private WasmFunction cceMethod;
private WasmGlobal exceptionGlobal;
private WasmTag exceptionTag;
private Map<String, Set<String>> interfaceImplementors;
private WasmGCNameProvider names;
private boolean strict;
public WasmGCGenerationContext(WasmModule module, WasmGCVirtualTableProvider virtualTables,
WasmGCTypeMapper typeMapper, WasmFunctionTypes functionTypes, ListableClassReaderSource classes,
@ -71,7 +70,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
WasmGCSupertypeFunctionProvider supertypeFunctions, WasmGCClassInfoProvider classInfoProvider,
WasmGCStandardClasses standardClasses, WasmGCStringProvider strings,
WasmGCCustomGeneratorProvider customGenerators, WasmGCIntrinsicProvider intrinsics,
WasmGCNameProvider names) {
WasmGCNameProvider names, boolean strict) {
this.module = module;
this.virtualTables = virtualTables;
this.typeMapper = typeMapper;
@ -87,6 +86,7 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
this.customGenerators = customGenerators;
this.intrinsics = intrinsics;
this.names = names;
this.strict = strict;
}
public WasmGCClassInfoProvider classInfoProvider() {
@ -143,6 +143,10 @@ public class WasmGCGenerationContext implements BaseWasmGenerationContext {
return classes;
}
public boolean isStrict() {
return strict;
}
public ClassLoader classLoader() {
return classLoader;
}

View File

@ -487,7 +487,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
}
}
if (!expr.isWeak()) {
if (!expr.isWeak() && context.isStrict()) {
result.acceptVisitor(typeInference);
var block = new WasmBlock(false);

View File

@ -83,6 +83,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
private WasmGCClassInfoProvider classInfoProvider;
private WasmGCStandardClasses standardClasses;
private WasmGCStringProvider strings;
private boolean strict;
public WasmGCMethodGenerator(
WasmModule module,
@ -95,7 +96,8 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
WasmGCNameProvider names,
Diagnostics diagnostics,
WasmGCCustomGeneratorProvider customGenerators,
WasmGCIntrinsicProvider intrinsics
WasmGCIntrinsicProvider intrinsics,
boolean strict
) {
this.module = module;
this.hierarchy = hierarchy;
@ -108,6 +110,7 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
this.diagnostics = diagnostics;
this.customGenerators = customGenerators;
this.intrinsics = intrinsics;
this.strict = strict;
}
public void setTypeMapper(WasmGCTypeMapper typeMapper) {
@ -332,7 +335,8 @@ public class WasmGCMethodGenerator implements BaseWasmFunctionRepository {
strings,
customGenerators,
intrinsics,
names
names,
strict
);
}
return context;