Skip to content

Commit f242168

Browse files
committed
[GR-22495] Enable TruffleCheckBlackListedMethods
PullRequest: graalpython/893
2 parents a2ce3ab + 6fb4115 commit f242168

File tree

91 files changed

+604
-327
lines changed

Some content is hidden

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

91 files changed

+604
-327
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
99
* Improve performance of tuples with primitive elements
1010
* Improve performance of using Python sequences from other GraalVM languages
1111
* Improve performance of dictionaries and sets
12+
* Improve performance of allocations for list comprehensions with range iterators
1213
* Support `cProfile` and `trace` modules through the GraalVM CPU sampler and coverage, respectively
1314
* Support NumPy on macOS
1415
* Support setuptools-scm and pytz.timezone
@@ -19,10 +20,13 @@ language runtime. The main focus is on user-observable behavior of the engine.
1920
* Fix DirEntry.stat
2021
* Fix passing non-ASCII strings to `gethostbyname`
2122
* Fix `help(numpy)` to work again in the interactive REPL
23+
* Fix multi-line continuation in the REPL for opening parens
24+
* Fix `select.select` for pipes
2225
* Polyglot: Rethrow AttributeError as UnknownIdentifierException in invokeMember
2326
* Jython mode: treat Java `null` as identical to Python `None` when comparing with the `is` operator
2427
* Jython mode: `isinstance` now works with Java classes and objects
2528
* Improve errno handling in `posix` module
29+
* Move all GraalPython specific functions on `sys` or `builtins` to the `__graalpython__` module
2630

2731
## Version 20.0.0
2832

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ protected Object getLanguageView(PythonContext context, Object value) {
339339
return new ForeignLanguageView(value);
340340
}
341341
} catch (UnsupportedMessageException e) {
342+
CompilerDirectives.transferToInterpreterAndInvalidate();
342343
throw new IllegalStateException(e);
343344
}
344345
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import static com.oracle.graal.python.nodes.SpecialMethodNames.__TRUNC__;
6969
import static com.oracle.graal.python.runtime.exception.PythonErrorType.NotImplementedError;
7070
import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
71+
import static com.oracle.graal.python.runtime.exception.PythonErrorType.RuntimeError;
7172
import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError;
7273
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
7374
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
@@ -1181,6 +1182,7 @@ private Object createInt(LazyPythonClass cls, Object value) {
11811182
return factory().createInt(cls, ((PInt) value).getValue());
11821183
}
11831184
}
1185+
CompilerDirectives.transferToInterpreterAndInvalidate();
11841186
throw new IllegalStateException("Unexpected type");
11851187
}
11861188

@@ -1479,7 +1481,7 @@ Object createInt(LazyPythonClass cls, PythonNativeVoidPtr arg, @SuppressWarnings
14791481
if (isPrimitiveInt(cls)) {
14801482
return arg;
14811483
} else {
1482-
CompilerDirectives.transferToInterpreter();
1484+
CompilerDirectives.transferToInterpreterAndInvalidate();
14831485
throw new IllegalStateException("cannot wrap void ptr in int subclass");
14841486
}
14851487
}
@@ -1683,6 +1685,7 @@ private static PythonNativeClass findFirstNativeBaseClass(PythonAbstractClass[]
16831685
return PythonNativeClass.cast(cls);
16841686
}
16851687
}
1688+
CompilerDirectives.transferToInterpreterAndInvalidate();
16861689
throw new IllegalStateException("class needs native allocation but has not native base class");
16871690
}
16881691

