Skip to content

Commit c211c49

Browse files
committed
[GR-38700] Update some nodes to use static specializations
PullRequest: graalpython/2781
2 parents e74ae19 + 7a7909f commit c211c49

18 files changed

+295
-257
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ static Object repr(VirtualFrame frame, Object obj,
20082008
public abstract static class FormatNode extends PythonBinaryBuiltinNode {
20092009

20102010
@Specialization
2011-
static Object format(VirtualFrame frame, Object obj, Object formatSpec,
2011+
public static Object format(VirtualFrame frame, Object obj, Object formatSpec,
20122012
@Bind("this") Node inliningTarget,
20132013
@Cached("create(Format)") LookupAndCallBinaryNode callFormat,
20142014
@Cached InlinedConditionProfile formatIsNoValueProfile,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictNodes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, 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
@@ -76,11 +76,11 @@ public abstract static class UpdateNode extends PNodeWithContext {
7676

7777
@SuppressWarnings("unused")
7878
@Specialization(guards = "isIdentical(self, other)")
79-
static void updateSelf(VirtualFrame frame, PDict self, Object other) {
79+
public static void updateSelf(VirtualFrame frame, PDict self, Object other) {
8080
}
8181

8282
@Specialization(guards = "!mayHaveSideEffectingEq(self)")
83-
static void updateDictNoSideEffects(PDict self, PDict other,
83+
public static void updateDictNoSideEffects(PDict self, PDict other,
8484
@Bind("this") Node inliningTarget,
8585
@Exclusive @Cached HashingStorageAddAllToOther addAllToOther) {
8686
// The contract is such that we iterate over 'other' and add its elements to 'self'. If
@@ -91,7 +91,7 @@ static void updateDictNoSideEffects(PDict self, PDict other,
9191
}
9292

9393
@Specialization(guards = "mayHaveSideEffectingEq(self)")
94-
static void updateDictGeneric(VirtualFrame frame, PDict self, PDict other,
94+
public static void updateDictGeneric(VirtualFrame frame, PDict self, PDict other,
9595
@Bind("this") Node inliningTarget,
9696
@Cached HashingStorageTransferItem transferItem,
9797
@Cached HashingStorageGetIterator getOtherIter,
@@ -112,7 +112,7 @@ static void updateDictGeneric(VirtualFrame frame, PDict self, PDict other,
112112
}
113113

114114
@Specialization(guards = "!isDict(other)")
115-
static void updateArg(VirtualFrame frame, PDict self, Object other,
115+
public static void updateArg(VirtualFrame frame, PDict self, Object other,
116116
@Bind("this") Node inliningTarget,
117117
@Cached HashingStorageSetItem setItem,
118118
@Cached PyObjectLookupAttr lookupKeys,
@@ -123,7 +123,7 @@ static void updateArg(VirtualFrame frame, PDict self, Object other,
123123
self.setDictStorage(storage);
124124
}
125125

126-
protected static boolean isIdentical(PDict dict, Object other) {
126+
public static boolean isIdentical(PDict dict, Object other) {
127127
return dict == other;
128128
}
129129

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public abstract static class ListExtendNode extends PythonBinaryBuiltinNode {
390390
public abstract PNone execute(VirtualFrame frame, PList list, Object source);
391391

392392
@Specialization
393-
PNone extendSequence(VirtualFrame frame, PList list, Object iterable,
393+
public static PNone extendSequence(VirtualFrame frame, PList list, Object iterable,
394394
@Bind("this") Node inliningTarget,
395395
@Cached IteratorNodes.GetLength lenNode,
396396
@Cached("createExtend()") SequenceStorageNodes.ExtendNode extendNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectAsciiNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public final TruffleString executeCached(Frame frame, Object object) {
7575
public abstract TruffleString execute(Frame frame, Node inliningTarget, Object object);
7676

7777
@Specialization
78-
static TruffleString ascii(VirtualFrame frame, Node inliningTarget, Object obj,
78+
public static TruffleString ascii(VirtualFrame frame, Node inliningTarget, Object obj,
7979
@Cached PyObjectReprAsTruffleStringNode reprNode,
8080
@Cached(inline = false) TruffleString.GetCodeRangeNode getCodeRangeNode,
8181
@Cached(inline = false) TruffleString.CreateCodePointIteratorNode createCodePointIteratorNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectReprAsTruffleStringNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public final TruffleString executeCached(Frame frame, Object object) {
7676
public abstract TruffleString execute(Frame frame, Node inliningTarget, Object object);
7777

7878
@Specialization
79-
static TruffleString repr(VirtualFrame frame, Node inliningTarget, Object obj,
79+
public static TruffleString repr(VirtualFrame frame, Node inliningTarget, Object obj,
8080
@Cached PyObjectReprAsObjectNode reprNode,
8181
@Cached CastToTruffleStringNode cast) {
8282
return cast.execute(inliningTarget, reprNode.execute(frame, inliningTarget, obj));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectStrAsTruffleStringNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2024, 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
@@ -78,7 +78,7 @@ static TruffleString doString(TruffleString obj) {
7878
}
7979

8080
@Specialization
81-
static TruffleString doGeneric(VirtualFrame frame, Node inliningTarget, Object obj,
81+
public static TruffleString doGeneric(VirtualFrame frame, Node inliningTarget, Object obj,
8282
@Cached PyObjectStrAsObjectNode strNode,
8383
@Cached CastToTruffleStringNode castToString) {
8484
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/MappingToKeywordsNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, 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
@@ -82,15 +82,15 @@ public abstract class MappingToKeywordsNode extends PNodeWithContext {
8282
public abstract PKeyword[] execute(VirtualFrame frame, Node inliningTarget, Object starargs) throws SameDictKeyException, NonMappingException;
8383

8484
@Specialization(guards = "hasBuiltinDictIter(inliningTarget, starargs, getClassNode, lookupIter)", limit = "1")
85-
static PKeyword[] doDict(VirtualFrame frame, Node inliningTarget, PDict starargs,
85+
public static PKeyword[] doDict(VirtualFrame frame, Node inliningTarget, PDict starargs,
8686
@SuppressWarnings("unused") @Cached GetPythonObjectClassNode getClassNode,
8787
@SuppressWarnings("unused") @Cached(parameters = "Iter", inline = false) LookupCallableSlotInMRONode lookupIter,
8888
@Exclusive @Cached HashingStorageToKeywords convert) {
8989
return convert.execute(frame, inliningTarget, starargs.getDictStorage());
9090
}
9191

9292
@Fallback
93-
static PKeyword[] doMapping(VirtualFrame frame, Node inliningTarget, Object starargs,
93+
public static PKeyword[] doMapping(VirtualFrame frame, Node inliningTarget, Object starargs,
9494
@Cached(inline = false) ConcatDictToStorageNode concatDictToStorageNode,
9595
@Exclusive @Cached HashingStorageToKeywords convert) throws SameDictKeyException, NonMappingException {
9696
HashingStorage storage = concatDictToStorageNode.execute(frame, EmptyStorage.INSTANCE, starargs);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/builtins/ListNodes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, 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
@@ -323,16 +323,16 @@ public abstract static class AppendNode extends PNodeWithContext {
323323
public abstract void execute(PList list, Object value);
324324

325325
@NeverDefault
326-
static BranchProfile[] getUpdateStoreProfile() {
326+
public static BranchProfile[] getUpdateStoreProfile() {
327327
return new BranchProfile[1];
328328
}
329329

330-
static BranchProfile[] getUpdateStoreProfileUncached() {
330+
public static BranchProfile[] getUpdateStoreProfileUncached() {
331331
return DISABLED;
332332
}
333333

334334
@Specialization
335-
void appendObjectGeneric(PList list, Object value,
335+
public static void appendObjectGeneric(PList list, Object value,
336336
@Bind("this") Node inliningTarget,
337337
@Cached SequenceStorageNodes.AppendNode appendNode,
338338
@Cached(value = "getUpdateStoreProfile()", uncached = "getUpdateStoreProfileUncached()", dimensions = 1) BranchProfile[] updateStoreProfile) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/GetYieldFromIterNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, 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
@@ -58,13 +58,13 @@ public abstract class GetYieldFromIterNode extends Node {
5858
public abstract Object execute(Frame frame, Object receiver);
5959

6060
@Specialization
61-
public Object getGeneratorOrCoroutine(PGenerator arg) {
61+
public static Object getGeneratorOrCoroutine(PGenerator arg) {
6262
// TODO check if the generator in which the yield from is an iterable or normal coroutine
6363
return arg;
6464
}
6565

6666
@Specialization
67-
public Object getGeneric(Frame frame, Object arg,
67+
public static Object getGeneric(Frame frame, Object arg,
6868
@Bind("this") Node inliningTarget,
6969
@Cached PyObjectGetIter getIter,
7070
@Cached IsBuiltinObjectExactProfile isCoro) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/RaiseNode.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -117,7 +117,7 @@ static void setCause(VirtualFrame frame, Object exception, Object causeClass,
117117
// raise * from <invalid>
118118
@Specialization(guards = {"!check.execute(inliningTarget, cause)", "!isTypeNode.execute(inliningTarget, cause)"}, limit = "1")
119119
static void setCause(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWarnings("unused") Object exception, @SuppressWarnings("unused") Object cause,
120-
@Bind("this") Node inliningTarget,
120+
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
121121
@Exclusive @SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode,
122122
@SuppressWarnings("unused") @Exclusive @Cached PyExceptionInstanceCheckNode check,
123123
@Cached PRaiseNode raise) {
@@ -127,7 +127,7 @@ static void setCause(@SuppressWarnings("unused") VirtualFrame frame, @SuppressWa
127127

128128
// raise
129129
@Specialization(guards = "isNoValue(type)")
130-
static void reraise(VirtualFrame frame, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") Object cause, boolean rootNodeVisible,
130+
public static void reraise(VirtualFrame frame, @SuppressWarnings("unused") PNone type, @SuppressWarnings("unused") Object cause, boolean rootNodeVisible,
131131
@Bind("this") Node inliningTarget,
132132
@Exclusive @Cached PRaiseNode.Lazy raise,
133133
@Exclusive @Cached GetCaughtExceptionNode getCaughtExceptionNode,
@@ -141,35 +141,37 @@ static void reraise(VirtualFrame frame, @SuppressWarnings("unused") PNone type,
141141

142142
// raise <exception>
143143
@Specialization(guards = "isNoValue(cause)")
144-
void doRaise(@SuppressWarnings("unused") VirtualFrame frame, PBaseException exception, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") boolean rootNodeVisible) {
145-
throw PRaiseNode.raiseExceptionObject(this, exception);
144+
public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, PBaseException exception, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") boolean rootNodeVisible,
145+
@Bind("this") Node inliningTarget) {
146+
throw PRaiseNode.raiseExceptionObject(inliningTarget, exception);
146147
}
147148

148149
// raise <native-exception>
149150
@Specialization(guards = {"check.execute(inliningTarget, exception)", "isNoValue(cause)"})
150-
void doRaiseNative(@SuppressWarnings("unused") VirtualFrame frame, PythonAbstractNativeObject exception, @SuppressWarnings("unused") PNone cause,
151+
public static void doRaiseNative(@SuppressWarnings("unused") VirtualFrame frame, PythonAbstractNativeObject exception, @SuppressWarnings("unused") PNone cause,
151152
@SuppressWarnings("unused") boolean rootNodeVisible,
152-
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
153+
@Bind("this") Node inliningTarget,
153154
@SuppressWarnings("unused") @Shared @Cached PyExceptionInstanceCheckNode check) {
154-
throw PRaiseNode.raiseExceptionObject(this, exception);
155+
throw PRaiseNode.raiseExceptionObject(inliningTarget, exception);
155156
}
156157

157158
// raise <exception> from *
158159
@Specialization(guards = "!isNoValue(cause)")
159-
void doRaise(@SuppressWarnings("unused") VirtualFrame frame, PBaseException exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
160+
public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, PBaseException exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
161+
@Bind("this") Node inliningTarget,
160162
@Shared @Cached SetExceptionCauseNode setExceptionCauseNode) {
161163
setExceptionCauseNode.execute(frame, exception, cause);
162-
throw PRaiseNode.raiseExceptionObject(this, exception);
164+
throw PRaiseNode.raiseExceptionObject(inliningTarget, exception);
163165
}
164166

165167
// raise <native-exception> from *
166168
@Specialization(guards = {"check.execute(inliningTarget, exception)", "!isNoValue(cause)"})
167-
void doRaiseNative(@SuppressWarnings("unused") VirtualFrame frame, PythonAbstractNativeObject exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
168-
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
169+
public static void doRaiseNative(@SuppressWarnings("unused") VirtualFrame frame, PythonAbstractNativeObject exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
170+
@Bind("this") Node inliningTarget,
169171
@SuppressWarnings("unused") @Shared @Cached PyExceptionInstanceCheckNode check,
170172
@Shared @Cached SetExceptionCauseNode setExceptionCauseNode) {
171173
setExceptionCauseNode.execute(frame, exception, cause);
172-
throw PRaiseNode.raiseExceptionObject(this, exception);
174+
throw PRaiseNode.raiseExceptionObject(inliningTarget, exception);
173175
}
174176

175177
private static void checkBaseClass(VirtualFrame frame, Node inliningTarget, Object pythonClass, ValidExceptionNode validException, PRaiseNode.Lazy raise,
@@ -182,7 +184,7 @@ private static void checkBaseClass(VirtualFrame frame, Node inliningTarget, Obje
182184

183185
// raise <class>
184186
@Specialization(guards = {"isTypeNode.execute(this, pythonClass)", "isNoValue(cause)"}, limit = "1")
185-
static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Object pythonClass, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") boolean rootNodeVisible,
187+
public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Object pythonClass, @SuppressWarnings("unused") PNone cause, @SuppressWarnings("unused") boolean rootNodeVisible,
186188
@Bind("this") Node inliningTarget,
187189
@Exclusive @SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode,
188190
@Exclusive @Cached ValidExceptionNode validException,
@@ -201,7 +203,7 @@ static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Object pytho
201203

202204
// raise <class> from *
203205
@Specialization(guards = {"isTypeNode.execute(this, pythonClass)", "!isNoValue(cause)"}, limit = "1")
204-
static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Object pythonClass, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
206+
public static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Object pythonClass, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
205207
@Bind("this") Node inliningTarget,
206208
@Exclusive @SuppressWarnings("unused") @Cached TypeNodes.IsTypeNode isTypeNode,
207209
@Exclusive @Cached ValidExceptionNode validException,
@@ -223,7 +225,7 @@ static void doRaise(@SuppressWarnings("unused") VirtualFrame frame, Object pytho
223225
// raise <invalid> [from *]
224226
@Fallback
225227
@SuppressWarnings("unused")
226-
static void doRaise(VirtualFrame frame, Object exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
228+
public static void doRaise(VirtualFrame frame, Object exception, Object cause, @SuppressWarnings("unused") boolean rootNodeVisible,
227229
@Bind("this") Node inliningTarget,
228230
@CachedLibrary(limit = "1") InteropLibrary lib,
229231
@Exclusive @Cached PRaiseNode.Lazy raise) {

0 commit comments

Comments
 (0)