Skip to content

Commit 6889aaa

Browse files
committed
[GR-30856] Profile the type of the lookup result in LookupSpecialBaseNode.
PullRequest: graalpython/1774
2 parents f5ef364 + 7ebd6e4 commit 6889aaa

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/SpecialMethodSlot.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ private static void initializeBuiltinTypeSlotsImpl(PythonCore core) {
284284
if (info != null) {
285285
typeSlots[slot.ordinal()] = info;
286286
}
287-
} else if (PythonLanguage.canCache(value)) {
287+
} else if (value instanceof BuiltinMethodDescriptor || PythonLanguage.canCache(value)) {
288288
typeSlots[slot.ordinal()] = value;
289289
}
290290
}
@@ -673,14 +673,16 @@ public static boolean checkSlotOverrides(PythonCore core) {
673673
Object typeValue = slot.getValue(type);
674674
if (typeValue != null) {
675675
Object klassValue = slot.getValue(klass);
676-
if (typeValue instanceof BuiltinMethodDescriptor) {
677-
if (!(klassValue instanceof PBuiltinFunction) ||
678-
((BuiltinMethodDescriptor) typeValue).getFactory() != ((PBuiltinFunction) klassValue).getBuiltinNodeFactory()) {
679-
mismatches.add(type.getName() + "." + slot.getName());
680-
}
681-
} else if (!typeValue.equals(klassValue)) {
682-
mismatches.add(type.getName() + "." + slot.getName());
676+
if (klassValue.equals(typeValue)) {
677+
// values are same: OK
678+
continue;
683679
}
680+
if (typeValue instanceof BuiltinMethodDescriptor && klassValue instanceof PBuiltinFunction &&
681+
((BuiltinMethodDescriptor) typeValue).getFactory() == ((PBuiltinFunction) klassValue).getBuiltinNodeFactory()) {
682+
// BuiltinMethodDescriptor and matching PBuiltinFunction: OK
683+
continue;
684+
}
685+
mismatches.add(type.getName() + "." + slot.getName());
684686
}
685687
}
686688
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialBaseNode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,21 @@
5252
import com.oracle.truffle.api.CompilerDirectives;
5353
import com.oracle.truffle.api.frame.VirtualFrame;
5454
import com.oracle.truffle.api.nodes.Node;
55+
import com.oracle.truffle.api.profiles.ValueProfile;
5556

5657
public abstract class LookupSpecialBaseNode extends Node {
5758
@Child LookupInMROBaseNode lookupNode; // this should be initialized by the subclass
5859
private final boolean ignoreDescriptorException;
5960
@Child private LookupInheritedAttributeNode lookupGet;
6061
@Child private CallNode callGet;
62+
private final ValueProfile lookupResProfile = ValueProfile.createClassProfile();
6163

6264
LookupSpecialBaseNode(boolean ignoreDescriptorException) {
6365
this.ignoreDescriptorException = ignoreDescriptorException;
6466
}
6567

6668
public final Object execute(VirtualFrame frame, Object type, Object receiver) {
67-
Object descriptor = lookupNode.execute(type);
69+
Object descriptor = lookupResProfile.profile(lookupNode.execute(type));
6870
if (descriptor == PNone.NO_VALUE || descriptor instanceof PBuiltinFunction || descriptor instanceof PFunction || descriptor instanceof BuiltinMethodDescriptor) {
6971
// Return unbound to avoid constructing the bound object
7072
return descriptor;

0 commit comments

Comments
 (0)