Skip to content

Commit 4cbf78e

Browse files
committed
Use singleContext field in MRO lookup node
1 parent ce3acb5 commit 4cbf78e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public void setMRO(PythonAbstractClass[] mro) {
223223

224224
public void setMRO(PythonAbstractClass[] mro, PythonLanguage language) {
225225
super.setMRO(mro);
226-
if (!language.singleContextAssumption.isValid()) {
226+
if (!language.isSingleContext()) {
227227
mroShape = null;
228228
invalidateMroShapeSubTypes();
229229
}
@@ -245,7 +245,7 @@ public MroShape getMroShape() {
245245
public void initializeMroShape(PythonLanguage language) {
246246
assert mroShapeSubTypes == null;
247247
assert mroShape == null;
248-
if (!language.singleContextAssumption.isValid()) {
248+
if (!language.isSingleContext()) {
249249
reinitializeMroShape(language);
250250
}
251251
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PNodeWithContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,8 @@ public final PythonLanguage getLanguage() {
7979
public final PythonContext getContext() {
8080
return PythonContext.get(this);
8181
}
82+
83+
public final boolean isSingleContext() {
84+
return getLanguage().isSingleContext();
85+
}
8286
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/LookupAttributeInMRONode.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static Object findAttr(Python3Core core, PythonBuiltinClassType klass, Ob
150150
return value;
151151
}
152152

153-
@Specialization(guards = {"klass == cachedKlass"}, limit = "getAttributeAccessInlineCacheMaxDepth()", assumptions = "singleContextAssumption()")
153+
@Specialization(guards = {"isSingleContext()", "klass == cachedKlass"}, limit = "getAttributeAccessInlineCacheMaxDepth()")
154154
protected static Object lookupPBCTCached(@SuppressWarnings("unused") PythonBuiltinClassType klass,
155155
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
156156
@Cached("findAttr(getContext(), cachedKlass, key)") Object cachedValue) {
@@ -184,7 +184,8 @@ public static PythonBuiltinClassType findOwnerInMro(Python3Core core, PythonBuil
184184
return null;
185185
}
186186

187-
@Specialization(replaces = "lookupPBCTCached", guards = "klass == cachedKlass", limit = "getAttributeAccessInlineCacheMaxDepth()")
187+
@Specialization(replaces = {"lookupPBCTCached", "lookupPBCTCachedMulti"}, guards = "klass == cachedKlass", //
188+
limit = "getAttributeAccessInlineCacheMaxDepth()")
188189
protected Object lookupPBCTCachedOwner(@SuppressWarnings("unused") PythonBuiltinClassType klass,
189190
@Cached("klass") @SuppressWarnings("unused") PythonBuiltinClassType cachedKlass,
190191
@Cached("findOwnerInMro(getContext(), cachedKlass, key)") PythonBuiltinClassType ownerKlass,
@@ -251,9 +252,9 @@ protected AttributeAssumptionPair findAttrAndAssumptionInMRO(Object klass) {
251252
return new AttributeAssumptionPair(attrAssumption, PNone.NO_VALUE);
252253
}
253254

254-
@Specialization(guards = {"isSameType(cachedKlass, klass)", "cachedAttrInMROInfo != null"}, //
255+
@Specialization(guards = {"isSingleContext()", "isSameType(cachedKlass, klass)", "cachedAttrInMROInfo != null"}, //
255256
limit = "getAttributeAccessInlineCacheMaxDepth()", //
256-
assumptions = {"cachedAttrInMROInfo.assumption", "singleContextAssumption()"})
257+
assumptions = "cachedAttrInMROInfo.assumption")
257258
protected static Object lookupConstantMROCached(@SuppressWarnings("unused") Object klass,
258259
@Cached("klass") @SuppressWarnings("unused") Object cachedKlass,
259260
@Cached("findAttrAndAssumptionInMRO(cachedKlass)") AttributeAssumptionPair cachedAttrInMROInfo) {
@@ -268,7 +269,7 @@ public MroShapeLookupResult lookupInMroShape(MroShape shape, Object klass) {
268269
// This specialization works well only for multi-context mode
269270
// Note: MroShape creation and updates are disabled in multi-context mode, see
270271
// PythonClass#initializeMroShape
271-
@Specialization(guards = {"!singleContextAssumption().isValid()", "cachedMroShape != null", "klass.getMroShape() == cachedMroShape"}, //
272+
@Specialization(guards = {"!isSingleContext()", "cachedMroShape != null", "klass.getMroShape() == cachedMroShape"}, //
272273
limit = "getAttributeAccessInlineCacheMaxDepth()")
273274
protected Object lookupConstantMROShape(PythonClass klass,
274275
@SuppressWarnings("unused") @Cached("klass.getMroShape()") MroShape cachedMroShape,
@@ -284,10 +285,10 @@ protected static ReadAttributeFromObjectNode[] create(int size) {
284285
return nodes;
285286
}
286287

287-
@Specialization(guards = {"isSameType(cachedKlass, klass)", "mroLength < 32"}, //
288+
@Specialization(guards = {"isSingleContext()", "isSameType(cachedKlass, klass)", "mroLength < 32"}, //
288289
limit = "getAttributeAccessInlineCacheMaxDepth()", //
289290
replaces = "lookupConstantMROShape", //
290-
assumptions = {"lookupStable", "singleContextAssumption()"})
291+
assumptions = "lookupStable")
291292
@ExplodeLoop(kind = ExplodeLoop.LoopExplosionKind.FULL_UNROLL_UNTIL_RETURN)
292293
protected Object lookupConstantMRO(@SuppressWarnings("unused") Object klass,
293294
@Cached("klass") @SuppressWarnings("unused") Object cachedKlass,

0 commit comments

Comments
 (0)