41
41
package com .oracle .graal .python .nodes .classes ;
42
42
43
43
import com .oracle .graal .python .builtins .objects .type .PythonAbstractClass ;
44
- import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetMroNode ;
44
+ import com .oracle .graal .python .builtins .objects .type .TypeNodes .GetMroStorageNode ;
45
45
import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsSameTypeNode ;
46
46
import com .oracle .graal .python .nodes .PNodeWithContext ;
47
47
import com .oracle .graal .python .runtime .PythonOptions ;
48
48
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
49
+ import com .oracle .graal .python .runtime .sequence .storage .MroSequenceStorage ;
49
50
import com .oracle .truffle .api .CompilerDirectives ;
50
51
import com .oracle .truffle .api .dsl .Cached ;
51
52
import com .oracle .truffle .api .dsl .Fallback ;
@@ -61,7 +62,7 @@ public abstract class IsSubtypeNode extends PNodeWithContext {
61
62
62
63
@ Child private AbstractObjectGetBasesNode getBasesNode = AbstractObjectGetBasesNode .create ();
63
64
@ Child private AbstractObjectIsSubclassNode abstractIsSubclassNode = AbstractObjectIsSubclassNode .create ();
64
- @ Child private GetMroNode getMroNode ;
65
+ @ Child private GetMroStorageNode getMroNode ;
65
66
@ Child private IsSameTypeNode isSameTypeNode ;
66
67
67
68
private final ConditionProfile exceptionDerivedProfile = ConditionProfile .createBinaryProfile ();
@@ -73,24 +74,39 @@ public static IsSubtypeNode create() {
73
74
74
75
public abstract boolean execute (Object derived , Object cls );
75
76
76
- @ Specialization (guards = {"derived == cachedDerived" , "cls == cachedCls" }, limit = "getVariableArgumentInlineCacheLimit()" )
77
+ @ Specialization (guards = { //
78
+ "derived == cachedDerived" , //
79
+ "cls == cachedCls" , //
80
+ "mro.length() < 32" //
81
+ }, //
82
+ limit = "getVariableArgumentInlineCacheLimit()" , //
83
+ assumptions = "mro.getLookupStableAssumption()" )
77
84
@ ExplodeLoop
78
85
boolean isSubtypeOfConstantType (@ SuppressWarnings ("unused" ) PythonAbstractClass derived , @ SuppressWarnings ("unused" ) PythonAbstractClass cls ,
79
- @ Cached ("derived" ) PythonAbstractClass cachedDerived ,
80
- @ Cached ("cls" ) PythonAbstractClass cachedCls ) {
81
- for (PythonAbstractClass n : getMro (cachedDerived )) {
86
+ @ Cached ("derived" ) @ SuppressWarnings ("unused" ) PythonAbstractClass cachedDerived ,
87
+ @ Cached ("cls" ) PythonAbstractClass cachedCls ,
88
+ @ Cached ("getMro(cachedDerived)" ) MroSequenceStorage mro ) {
89
+ for (PythonAbstractClass n : mro .getInternalClassArray ()) {
82
90
if (isSameType (n , cachedCls )) {
83
91
return true ;
84
92
}
85
93
}
86
94
return false ;
87
95
}
88
96
89
- @ Specialization (guards = {"derived == cachedDerived" }, limit = "getVariableArgumentInlineCacheLimit()" , replaces = "isSubtypeOfConstantType" )
97
+ @ Specialization (guards = { //
98
+ "derived == cachedDerived" , //
99
+ "mro.length() < 32" //
100
+ }, //
101
+ limit = "getVariableArgumentInlineCacheLimit()" , //
102
+ replaces = "isSubtypeOfConstantType" , //
103
+ assumptions = "mro.getLookupStableAssumption()" //
104
+ )
90
105
@ ExplodeLoop
91
106
boolean isSubtypeOfVariableType (@ SuppressWarnings ("unused" ) PythonAbstractClass derived , PythonAbstractClass cls ,
92
- @ Cached ("derived" ) PythonAbstractClass cachedDerived ) {
93
- for (PythonAbstractClass n : getMro (cachedDerived )) {
107
+ @ Cached ("derived" ) @ SuppressWarnings ("unused" ) PythonAbstractClass cachedDerived ,
108
+ @ Cached ("getMro(cachedDerived)" ) MroSequenceStorage mro ) {
109
+ for (PythonAbstractClass n : mro .getInternalClassArray ()) {
94
110
if (isSameType (n , cls )) {
95
111
return true ;
96
112
}
@@ -100,7 +116,7 @@ boolean isSubtypeOfVariableType(@SuppressWarnings("unused") PythonAbstractClass
100
116
101
117
@ Specialization (replaces = {"isSubtypeOfConstantType" , "isSubtypeOfVariableType" })
102
118
boolean issubTypeGeneric (PythonAbstractClass derived , PythonAbstractClass cls ) {
103
- for (PythonAbstractClass n : getMro (derived )) {
119
+ for (PythonAbstractClass n : getMro (derived ). getInternalClassArray () ) {
104
120
if (isSameType (n , cls )) {
105
121
return true ;
106
122
}
@@ -121,10 +137,10 @@ public boolean isSubclass(Object derived, Object cls) {
121
137
return abstractIsSubclassNode .execute (derived , cls );
122
138
}
123
139
124
- private PythonAbstractClass [] getMro (PythonAbstractClass clazz ) {
140
+ protected MroSequenceStorage getMro (PythonAbstractClass clazz ) {
125
141
if (getMroNode == null ) {
126
142
CompilerDirectives .transferToInterpreterAndInvalidate ();
127
- getMroNode = insert (GetMroNode .create ());
143
+ getMroNode = insert (GetMroStorageNode .create ());
128
144
}
129
145
return getMroNode .execute (clazz );
130
146
}
0 commit comments