From 36f7ec36f3fbfb75fa68bfa97119ce781a88849a Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 17 Sep 2024 08:02:50 +0200 Subject: [PATCH] wasm gc: disable cast optimization and fix issue with short/char fields --- .../wasm/generate/gc/classes/WasmGCTypeMapper.java | 2 +- .../generate/gc/methods/WasmGCGenerationVisitor.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCTypeMapper.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCTypeMapper.java index 83d80c0ed..247d22572 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCTypeMapper.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCTypeMapper.java @@ -56,7 +56,7 @@ public class WasmGCTypeMapper { return WasmStorageType.packed(WasmPackedType.INT8); case SHORT: case CHARACTER: - return WasmStorageType.packed(WasmPackedType.INT8); + return WasmStorageType.packed(WasmPackedType.INT16); case INTEGER: return WasmType.INT32.asStorage(); case LONG: diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java index f448479d7..1f82b39ed 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/methods/WasmGCGenerationVisitor.java @@ -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.WasmUnreachable; import org.teavm.model.ClassHierarchy; -import org.teavm.model.ElementModifier; import org.teavm.model.FieldReference; import org.teavm.model.MethodReference; import org.teavm.model.TextLocation; @@ -444,7 +443,6 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { @Override public void visit(CastExpr expr) { - var needsCast = true; acceptWithType(expr.getValue(), expr.getTarget()); result.acceptVisitor(typeInference); var sourceType = (WasmType.Reference) typeInference.getResult(); @@ -485,8 +483,8 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { var block = new WasmBlock(false); block.setLocation(expr.getLocation()); - block.setType(targetType); if (canCastNatively(expr.getTarget())) { + block.setType(targetType); if (!canInsertCast) { return; } @@ -494,6 +492,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { targetType, block)); result = block; } else { + block.setType(sourceType); var nonNullValue = new WasmNullBranch(WasmNullCondition.NULL, result, block); nonNullValue.setResult(new WasmNullConstant(sourceType)); var valueToCast = exprCache.create(nonNullValue, sourceType, expr.getLocation(), block.getBody()); @@ -518,7 +517,7 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { } private boolean canCastNatively(ValueType type) { - if (type instanceof ValueType.Array) { + /*if (type instanceof ValueType.Array) { return true; } var className = ((ValueType.Object) type).getClassName(); @@ -526,7 +525,8 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor { if (cls == null) { return false; } - return !cls.hasModifier(ElementModifier.INTERFACE); + return !cls.hasModifier(ElementModifier.INTERFACE);*/ + return false; } @Override