Skip to content

Commit b0eb0e3

Browse files
committed
[GR-13920] Prevent toggling of frame slot kinds to let code stabilize
PullRequest: graalpython/407
2 parents 6b0e6d7 + 097987f commit b0eb0e3

File tree

7 files changed

+73
-102
lines changed

7 files changed

+73
-102
lines changed

graalpython/com.oracle.graal.python.cext/src/setobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -45,7 +45,7 @@ PyTypeObject PyFrozenSet_Type = PY_TRUFFLE_TYPE("frozenset", &PyType_Type, Py_TP
4545

4646
UPCALL_ID(PySet_New);
4747
PyObject * PySet_New(PyObject *iterable) {
48-
return UPCALL_CEXT_O(_jls_PySet_New, native_to_java(iterable));
48+
return UPCALL_CEXT_O(_jls_PySet_New, native_to_java(iterable != NULL ? iterable : Py_None));
4949
}
5050

5151
UPCALL_ID(PyFrozenSet_New);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -104,9 +104,9 @@ 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 ensureObjectKind(Frame frame) {
108108
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) != FrameSlotKind.Object) {
109-
CompilerDirectives.transferToInterpreter();
109+
CompilerDirectives.transferToInterpreterAndInvalidate();
110110
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, FrameSlotKind.Object);
111111
}
112112
return true;
@@ -118,7 +118,7 @@ private boolean isKind(Frame frame, FrameSlotKind kind) {
118118

119119
private boolean initialSetKind(Frame frame, FrameSlotKind kind) {
120120
if (frame.getFrameDescriptor().getFrameSlotKind(frameSlot) == FrameSlotKind.Illegal) {
121-
CompilerDirectives.transferToInterpreter();
121+
CompilerDirectives.transferToInterpreterAndInvalidate();
122122
frame.getFrameDescriptor().setFrameSlotKind(frameSlot, kind);
123123
return true;
124124
}

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

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -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

@@ -87,15 +82,9 @@ public final boolean executeBoolean(VirtualFrame frame) {
8782
public abstract Object executeWith(VirtualFrame frame, Object value);
8883

8984
@Specialization(guards = "isBooleanKind(frame)")
90-
public PNone write(VirtualFrame frame, PNone right) {
91-
frame.setObject(frameSlot, PNone.NONE);
92-
return right;
93-
}
94-
95-
@Specialization(guards = "isBooleanKind(frame)")
96-
public boolean write(VirtualFrame frame, boolean right) {
97-
frame.setBoolean(frameSlot, right);
98-
return right;
85+
public boolean write(VirtualFrame frame, boolean value) {
86+
frame.setBoolean(frameSlot, value);
87+
return value;
9988
}
10089

10190
@Specialization(guards = "isIntegerKind(frame)")
@@ -104,42 +93,36 @@ 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()"}, rewriteOn = ArithmeticException.class)
104+
public long writeSmallPIntAsObject(VirtualFrame frame, PInt value) {
105+
ensureObjectKind(frame);
106+
long longValue = value.longValueExact();
107+
frame.setObject(frameSlot, longValue);
108+
return longValue;
119109
}
120110

121111
@Specialization(guards = "isDoubleKind(frame)")
122-
public double write(VirtualFrame frame, double right) {
123-
frame.setDouble(frameSlot, right);
124-
return right;
125-
}
126-
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;
112+
public double write(VirtualFrame frame, double value) {
113+
frame.setDouble(frameSlot, value);
114+
return value;
132115
}
133116

134-
@Specialization(guards = "isObjectKind(frame)")
135-
public Object write(VirtualFrame frame, Object right) {
136-
frame.setObject(frameSlot, right);
137-
return right;
117+
@Specialization
118+
public Object write(VirtualFrame frame, Object value) {
119+
ensureObjectKind(frame);
120+
frame.setObject(frameSlot, value);
121+
return value;
138122
}
139123
}
140124

141125
public WriteLocalVariableNode(FrameSlot slot) {
142-
super();
143126
this.writeNode = WriteLocalFrameSlotNodeGen.create(slot);
144127
}
145128

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -26,7 +26,6 @@
2626
package com.oracle.graal.python.nodes.generator;
2727

2828
import com.oracle.graal.python.builtins.objects.function.PArguments;
29-
import com.oracle.graal.python.builtins.objects.ints.PInt;
3029
import com.oracle.graal.python.nodes.expression.ExpressionNode;
3130
import com.oracle.graal.python.nodes.frame.FrameSlotNode;
3231
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -61,9 +60,9 @@ private Frame getCargoFrame(VirtualFrame frame) {
6160
}
6261

6362
@Specialization(guards = "isBooleanKind(frame)")
64-
public boolean write(VirtualFrame frame, boolean right) {
65-
getCargoFrame(frame).setBoolean(frameSlot, right);
66-
return right;
63+
public boolean write(VirtualFrame frame, boolean value) {
64+
getCargoFrame(frame).setBoolean(frameSlot, value);
65+
return value;
6766
}
6867

6968
@Specialization(guards = "isIntegerKind(frame)")
@@ -72,27 +71,22 @@ public int doInteger(VirtualFrame frame, int value) {
7271
return value;
7372
}
7473

75-
@Specialization(guards = "isIntOrObjectKind(frame)")
76-
public PInt write(VirtualFrame frame, PInt value) {
77-
setObject(getCargoFrame(frame), value);
78-
return value;
79-
}
80-
8174
@Specialization(guards = "isLongKind(frame)")
8275
public long doLong(VirtualFrame frame, long value) {
8376
getCargoFrame(frame).setLong(frameSlot, value);
8477
return value;
8578
}
8679

8780
@Specialization(guards = "isDoubleKind(frame)")
88-
public double doDouble(VirtualFrame frame, double right) {
89-
getCargoFrame(frame).setDouble(frameSlot, right);
90-
return right;
81+
public double doDouble(VirtualFrame frame, double value) {
82+
getCargoFrame(frame).setDouble(frameSlot, value);
83+
return value;
9184
}
9285

93-
@Specialization(guards = "isObjectKind(frame)")
94-
public Object write(VirtualFrame frame, Object right) {
95-
setObject(getCargoFrame(frame), right);
96-
return right;
86+
@Specialization
87+
public Object write(VirtualFrame frame, Object value) {
88+
ensureObjectKind(frame);
89+
setObject(getCargoFrame(frame), value);
90+
return value;
9791
}
9892
}

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

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -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,54 +94,48 @@ 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)")
110-
public boolean write(VirtualFrame frame, boolean right) {
111-
getGeneratorFrame(frame).setBoolean(frameSlot, right);
112-
return right;
101+
@Specialization(guards = "isBooleanKind(getGeneratorFrame(frame))")
102+
public boolean write(VirtualFrame frame, boolean value) {
103+
getGeneratorFrame(frame).setBoolean(frameSlot, value);
104+
return value;
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()"}, rewriteOn = ArithmeticException.class)
121+
public long writeSmallPIntAsObject(VirtualFrame frame, PInt value) {
122+
ensureObjectKind(frame);
123+
long longValue = value.longValueExact();
124+
getGeneratorFrame(frame).setObject(frameSlot, longValue);
125+
return longValue;
135126
}
136127

137-
@Specialization(guards = "isDoubleKind(frame)")
138-
public double write(VirtualFrame frame, double right) {
139-
getGeneratorFrame(frame).setDouble(frameSlot, right);
140-
return right;
128+
@Specialization(guards = "isDoubleKind(getGeneratorFrame(frame))")
129+
public double write(VirtualFrame frame, double value) {
130+
getGeneratorFrame(frame).setDouble(frameSlot, value);
131+
return value;
141132
}
142133

143-
@Specialization(guards = "isObjectKind(frame)")
144-
public Object write(VirtualFrame frame, Object right) {
145-
getGeneratorFrame(frame).setObject(frameSlot, right);
146-
return right;
134+
@Specialization
135+
public Object write(VirtualFrame frame, Object value) {
136+
ensureObjectKind(frame);
137+
getGeneratorFrame(frame).setObject(frameSlot, value);
138+
return value;
147139
}
148140
}
149141

graalpython/lib-python/3/platform.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,10 @@ def _mac_ver_xml():
555555
except ImportError:
556556
return None
557557

558-
with open(fn, 'rb') as f:
559-
pl = plistlib.load(f)
558+
# this would require xml parsing
559+
# with open(fn, 'rb') as f:
560+
# pl = plistlib.load(f)
561+
pl = {'ProductVersion': '10.14.1'}
560562
release = pl['ProductVersion']
561563
versioninfo = ('', '', '')
562564
machine = os.uname().machine

graalpython/lib-python/3/urllib/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ def ip2num(ipAddr):
25812581
return False
25822582

25832583

2584-
if sys.platform == 'darwin':
2584+
if sys.platform == 'darwin' and False: # changed: use default path in darwin
25852585
from _scproxy import _get_proxy_settings, _get_proxies
25862586

25872587
def proxy_bypass_macosx_sysconf(host):

0 commit comments

Comments
 (0)