@@ -2221,7 +2224,7 @@ private String getModuleNameFromGlobals(PythonObject globals, HashingStorageLibr
22212224
} else if (globals instanceof PDict) {
22222225
nameAttr = hlib.getItem(((PDict) globals).getDictStorage(), __NAME__);
22232226
} else {
2224-
CompilerDirectives.transferToInterpreter();
2227+
CompilerDirectives.transferToInterpreterAndInvalidate();
22252228
throw new IllegalStateException("invalid globals object");
22262229
}
22272230
return ensureCastToStringNode().execute(nameAttr);
@@ -2817,7 +2820,7 @@ Object method(LazyPythonClass cls, Object self, PBuiltinFunction func) {
28172820
public abstract static class FrameTypeNode extends PythonBuiltinNode {
28182821
@Specialization
28192822
Object call() {
2820-
throw new RuntimeException("cannot call constructor of frame type");
2823+
throw raise(RuntimeError, "cannot call constructor of frame type");
28212824
}
28222825
}
28232826

@@ -2826,7 +2829,7 @@ Object call() {
28262829
public abstract static class TracebackTypeNode extends PythonBuiltinNode {
28272830
@Specialization
28282831
Object call() {
2829-
throw new RuntimeException("cannot call constructor of traceback type");
2832+
throw raise(RuntimeError, "cannot call constructor of traceback type");
28302833
}
28312834
}
28322835

@@ -2927,7 +2930,7 @@ private static byte[] toBytes(String data) {
29272930
public abstract static class CellTypeNode extends PythonBuiltinNode {
29282931
@Specialization
29292932
Object call() {
2930-
throw new RuntimeException("cannot call constructor of cell type");
2933+
throw raise(RuntimeError, "cannot call constructor of cell type");
29312934
}
29322935
}
29332936

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ boolean doGeneric(Object object,
398398
* Added temporarily to skip translation/execution errors in unit testing
399399
*/
400400

401-
if (object.equals(GraalPythonTranslationErrorNode.MESSAGE)) {
401+
if (GraalPythonTranslationErrorNode.MESSAGE.equals(object)) {
402402
return true;
403403
}
404404

@@ -603,7 +603,7 @@ private void setBuiltinsInGlobals(VirtualFrame frame, PDict globals, HashingColl
603603
try {
604604
lib.setDict(builtins, builtinsDict);
605605
} catch (UnsupportedMessageException e) {
606-
CompilerDirectives.transferToInterpreter();
606+
CompilerDirectives.transferToInterpreterAndInvalidate();
607607
throw new IllegalStateException(e);
608608
}
609609
}
@@ -1444,7 +1444,7 @@ public int ord(VirtualFrame frame, PIBytesLike chr,
14441444
} else if (element instanceof Byte) {
14451445
return (byte) element;
14461446
}
1447-
CompilerDirectives.transferToInterpreter();
1447+
CompilerDirectives.transferToInterpreterAndInvalidate();
14481448
throw new IllegalStateException("got a bytes-like with non-byte elements");
14491449
}
14501450
}
@@ -1860,7 +1860,7 @@ public Object globals(VirtualFrame frame,
18601860
try {
18611861
lib.setDict(globals, dict);
18621862
} catch (UnsupportedMessageException e) {
1863-
CompilerDirectives.transferToInterpreter();
1863+
CompilerDirectives.transferToInterpreterAndInvalidate();
18641864
throw new IllegalStateException(e);
18651865
}
18661866
}

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
import com.oracle.truffle.api.dsl.TypeSystemReference;
9191
import com.oracle.truffle.api.frame.VirtualFrame;
9292
import com.oracle.truffle.api.library.CachedLibrary;
93-
import com.oracle.truffle.api.profiles.ValueProfile;
9493

9594
@CoreFunctions(defineModule = "_codecs")
9695
public class CodecsModuleBuiltins extends PythonBuiltins {
@@ -322,41 +321,41 @@ public abstract static class CodecsEncodeNode extends EncodeBaseNode {
322321

323322
@Specialization(guards = "isString(str)")
324323
Object encode(Object str, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors,
325-
@Cached("createClassProfile()") ValueProfile strTypeProfile) {
326-
Object profiledStr = strTypeProfile.profile(str);
327-
PBytes bytes = encodeString(profiledStr.toString(), "utf-8", "strict");
324+
@Shared("castStr") @Cached CastToJavaStringNode castStr) {
325+
String profiledStr = castStr.execute(str);
326+
PBytes bytes = encodeString(profiledStr, "utf-8", "strict");
328327
return factory().createTuple(new Object[]{bytes, getLength(bytes)});
329328
}
330329

331330
@Specialization(guards = {"isString(str)", "isString(encoding)"})
332331
Object encode(Object str, Object encoding, @SuppressWarnings("unused") PNone errors,
333-
@Cached("createClassProfile()") ValueProfile strTypeProfile,
334-
@Cached("createClassProfile()") ValueProfile encodingTypeProfile) {
335-
Object profiledStr = strTypeProfile.profile(str);
336-
Object profiledEncoding = encodingTypeProfile.profile(encoding);
337-
PBytes bytes = encodeString(profiledStr.toString(), profiledEncoding.toString(), "strict");
332+
@Shared("castStr") @Cached CastToJavaStringNode castStr,
333+
@Shared("castEncoding") @Cached CastToJavaStringNode castEncoding) {
334+
String profiledStr = castStr.execute(str);
335+
String profiledEncoding = castEncoding.execute(encoding);
336+
PBytes bytes = encodeString(profiledStr, profiledEncoding, "strict");
338337
return factory().createTuple(new Object[]{bytes, getLength(bytes)});
339338
}
340339

341340
@Specialization(guards = {"isString(str)", "isString(errors)"})
342341
Object encode(Object str, @SuppressWarnings("unused") PNone encoding, Object errors,
343-
@Cached("createClassProfile()") ValueProfile strTypeProfile,
344-
@Cached("createClassProfile()") ValueProfile errorsTypeProfile) {
345-
Object profiledStr = strTypeProfile.profile(str);
346-
Object profiledErrors = errorsTypeProfile.profile(errors);
347-
PBytes bytes = encodeString(profiledStr.toString(), "utf-8", profiledErrors.toString());
342+
@Shared("castStr") @Cached CastToJavaStringNode castStr,
343+
@Shared("castErrors") @Cached CastToJavaStringNode castErrors) {
344+
String profiledStr = castStr.execute(str);
345+
String profiledErrors = castErrors.execute(errors);
346+
PBytes bytes = encodeString(profiledStr, "utf-8", profiledErrors);
348347
return factory().createTuple(new Object[]{bytes, getLength(bytes)});
349348
}
350349

351350
@Specialization(guards = {"isString(str)", "isString(encoding)", "isString(errors)"})
352351
Object encode(Object str, Object encoding, Object errors,
353-
@Cached("createClassProfile()") ValueProfile strTypeProfile,
354-
@Cached("createClassProfile()") ValueProfile encodingTypeProfile,
355-
@Cached("createClassProfile()") ValueProfile errorsTypeProfile) {
356-
Object profiledStr = strTypeProfile.profile(str);
357-
Object profiledEncoding = encodingTypeProfile.profile(encoding);
358-
Object profiledErrors = errorsTypeProfile.profile(errors);
359-
PBytes bytes = encodeString(profiledStr.toString(), profiledEncoding.toString(), profiledErrors.toString());
352+
@Shared("castStr") @Cached CastToJavaStringNode castStr,
353+
@Shared("castEncoding") @Cached CastToJavaStringNode castEncoding,
354+
@Shared("castErrors") @Cached CastToJavaStringNode castErrors) {
355+
String profiledStr = castStr.execute(str);
356+
String profiledEncoding = castEncoding.execute(encoding);
357+
String profiledErrors = castErrors.execute(errors);
358+
PBytes bytes = encodeString(profiledStr, profiledEncoding, profiledErrors);
360359
return factory().createTuple(new Object[]{bytes, getLength(bytes)});
361360
}
362361

@@ -546,9 +545,9 @@ Object decode(PIBytesLike bytes, @SuppressWarnings("unused") PNone errors) {
546545

547546
@Specialization(guards = {"isString(errors)"})
548547
Object decode(PIBytesLike bytes, Object errors,
549-
@Cached("createClassProfile()") ValueProfile errorsTypeProfile) {
550-
Object profiledErrors = errorsTypeProfile.profile(errors);
551-
String string = decodeBytes(getBytesBuffer(bytes), profiledErrors.toString());
548+
@Cached CastToJavaStringNode castStr) {
549+
String profiledErrors = castStr.execute(errors);
550+
String string = decodeBytes(getBytesBuffer(bytes), profiledErrors);
552551
return factory().createTuple(new Object[]{string, string.length()});
553552
}
554553

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242

4343
import com.oracle.graal.python.PythonLanguage;
4444
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
45+
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodesFactory.ExternalFunctionNodeGen;
4546
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.CheckFunctionResultNode;
4647
import com.oracle.graal.python.builtins.modules.PythonCextBuiltins.TrufflePInt_AsPrimitive;
4748
import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.TrufflePInt_AsPrimitiveFactory;
48-
import com.oracle.graal.python.builtins.modules.ExternalFunctionNodesFactory.ExternalFunctionNodeGen;
4949
import com.oracle.graal.python.builtins.objects.PNone;
5050
import com.oracle.graal.python.builtins.objects.cext.CExtNodes;
5151
import com.oracle.graal.python.builtins.objects.cext.CExtNodes.ConvertArgsToSulongNode;
@@ -141,10 +141,10 @@ Object doIt(VirtualFrame frame,
141141
try {
142142
return fromNative(asPythonObjectNode.execute(checkResultNode.execute(name, lib.execute(callable, arguments))));
143143
} catch (UnsupportedTypeException | UnsupportedMessageException e) {
144-
CompilerDirectives.transferToInterpreter();
144+
CompilerDirectives.transferToInterpreterAndInvalidate();
145145
throw raiseNode.raise(PythonBuiltinClassType.TypeError, "Calling native function %s failed: %m", name, e);
146146
} catch (ArityException e) {
147-
CompilerDirectives.transferToInterpreter();
147+
CompilerDirectives.transferToInterpreterAndInvalidate();
148148
throw raiseNode.raise(PythonBuiltinClassType.TypeError, "Calling native function %s expected %d arguments but got %d.", name, e.getExpectedArity(), e.getActualArity());
149149
} finally {
150150
// special case after calling a C function: transfer caught exception back to frame

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7474
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
7575
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
76+
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
7677
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
7778
import com.oracle.graal.python.runtime.PythonContext;
7879
import com.oracle.graal.python.runtime.exception.PException;
@@ -248,6 +249,7 @@ abstract static class MarshallerNode extends PNodeWithState {
248249

249250
public abstract void execute(VirtualFrame frame, Object x, int version, DataOutputStream buffer);
250251

252+
@Child private CastToJavaStringNode castStrNode;
251253
@Child private MarshallerNode recursiveNode;
252254
private int depth = 0;
253255
private IsBuiltinClassProfile isBuiltinProfile;
@@ -476,12 +478,16 @@ private PTuple internStrings(Object[] values) {
476478
} else {
477479
interned = new Object[values.length];
478480
for (int i = 0; i < interned.length; i++) {
479-
if (values[i] instanceof String) {
480-
interned[i] = new InternedString((String) values[i]);
481-
} else if (values[i] instanceof PString) {
482-
interned[i] = new InternedString(((PString) values[i]).getValue());
481+
if (castStrNode == null) {
482+
CompilerDirectives.transferToInterpreterAndInvalidate();
483+
castStrNode = insert(CastToJavaStringNode.create());
484+
}
485+
Object value = values[i];
486+
String strValue = castStrNode.execute(value);
487+
if (strValue != null) {
488+
interned[i] = new InternedString(strValue);
483489
} else {
484-
interned[i] = values[i];
490+
interned[i] = value;
485491
}
486492
}
487493
}

0 commit comments

Comments
 (0)