168
168
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetMroStorageNodeGen ;
169
169
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetNameNodeGen ;
170
170
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetSolidBaseNodeGen ;
171
- import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetSubclassesAsArrayNodeGen ;
172
- import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetSubclassesNodeGen ;
173
171
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetTpNameNodeGen ;
174
172
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetTypeFlagsNodeGen ;
175
173
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .InstancesOfTypeHaveDictNodeGen ;
@@ -804,15 +802,7 @@ static TruffleString getQualName(Node inliningTarget, PythonAbstractNativeObject
804
802
}
805
803
}
806
804
807
- @ GenerateUncached
808
- @ GenerateCached (false )
809
- public abstract static class GetSubclassesNode extends PNodeWithContext {
810
- abstract PDict execute (Node inliningTarget , Object clazz );
811
-
812
- public static PDict executeUncached (Object clazz ) {
813
- return GetSubclassesNodeGen .getUncached ().execute (null , clazz );
814
- }
815
-
805
+ public static final class GetSubclassesNode {
816
806
protected static void addSubclass (PythonAbstractClass base , PythonManagedClass subclass ) {
817
807
CompilerAsserts .neverPartOfCompilation ();
818
808
PDict dict = executeUncached (base );
@@ -855,50 +845,28 @@ protected static void removeSubclass(PythonAbstractClass base, PythonManagedClas
855
845
}
856
846
}
857
847
858
- @ Specialization
859
- static PDict doPythonClass (PythonManagedClass obj ) {
860
- return obj .getSubClasses ();
861
- }
862
-
863
- @ Specialization
864
- static PDict doPythonClass (PythonBuiltinClassType obj ) {
865
- return PythonContext .get (null ).lookupType (obj ).getSubClasses ();
866
- }
867
-
868
- @ Specialization
869
- static PDict doNativeClass (PythonAbstractNativeObject obj ,
870
- @ Cached (inline = false ) CStructAccess .ReadObjectNode getTpSubclassesNode ) {
871
- Object tpSubclasses = getTpSubclassesNode .readFromObj (obj , PyTypeObject__tp_subclasses );
872
- Object profiled = tpSubclasses ;
873
- if (profiled instanceof PDict dict ) {
874
- return dict ;
848
+ public static PDict executeUncached (PythonAbstractClass clazz ) {
849
+ if (clazz instanceof PythonManagedClass mc ) {
850
+ return mc .getSubClasses ();
851
+ } else if (PythonNativeClass .isInstance (clazz )) {
852
+ Object tpSubclasses = CStructAccess .ReadObjectNode .getUncached ().readFromObj (PythonNativeClass .cast (clazz ), PyTypeObject__tp_subclasses );
853
+ if (tpSubclasses instanceof PDict dict ) {
854
+ return dict ;
855
+ }
856
+ throw CompilerDirectives .shouldNotReachHere ("invalid subclasses dict " + tpSubclasses .getClass ().getName ());
857
+ } else {
858
+ throw CompilerDirectives .shouldNotReachHere ("unexpected value for GetSubclassesNode: " + clazz .getClass ().getName ());
875
859
}
876
- throw CompilerDirectives .shouldNotReachHere ("invalid subclasses dict " + profiled .getClass ().getName ());
877
860
}
878
861
}
879
862
880
- @ GenerateUncached
881
- @ GenerateInline (false )
882
- @ GenerateCached (false )
883
- public abstract static class GetSubclassesAsArrayNode extends Node {
863
+ public static final class GetSubclassesAsArrayNode {
884
864
private static final PythonAbstractClass [] EMPTY = new PythonAbstractClass [0 ];
885
865
886
- abstract PythonAbstractClass [] execute (Node inliningTarget , Object clazz );
887
-
888
- public static PythonAbstractClass [] executeUncached (Object clazz ) {
889
- return GetSubclassesAsArrayNodeGen .getUncached ().execute (null , clazz );
890
- }
891
-
892
- @ GenerateUncached
893
- @ GenerateCached (false )
894
- abstract static class EachSubclassAdd extends HashingStorageForEachCallback <ArrayList <PythonAbstractClass >> {
866
+ static final class EachSubclassAdd extends HashingStorageForEachCallback <ArrayList <PythonAbstractClass >> {
895
867
@ Override
896
- public abstract ArrayList <PythonAbstractClass > execute (Frame frame , Node inliningTarget , HashingStorage storage , HashingStorageIterator it , ArrayList <PythonAbstractClass > subclasses );
897
-
898
- @ Specialization
899
- static ArrayList <PythonAbstractClass > doIt (Node inliningTarget , HashingStorage storage , HashingStorageIterator it , ArrayList <PythonAbstractClass > subclasses ,
900
- @ Cached HashingStorageIteratorValue itValue ) {
901
- Object value = itValue .execute (inliningTarget , storage , it );
868
+ public final ArrayList <PythonAbstractClass > execute (Frame frame , Node inliningTarget , HashingStorage storage , HashingStorageIterator it , ArrayList <PythonAbstractClass > subclasses ) {
869
+ Object value = HashingStorageIteratorValue .executeUncached (storage , it );
902
870
PythonAbstractClass clazz = PythonAbstractClass .cast (((PReferenceType ) value ).getObject ());
903
871
if (clazz != null ) {
904
872
subclasses .add (clazz );
@@ -907,22 +875,23 @@ static ArrayList<PythonAbstractClass> doIt(Node inliningTarget, HashingStorage s
907
875
}
908
876
}
909
877
910
- @ Specialization
911
- static PythonAbstractClass [] doTpSubclasses (PythonAbstractClass object ,
912
- @ Cached EachSubclassAdd eachNode ,
913
- @ Cached HashingStorageForEach forEachNode ) {
914
- PDict subclasses = GetSubclassesNode .executeUncached (object );
878
+ public static PythonAbstractClass [] executeUncached (Object object ) {
879
+ PythonAbstractClass clazz ;
880
+ if (object instanceof PythonBuiltinClassType bt ) {
881
+ clazz = PythonContext .get (null ).lookupType (bt );
882
+ } else {
883
+ clazz = PythonAbstractClass .cast (object );
884
+ }
885
+ PDict subclasses = GetSubclassesNode .executeUncached (clazz );
915
886
if (subclasses == null ) {
916
887
return EMPTY ;
917
888
}
918
-
919
889
HashingStorage storage = subclasses .getDictStorage ();
920
890
if (storage == EmptyStorage .INSTANCE ) {
921
891
return EMPTY ;
922
892
}
923
-
924
893
ArrayList <PythonAbstractClass > list = new ArrayList <>();
925
- forEachNode . execute ( null , null , storage , eachNode , list );
894
+ HashingStorageForEach . executeUncached ( storage , new EachSubclassAdd () , list );
926
895
return list .toArray (EMPTY );
927
896
}
928
897
}
0 commit comments