Skip to content

Commit

Permalink
wasm gc: disable cast optimization and fix issue with short/char fields
Browse files Browse the repository at this point in the history
  • Loading branch information
konsoletyper committed Sep 17, 2024
1 parent 07b45fb commit 36f7ec3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public WasmStorageType mapStorageType(ValueType type) {
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
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;
Expand Down Expand Up @@ -444,7 +443,6 @@ public void visit(InstanceOfExpr expr) {

@Override
public void visit(CastExpr expr) {
var needsCast = true;
acceptWithType(expr.getValue(), expr.getTarget());
result.acceptVisitor(typeInference);
var sourceType = (WasmType.Reference) typeInference.getResult();
Expand Down Expand Up @@ -485,15 +483,16 @@ public void visit(CastExpr expr) {

var block = new WasmBlock(false);
block.setLocation(expr.getLocation());
block.setType(targetType);
if (canCastNatively(expr.getTarget())) {
block.setType(targetType);
if (!canInsertCast) {
return;
}
block.getBody().add(new WasmCastBranch(WasmCastCondition.SUCCESS, result, sourceType,
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());
Expand All @@ -518,15 +517,16 @@ public void visit(CastExpr expr) {
}

private boolean canCastNatively(ValueType type) {
if (type instanceof ValueType.Array) {
/*if (type instanceof ValueType.Array) {
return true;
}
var className = ((ValueType.Object) type).getClassName();
var cls = context.classes().get(className);
if (cls == null) {
return false;
}
return !cls.hasModifier(ElementModifier.INTERFACE);
return !cls.hasModifier(ElementModifier.INTERFACE);*/
return false;
}

@Override
Expand Down

0 comments on commit 36f7ec3

Please sign in to comment.