Skip to content

Commit 94c8951

Browse files
committed
Use IsSubtypeNode in DescriptorCheckNode
1 parent 7ead338 commit 94c8951

File tree

1 file changed

+8
-34
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor

1 file changed

+8
-34
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/DescriptorBuiltins.java

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@
5454
import com.oracle.graal.python.builtins.PythonBuiltins;
5555
import com.oracle.graal.python.builtins.objects.PNone;
5656
import com.oracle.graal.python.builtins.objects.str.PString;
57-
import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
58-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroNode;
5957
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
60-
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsSameTypeNode;
61-
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.IsSameTypeNodeGen;
6258
import com.oracle.graal.python.nodes.ErrorMessages;
6359
import com.oracle.graal.python.nodes.PGuards;
6460
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -67,6 +63,7 @@
6763
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
6864
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
6965
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
66+
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
7067
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7168
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
7269
import com.oracle.graal.python.nodes.object.GetClassNode;
@@ -125,16 +122,12 @@ static Object doHiddenKeyDescriptor(HiddenKeyDescriptor self) {
125122

126123
static final class DescriptorCheckNode extends Node {
127124

128-
@Child private GetMroNode getMroNode;
125+
@Child private IsSubtypeNode isSubtypeNode;
129126
@Child private GetNameNode getNameNode;
130-
@Child private IsSameTypeNode isSameTypeNode;
131127
@Child private PRaiseNode raiseNode;
132128
@Child private GetClassNode getClassNode;
133129

134130
@Child private IsBuiltinClassProfile isBuiltinPythonClassObject = IsBuiltinClassProfile.create();
135-
@Child private IsBuiltinClassProfile isBuiltinClassProfile = IsBuiltinClassProfile.create();
136-
137-
private final ConditionProfile isBuiltinProfile = ConditionProfile.createBinaryProfile();
138131

139132
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L70
140133
public boolean execute(Object descrType, String name, Object obj) {
@@ -145,29 +138,18 @@ public boolean execute(Object descrType, String name, Object obj) {
145138
}
146139
}
147140
Object type = getPythonClass(obj);
148-
if (isBuiltinProfile.profile(descrType instanceof PythonBuiltinClassType)) {
149-
PythonBuiltinClassType builtinClassType = (PythonBuiltinClassType) descrType;
150-
for (PythonAbstractClass o : getMro(type)) {
151-
if (isBuiltinClassProfile.profileClass(o, builtinClassType)) {
152-
return false;
153-
}
154-
}
155-
} else {
156-
for (PythonAbstractClass o : getMro(type)) {
157-
if (isSameType(o, descrType)) {
158-
return false;
159-
}
160-
}
141+
if (isSubtype(type, descrType)) {
142+
return false;
161143
}
162144
throw getRaiseNode().raise(TypeError, ErrorMessages.DESC_S_FOR_S_DOESNT_APPLY_TO_S, name, getTypeName(descrType), getTypeName(type));
163145
}
164146

165-
private PythonAbstractClass[] getMro(Object clazz) {
166-
if (getMroNode == null) {
147+
private boolean isSubtype(Object derived, Object base) {
148+
if (isSubtypeNode == null) {
167149
CompilerDirectives.transferToInterpreterAndInvalidate();
168-
getMroNode = insert(GetMroNode.create());
150+
isSubtypeNode = insert(IsSubtypeNode.create());
169151
}
170-
return getMroNode.execute(clazz);
152+
return isSubtypeNode.execute(derived, base);
171153
}
172154

173155
private Object getTypeName(Object descrType) {
@@ -178,14 +160,6 @@ private Object getTypeName(Object descrType) {
178160
return getNameNode.execute(descrType);
179161
}
180162

181-
private boolean isSameType(Object left, Object right) {
182-
if (isSameTypeNode == null) {
183-
CompilerDirectives.transferToInterpreterAndInvalidate();
184-
isSameTypeNode = insert(IsSameTypeNodeGen.create());
185-
}
186-
return isSameTypeNode.execute(left, right);
187-
}
188-
189163
private PRaiseNode getRaiseNode() {
190164
if (raiseNode == null) {
191165
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)