54
54
import com .oracle .graal .python .builtins .PythonBuiltins ;
55
55
import com .oracle .graal .python .builtins .objects .PNone ;
56
56
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 ;
59
57
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 ;
62
58
import com .oracle .graal .python .nodes .ErrorMessages ;
63
59
import com .oracle .graal .python .nodes .PGuards ;
64
60
import com .oracle .graal .python .nodes .PRaiseNode ;
67
63
import com .oracle .graal .python .nodes .attributes .WriteAttributeToObjectNode ;
68
64
import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
69
65
import com .oracle .graal .python .nodes .call .special .CallUnaryMethodNode ;
66
+ import com .oracle .graal .python .nodes .classes .IsSubtypeNode ;
70
67
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
71
68
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
72
69
import com .oracle .graal .python .nodes .object .GetClassNode ;
@@ -125,16 +122,12 @@ static Object doHiddenKeyDescriptor(HiddenKeyDescriptor self) {
125
122
126
123
static final class DescriptorCheckNode extends Node {
127
124
128
- @ Child private GetMroNode getMroNode ;
125
+ @ Child private IsSubtypeNode isSubtypeNode ;
129
126
@ Child private GetNameNode getNameNode ;
130
- @ Child private IsSameTypeNode isSameTypeNode ;
131
127
@ Child private PRaiseNode raiseNode ;
132
128
@ Child private GetClassNode getClassNode ;
133
129
134
130
@ Child private IsBuiltinClassProfile isBuiltinPythonClassObject = IsBuiltinClassProfile .create ();
135
- @ Child private IsBuiltinClassProfile isBuiltinClassProfile = IsBuiltinClassProfile .create ();
136
-
137
- private final ConditionProfile isBuiltinProfile = ConditionProfile .createBinaryProfile ();
138
131
139
132
// https://github.com/python/cpython/blob/e8b19656396381407ad91473af5da8b0d4346e88/Objects/descrobject.c#L70
140
133
public boolean execute (Object descrType , String name , Object obj ) {
@@ -145,29 +138,18 @@ public boolean execute(Object descrType, String name, Object obj) {
145
138
}
146
139
}
147
140
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 ;
161
143
}
162
144
throw getRaiseNode ().raise (TypeError , ErrorMessages .DESC_S_FOR_S_DOESNT_APPLY_TO_S , name , getTypeName (descrType ), getTypeName (type ));
163
145
}
164
146
165
- private PythonAbstractClass [] getMro (Object clazz ) {
166
- if (getMroNode == null ) {
147
+ private boolean isSubtype (Object derived , Object base ) {
148
+ if (isSubtypeNode == null ) {
167
149
CompilerDirectives .transferToInterpreterAndInvalidate ();
168
- getMroNode = insert (GetMroNode .create ());
150
+ isSubtypeNode = insert (IsSubtypeNode .create ());
169
151
}
170
- return getMroNode .execute (clazz );
152
+ return isSubtypeNode .execute (derived , base );
171
153
}
172
154
173
155
private Object getTypeName (Object descrType ) {
@@ -178,14 +160,6 @@ private Object getTypeName(Object descrType) {
178
160
return getNameNode .execute (descrType );
179
161
}
180
162
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
-
189
163
private PRaiseNode getRaiseNode () {
190
164
if (raiseNode == null ) {
191
165
CompilerDirectives .transferToInterpreterAndInvalidate ();
0 commit comments