Skip to content

Commit

Permalink
Revert "GROOVY-11415: Tweak bytecode for identity"
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellansun committed Aug 30, 2024
1 parent ef3fdc5 commit a425cc2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@
import static org.objectweb.asm.Opcodes.IFEQ;
import static org.objectweb.asm.Opcodes.IFNE;
import static org.objectweb.asm.Opcodes.IF_ACMPEQ;
import static org.objectweb.asm.Opcodes.IF_ACMPNE;
import static org.objectweb.asm.Opcodes.INSTANCEOF;
import static org.objectweb.asm.Opcodes.POP;

public class BinaryExpressionHelper {
// compare
private static final MethodCaller compareIdenticalMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareIdentical");
private static final MethodCaller compareNotIdenticalMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareNotIdentical");
private static final MethodCaller compareEqualMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareEqual");
private static final MethodCaller compareNotEqualMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareNotEqual");
private static final MethodCaller compareToMethod = MethodCaller.newStatic(ScriptBytecodeAdapter.class, "compareTo");
Expand Down Expand Up @@ -351,56 +352,18 @@ public void eval(final BinaryExpression expression) {
break;

case COMPARE_IDENTICAL:
evaluateIdentity(expression, true);
evaluateCompareExpression(compareIdenticalMethod, expression);
break;

case COMPARE_NOT_IDENTICAL:
evaluateIdentity(expression, false);
evaluateCompareExpression(compareNotIdenticalMethod, expression);
break;

default:
throw new GroovyBugError("Operation: " + expression.getOperation() + " not supported");
}
}

private void evaluateIdentity(BinaryExpression expression, boolean identical) {
AsmClassGenerator acg = controller.getAcg();
MethodVisitor mv = controller.getMethodVisitor();
OperandStack operandStack = controller.getOperandStack();
TypeChooser typeChooser = controller.getTypeChooser();

Expression lhs = expression.getLeftExpression();
ClassNode leftType = typeChooser.resolveType(lhs, controller.getClassNode());

Expression rhs = expression.getRightExpression();
ClassNode rightType = typeChooser.resolveType(rhs, controller.getClassNode());

boolean leftPrimitive = ClassHelper.isPrimitiveType(leftType);
boolean rightPrimitive = ClassHelper.isPrimitiveType(rightType);
if (leftPrimitive && rightPrimitive) {
BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(controller);
boolean done = helper.doPrimitiveCompare(leftType, rightType, expression);
if (done) return;
}

lhs.visit(acg);
if (leftPrimitive) operandStack.box();

rhs.visit(acg);
if (rightPrimitive) operandStack.box();

Label trueCase = operandStack.jump(identical ? IF_ACMPEQ : IF_ACMPNE);
ConstantExpression.PRIM_FALSE.visit(acg);
Label end = new Label();
mv.visitJumpInsn(GOTO, end);

mv.visitLabel(trueCase);
ConstantExpression.PRIM_TRUE.visit(acg);

mv.visitLabel(end);
operandStack.replace(ClassHelper.boolean_TYPE, 3);
}

@Deprecated
protected void assignToArray(final Expression parent, final Expression receiver, final Expression index, final Expression rhsValueLoader) {
assignToArray(parent, receiver, index, rhsValueLoader, false);
Expand Down
53 changes: 0 additions & 53 deletions src/test/groovy/bugs/Groovy11415.groovy

This file was deleted.

0 comments on commit a425cc2

Please sign in to comment.