Skip to content

Commit 7882969

Browse files
committed
prevent toggling of frame slot kinds to let code stabilize
1 parent 9104425 commit 7882969

File tree

4 files changed

+28
-57
lines changed

4 files changed

+28
-57
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/FrameSlotNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected final boolean isLongOrObjectKind(Frame frame) {
104104
return isKind(frame, FrameSlotKind.Long) || isKind(frame, FrameSlotKind.Object);
105105
}
106106

107-
protected final boolean isObjectKind(Frame frame) {
107+
protected final boolean isOrSetObjectKind(Frame frame) {
108108
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) != FrameSlotKind.Object) {
109109
CompilerDirectives.transferToInterpreter();
110110
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/WriteLocalVariableNode.java

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@
2525
*/
2626
package com.oracle.graal.python.nodes.frame;
2727

28-
import com.oracle.graal.python.builtins.objects.PNone;
29-
import com.oracle.graal.python.builtins.objects.common.KeywordsStorage;
30-
import com.oracle.graal.python.builtins.objects.function.PKeyword;
3128
import com.oracle.graal.python.builtins.objects.ints.PInt;
3229
import com.oracle.graal.python.nodes.expression.ExpressionNode;
3330
import com.oracle.graal.python.nodes.frame.WriteLocalVariableNodeGen.WriteLocalFrameSlotNodeGen;
3431
import com.oracle.graal.python.nodes.statement.StatementNode;
3532
import com.oracle.truffle.api.dsl.NodeChild;
3633
import com.oracle.truffle.api.dsl.Specialization;
3734
import com.oracle.truffle.api.frame.FrameSlot;
38-
import com.oracle.truffle.api.frame.FrameSlotKind;
3935
import com.oracle.truffle.api.frame.VirtualFrame;
40-
import com.oracle.truffle.api.nodes.ExplodeLoop;
4136
import com.oracle.truffle.api.nodes.NodeCost;
4237
import com.oracle.truffle.api.nodes.NodeInfo;
4338

@@ -86,12 +81,6 @@ public final boolean executeBoolean(VirtualFrame frame) {
8681

8782
public abstract Object executeWith(VirtualFrame frame, Object value);
8883

89-
@Specialization(guards = "isBooleanKind(frame)")
90-
public PNone write(VirtualFrame frame, PNone right) {
91-
frame.setObject(frameSlot, PNone.NONE);
92-
return right;
93-
}
94-
9584
@Specialization(guards = "isBooleanKind(frame)")
9685
public boolean write(VirtualFrame frame, boolean right) {
9786
frame.setBoolean(frameSlot, right);
@@ -104,18 +93,18 @@ public int write(VirtualFrame frame, int value) {
10493
return value;
10594
}
10695

107-
@Specialization(guards = {"isLongOrObjectKind(frame)", "isPrimitiveInt(value)", "!value.isNative()"}, rewriteOn = ArithmeticException.class)
108-
public PInt writePIntAsLong(VirtualFrame frame, PInt value) {
109-
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Long);
110-
frame.setLong(frameSlot, value.longValueExact());
111-
return value;
96+
@Specialization(guards = {"isPrimitiveInt(value)", "!value.isNative()", "isLongKind(frame)"}, rewriteOn = ArithmeticException.class)
97+
public long writeSmallPIntAsLong(VirtualFrame frame, PInt value) {
98+
long longValue = value.longValueExact();
99+
frame.setLong(frameSlot, longValue);
100+
return longValue;
112101
}
113102

114-
@Specialization(guards = "isLongOrObjectKind(frame)")
115-
public PInt writePIntAsObject(VirtualFrame frame, PInt value) {
116-
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);
117-
frame.setObject(frameSlot, value);
118-
return value;
103+
@Specialization(guards = {"isPrimitiveInt(value)", "!value.isNative()", "isOrSetObjectKind(frame)"}, rewriteOn = ArithmeticException.class)
104+
public long writeSmallPIntAsObject(VirtualFrame frame, PInt value) {
105+
long longValue = value.longValueExact();
106+
frame.setObject(frameSlot, longValue);
107+
return longValue;
119108
}
120109

121110
@Specialization(guards = "isDoubleKind(frame)")
@@ -124,22 +113,14 @@ public double write(VirtualFrame frame, double right) {
124113
return right;
125114
}
126115

127-
@Specialization(guards = "isObjectKind(frame)")
128-
@ExplodeLoop
129-
public Object write(VirtualFrame frame, PKeyword[] right) {
130-
frame.setObject(frameSlot, factory().createDict(KeywordsStorage.create(right)));
131-
return right;
132-
}
133-
134-
@Specialization(guards = "isObjectKind(frame)")
116+
@Specialization(guards = "isOrSetObjectKind(frame)")
135117
public Object write(VirtualFrame frame, Object right) {
136118
frame.setObject(frameSlot, right);
137119
return right;
138120
}
139121
}
140122

141123
public WriteLocalVariableNode(FrameSlot slot) {
142-
super();
143124
this.writeNode = WriteLocalFrameSlotNodeGen.create(slot);
144125
}
145126

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/FrameTransferNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public double doDouble(VirtualFrame frame, double right) {
9090
return right;
9191
}
9292

93-
@Specialization(guards = "isObjectKind(frame)")
93+
@Specialization(guards = "isOrSetObjectKind(frame)")
9494
public Object write(VirtualFrame frame, Object right) {
9595
setObject(getCargoFrame(frame), right);
9696
return right;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/WriteGeneratorFrameVariableNode.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626
package com.oracle.graal.python.nodes.generator;
2727

28-
import com.oracle.graal.python.builtins.objects.PNone;
2928
import com.oracle.graal.python.builtins.objects.function.PArguments;
3029
import com.oracle.graal.python.builtins.objects.ints.PInt;
3130
import com.oracle.graal.python.nodes.expression.ExpressionNode;
@@ -37,7 +36,6 @@
3736
import com.oracle.truffle.api.dsl.Specialization;
3837
import com.oracle.truffle.api.frame.Frame;
3938
import com.oracle.truffle.api.frame.FrameSlot;
40-
import com.oracle.truffle.api.frame.FrameSlotKind;
4139
import com.oracle.truffle.api.frame.VirtualFrame;
4240
import com.oracle.truffle.api.nodes.NodeCost;
4341
import com.oracle.truffle.api.profiles.ValueProfile;
@@ -96,51 +94,43 @@ public final boolean executeBoolean(VirtualFrame frame) {
9694

9795
public abstract Object executeWith(VirtualFrame frame, Object value);
9896

99-
private Frame getGeneratorFrame(VirtualFrame frame) {
97+
protected Frame getGeneratorFrame(VirtualFrame frame) {
10098
return frameProfile.profile(PArguments.getGeneratorFrame(frame));
10199
}
102100

103-
@Specialization(guards = "isBooleanKind(frame)")
104-
public PNone write(VirtualFrame frame, PNone right) {
105-
getGeneratorFrame(frame).setObject(frameSlot, PNone.NONE);
106-
return right;
107-
}
108-
109-
@Specialization(guards = "isBooleanKind(frame)")
101+
@Specialization(guards = "isBooleanKind(getGeneratorFrame(frame))")
110102
public boolean write(VirtualFrame frame, boolean right) {
111103
getGeneratorFrame(frame).setBoolean(frameSlot, right);
112104
return right;
113105
}
114106

115-
@Specialization(guards = "isIntegerKind(frame)")
107+
@Specialization(guards = "isIntegerKind(getGeneratorFrame(frame))")
116108
public int write(VirtualFrame frame, int value) {
117109
getGeneratorFrame(frame).setInt(frameSlot, value);
118110
return value;
119111
}
120112

121-
@Specialization(guards = {"isLongOrObjectKind(frame)", "isPrimitiveInt(value)", "!value.isNative()"}, rewriteOn = ArithmeticException.class)
122-
public PInt writePIntAsLong(VirtualFrame frame, PInt value) {
123-
Frame generatorFrame = getGeneratorFrame(frame);
124-
generatorFrame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Long);
125-
generatorFrame.setLong(frameSlot, value.longValueExact());
126-
return value;
113+
@Specialization(guards = {"isPrimitiveInt(value)", "!value.isNative()", "isLongKind(getGeneratorFrame(frame))"}, rewriteOn = ArithmeticException.class)
114+
public long writeSmallPIntAsLong(VirtualFrame frame, PInt value) {
115+
long longValue = value.longValueExact();
116+
getGeneratorFrame(frame).setLong(frameSlot, longValue);
117+
return longValue;
127118
}
128119

129-
@Specialization(guards = "isLongOrObjectKind(frame)")
130-
public PInt writePIntAsObject(VirtualFrame frame, PInt value) {
131-
Frame generatorFrame = getGeneratorFrame(frame);
132-
generatorFrame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);
133-
generatorFrame.setObject(frameSlot, value);
134-
return value;
120+
@Specialization(guards = {"isPrimitiveInt(value)", "!value.isNative()", "isOrSetObjectKind(getGeneratorFrame(frame))"}, rewriteOn = ArithmeticException.class)
121+
public long writeSmallPIntAsObject(VirtualFrame frame, PInt value) {
122+
long longValue = value.longValueExact();
123+
getGeneratorFrame(frame).setObject(frameSlot, longValue);
124+
return longValue;
135125
}
136126

137-
@Specialization(guards = "isDoubleKind(frame)")
127+
@Specialization(guards = "isDoubleKind(getGeneratorFrame(frame))")
138128
public double write(VirtualFrame frame, double right) {
139129
getGeneratorFrame(frame).setDouble(frameSlot, right);
140130
return right;
141131
}
142132

143-
@Specialization(guards = "isObjectKind(frame)")
133+
@Specialization(guards = "isOrSetObjectKind(getGeneratorFrame(frame))")
144134
public Object write(VirtualFrame frame, Object right) {
145135
getGeneratorFrame(frame).setObject(frameSlot, right);
146136
return right;

0 commit comments

Comments
 (0)