Skip to content

Commit 0c11cad

Browse files
committed
Unbreak name/hashcode/equal for float/fixnum/etc. tmp vars
* Closure, float, boolean, fixnum were all using "%v_" prefixes. * Some code refactoring somewhere broke this. * Since closure and non-clusre tmp vars aren't used in the same scope, this doesn't cause hashing conflicts. But, with unboxing, this bug got exposed since these types co-exist within the same scope. * IR output now also use the "%cl_1_5" form for local variables in closures which makes for easier debugging. * Also used a base equals implementation in TemporaryVariable which mirrors the hashCode() implementation there.
1 parent 2dd881b commit 0c11cad

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

core/src/main/java/org/jruby/ir/operands/TemporaryBooleanVariable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
* Represents a temporary variable for an unboxed Boolean operand.
3636
*/
3737
public class TemporaryBooleanVariable extends TemporaryLocalVariable {
38+
public static final String PREFIX = "%b_";
3839
public TemporaryBooleanVariable(int offset) {
39-
super(offset);
40+
super(PREFIX+offset, offset);
4041
}
4142

4243
@Override
@@ -46,7 +47,7 @@ public TemporaryVariableType getType() {
4647

4748
@Override
4849
public String getPrefix() {
49-
return "%b_";
50+
return PREFIX;
5051
}
5152

5253
@Override

core/src/main/java/org/jruby/ir/operands/TemporaryClosureVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class TemporaryClosureVariable extends TemporaryLocalVariable {
66
private final int closureId;
77

88
public TemporaryClosureVariable(int closureId, int offset) {
9-
super(offset);
9+
super("%cl_" + closureId + "_" + offset, offset);
1010

1111
this.closureId = closureId;
1212
}

core/src/main/java/org/jruby/ir/operands/TemporaryFixnumVariable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
* Represents a temporary variable for an unboxed Float operand.
3636
*/
3737
public class TemporaryFixnumVariable extends TemporaryLocalVariable {
38+
public static final String PREFIX = "%i_";
3839
public TemporaryFixnumVariable(int offset) {
39-
super(offset);
40+
super(PREFIX+offset, offset);
4041
}
4142

4243
@Override
@@ -46,7 +47,7 @@ public TemporaryVariableType getType() {
4647

4748
@Override
4849
public String getPrefix() {
49-
return "%i_";
50+
return PREFIX;
5051
}
5152

5253
@Override

core/src/main/java/org/jruby/ir/operands/TemporaryFloatVariable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
* Represents a temporary variable for an unboxed Float operand.
3636
*/
3737
public class TemporaryFloatVariable extends TemporaryLocalVariable {
38+
public static final String PREFIX = "%f_";
3839
public TemporaryFloatVariable(int offset) {
39-
super(offset);
40+
super(PREFIX+offset, offset);
4041
}
4142

4243
@Override
@@ -46,7 +47,7 @@ public TemporaryVariableType getType() {
4647

4748
@Override
4849
public String getPrefix() {
49-
return "%f_";
50+
return PREFIX;
5051
}
5152

5253
@Override

core/src/main/java/org/jruby/ir/operands/TemporaryLocalVariable.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,8 @@ public TemporaryVariableType getType() {
3434
return TemporaryVariableType.LOCAL;
3535
}
3636

37-
@Override
38-
public boolean equals(Object other) {
39-
if (other == null || !(other instanceof TemporaryLocalVariable)) return false;
40-
41-
return super.equals(other) && getOffset() == ((TemporaryLocalVariable) other).getOffset();
42-
}
43-
4437
public String getPrefix() {
45-
return "%v_";
38+
return PREFIX;
4639
}
4740

4841
@Override

core/src/main/java/org/jruby/ir/operands/TemporaryVariable.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ public TemporaryVariable(String name) {
1616
*/
1717
public abstract TemporaryVariableType getType();
1818

19-
@Override
20-
public boolean equals(Object other) {
21-
if (other == null || !(other instanceof TemporaryVariable)) return false;
22-
23-
return getType() == ((TemporaryVariable) other).getType();
24-
}
25-
2619
public String getName() {
2720
return name;
2821
}
@@ -32,6 +25,13 @@ public int hashCode() {
3225
return getName().hashCode();
3326
}
3427

28+
@Override
29+
public boolean equals(Object other) {
30+
if (other == null || !(other instanceof TemporaryVariable)) return false;
31+
32+
return ((TemporaryVariable)other).getName().equals(getName());
33+
}
34+
3535
@Override
3636
public int compareTo(Object other) {
3737
if (!(other instanceof TemporaryVariable)) return 0;

0 commit comments

Comments
 (0)