Skip to content

Commit 6d3616f

Browse files
committed
allow PythonBuiltinClassType to flow to more places
1 parent a4cb955 commit 6d3616f

File tree

1 file changed

+61
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext

1 file changed

+61
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,21 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
450450
return PythonClassNativeWrapper.wrap(object, getNameNode.execute(object));
451451
}
452452

453+
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
454+
static Object doPythonType(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonBuiltinClassType object,
455+
@SuppressWarnings("unused") @Cached("object") PythonBuiltinClassType cachedObject,
456+
@SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext ctx,
457+
@Cached("wrapNativeClass(ctx, object)") PythonClassNativeWrapper wrapper) {
458+
return wrapper;
459+
}
460+
461+
@Specialization(replaces = "doPythonType")
462+
static Object doPythonTypeUncached(@SuppressWarnings("unused") CExtContext cextContext, PythonBuiltinClassType object,
463+
@CachedContext(PythonLanguage.class) PythonContext ctx,
464+
@Cached TypeNodes.GetNameNode getNameNode) {
465+
return PythonClassNativeWrapper.wrap(ctx.getCore().lookupType(object), getNameNode.execute(object));
466+
}
467+
453468
@Specialization(guards = {"cachedClass == object.getClass()", "!isClass(object, lib)", "!isNativeObject(object)", "!isSpecialSingleton(object)"})
454469
static Object runAbstractObjectCached(@SuppressWarnings("unused") CExtContext cextContext, PythonAbstractObject object,
455470
@Cached("createBinaryProfile()") ConditionProfile noWrapperProfile,
@@ -486,10 +501,14 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonManagedClass obj
486501
return PythonClassNativeWrapper.wrap(object, GetNameNode.doSlowPath(object));
487502
}
488503

504+
protected static PythonClassNativeWrapper wrapNativeClass(PythonContext ctx, PythonBuiltinClassType object) {
505+
return PythonClassNativeWrapper.wrap(ctx.getCore().lookupType(object), GetNameNode.doSlowPath(object));
506+
}
507+
489508
static boolean isFallback(Object object, PythonObjectLibrary lib) {
490509
return !(object instanceof String || object instanceof Boolean || object instanceof Integer || object instanceof Long || object instanceof Double ||
491-
object instanceof PythonNativeNull || object == DescriptorDeleteMarker.INSTANCE || object instanceof PythonAbstractObject) &&
492-
!(lib.isForeignObject(object) && !CApiGuards.isNativeWrapper(object));
510+
object instanceof PythonBuiltinClassType || object instanceof PythonNativeNull || object == DescriptorDeleteMarker.INSTANCE ||
511+
object instanceof PythonAbstractObject) && !(lib.isForeignObject(object) && !CApiGuards.isNativeWrapper(object));
493512
}
494513

495514
protected static boolean isNaN(double d) {
@@ -688,6 +707,22 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
688707
return PythonClassNativeWrapper.wrapNewRef(object, getNameNode.execute(object));
689708
}
690709

710+
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
711+
static Object doPythonType(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonBuiltinClassType object,
712+
@SuppressWarnings("unused") @Cached("object") PythonBuiltinClassType cachedObject,
713+
@SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext ctx,
714+
@Cached("wrapNativeClass(ctx, object)") PythonClassNativeWrapper wrapper) {
715+
wrapper.increaseRefCount();
716+
return wrapper;
717+
}
718+
719+
@Specialization(replaces = "doPythonType")
720+
static Object doPythonTypeUncached(@SuppressWarnings("unused") CExtContext cextContext, PythonBuiltinClassType object,
721+
@CachedContext(PythonLanguage.class) PythonContext ctx,
722+
@Cached TypeNodes.GetNameNode getNameNode) {
723+
return PythonClassNativeWrapper.wrapNewRef(ctx.getCore().lookupType(object), getNameNode.execute(object));
724+
}
725+
691726
@Specialization(guards = {"cachedClass == object.getClass()", "!isClass(object, lib)", "!isNativeObject(object)", "!isSpecialSingleton(object)"})
692727
static Object runAbstractObjectCached(@SuppressWarnings("unused") CExtContext cextContext, PythonAbstractObject object,
693728
@Cached("createBinaryProfile()") ConditionProfile noWrapperProfile,
@@ -722,6 +757,10 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonManagedClass obj
722757
return PythonClassNativeWrapper.wrap(object, GetNameNode.doSlowPath(object));
723758
}
724759

760+
protected static PythonClassNativeWrapper wrapNativeClass(PythonContext ctx, PythonBuiltinClassType object) {
761+
return PythonClassNativeWrapper.wrap(ctx.getCore().lookupType(object), GetNameNode.doSlowPath(object));
762+
}
763+
725764
static boolean isFallback(Object object, PythonObjectLibrary lib) {
726765
return ToSulongNode.isFallback(object, lib);
727766
}
@@ -851,6 +890,22 @@ static Object doPythonClassUncached(@SuppressWarnings("unused") CExtContext cext
851890
return PythonClassNativeWrapper.wrapNewRef(object, getNameNode.execute(object));
852891
}
853892

893+
@Specialization(guards = "object == cachedObject", limit = "3", assumptions = "singleContextAssumption()")
894+
static Object doPythonType(@SuppressWarnings("unused") CExtContext cextContext, @SuppressWarnings("unused") PythonBuiltinClassType object,
895+
@SuppressWarnings("unused") @Cached("object") PythonBuiltinClassType cachedObject,
896+
@SuppressWarnings("unused") @CachedContext(PythonLanguage.class) PythonContext ctx,
897+
@Cached("wrapNativeClass(ctx, object)") PythonClassNativeWrapper wrapper) {
898+
wrapper.increaseRefCount();
899+
return wrapper;
900+
}
901+
902+
@Specialization(replaces = "doPythonType")
903+
static Object doPythonTypeUncached(@SuppressWarnings("unused") CExtContext cextContext, PythonBuiltinClassType object,
904+
@CachedContext(PythonLanguage.class) PythonContext ctx,
905+
@Cached TypeNodes.GetNameNode getNameNode) {
906+
return PythonClassNativeWrapper.wrapNewRef(ctx.getCore().lookupType(object), getNameNode.execute(object));
907+
}
908+
854909
@Specialization(guards = {"cachedClass == object.getClass()", "!isClass(object, lib)", "!isNativeObject(object)", "!isSpecialSingleton(object)"})
855910
static Object runAbstractObjectCached(@SuppressWarnings("unused") CExtContext cextContext, PythonAbstractObject object,
856911
@Cached("createBinaryProfile()") ConditionProfile noWrapperProfile,
@@ -885,6 +940,10 @@ protected static PythonClassNativeWrapper wrapNativeClass(PythonManagedClass obj
885940
return PythonClassNativeWrapper.wrap(object, GetNameNode.doSlowPath(object));
886941
}
887942

943+
protected static PythonClassNativeWrapper wrapNativeClass(PythonContext ctx, PythonBuiltinClassType object) {
944+
return PythonClassNativeWrapper.wrap(ctx.getCore().lookupType(object), GetNameNode.doSlowPath(object));
945+
}
946+
888947
static boolean isFallback(Object object, PythonObjectLibrary lib) {
889948
return ToSulongNode.isFallback(object, lib);
890949
}

0 commit comments

Comments
 (0)