Skip to content

Commit c5c7729

Browse files
committed
Simplify AbstractObjectGetBasesNode
1 parent 0e5c2b7 commit c5c7729

File tree

4 files changed

+17
-57
lines changed

4 files changed

+17
-57
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ boolean isInstance(VirtualFrame frame, Object cls, Object instance,
837837
@Cached AbstractObjectIsSubclassNode abstractIsSubclassNode,
838838
@Cached AbstractObjectGetBasesNode getBasesNode,
839839
@Cached PRaiseNode raiseNode) {
840-
if (typeErrorProfile.profile(inliningTarget, getBasesNode.execute(frame, cls) == null)) {
840+
if (typeErrorProfile.profile(inliningTarget, getBasesNode.execute(frame, inliningTarget, cls) == null)) {
841841
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.ISINSTANCE_ARG_2_MUST_BE_TYPE_OR_TUPLE_OF_TYPE, instance);
842842
}
843843

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

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -41,72 +41,32 @@
4141
package com.oracle.graal.python.nodes.classes;
4242

4343
import static com.oracle.graal.python.nodes.SpecialAttributeNames.T___BASES__;
44-
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___GETATTRIBUTE__;
4544

4645
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
47-
import com.oracle.graal.python.lib.PyObjectGetAttr;
46+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
4847
import com.oracle.graal.python.nodes.PNodeWithContext;
49-
import com.oracle.graal.python.nodes.SpecialMethodNames;
50-
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
51-
import com.oracle.graal.python.nodes.call.CallNode;
52-
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
53-
import com.oracle.graal.python.runtime.exception.PException;
54-
import com.oracle.truffle.api.dsl.Bind;
5548
import com.oracle.truffle.api.dsl.Cached;
56-
import com.oracle.truffle.api.dsl.Cached.Exclusive;
49+
import com.oracle.truffle.api.dsl.GenerateCached;
50+
import com.oracle.truffle.api.dsl.GenerateInline;
5751
import com.oracle.truffle.api.dsl.GenerateUncached;
58-
import com.oracle.truffle.api.dsl.ImportStatic;
59-
import com.oracle.truffle.api.dsl.NeverDefault;
6052
import com.oracle.truffle.api.dsl.Specialization;
6153
import com.oracle.truffle.api.frame.Frame;
6254
import com.oracle.truffle.api.frame.VirtualFrame;
6355
import com.oracle.truffle.api.nodes.Node;
6456

57+
@GenerateInline
58+
@GenerateCached(false)
6559
@GenerateUncached
66-
@ImportStatic({SpecialMethodNames.class})
67-
@SuppressWarnings("truffle-inlining") // footprint reduction 44 -> 26
6860
public abstract class AbstractObjectGetBasesNode extends PNodeWithContext {
69-
@NeverDefault
70-
public static AbstractObjectGetBasesNode create() {
71-
return AbstractObjectGetBasesNodeGen.create();
72-
}
73-
74-
protected abstract PTuple executeInternal(Frame frame, Object cls);
75-
76-
public final PTuple execute(VirtualFrame frame, Object cls) {
77-
return executeInternal(frame, cls);
78-
}
7961

80-
@Specialization(guards = "!isUncachedNode()")
81-
static PTuple getBasesCached(VirtualFrame frame, Object cls,
82-
@Bind("this") Node inliningTarget,
83-
@Cached PyObjectGetAttr getAttributeNode,
84-
@Exclusive @Cached IsBuiltinObjectProfile exceptionMaskProfile) {
85-
try {
86-
Object bases = getAttributeNode.execute(frame, inliningTarget, cls, T___BASES__);
87-
if (bases instanceof PTuple) {
88-
return (PTuple) bases;
89-
}
90-
} catch (PException pe) {
91-
pe.expectAttributeError(inliningTarget, exceptionMaskProfile);
92-
}
93-
return null;
94-
}
62+
public abstract PTuple execute(Frame frame, Node inliningTarget, Object cls);
9563

96-
@Specialization(replaces = "getBasesCached")
97-
static PTuple getBasesUncached(VirtualFrame frame, Object cls,
98-
@Bind("this") Node inliningTarget,
99-
@Cached LookupInheritedAttributeNode.Dynamic lookupGetattributeNode,
100-
@Cached CallNode callGetattributeNode,
101-
@Exclusive @Cached IsBuiltinObjectProfile exceptionMaskProfile) {
102-
Object getattr = lookupGetattributeNode.execute(inliningTarget, cls, T___GETATTRIBUTE__);
103-
try {
104-
Object bases = callGetattributeNode.execute(frame, getattr, cls, T___BASES__);
105-
if (bases instanceof PTuple) {
106-
return (PTuple) bases;
107-
}
108-
} catch (PException pe) {
109-
pe.expectAttributeError(inliningTarget, exceptionMaskProfile);
64+
@Specialization
65+
static PTuple getBasesCached(VirtualFrame frame, Node inliningTarget, Object cls,
66+
@Cached PyObjectLookupAttr lookupAttr) {
67+
Object bases = lookupAttr.execute(frame, inliningTarget, cls, T___BASES__);
68+
if (bases instanceof PTuple) {
69+
return (PTuple) bases;
11070
}
11171
return null;
11272
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static boolean doSubclass(VirtualFrame frame, @SuppressWarnings("unused") Object
106106
@Cached AbstractObjectIsSubclassNode isSubclassNode,
107107
@Shared @Cached GetObjectArrayNode getObjectArrayNode) {
108108
CompilerAsserts.partialEvaluationConstant(depth);
109-
PTuple bases = getBasesNode.execute(frame, cachedDerived);
109+
PTuple bases = getBasesNode.execute(frame, inliningTarget, cachedDerived);
110110
if (bases == null || isEmpty(bases)) {
111111
return false;
112112
}
@@ -158,7 +158,7 @@ static boolean doGeneric(VirtualFrame frame, Object derived, Object cls, int dep
158158
return true;
159159
}
160160

161-
PTuple bases = getBasesNode.execute(frame, derived);
161+
PTuple bases = getBasesNode.execute(frame, inliningTarget, derived);
162162
if (bases == null || isEmpty(bases)) {
163163
return false;
164164
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ static boolean fallback(VirtualFrame frame, Object derived, Object cls,
336336
@Exclusive @Cached InlinedConditionProfile exceptionDerivedProfile,
337337
@Exclusive @Cached InlinedConditionProfile exceptionClsProfile,
338338
@Cached PRaiseNode raise) {
339-
if (exceptionDerivedProfile.profile(inliningTarget, getBasesNode.execute(frame, derived) == null)) {
339+
if (exceptionDerivedProfile.profile(inliningTarget, getBasesNode.execute(frame, inliningTarget, derived) == null)) {
340340
throw raise.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ARG_D_MUST_BE_S, "issubclass()", 1, "class");
341341
}
342342

343-
if (exceptionClsProfile.profile(inliningTarget, getBasesNode.execute(frame, cls) == null)) {
343+
if (exceptionClsProfile.profile(inliningTarget, getBasesNode.execute(frame, inliningTarget, cls) == null)) {
344344
throw raise.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.ISSUBCLASS_MUST_BE_CLASS_OR_TUPLE);
345345
}
346346

0 commit comments

Comments
 (0)