Skip to content

Commit 1d8d1a4

Browse files
committed
[GR-28698] Various smaller fixes and cleanups.
PullRequest: graalpython/1631
2 parents 4e65b2b + 7482bc9 commit 1d8d1a4

File tree

15 files changed

+53
-48
lines changed

15 files changed

+53
-48
lines changed

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
@@ -150,7 +150,7 @@ protected Source doBytesLike(Object pattern, String flags,
150150
abstract static class TRegexCallCompile extends PythonTernaryBuiltinNode {
151151

152152
@Specialization
153-
Object call(Object pattern, Object flags, PFunction fallbackCompiler,
153+
Object call(VirtualFrame frame, Object pattern, Object flags, PFunction fallbackCompiler,
154154
@Cached BranchProfile potentialSyntaxError,
155155
@Cached BranchProfile syntaxError,
156156
@Cached BranchProfile unsupportedRegexError,
@@ -167,7 +167,7 @@ Object call(Object pattern, Object flags, PFunction fallbackCompiler,
167167
if (compiledRegexLib.isNull(compiledRegex)) {
168168
unsupportedRegexError.enter();
169169
if (context.getLanguage().getEngineOption(PythonOptions.TRegexUsesSREFallback)) {
170-
return callFallbackCompilerNode.execute(fallbackCompiler, pattern, flags);
170+
return callFallbackCompilerNode.execute(frame, fallbackCompiler, pattern, flags);
171171
} else {
172172
throw raise(ValueError, "regular expression not supported, no fallback engine present");
173173
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ public static Object lookupAttributeImpl(VirtualFrame frame, Object receiver, St
898898
try {
899899
Object getAttrFunc = lookup.execute(receiver, __GETATTRIBUTE__);
900900
try {
901-
return callNode.execute(getAttrFunc, receiver, name);
901+
return callNode.execute(frame, getAttrFunc, receiver, name);
902902
} catch (PException pe) {
903903
pe.expect(AttributeError, isAttrErrorProfile1);
904904
getAttrFunc = lookup.execute(receiver, __GETATTR__);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Object dir(VirtualFrame frame, PythonModule self,
159159
HashingStorage dictStorage = getDictStorageNode.execute((PHashingCollection) dict);
160160
Object dirFunc = hashLib.getItem(dictStorage, __DIR__);
161161
if (dirFunc != null) {
162-
return callNode.execute(dirFunc);
162+
return callNode.execute(frame, dirFunc);
163163
} else {
164164
return constructListNode.execute(dict);
165165
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/PythonObject.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.oracle.graal.python.runtime.PythonOptions;
4343
import com.oracle.truffle.api.CompilerAsserts;
4444
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
45+
import com.oracle.truffle.api.dsl.Bind;
4546
import com.oracle.truffle.api.dsl.Cached;
4647
import com.oracle.truffle.api.dsl.Cached.Shared;
4748
import com.oracle.truffle.api.dsl.Specialization;
@@ -92,24 +93,31 @@ public void setLazyPythonClass(Object cls,
9293

9394
@ExportMessage
9495
public static class GetLazyPythonClass {
95-
public static boolean hasInitialClass(PythonObject self, DynamicObjectLibrary dylib) {
96-
return (dylib.getShapeFlags(self) & CLASS_CHANGED_FLAG) == 0;
96+
public static boolean hasInitialClass(Shape shape) {
97+
return (shape.getFlags() & CLASS_CHANGED_FLAG) == 0;
9798
}
9899

99100
public static Object getInitialClass(PythonObject self) {
100101
return self.initialPythonClass;
101102
}
102103

103104
@SuppressWarnings("unused")
104-
@Specialization(guards = {"klass != null", "self.getShape() == cachedShape", "hasInitialClass(self, dylib)"}, limit = "1", assumptions = "singleContextAssumption()")
105+
@Specialization(guards = {"klass != null", "self.getShape() == cachedShape", "hasInitialClass(cachedShape)"}, limit = "1", assumptions = "singleContextAssumption()")
105106
public static Object getConstantClass(PythonObject self,
106-
@Shared("dylib") @CachedLibrary(limit = "4") DynamicObjectLibrary dylib,
107107
@Cached("self.getShape()") Shape cachedShape,
108108
@Cached(value = "getInitialClass(self)", weak = true) Object klass) {
109109
return klass;
110110
}
111111

112-
@Specialization(replaces = "getConstantClass")
112+
@SuppressWarnings("unused")
113+
@Specialization(guards = "hasInitialClass(self.getShape())")
114+
public static Object getClass(PythonObject self,
115+
@Bind("getInitialClass(self)") Object klass) {
116+
assert klass != null;
117+
return klass;
118+
}
119+
120+
@Specialization(guards = "!hasInitialClass(self.getShape())", replaces = "getConstantClass")
113121
public static Object getPythonClass(PythonObject self,
114122
@Shared("dylib") @CachedLibrary(limit = "4") DynamicObjectLibrary dylib) {
115123
return dylib.getOrDefault(self, CLASS, self.initialPythonClass);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetNodes.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@
6060
import com.oracle.truffle.api.CompilerDirectives;
6161
import com.oracle.truffle.api.dsl.Cached;
6262
import com.oracle.truffle.api.dsl.Fallback;
63-
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6463
import com.oracle.truffle.api.dsl.ImportStatic;
6564
import com.oracle.truffle.api.dsl.Specialization;
6665
import com.oracle.truffle.api.frame.VirtualFrame;
6766
import com.oracle.truffle.api.library.CachedLibrary;
6867

69-
@GenerateNodeFactory
7068
public abstract class SetNodes {
7169

7270
@ImportStatic({PGuards.class, SpecialMethodNames.class, PythonOptions.class})

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/NodeFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
import com.oracle.graal.python.nodes.frame.WriteNode;
7171
import com.oracle.graal.python.nodes.function.ClassBodyRootNode;
7272
import com.oracle.graal.python.nodes.function.FunctionRootNode;
73-
import com.oracle.graal.python.nodes.generator.DictConcatNodeFactory;
73+
import com.oracle.graal.python.nodes.generator.DictConcatNodeGen;
7474
import com.oracle.graal.python.nodes.generator.YieldFromNode;
7575
import com.oracle.graal.python.nodes.generator.YieldNode;
7676
import com.oracle.graal.python.nodes.literal.BooleanLiteralNode;
@@ -85,7 +85,7 @@
8585
import com.oracle.graal.python.nodes.literal.LongLiteralNode;
8686
import com.oracle.graal.python.nodes.literal.ObjectLiteralNode;
8787
import com.oracle.graal.python.nodes.literal.PIntLiteralNode;
88-
import com.oracle.graal.python.nodes.literal.SetLiteralNodeFactory;
88+
import com.oracle.graal.python.nodes.literal.SetLiteralNodeGen;
8989
import com.oracle.graal.python.nodes.literal.StringLiteralNode;
9090
import com.oracle.graal.python.nodes.literal.TupleLiteralNode;
9191
import com.oracle.graal.python.nodes.statement.AssertNode;
@@ -279,11 +279,11 @@ public ExpressionNode createListLiteral(ExpressionNode[] values) {
279279

280280
public ExpressionNode createSetLiteral(List<ExpressionNode> values) {
281281
ExpressionNode[] convertedValues = values.toArray(new ExpressionNode[values.size()]);
282-
return SetLiteralNodeFactory.create(convertedValues);
282+
return SetLiteralNodeGen.create(convertedValues);
283283
}
284284

285285
public ExpressionNode createSetLiteral(ExpressionNode[] values) {
286-
return SetLiteralNodeFactory.create(values);
286+
return SetLiteralNodeGen.create(values);
287287
}
288288

289289
public ExpressionNode createUnaryOperation(String string, ExpressionNode operand) {
@@ -520,7 +520,7 @@ public StatementNode createWithNode(ExpressionNode withContext, WriteNode target
520520
}
521521

522522
public ExpressionNode createDictionaryConcat(ExpressionNode... dictNodes) {
523-
return DictConcatNodeFactory.create(dictNodes);
523+
return DictConcatNodeGen.create(dictNodes);
524524
}
525525

526526
public ExpressionNode callBuiltin(String string, ExpressionNode argument) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@
5353
import com.oracle.truffle.api.CompilerDirectives;
5454
import com.oracle.truffle.api.dsl.Cached;
5555
import com.oracle.truffle.api.dsl.Fallback;
56-
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5756
import com.oracle.truffle.api.dsl.ImportStatic;
5857
import com.oracle.truffle.api.dsl.Specialization;
5958
import com.oracle.truffle.api.frame.VirtualFrame;
6059
import com.oracle.truffle.api.library.CachedLibrary;
6160

62-
@GenerateNodeFactory
6361
public abstract class TupleNodes {
6462

6563
@ImportStatic({PGuards.class, SpecialMethodNames.class})

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/AbstractObjectGetBasesNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ public final PTuple execute(VirtualFrame frame, Object cls) {
7474
return executeInternal(frame, cls);
7575
}
7676

77-
public final PTuple execute(Object cls) {
78-
return executeInternal(null, cls);
79-
}
80-
8177
@Specialization(guards = "!isUncached()")
8278
PTuple getBasesCached(VirtualFrame frame, Object cls,
8379
@Cached("create(__GETATTRIBUTE__)") LookupAndCallBinaryNode getAttributeNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/MaterializeFrameNode.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.oracle.truffle.api.nodes.Node;
7777
import com.oracle.truffle.api.profiles.BranchProfile;
7878
import com.oracle.truffle.api.profiles.ConditionProfile;
79+
import com.oracle.truffle.api.profiles.ValueProfile;
7980

8081
/**
8182
* This node makes sure that the current frame has a filled-in PFrame object with a backref
@@ -317,16 +318,17 @@ public SyncFrameValuesNode(boolean adoptable) {
317318

318319
public abstract void execute(VirtualFrame frame, PFrame pyframe, Frame frameToSync);
319320

320-
@Specialization(guards = {"hasLocalsStorage(pyFrame, frameToSync)", "frameToSync.getFrameDescriptor() == cachedFd", "cachedSlots.length < 32"}, //
321+
@Specialization(guards = {"hasLocalsStorage(pyFrame, frameToSync, frameProfile)", "frameToSync.getFrameDescriptor() == cachedFd", "cachedSlots.length < 32"}, //
321322
assumptions = "cachedFd.getVersion()", //
322323
limit = "1")
323324
@ExplodeLoop
324325
static void doLocalsStorageCached(PFrame pyFrame, Frame frameToSync,
326+
@Cached("createClassProfile()") ValueProfile frameProfile,
325327
@Cached("frameToSync.getFrameDescriptor()") FrameDescriptor cachedFd,
326328
@Cached(value = "getSlots(cachedFd)", dimensions = 1) FrameSlot[] cachedSlots) {
327329
boolean invalidState = false;
328330
LocalsStorage localsStorage = getLocalsStorage(pyFrame);
329-
MaterializedFrame target = localsStorage.getFrame();
331+
MaterializedFrame target = frameProfile.profile(localsStorage.getFrame());
330332
assert cachedFd == target.getFrameDescriptor();
331333

332334
for (int i = 0; i < cachedSlots.length; i++) {
@@ -390,15 +392,16 @@ static void doLocalsStorageCached(PFrame pyFrame, Frame frameToSync,
390392
}
391393
}
392394

393-
@Specialization(guards = {"hasLocalsStorage(pyFrame, frameToSync)", "frameToSync.getFrameDescriptor() == cachedFd"}, //
395+
@Specialization(guards = {"hasLocalsStorage(pyFrame, frameToSync, frameProfile)", "frameToSync.getFrameDescriptor() == cachedFd"}, //
394396
assumptions = "cachedFd.getVersion()", //
395397
limit = "1")
396398
static void doLocalsStorageLoop(PFrame pyFrame, Frame frameToSync,
399+
@Cached("createClassProfile()") ValueProfile frameProfile,
397400
@Cached("frameToSync.getFrameDescriptor()") FrameDescriptor cachedFd,
398401
@Cached(value = "getSlots(cachedFd)", dimensions = 1) FrameSlot[] cachedSlots) {
399402
boolean invalidState = false;
400403
LocalsStorage localsStorage = getLocalsStorage(pyFrame);
401-
MaterializedFrame target = localsStorage.getFrame();
404+
MaterializedFrame target = frameProfile.profile(localsStorage.getFrame());
402405
assert cachedFd == target.getFrameDescriptor();
403406

404407
for (int i = 0; i < cachedSlots.length; i++) {
@@ -462,13 +465,14 @@ static void doLocalsStorageLoop(PFrame pyFrame, Frame frameToSync,
462465
}
463466
}
464467

465-
@Specialization(guards = "hasLocalsStorage(pyFrame, frameToSync)", replaces = {"doLocalsStorageCached", "doLocalsStorageLoop"})
466-
static void doLocalsStorageUncached(PFrame pyFrame, Frame frameToSync) {
468+
@Specialization(guards = "hasLocalsStorage(pyFrame, frameToSync, frameProfile)", replaces = {"doLocalsStorageCached", "doLocalsStorageLoop"})
469+
static void doLocalsStorageUncached(PFrame pyFrame, Frame frameToSync,
470+
@Cached("createClassProfile()") ValueProfile frameProfile) {
467471
FrameDescriptor fd = frameToSync.getFrameDescriptor();
468472
FrameSlot[] cachedSlots = getSlots(fd);
469473
try {
470474
LocalsStorage localsStorage = getLocalsStorage(pyFrame);
471-
MaterializedFrame target = localsStorage.getFrame();
475+
MaterializedFrame target = frameProfile.profile(localsStorage.getFrame());
472476
assert fd == target.getFrameDescriptor();
473477

474478
for (int i = 0; i < cachedSlots.length; i++) {
@@ -615,9 +619,10 @@ static void doGenericDict(VirtualFrame frame, PFrame pyFrame, Frame frameToSync)
615619
}
616620
}
617621

618-
@Specialization(guards = "isCustomLocalsObject(pyFrame, frameToSync)")
622+
@Specialization(guards = "isCustomLocalsObject(pyFrame, frameToSync, frameProfile)")
619623
@SuppressWarnings("unused")
620-
static void doCustomLocalsObject(PFrame pyFrame, Frame frameToSync) {
624+
static void doCustomLocalsObject(PFrame pyFrame, Frame frameToSync,
625+
@Cached("createClassProfile()") ValueProfile frameProfile) {
621626
// nothing to do; we already worked on the custom object
622627
}
623628

@@ -639,9 +644,9 @@ protected static ConditionProfile[] getProfiles(int n) {
639644
* same frame descriptor as the frame to synchronize. That means, the dict represents
640645
* unmodified set of frame values of the frame to sync.
641646
*/
642-
protected static boolean hasLocalsStorage(PFrame pyFrame, Frame frameToSync) {
647+
protected static boolean hasLocalsStorage(PFrame pyFrame, Frame frameToSync, ValueProfile frameProfile) {
643648
Object localsObject = pyFrame.getLocalsDict();
644-
return localsObject instanceof PDict && getFd(((PDict) localsObject).getDictStorage()) == frameToSync.getFrameDescriptor();
649+
return localsObject instanceof PDict && getFd(((PDict) localsObject).getDictStorage(), frameProfile) == frameToSync.getFrameDescriptor();
645650
}
646651

647652
protected static boolean isDictWithCustomStorage(PFrame pyFrame) {
@@ -650,17 +655,17 @@ protected static boolean isDictWithCustomStorage(PFrame pyFrame) {
650655
return PythonObjectLibrary.getUncached().getLazyPythonClass(localsObject) == PythonBuiltinClassType.PDict;
651656
}
652657

653-
protected static boolean isCustomLocalsObject(PFrame pyFrame, Frame frameToSync) {
654-
return !hasLocalsStorage(pyFrame, frameToSync);
658+
protected static boolean isCustomLocalsObject(PFrame pyFrame, Frame frameToSync, ValueProfile frameProfile) {
659+
return !hasLocalsStorage(pyFrame, frameToSync, frameProfile);
655660
}
656661

657662
protected static LocalsStorage getLocalsStorage(PFrame pyFrame) {
658663
return (LocalsStorage) ((PDict) pyFrame.getLocalsDict()).getDictStorage();
659664
}
660665

661-
private static FrameDescriptor getFd(HashingStorage storage) {
666+
private static FrameDescriptor getFd(HashingStorage storage, ValueProfile frameProfile) {
662667
if (storage instanceof LocalsStorage) {
663-
return ((LocalsStorage) storage).getFrame().getFrameDescriptor();
668+
return frameProfile.profile(((LocalsStorage) storage).getFrame()).getFrameDescriptor();
664669
}
665670
return null;
666671
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/BuiltinFunctionRootNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ public Builtin getBuiltin() {
354354
@Override
355355
public String toString() {
356356
CompilerAsserts.neverPartOfCompilation();
357-
return "<builtin function " + name + " at " + Integer.toHexString(hashCode()) + ">";
357+
Class<?> clazz = factory.getNodeClass().getEnclosingClass();
358+
String context = clazz == null ? "" : clazz.getSimpleName() + ".";
359+
return "<builtin function " + context + name + " at " + Integer.toHexString(hashCode()) + ">";
358360
}
359361

360362
@Override

0 commit comments

Comments
 (0)