Skip to content

Commit ce79a38

Browse files
committed
Pass frame to CallNode#execute in PE code wherever possible/practical
1 parent 5bbbe43 commit ce79a38

17 files changed

+50
-46
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
@@ -1292,7 +1292,7 @@ TruffleString sourceAsString(VirtualFrame frame, Node inliningTarget, Object sou
12921292
CodecsModuleBuiltins.TruffleDecoder decoder = new CodecsModuleBuiltins.TruffleDecoder(pythonEncodingNameFromJavaName, charset, bytes, bytesLen, CodingErrorAction.REPORT);
12931293
if (!decoder.decodingStep(true)) {
12941294
try {
1295-
handleDecodingErrorNode.execute(decoder, T_STRICT, factory.createBytes(bytes, bytesLen));
1295+
handleDecodingErrorNode.execute(frame, decoder, T_STRICT, factory.createBytes(bytes, bytesLen));
12961296
throw CompilerDirectives.shouldNotReachHere();
12971297
} catch (PException e) {
12981298
throw raiseInvalidSyntax(filename, "(unicode error) %s", asStrNode.execute(frame, inliningTarget, e.getEscapedException()));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public static TruffleString intern(Node inliningTarget, TruffleString errorActio
420420
// "lazily", i.e., not on all code-paths
421421
@GenerateInline(false)
422422
public abstract static class HandleDecodingErrorNode extends Node {
423-
public abstract void execute(TruffleDecoder decoder, TruffleString errorAction, Object inputObject);
423+
public abstract void execute(VirtualFrame frame, TruffleDecoder decoder, TruffleString errorAction, Object inputObject);
424424

425425
@Specialization(guards = "errorAction == T_STRICT")
426426
static void doStrict(TruffleDecoder decoder, @SuppressWarnings("unused") TruffleString errorAction, Object inputObject,
@@ -476,7 +476,7 @@ static void doSurrogateescape(TruffleDecoder decoder, @SuppressWarnings("unused"
476476
}
477477

478478
@Fallback
479-
static void doCustom(TruffleDecoder decoder, TruffleString errorAction, Object inputObject,
479+
static void doCustom(VirtualFrame frame, TruffleDecoder decoder, TruffleString errorAction, Object inputObject,
480480
@Bind("this") Node inliningTarget,
481481
@Cached CallNode callNode,
482482
@Cached BaseExceptionAttrNode attrNode,
@@ -493,7 +493,7 @@ static void doCustom(TruffleDecoder decoder, TruffleString errorAction, Object i
493493
throw raiseNode.get(inliningTarget).raise(LookupError, UNKNOWN_ERROR_HANDLER, errorAction);
494494
}
495495
Object exceptionObject = raiseDecodingErrorNode.makeDecodeException(inliningTarget, decoder, inputObject);
496-
Object restuple = callNode.execute(errorHandler, exceptionObject);
496+
Object restuple = callNode.execute(frame, errorHandler, exceptionObject);
497497

498498
Object[] t = null;
499499
if (PGuards.isPTuple(restuple)) {
@@ -705,7 +705,7 @@ static Object decode(VirtualFrame frame, Object input, TruffleString encoding, T
705705
try {
706706
decoder = new TruffleDecoder(normalizedEncoding, charset, bytes, len, errorAction);
707707
while (!decoder.decodingStep(finalData)) {
708-
errorHandler.execute(decoder, internErrorAction.execute(inliningTarget, errors), factory.createBytes(bytes, len));
708+
errorHandler.execute(frame, decoder, internErrorAction.execute(inliningTarget, errors), factory.createBytes(bytes, len));
709709
}
710710
} catch (OutOfMemoryError e) {
711711
CompilerDirectives.transferToInterpreterAndInvalidate();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,15 @@ Object localeNonSensitive(PythonObject pattern, PythonMethod method, boolean mus
518518

519519
@Specialization(guards = {"method == cachedMethod", "mustAdvance == cachedMustAdvance", "getTRegexCache(pattern).isLocaleSensitive()"}, limit = "SPECIALIZATION_LIMIT", replaces = "cached")
520520
@SuppressWarnings("truffle-static-method")
521-
Object localeSensitive(PythonObject pattern, PythonMethod method, boolean mustAdvance,
521+
Object localeSensitive(VirtualFrame frame, PythonObject pattern, PythonMethod method, boolean mustAdvance,
522522
@Bind("this") Node inliningTarget,
523523
@Cached("method") @SuppressWarnings("unused") PythonMethod cachedMethod,
524524
@Cached("mustAdvance") @SuppressWarnings("unused") boolean cachedMustAdvance,
525525
@Cached("lookupGetLocaleFunction()") Object getLocale,
526526
@Cached CallNode callGetLocale,
527527
@Cached CastToTruffleStringNode castToTruffleStringNode) {
528528
TRegexCache tRegexCache = getTRegexCache(pattern);
529-
TruffleString locale = castToTruffleStringNode.execute(inliningTarget, callGetLocale.execute(getLocale));
529+
TruffleString locale = castToTruffleStringNode.execute(inliningTarget, callGetLocale.execute(frame, getLocale));
530530
final Object tRegex = tRegexCache.getLocaleSensitiveRegexp(method, mustAdvance, locale);
531531
if (tRegex != null) {
532532
return tRegex;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ Object doHook(VirtualFrame frame, Object[] args, PKeyword[] keywords,
18091809
return PNone.NONE;
18101810
}
18111811

1812-
return callNode.execute(hook, args, keywords);
1812+
return callNode.execute(frame, hook, args, keywords);
18131813
}
18141814
}
18151815

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cjkcodecs/MultibyteCodecUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ abstract static class CallErrorCallbackNode extends Node {
142142

143143
// call_error_callback
144144
@Specialization
145-
static Object callErrorCallback(Node inliningTarget, Object errors, Object exc,
145+
static Object callErrorCallback(VirtualFrame frame, Node inliningTarget, Object errors, Object exc,
146146
@Cached CastToTruffleStringNode castToStringNode,
147147
@Cached PyCodecLookupErrorNode lookupErrorNode,
148148
@Cached(inline = false) CallNode callNode) {
149149
assert (PyUnicodeCheckNode.executeUncached(errors));
150150
TruffleString str = castToStringNode.execute(inliningTarget, errors);
151151
Object cb = lookupErrorNode.execute(inliningTarget, str);
152-
return callNode.execute(cb, exc);
152+
return callNode.execute(frame, cb, exc);
153153
}
154154
}
155155

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/CharmapNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 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
@@ -274,7 +274,7 @@ static int doIt(VirtualFrame frame, Node inliningTarget, ErrorHandlerCache cache
274274
for (int i = 0; i < repLen; ++i) {
275275
int cp = codePointAtIndexNode.execute(replacement, i, TS_ENCODING, ErrorHandling.BEST_EFFORT);
276276
if (!charmapEncodeOutputNode.execute(frame, inliningTarget, cp, mapping, builder)) {
277-
raiseEncodeException.execute(inliningTarget, cache, T_CHARMAP, src, pos, errEnd, CHARACTER_MAPS_TO_UNDEFINED);
277+
raiseEncodeException.execute(frame, inliningTarget, cache, T_CHARMAP, src, pos, errEnd, CHARACTER_MAPS_TO_UNDEFINED);
278278
}
279279
}
280280
return result.newPos;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/codecs/ErrorHandlers.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 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
@@ -887,7 +887,7 @@ static DecodingErrorHandlerResult doIt(VirtualFrame frame, Node inliningTarget,
887887
@Cached PyObjectSizeNode sizeNode,
888888
@Cached PRaiseNode.Lazy raiseNode) {
889889
cache.errorHandlerObject = cache.errorHandlerObject == null ? lookupErrorNode.execute(inliningTarget, errors) : cache.errorHandlerObject;
890-
cache.exceptionObject = makeDecodeExceptionNode.execute(inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
890+
cache.exceptionObject = makeDecodeExceptionNode.execute(frame, inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
891891
Object resultObj = callNode.execute(frame, cache.errorHandlerObject, cache.exceptionObject);
892892
DecodingErrorHandlerResult result = parseResultNode.execute(frame, inliningTarget, resultObj);
893893
result.newSrcObj = getObjectNode.execute(inliningTarget, cache.exceptionObject);
@@ -965,7 +965,7 @@ static EncodingErrorHandlerResult doIt(VirtualFrame frame, Node inliningTarget,
965965
@Cached PRaiseNode.Lazy raiseNode) {
966966
cache.errorHandlerObject = cache.errorHandlerObject == null ? lookupErrorNode.execute(inliningTarget, errors) : cache.errorHandlerObject;
967967
int len = codePointLengthNode.execute(srcObj, TS_ENCODING);
968-
cache.exceptionObject = makeEncodeExceptionNode.execute(inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
968+
cache.exceptionObject = makeEncodeExceptionNode.execute(frame, inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
969969
Object resultObj = callNode.execute(frame, cache.errorHandlerObject, cache.exceptionObject);
970970
EncodingErrorHandlerResult result = parseResultNode.execute(inliningTarget, resultObj);
971971
result.newPos = adjustAndCheckPos(result.newPos, len, inliningTarget, raiseNode);
@@ -978,13 +978,13 @@ static EncodingErrorHandlerResult doIt(VirtualFrame frame, Node inliningTarget,
978978
@GenerateCached(false)
979979
abstract static class RaiseEncodeException extends Node {
980980

981-
abstract void execute(Node inliningTarget, ErrorHandlerCache cache, TruffleString encoding, TruffleString srcObj, int startPos, int endPos, TruffleString reason);
981+
abstract void execute(VirtualFrame frame, Node inliningTarget, ErrorHandlerCache cache, TruffleString encoding, TruffleString srcObj, int startPos, int endPos, TruffleString reason);
982982

983983
@Specialization
984-
static void doIt(Node inliningTarget, ErrorHandlerCache cache, TruffleString encoding, TruffleString srcObj, int startPos, int endPos, TruffleString reason,
984+
static void doIt(VirtualFrame frame, Node inliningTarget, ErrorHandlerCache cache, TruffleString encoding, TruffleString srcObj, int startPos, int endPos, TruffleString reason,
985985
@Cached MakeEncodeExceptionNode makeEncodeExceptionNode,
986986
@Cached(inline = false) PRaiseNode raiseNode) {
987-
cache.exceptionObject = makeEncodeExceptionNode.execute(inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
987+
cache.exceptionObject = makeEncodeExceptionNode.execute(frame, inliningTarget, cache.exceptionObject, encoding, srcObj, startPos, endPos, reason);
988988
raiseNode.raiseExceptionObject(cache.exceptionObject);
989989
}
990990
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/CtypesModuleBuiltins.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@
103103
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.FsConverterNode;
104104
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins.AuditNode;
105105
import com.oracle.graal.python.builtins.modules.ctypes.CFieldBuiltins.GetFuncNode;
106-
import com.oracle.graal.python.builtins.modules.ctypes.CtypesModuleBuiltinsClinicProviders.DyldSharedCacheContainsPathClinicProviderGen;
107106
import com.oracle.graal.python.builtins.modules.ctypes.CtypesNodes.PyTypeCheck;
108107
import com.oracle.graal.python.builtins.modules.ctypes.FFIType.FFI_TYPES;
109108
import com.oracle.graal.python.builtins.modules.ctypes.FFIType.FieldGet;
110109
import com.oracle.graal.python.builtins.modules.ctypes.StgDictBuiltins.PyObjectStgDictNode;
111110
import com.oracle.graal.python.builtins.modules.ctypes.StgDictBuiltins.PyTypeStgDictNode;
111+
import com.oracle.graal.python.builtins.modules.ctypes.CtypesModuleBuiltinsClinicProviders.DyldSharedCacheContainsPathClinicProviderGen;
112112
import com.oracle.graal.python.builtins.modules.ctypes.memory.Pointer;
113113
import com.oracle.graal.python.builtins.modules.ctypes.memory.PointerNodes;
114114
import com.oracle.graal.python.builtins.modules.ctypes.memory.PointerReference;
@@ -1246,7 +1246,7 @@ Object _ctypes_callproc(VirtualFrame frame, NativeFunction pProc, Object[] argar
12461246
}
12471247
}
12481248

1249-
return getResultNode.execute(restype, rtype, result, checker);
1249+
return getResultNode.execute(frame, restype, rtype, result, checker);
12501250
}
12511251

12521252
static Object callManagedFunction(Node inliningTarget, NativeFunction pProc, Object[] argarray, InteropLibrary ilib, PRaiseNode.Lazy raiseNode) {
@@ -1368,7 +1368,7 @@ void _call_function_pointer(int flags,
13681368
@SuppressWarnings("truffle-inlining") // footprint reduction 44 -> 25
13691369
abstract static class GetResultNode extends Node {
13701370

1371-
abstract Object execute(Object restype, FFIType rtype, Object result, Object checker);
1371+
abstract Object execute(VirtualFrame frame, Object restype, FFIType rtype, Object result, Object checker);
13721372

13731373
/*
13741374
* Convert the C value in result into a Python object, depending on restype.
@@ -1395,21 +1395,21 @@ static Object none(Object restype, FFIType rtype, Object result, Object checker)
13951395
}
13961396

13971397
@Specialization(guards = {"restype != null", "!isNone(restype)", "dict == null"}, limit = "1")
1398-
static Object callResType(Object restype, @SuppressWarnings("unused") FFIType rtype, Object result, @SuppressWarnings("unused") Object checker,
1398+
static Object callResType(VirtualFrame frame, Object restype, @SuppressWarnings("unused") FFIType rtype, Object result, @SuppressWarnings("unused") Object checker,
13991399
@Bind("this") Node inliningTarget,
14001400
@CachedLibrary("result") InteropLibrary ilib,
14011401
@SuppressWarnings("unused") @Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
14021402
@SuppressWarnings("unused") @Bind("getStgDict(inliningTarget, restype, pyTypeStgDictNode)") StgDictObject dict,
14031403
@Shared @Cached CallNode callNode) {
14041404
try {
1405-
return callNode.execute(restype, ilib.asInt(result));
1405+
return callNode.execute(frame, restype, ilib.asInt(result));
14061406
} catch (UnsupportedMessageException e) {
14071407
throw CompilerDirectives.shouldNotReachHere(e);
14081408
}
14091409
}
14101410

14111411
@Specialization(guards = {"restype != null", "!isNone(restype)", "dict != null"}, limit = "1")
1412-
static Object callGetFunc(Object restype, FFIType rtype, Object result, Object checker,
1412+
static Object callGetFunc(VirtualFrame frame, Object restype, FFIType rtype, Object result, Object checker,
14131413
@Bind("this") Node inliningTarget,
14141414
@CachedLibrary("result") InteropLibrary ilib,
14151415
@SuppressWarnings("unused") @Exclusive @Cached PyTypeStgDictNode pyTypeStgDictNode,
@@ -1466,7 +1466,7 @@ static Object callGetFunc(Object restype, FFIType rtype, Object result, Object c
14661466
if (PGuards.isPNone(checker) || checker == null) {
14671467
return retval;
14681468
}
1469-
return callNode.execute(checker, retval);
1469+
return callNode.execute(frame, checker, retval);
14701470
}
14711471

14721472
protected static StgDictObject getStgDict(Node inliningTarget, Object restype, PyTypeStgDictNode pyTypeStgDictNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeDecodeErrorBuiltins.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -169,14 +169,16 @@ public abstract static class MakeDecodeExceptionNode extends Node {
169169
* one
170170
* @return either {@code exceptionObject} if provided or a new exception object
171171
*/
172-
public abstract PBaseException execute(Node inliningTarget, PBaseException exceptionObject, TruffleString encoding, Object inputObject, int startPos, int endPos, TruffleString reason);
172+
public abstract PBaseException execute(VirtualFrame frame, Node inliningTarget, PBaseException exceptionObject, TruffleString encoding, Object inputObject, int startPos, int endPos,
173+
TruffleString reason);
173174

174175
@Specialization(guards = "exceptionObject == null")
175-
static PBaseException createNew(Node inliningTarget, @SuppressWarnings("unused") PBaseException exceptionObject, TruffleString encoding, Object inputObject, int startPos, int endPos,
176+
static PBaseException createNew(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") PBaseException exceptionObject, TruffleString encoding, Object inputObject, int startPos,
177+
int endPos,
176178
TruffleString reason,
177179
@Cached(inline = false) CallNode callNode,
178180
@Cached PRaiseNode.Lazy raiseNode) {
179-
Object obj = callNode.execute(UnicodeDecodeError, encoding, inputObject, startPos, endPos, reason);
181+
Object obj = callNode.execute(frame, UnicodeDecodeError, encoding, inputObject, startPos, endPos, reason);
180182
if (obj instanceof PBaseException exception) {
181183
return exception;
182184
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/exception/UnicodeEncodeErrorBuiltins.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 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
@@ -170,14 +170,16 @@ public abstract static class MakeEncodeExceptionNode extends Node {
170170
* one
171171
* @return either {@code exceptionObject} if provided or a new exception object
172172
*/
173-
public abstract PBaseException execute(Node inliningTarget, PBaseException exceptionObject, TruffleString encoding, TruffleString inputObject, int startPos, int endPos, TruffleString reason);
173+
public abstract PBaseException execute(VirtualFrame frame, Node inliningTarget, PBaseException exceptionObject, TruffleString encoding, TruffleString inputObject, int startPos, int endPos,
174+
TruffleString reason);
174175

175176
@Specialization(guards = "exceptionObject == null")
176-
static PBaseException createNew(Node inliningTarget, @SuppressWarnings("unused") PBaseException exceptionObject, TruffleString encoding, TruffleString inputObject, int startPos, int endPos,
177+
static PBaseException createNew(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") PBaseException exceptionObject, TruffleString encoding, TruffleString inputObject,
178+
int startPos, int endPos,
177179
TruffleString reason,
178180
@Cached(inline = false) CallNode callNode,
179181
@Cached PRaiseNode.Lazy raiseNode) {
180-
Object obj = callNode.execute(UnicodeEncodeError, encoding, inputObject, startPos, endPos, reason);
182+
Object obj = callNode.execute(frame, UnicodeEncodeError, encoding, inputObject, startPos, endPos, reason);
181183
if (obj instanceof PBaseException exception) {
182184
return exception;
183185
}

0 commit comments

Comments
 (0)