wasm gc: disable cast optimization and fix issue with short/char fields

This commit is contained in:
Alexey Andreev 2024-09-17 08:02:50 +02:00
parent 07b45fbec7
commit 36f7ec36f3
2 changed files with 6 additions and 6 deletions

View File

@ -56,7 +56,7 @@ public class WasmGCTypeMapper {
return WasmStorageType.packed(WasmPackedType.INT8); return WasmStorageType.packed(WasmPackedType.INT8);
case SHORT: case SHORT:
case CHARACTER: case CHARACTER:
return WasmStorageType.packed(WasmPackedType.INT8); return WasmStorageType.packed(WasmPackedType.INT16);
case INTEGER: case INTEGER:
return WasmType.INT32.asStorage(); return WasmType.INT32.asStorage();
case LONG: case LONG:

View File

@ -81,7 +81,6 @@ import org.teavm.backend.wasm.model.expression.WasmTest;
import org.teavm.backend.wasm.model.expression.WasmThrow; import org.teavm.backend.wasm.model.expression.WasmThrow;
import org.teavm.backend.wasm.model.expression.WasmUnreachable; import org.teavm.backend.wasm.model.expression.WasmUnreachable;
import org.teavm.model.ClassHierarchy; import org.teavm.model.ClassHierarchy;
import org.teavm.model.ElementModifier;
import org.teavm.model.FieldReference; import org.teavm.model.FieldReference;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
import org.teavm.model.TextLocation; import org.teavm.model.TextLocation;
@ -444,7 +443,6 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
@Override @Override
public void visit(CastExpr expr) { public void visit(CastExpr expr) {
var needsCast = true;
acceptWithType(expr.getValue(), expr.getTarget()); acceptWithType(expr.getValue(), expr.getTarget());
result.acceptVisitor(typeInference); result.acceptVisitor(typeInference);
var sourceType = (WasmType.Reference) typeInference.getResult(); var sourceType = (WasmType.Reference) typeInference.getResult();
@ -485,8 +483,8 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
var block = new WasmBlock(false); var block = new WasmBlock(false);
block.setLocation(expr.getLocation()); block.setLocation(expr.getLocation());
block.setType(targetType);
if (canCastNatively(expr.getTarget())) { if (canCastNatively(expr.getTarget())) {
block.setType(targetType);
if (!canInsertCast) { if (!canInsertCast) {
return; return;
} }
@ -494,6 +492,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
targetType, block)); targetType, block));
result = block; result = block;
} else { } else {
block.setType(sourceType);
var nonNullValue = new WasmNullBranch(WasmNullCondition.NULL, result, block); var nonNullValue = new WasmNullBranch(WasmNullCondition.NULL, result, block);
nonNullValue.setResult(new WasmNullConstant(sourceType)); nonNullValue.setResult(new WasmNullConstant(sourceType));
var valueToCast = exprCache.create(nonNullValue, sourceType, expr.getLocation(), block.getBody()); var valueToCast = exprCache.create(nonNullValue, sourceType, expr.getLocation(), block.getBody());
@ -518,7 +517,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
} }
private boolean canCastNatively(ValueType type) { private boolean canCastNatively(ValueType type) {
if (type instanceof ValueType.Array) { /*if (type instanceof ValueType.Array) {
return true; return true;
} }
var className = ((ValueType.Object) type).getClassName(); var className = ((ValueType.Object) type).getClassName();
@ -526,7 +525,8 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
if (cls == null) { if (cls == null) {
return false; return false;
} }
return !cls.hasModifier(ElementModifier.INTERFACE); return !cls.hasModifier(ElementModifier.INTERFACE);*/
return false;
} }
@Override @Override