Skip to content

Commit c73da4e

Browse files
committed
[GR-48309] Remove PRaiseNode from non-builtin nodes
PullRequest: graalpython/2981
2 parents 2092b59 + d7ec202 commit c73da4e

File tree

66 files changed

+1218
-1090
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1218
-1090
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "8392242bfdb60905883302a1f3fc523e0526ca59" }
1+
{ "overlay": "905cc34681f8adc50a8e10f8e82324a41cf00a5c" }

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@
187187
import com.oracle.graal.python.nodes.ErrorMessages;
188188
import com.oracle.graal.python.nodes.PGuards;
189189
import com.oracle.graal.python.nodes.PNodeWithContext;
190-
import com.oracle.graal.python.nodes.PNodeWithRaise;
191190
import com.oracle.graal.python.nodes.PRaiseNode;
192191
import com.oracle.graal.python.nodes.SpecialAttributeNames;
193192
import com.oracle.graal.python.nodes.SpecialMethodNames;
@@ -2383,16 +2382,18 @@ protected ArgumentClinicProvider getArgumentClinic() {
23832382
}
23842383

23852384
@ImportStatic(SpecialMethodNames.class)
2386-
abstract static class UpdateBasesNode extends PNodeWithRaise {
2385+
@SuppressWarnings("truffle-inlining") // footprint reduction 72 -> 53
2386+
abstract static class UpdateBasesNode extends Node {
23872387

23882388
abstract PTuple execute(PTuple bases, Object[] arguments, int nargs);
23892389

23902390
@Specialization
2391-
PTuple update(PTuple bases, Object[] arguments, int nargs,
2391+
static PTuple update(PTuple bases, Object[] arguments, int nargs,
23922392
@Bind("this") Node inliningTarget,
23932393
@Cached PythonObjectFactory factory,
23942394
@Cached PyObjectLookupAttr getMroEntries,
2395-
@Cached CallUnaryMethodNode callMroEntries) {
2395+
@Cached CallUnaryMethodNode callMroEntries,
2396+
@Cached PRaiseNode.Lazy raiseNode) {
23962397
CompilerAsserts.neverPartOfCompilation();
23972398
ArrayList<Object> newBases = null;
23982399
for (int i = 0; i < nargs; i++) {
@@ -2415,7 +2416,7 @@ PTuple update(PTuple bases, Object[] arguments, int nargs,
24152416
}
24162417
Object newBase = callMroEntries.executeObject(null, meth, bases);
24172418
if (!PGuards.isPTuple(newBase)) {
2418-
throw raise(PythonErrorType.TypeError, ErrorMessages.MRO_ENTRIES_MUST_RETURN_TUPLE);
2419+
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.MRO_ENTRIES_MUST_RETURN_TUPLE);
24192420
}
24202421
PTuple newBaseTuple = (PTuple) newBase;
24212422
if (newBases == null) {
@@ -2438,17 +2439,19 @@ PTuple update(PTuple bases, Object[] arguments, int nargs,
24382439
}
24392440
}
24402441

2441-
abstract static class CalculateMetaclassNode extends PNodeWithRaise {
2442+
@SuppressWarnings("truffle-inlining") // footprint reduction 36 -> 19
2443+
abstract static class CalculateMetaclassNode extends Node {
24422444

24432445
abstract Object execute(Object metatype, PTuple bases);
24442446

24452447
/* Determine the most derived metatype. */
24462448
@Specialization
2447-
Object calculate(Object metatype, PTuple bases,
2449+
static Object calculate(Object metatype, PTuple bases,
24482450
@Bind("this") Node inliningTarget,
24492451
@Cached GetClassNode getClass,
24502452
@Cached IsSubtypeNode isSubType,
2451-
@Cached IsSubtypeNode isSubTypeReverse) {
2453+
@Cached IsSubtypeNode isSubTypeReverse,
2454+
@Cached PRaiseNode.Lazy raiseNode) {
24522455
CompilerAsserts.neverPartOfCompilation();
24532456
/*
24542457
* Determine the proper metatype to deal with this, and check for metatype conflicts
@@ -2467,7 +2470,7 @@ Object calculate(Object metatype, PTuple bases,
24672470
} else if (isSubTypeReverse.execute(tmpType, winner)) {
24682471
winner = tmpType;
24692472
} else {
2470-
throw raise(PythonErrorType.TypeError, ErrorMessages.METACLASS_CONFLICT);
2473+
throw raiseNode.get(inliningTarget).raise(PythonErrorType.TypeError, ErrorMessages.METACLASS_CONFLICT);
24712474
}
24722475
}
24732476
return winner;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CmathModuleBuiltins.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3333
import com.oracle.truffle.api.dsl.Bind;
3434
import com.oracle.truffle.api.dsl.Cached;
35-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
3635
import com.oracle.truffle.api.dsl.Cached.Shared;
3736
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
3837
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -178,10 +177,12 @@ PComplex doC(VirtualFrame frame, PComplex value,
178177
}
179178

180179
@Specialization
180+
@SuppressWarnings("truffle-static-method")
181181
PComplex doGeneral(VirtualFrame frame, Object value,
182+
@Bind("this") Node inliningTarget,
182183
@Cached CoerceToComplexNode coerceToComplex,
183184
@Shared @Cached PythonObjectFactory factory) {
184-
return doC(frame, coerceToComplex.execute(frame, value), factory);
185+
return doC(frame, coerceToComplex.execute(frame, inliningTarget, value), factory);
185186
}
186187
}
187188

@@ -210,9 +211,11 @@ boolean doC(PComplex value) {
210211
}
211212

212213
@Specialization
214+
@SuppressWarnings("truffle-static-method")
213215
boolean doGeneral(VirtualFrame frame, Object value,
216+
@Bind("this") Node inliningTarget,
214217
@Cached CoerceToComplexNode coerceToComplex) {
215-
return doC(coerceToComplex.execute(frame, value));
218+
return doC(coerceToComplex.execute(frame, inliningTarget, value));
216219
}
217220
}
218221

@@ -265,9 +268,11 @@ abstract static class PhaseNode extends PythonUnaryBuiltinNode {
265268
}
266269

267270
@Specialization
271+
@SuppressWarnings("truffle-static-method")
268272
double doGeneral(VirtualFrame frame, Object value,
273+
@Bind("this") Node inliningTarget,
269274
@Cached CoerceToComplexNode coerceToComplex) {
270-
return doC(coerceToComplex.execute(frame, value));
275+
return doC(coerceToComplex.execute(frame, inliningTarget, value));
271276
}
272277
}
273278

@@ -297,11 +302,13 @@ PTuple doC(PComplex value,
297302
}
298303

299304
@Specialization
305+
@SuppressWarnings("truffle-static-method")
300306
PTuple doGeneral(VirtualFrame frame, Object value,
307+
@Bind("this") Node inliningTarget,
301308
@Cached CoerceToComplexNode coerceToComplex,
302309
@Shared @Cached ComplexBuiltins.AbsNode absNode,
303310
@Shared @Cached PythonObjectFactory factory) {
304-
return toPolar(coerceToComplex.execute(frame, value), absNode, factory);
311+
return toPolar(coerceToComplex.execute(frame, inliningTarget, value), absNode, factory);
305312
}
306313

307314
private static PTuple toPolar(PComplex value, ComplexBuiltins.AbsNode absNode, PythonObjectFactory factory) {
@@ -426,19 +433,23 @@ PComplex doComplexComplex(VirtualFrame frame, PComplex x, PComplex y,
426433

427434
@Specialization(guards = "isNoValue(yObj)")
428435
PComplex doGeneral(VirtualFrame frame, Object xObj, @SuppressWarnings("unused") PNone yObj,
436+
@Bind("this") Node inliningTarget,
429437
@Shared @Cached CoerceToComplexNode coerceXToComplex,
438+
// unused node to avoid mixing shared and non-shared inlined nodes
439+
@SuppressWarnings("unsued") @Shared @Cached CoerceToComplexNode coerceYToComplex,
430440
@Shared @Cached PythonObjectFactory factory) {
431-
return log(coerceXToComplex.execute(frame, xObj), factory);
441+
return log(coerceXToComplex.execute(frame, inliningTarget, xObj), factory);
432442
}
433443

434444
@Specialization(guards = "!isNoValue(yObj)")
435445
PComplex doGeneral(VirtualFrame frame, Object xObj, Object yObj,
446+
@Bind("this") Node inliningTarget,
436447
@Shared @Cached CoerceToComplexNode coerceXToComplex,
437-
@Exclusive @Cached CoerceToComplexNode coerceYToComplex,
448+
@Shared @Cached CoerceToComplexNode coerceYToComplex,
438449
@Shared @Cached ComplexBuiltins.DivNode divNode,
439450
@Shared @Cached PythonObjectFactory factory) {
440-
PComplex x = log(coerceXToComplex.execute(frame, xObj), factory);
441-
PComplex y = log(coerceYToComplex.execute(frame, yObj), factory);
451+
PComplex x = log(coerceXToComplex.execute(frame, inliningTarget, xObj), factory);
452+
PComplex y = log(coerceYToComplex.execute(frame, inliningTarget, yObj), factory);
442453
return divNode.executeComplex(frame, x, y);
443454
}
444455

@@ -493,9 +504,10 @@ PComplex doComplex(VirtualFrame frame, PComplex z,
493504

494505
@Specialization
495506
PComplex doGeneral(VirtualFrame frame, Object zObj,
507+
@Bind("this") Node inliningTarget,
496508
@Cached CoerceToComplexNode coerceXToComplex,
497509
@Shared @Cached PythonObjectFactory factory) {
498-
return doComplex(frame, coerceXToComplex.execute(frame, zObj), factory);
510+
return doComplex(frame, coerceXToComplex.execute(frame, inliningTarget, zObj), factory);
499511
}
500512
}
501513

@@ -1046,8 +1058,8 @@ boolean doGeneral(VirtualFrame frame, Object aObj, Object bObj, Object relTolObj
10461058
@Cached PyFloatAsDoubleNode relAsDoubleNode,
10471059
@Cached PyFloatAsDoubleNode absAsDoubleNode,
10481060
@Shared @Cached PythonObjectFactory factory) {
1049-
PComplex a = coerceAToComplex.execute(frame, aObj);
1050-
PComplex b = coerceBToComplex.execute(frame, bObj);
1061+
PComplex a = coerceAToComplex.execute(frame, inliningTarget, aObj);
1062+
PComplex b = coerceBToComplex.execute(frame, inliningTarget, bObj);
10511063
double relTol = PGuards.isNoValue(relTolObj) ? DEFAULT_REL_TOL : relAsDoubleNode.execute(frame, inliningTarget, relTolObj);
10521064
double absTol = PGuards.isPNone(absTolObj) ? DEFAULT_ABS_TOL : absAsDoubleNode.execute(frame, inliningTarget, absTolObj);
10531065
return isClose(a, b, relTol, absTol, factory);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JArrayModuleBuiltins.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
5656
import com.oracle.graal.python.builtins.objects.list.PList;
5757
import com.oracle.graal.python.nodes.ErrorMessages;
58-
import com.oracle.graal.python.nodes.PNodeWithRaise;
58+
import com.oracle.graal.python.nodes.PNodeWithContext;
59+
import com.oracle.graal.python.nodes.PRaiseNode;
5960
import com.oracle.graal.python.nodes.builtins.ListNodes;
6061
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6162
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -70,6 +71,8 @@
7071
import com.oracle.truffle.api.dsl.Cached;
7172
import com.oracle.truffle.api.dsl.Cached.Shared;
7273
import com.oracle.truffle.api.dsl.Fallback;
74+
import com.oracle.truffle.api.dsl.GenerateCached;
75+
import com.oracle.truffle.api.dsl.GenerateInline;
7376
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7477
import com.oracle.truffle.api.dsl.NodeFactory;
7578
import com.oracle.truffle.api.dsl.Specialization;
@@ -89,8 +92,10 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
8992
return JArrayModuleBuiltinsFactory.getFactories();
9093
}
9194

92-
abstract static class ArrayFromTypeCode extends PNodeWithRaise {
93-
public abstract Object execute(int length, String typeCode);
95+
@GenerateInline
96+
@GenerateCached(false)
97+
abstract static class ArrayFromTypeCode extends PNodeWithContext {
98+
public abstract Object execute(Node inliningTarget, int length, String typeCode);
9499

95100
protected static final String Z = "z";
96101
protected static final String C = "c";
@@ -143,8 +148,9 @@ static Object d(int length, @SuppressWarnings("unused") String typeCode) {
143148

144149
@Fallback
145150
@SuppressWarnings("unused")
146-
Object error(int length, String typeCode) {
147-
throw raise(ValueError, ErrorMessages.INVALID_TYPE_CODE, typeCode);
151+
static Object error(int length, String typeCode,
152+
@Cached(inline = false) PRaiseNode raiseNode) {
153+
throw raiseNode.raise(ValueError, ErrorMessages.INVALID_TYPE_CODE, typeCode);
148154
}
149155

150156
protected static boolean eq(String a, String b) {
@@ -160,10 +166,11 @@ abstract static class ZerosNode extends PythonBinaryClinicBuiltinNode {
160166

161167
@Specialization(guards = "isString(typeCodeObj)")
162168
Object fromTypeCode(int length, Object typeCodeObj,
169+
@Bind("this") Node inliningTarget,
163170
@Cached CastToJavaStringNode cast,
164171
@Cached ArrayFromTypeCode fromTypeCodeNode) {
165172
String typeCode = cast.execute(typeCodeObj);
166-
Object array = fromTypeCodeNode.execute(length, typeCode);
173+
Object array = fromTypeCodeNode.execute(inliningTarget, length, typeCode);
167174
return getContext().getEnv().asGuestValue(array);
168175
}
169176

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
import com.oracle.graal.python.lib.PyObjectGetIter;
6060
import com.oracle.graal.python.nodes.ErrorMessages;
6161
import com.oracle.graal.python.nodes.PGuards;
62-
import com.oracle.graal.python.nodes.PNodeWithRaise;
62+
import com.oracle.graal.python.nodes.PRaiseNode;
6363
import com.oracle.graal.python.nodes.builtins.TupleNodes;
6464
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
6565
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
@@ -998,7 +998,7 @@ public int gcdKeywords(Object self, Object[] args, PKeyword[] keywords) {
998998

999999
@TypeSystemReference(PythonArithmeticTypes.class)
10001000
@ImportStatic(MathGuards.class)
1001-
public abstract static class Gcd2Node extends PNodeWithRaise {
1001+
public abstract static class Gcd2Node extends Node {
10021002

10031003
protected final boolean isRecursive;
10041004

@@ -1008,26 +1008,26 @@ public Gcd2Node(boolean isRecursive) {
10081008

10091009
abstract Object execute(VirtualFrame frame, Object a, Object b);
10101010

1011-
private long count(long a, long b) {
1011+
private static long count(long a, long b) {
10121012
if (b == 0) {
10131013
return a;
10141014
}
10151015
return count(b, a % b);
10161016
}
10171017

10181018
@Specialization
1019-
long gcd(long x, long y) {
1019+
static long gcd(long x, long y) {
10201020
return Math.abs(count(x, y));
10211021
}
10221022

10231023
@Specialization
1024-
PInt gcd(long x, PInt y,
1024+
static PInt gcd(long x, PInt y,
10251025
@Shared("factory") @Cached PythonObjectFactory factory) {
10261026
return factory.createInt(op(PInt.longToBigInteger(x), y.getValue()));
10271027
}
10281028

10291029
@Specialization
1030-
PInt gcd(PInt x, long y,
1030+
static PInt gcd(PInt x, long y,
10311031
@Shared("factory") @Cached PythonObjectFactory factory) {
10321032
return factory.createInt(op(x.getValue(), PInt.longToBigInteger(y)));
10331033
}
@@ -1044,28 +1044,33 @@ PInt gcd(PInt x, PInt y,
10441044
}
10451045

10461046
@Specialization
1047-
int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") double y) {
1048-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
1047+
static int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") double y,
1048+
@Shared @Cached PRaiseNode raiseNode) {
1049+
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
10491050
}
10501051

10511052
@Specialization
1052-
int gcd(@SuppressWarnings("unused") long x, @SuppressWarnings("unused") double y) {
1053-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
1053+
static int gcd(@SuppressWarnings("unused") long x, @SuppressWarnings("unused") double y,
1054+
@Shared @Cached PRaiseNode raiseNode) {
1055+
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
10541056
}
10551057

10561058
@Specialization
1057-
int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") long y) {
1058-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
1059+
static int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") long y,
1060+
@Shared @Cached PRaiseNode raiseNode) {
1061+
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
10591062
}
10601063

10611064
@Specialization
1062-
int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") PInt y) {
1063-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
1065+
static int gcd(@SuppressWarnings("unused") double x, @SuppressWarnings("unused") PInt y,
1066+
@Shared @Cached PRaiseNode raiseNode) {
1067+
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
10641068
}
10651069

10661070
@Specialization(guards = "!isRecursive")
1067-
int gcd(@SuppressWarnings("unused") PInt x, @SuppressWarnings("unused") double y) {
1068-
throw raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
1071+
static int gcd(@SuppressWarnings("unused") PInt x, @SuppressWarnings("unused") double y,
1072+
@Shared @Cached PRaiseNode raiseNode) {
1073+
throw raiseNode.raise(TypeError, ErrorMessages.OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER, "float");
10691074
}
10701075

10711076
@Specialization(guards = {"!isRecursive", "!isNumber(x) || !isNumber(y)"})
@@ -1080,7 +1085,8 @@ static Object gcd(VirtualFrame frame, Object x, Object y,
10801085

10811086
@Specialization
10821087
Object gcdNative(@SuppressWarnings("unused") PythonAbstractNativeObject a, @SuppressWarnings("unused") Object b) {
1083-
throw raise(SystemError, ErrorMessages.GCD_FOR_NATIVE_NOT_SUPPORTED);
1088+
CompilerDirectives.transferToInterpreter();
1089+
throw PRaiseNode.raiseUncached(this, SystemError, ErrorMessages.GCD_FOR_NATIVE_NOT_SUPPORTED);
10841090
}
10851091

10861092
@NeverDefault

0 commit comments

Comments
 (0)