Skip to content

Commit f8d7a58

Browse files
committed
[GR-47899] Remove PConstructAndRaiseNode from builtins
2 parents 812f7fa + a1077ba commit f8d7a58

Some content is hidden

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

51 files changed

+952
-767
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2930,7 +2930,7 @@ Object doMissing(Object klass, PNone none) {
29302930
abstract static class DescriptorNode extends PythonBuiltinNode {
29312931
@TruffleBoundary
29322932
protected final void denyInstantiationAfterInitialization(TruffleString name) {
2933-
if (getCore().isCoreInitialized()) {
2933+
if (getContext().isCoreInitialized()) {
29342934
throw PRaiseNode.raiseUncached(this, TypeError, ErrorMessages.CANNOT_CREATE_INSTANCES, name);
29352935
}
29362936
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,10 @@ Object compile(TruffleString expression, TruffleString filename, TruffleString m
11451145
return context.getLanguage().parse(context, source, InputType.SINGLE, false, optimize, false, null, FutureFeature.fromFlags(flags));
11461146
}
11471147
};
1148-
if (getCore().isCoreInitialized()) {
1148+
if (getContext().isCoreInitialized()) {
11491149
ct = createCode.get();
11501150
} else {
1151-
ct = getCore().getLanguage().cacheCode(filename, createCode);
1151+
ct = getContext().getLanguage().cacheCode(filename, createCode);
11521152
}
11531153
return wrapRootCallTarget((RootCallTarget) ct);
11541154
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@
4646
import com.oracle.graal.python.builtins.Builtin;
4747
import com.oracle.graal.python.builtins.CoreFunctions;
4848
import com.oracle.graal.python.builtins.PythonBuiltins;
49+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
4950
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5051
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
5152
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
5253
import com.oracle.graal.python.runtime.PosixSupportLibrary;
54+
import com.oracle.truffle.api.dsl.Bind;
55+
import com.oracle.truffle.api.dsl.Cached;
5356
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5457
import com.oracle.truffle.api.dsl.NodeFactory;
5558
import com.oracle.truffle.api.dsl.Specialization;
5659
import com.oracle.truffle.api.frame.VirtualFrame;
5760
import com.oracle.truffle.api.library.CachedLibrary;
61+
import com.oracle.truffle.api.nodes.Node;
5862
import com.oracle.truffle.api.strings.TruffleString;
5963

6064
@CoreFunctions(defineModule = "_crypt")
@@ -71,11 +75,13 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7175
abstract static class CryptNode extends PythonBinaryClinicBuiltinNode {
7276
@Specialization
7377
Object crypt(VirtualFrame frame, TruffleString word, TruffleString salt,
74-
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
78+
@Bind("this") Node inliningTarget,
79+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib,
80+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
7581
try {
7682
return posixLib.crypt(getPosixSupport(), word, salt);
7783
} catch (PosixSupportLibrary.PosixException e) {
78-
throw raiseOSErrorFromPosixException(frame, e);
84+
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
7985
}
8086
}
8187

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.oracle.graal.python.builtins.modules.FcntlModuleBuiltinsClinicProviders.FlockNodeClinicProviderGen;
5252
import com.oracle.graal.python.builtins.modules.PosixModuleBuiltins.FileDescriptorConversionNode;
5353
import com.oracle.graal.python.builtins.objects.PNone;
54+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
5455
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5556
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryClinicBuiltinNode;
5657
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
@@ -104,12 +105,13 @@ protected ArgumentClinicProvider getArgumentClinic() {
104105
synchronized PNone flock(VirtualFrame frame, int fd, int operation,
105106
@Bind("this") Node inliningTarget,
106107
@Cached SysModuleBuiltins.AuditNode auditNode,
107-
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posix) {
108+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posix,
109+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
108110
auditNode.audit(inliningTarget, "fcntl.flock", fd, operation);
109111
try {
110112
posix.flock(getPosixSupport(), fd, operation);
111113
} catch (PosixException e) {
112-
throw raiseOSErrorFromPosixException(frame, e);
114+
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
113115
}
114116
return PNone.NONE;
115117
}

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.python.builtins.objects.cext.hpy.HPyMode;
6060
import com.oracle.graal.python.lib.PyObjectGetItem;
6161
import com.oracle.graal.python.nodes.ErrorMessages;
62+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
6263
import com.oracle.graal.python.nodes.SpecialAttributeNames;
6364
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
6465
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -72,11 +73,13 @@
7273
import com.oracle.graal.python.runtime.exception.PException;
7374
import com.oracle.graal.python.util.PythonUtils;
7475
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
76+
import com.oracle.truffle.api.dsl.Bind;
7577
import com.oracle.truffle.api.dsl.Cached;
7678
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
7779
import com.oracle.truffle.api.dsl.NodeFactory;
7880
import com.oracle.truffle.api.dsl.Specialization;
7981
import com.oracle.truffle.api.frame.VirtualFrame;
82+
import com.oracle.truffle.api.nodes.Node;
8083
import com.oracle.truffle.api.strings.TruffleString;
8184

8285
@CoreFunctions(defineModule = GraalHPyUniversalModuleBuiltins.J_HPY_UNIVERSAL)
@@ -113,7 +116,9 @@ protected ArgumentClinicProvider getArgumentClinic() {
113116

114117
@Specialization
115118
Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString path, Object spec, boolean debug, int mode,
116-
@Cached TruffleString.EqualNode eqNode) {
119+
@Bind("this") Node inliningTarget,
120+
@Cached TruffleString.EqualNode eqNode,
121+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
117122
PythonContext context = getContext();
118123
PythonLanguage language = getLanguage();
119124
Object state = IndirectCallContext.enter(frame, language, context, this);
@@ -125,11 +130,11 @@ Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString path, Obj
125130
}
126131
return GraalHPyContext.loadHPyModule(this, context, name, path, spec, hmode);
127132
} catch (ApiInitException ie) {
128-
throw ie.reraise(getConstructAndRaiseNode(), frame);
133+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
129134
} catch (ImportException ie) {
130-
throw ie.reraise(getConstructAndRaiseNode(), frame);
135+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
131136
} catch (IOException e) {
132-
throw getConstructAndRaiseNode().raiseOSError(frame, e, eqNode);
137+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e, eqNode);
133138
} finally {
134139
IndirectCallContext.exit(frame, language, context, state);
135140
}
@@ -150,8 +155,10 @@ protected ArgumentClinicProvider getArgumentClinic() {
150155

151156
@Specialization
152157
Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString extName, Object pkg, TruffleString file, Object loader, Object spec, Object env,
158+
@Bind("this") Node inliningTarget,
153159
@Cached TruffleString.EqualNode eqNode,
154-
@Cached WriteAttributeToObjectNode writeAttrNode) {
160+
@Cached WriteAttributeToObjectNode writeAttrNode,
161+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
155162
Object module;
156163

157164
PythonContext context = getContext();
@@ -164,11 +171,11 @@ Object doGeneric(VirtualFrame frame, TruffleString name, TruffleString extName,
164171
// thrown by getHPyModeFromEnviron if value is not a string
165172
throw raise(PythonBuiltinClassType.TypeError, ErrorMessages.HPY_MODE_VALUE_MUST_BE_STRING);
166173
} catch (ApiInitException ie) {
167-
throw ie.reraise(getConstructAndRaiseNode(), frame);
174+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
168175
} catch (ImportException ie) {
169-
throw ie.reraise(getConstructAndRaiseNode(), frame);
176+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
170177
} catch (IOException e) {
171-
throw getConstructAndRaiseNode().raiseOSError(frame, e, eqNode);
178+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e, eqNode);
172179
} finally {
173180
IndirectCallContext.exit(frame, language, context, state);
174181
}

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

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
123123
import com.oracle.graal.python.lib.PyObjectGetItem;
124124
import com.oracle.graal.python.nodes.ErrorMessages;
125+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
125126
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetCallTargetNode;
126127
import com.oracle.graal.python.nodes.bytecode.PBytecodeRootNode;
127128
import com.oracle.graal.python.nodes.call.CallNode;
@@ -158,7 +159,6 @@
158159
import com.oracle.truffle.api.TruffleLogger;
159160
import com.oracle.truffle.api.dsl.Bind;
160161
import com.oracle.truffle.api.dsl.Cached;
161-
import com.oracle.truffle.api.dsl.Cached.Shared;
162162
import com.oracle.truffle.api.dsl.Fallback;
163163
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
164164
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -396,25 +396,21 @@ private static Object[] convertToObjectArray(TruffleString[] arr) {
396396
@GenerateNodeFactory
397397
public abstract static class ReadFileNode extends PythonUnaryBuiltinNode {
398398
@Specialization
399-
public PBytes doString(VirtualFrame frame, TruffleString filename,
400-
@Shared @Cached TruffleString.EqualNode eqNode) {
399+
PBytes doString(VirtualFrame frame, Object filenameObj,
400+
@Bind("this") Node inliningTarget,
401+
@Cached CastToTruffleStringNode castToTruffleStringNode,
402+
@Cached TruffleString.EqualNode eqNode,
403+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
401404
try {
405+
TruffleString filename = castToTruffleStringNode.execute(inliningTarget, filenameObj);
402406
TruffleFile file = getContext().getPublicTruffleFileRelaxed(filename, PythonLanguage.T_DEFAULT_PYTHON_EXTENSIONS);
403407
byte[] bytes = file.readAllBytes();
404408
return factory().createBytes(bytes);
405409
} catch (Exception ex) {
406410
ErrorAndMessagePair errAndMsg = OSErrorEnum.fromException(ex, eqNode);
407-
throw raiseOSError(frame, errAndMsg.oserror.getNumber(), errAndMsg.message);
411+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, errAndMsg.oserror.getNumber(), errAndMsg.message);
408412
}
409413
}
410-
411-
@Specialization
412-
public Object doGeneric(VirtualFrame frame, Object filename,
413-
@Bind("this") Node inliningTarget,
414-
@Cached CastToTruffleStringNode castToTruffleStringNode,
415-
@Shared @Cached TruffleString.EqualNode eqNode) {
416-
return doString(frame, castToTruffleStringNode.execute(inliningTarget, filename), eqNode);
417-
}
418414
}
419415

420416
@Builtin(name = "dump_truffle_ast", minNumOfPositionalArgs = 1)
@@ -501,7 +497,7 @@ public Object doIt(VirtualFrame frame, PFunction func,
501497
builtinModule = (PythonModule) globals;
502498
} else {
503499
TruffleString moduleName = (TruffleString) getItem.execute(frame, inliningTarget, globals, T___NAME__);
504-
builtinModule = getCore().lookupBuiltinModule(moduleName);
500+
builtinModule = getContext().lookupBuiltinModule(moduleName);
505501
assert builtinModule != null;
506502
}
507503
return factory().createBuiltinMethod(builtinModule, builtinFunc);
@@ -940,15 +936,17 @@ Object which(Object object) {
940936
abstract static class DumpHeapNode extends PythonBuiltinNode {
941937
@Specialization
942938
TruffleString doit(VirtualFrame frame,
939+
@Bind("this") Node inliningTarget,
943940
@Cached TruffleString.FromJavaStringNode fromJavaStringNode,
944-
@Cached TruffleString.EqualNode eqNode) {
941+
@Cached TruffleString.EqualNode eqNode,
942+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
945943
TruffleFile tempFile;
946944
try {
947945
PythonContext context = getContext();
948946
tempFile = context.getEnv().createTempFile(context.getEnv().getCurrentWorkingDirectory(), J_GRAALPYTHON_ID, ".hprof");
949947
tempFile.delete();
950948
} catch (IOException e) {
951-
throw raiseOSError(frame, e, eqNode);
949+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e, eqNode);
952950
}
953951
PythonUtils.dumpHeap(tempFile.getPath());
954952
return fromJavaStringNode.execute(tempFile.getPath(), TS_ENCODING);

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import com.oracle.graal.python.lib.PyObjectLookupAttr;
101101
import com.oracle.graal.python.lib.PyObjectStrAsTruffleStringNode;
102102
import com.oracle.graal.python.nodes.ErrorMessages;
103+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
103104
import com.oracle.graal.python.nodes.PGuards;
104105
import com.oracle.graal.python.nodes.PRaiseNode;
105106
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
@@ -289,7 +290,8 @@ Object run(VirtualFrame frame, PythonObject moduleSpec, @SuppressWarnings("unuse
289290
@Cached ReadAttributeFromDynamicObjectNode readNameNode,
290291
@Cached ReadAttributeFromDynamicObjectNode readOriginNode,
291292
@Cached CastToTruffleStringNode castToTruffleStringNode,
292-
@Cached TruffleString.EqualNode eqNode) {
293+
@Cached TruffleString.EqualNode eqNode,
294+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
293295
TruffleString name = castToTruffleStringNode.execute(inliningTarget, readNameNode.execute(moduleSpec, T_NAME));
294296
TruffleString path = castToTruffleStringNode.execute(inliningTarget, readOriginNode.execute(moduleSpec, T_ORIGIN));
295297

@@ -299,11 +301,11 @@ Object run(VirtualFrame frame, PythonObject moduleSpec, @SuppressWarnings("unuse
299301
try {
300302
return run(context, new ModuleSpec(name, path, moduleSpec));
301303
} catch (ApiInitException ie) {
302-
throw ie.reraise(getConstructAndRaiseNode(), frame);
304+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
303305
} catch (ImportException ie) {
304-
throw ie.reraise(getConstructAndRaiseNode(), frame);
306+
throw ie.reraise(frame, inliningTarget, constructAndRaiseNode);
305307
} catch (IOException e) {
306-
throw getConstructAndRaiseNode().raiseOSError(frame, e, eqNode);
308+
throw constructAndRaiseNode.get(inliningTarget).raiseOSError(frame, e, eqNode);
307309
} finally {
308310
IndirectCallContext.exit(frame, language, context, state);
309311
}
@@ -394,7 +396,7 @@ public abstract static class IsBuiltin extends PythonBuiltinNode {
394396
@Specialization
395397
@TruffleBoundary
396398
public int run(TruffleString name) {
397-
if (getCore().lookupBuiltinModule(name) != null) {
399+
if (getContext().lookupBuiltinModule(name) != null) {
398400
// TODO: missing "1" case when the builtin module can be re-initialized
399401
return -1;
400402
} else {
@@ -433,7 +435,7 @@ public Object run(VirtualFrame frame, PythonObject moduleSpec,
433435
@Cached("create(T___LOADER__)") SetAttributeNode setAttributeNode,
434436
@Cached PyObjectLookupAttr lookup) {
435437
Object name = lookup.execute(frame, inliningTarget, moduleSpec, T_NAME);
436-
PythonModule builtinModule = getCore().lookupBuiltinModule(toStringNode.execute(inliningTarget, name));
438+
PythonModule builtinModule = getContext().lookupBuiltinModule(toStringNode.execute(inliningTarget, name));
437439
if (builtinModule != null) {
438440
// TODO: GR-26411 builtin modules cannot be re-initialized (see is_builtin)
439441
// We are setting the loader to the spec loader (since this is the loader that is
@@ -455,7 +457,7 @@ public abstract static class ExecBuiltin extends PythonBuiltinNode {
455457
@Specialization
456458
@TruffleBoundary
457459
public Object exec(PythonModule pythonModule) {
458-
final Python3Core core = getCore();
460+
final Python3Core core = getContext();
459461
if (!ImageInfo.inImageBuildtimeCode()) {
460462
final PythonBuiltins builtins = pythonModule.getBuiltins();
461463
assert builtins != null; // this is a builtin, therefore its builtins must have been
@@ -652,7 +654,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
652654

653655
@Specialization
654656
PythonModule run(TruffleString name) {
655-
return importFrozenModuleObject(getCore(), name, true);
657+
return importFrozenModuleObject(getContext(), name, true);
656658
}
657659
}
658660

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.oracle.graal.python.builtins.objects.cext.capi.transitions.CApiTransitions.PythonToNativeNode;
6666
import com.oracle.graal.python.builtins.objects.mmap.PMMap;
6767
import com.oracle.graal.python.nodes.ErrorMessages;
68+
import com.oracle.graal.python.nodes.PConstructAndRaiseNode;
6869
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6970
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
7071
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
@@ -160,7 +161,8 @@ protected ArgumentClinicProvider getArgumentClinic() {
160161
PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int flagsIn, int protIn, @SuppressWarnings("unused") int accessIn, long offset,
161162
@Bind("this") Node inliningTarget,
162163
@Cached SysModuleBuiltins.AuditNode auditNode,
163-
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupport) {
164+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixSupport,
165+
@Cached PConstructAndRaiseNode.Lazy constructAndRaiseNode) {
164166
checkLength(lengthIn);
165167
checkOffset(offset);
166168
int flags = flagsIn;
@@ -229,15 +231,15 @@ PMMap doFile(VirtualFrame frame, Object clazz, int fd, long lengthIn, int flagsI
229231
try {
230232
dupFd = posixSupport.dup(getPosixSupport(), fd);
231233
} catch (PosixException e) {
232-
throw raiseOSErrorFromPosixException(frame, e);
234+
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
233235
}
234236
}
235237

236238
Object mmapHandle;
237239
try {
238240
mmapHandle = posixSupport.mmap(getPosixSupport(), length, prot, flags, dupFd, offset);
239241
} catch (PosixException e) {
240-
throw raiseOSErrorFromPosixException(frame, e);
242+
throw constructAndRaiseNode.get(inliningTarget).raiseOSErrorFromPosixException(frame, e);
241243
}
242244
return factory().createMMap(getContext(), clazz, mmapHandle, dupFd, length, access);
243245
}

0 commit comments

Comments
 (0)