Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1709,27 +1709,12 @@ trait BCodeBodyBuilder(val primitives: DottyPrimitives)(using ctx: Context) exte
genCallMethod(defn.Any_equals, InvokeStyle.Virtual)
genCZJUMP(success, failure, Primitives.NE, BOOL, targetIfNoJump)
} else {
// l == r -> if (l eq null) r eq null else l.equals(r)
val eqEqTempLocal = locals.makeLocal(ts.ObjectRef, nme.EQEQ_LOCAL_VAR.mangledString, defn.ObjectType, r.span)
val lNull = new asm.Label
val lNonNull = new asm.Label

// l == r -> Objects.equals(l, r)
genLoad(l, ts.ObjectRef)
stack.push(ts.ObjectRef)
genLoad(r, ts.ObjectRef)
stack.pop()
locals.store(eqEqTempLocal)
bc.dup(ts.ObjectRef)
genCZJUMP(lNull, lNonNull, Primitives.EQ, ts.ObjectRef, targetIfNoJump = lNull)

markProgramPoint(lNull)
bc.drop(ts.ObjectRef)
locals.load(eqEqTempLocal)
genCZJUMP(success, failure, Primitives.EQ, ts.ObjectRef, targetIfNoJump = lNonNull)

markProgramPoint(lNonNull)
locals.load(eqEqTempLocal)
genCallMethod(defn.Any_equals, InvokeStyle.Virtual)
genCallMethod(defn.Objects_equals, InvokeStyle.Static)
genCZJUMP(success, failure, Primitives.NE, BOOL, targetIfNoJump)
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ class Definitions {
@tu lazy val JavaUtilObjectsClass: ClassSymbol = requiredModule("java.util.Objects").moduleClass.asClass
def Objects_hashCode(using Context): Symbol =
JavaUtilObjectsClass.info.member(nme.hashCode_).suchThat(_.info.firstParamTypes.length == 1).symbol
def Objects_equals(using Context): Symbol =
JavaUtilObjectsClass.info.member(nme.equals_).suchThat(_.info.firstParamTypes.length == 2).symbol

@tu lazy val JavaEnumClass: ClassSymbol = {
val cls = requiredClass("java.lang.Enum")
Expand Down
16 changes: 3 additions & 13 deletions compiler/test/dotty/tools/backend/jvm/DottyBytecodeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1192,21 +1192,11 @@ class DottyBytecodeTests extends DottyBytecodeTest {
Field(GETSTATIC, "scala/package$", "MODULE$", "Lscala/package$;"),
Invoke(INVOKEVIRTUAL, "scala/package$", "Nil", "()Lscala/collection/immutable/Nil$;", false),
VarOp(ALOAD, 2),
VarOp(ASTORE, 7),
Op(DUP),
Jump(IFNONNULL, Label(31)),
Op(POP),
VarOp(ALOAD, 7),
Jump(IFNULL, Label(36)),
Jump(GOTO, Label(40)),
Label(31),
VarOp(ALOAD, 7),
Invoke(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false),
Jump(IFEQ, Label(40)),
Label(36),
Invoke(INVOKESTATIC, "java/util/Objects", "equals", "(Ljava/lang/Object;Ljava/lang/Object;)Z", false),
Jump(IFEQ, Label(28)),
IntOp(BIPUSH, 20),
Op(IRETURN),
Label(40),
Label(28),
TypeOp(NEW, "scala/MatchError"),
Op(DUP),
VarOp(ALOAD, 2),
Expand Down
Loading