Skip to content

Commit 6ecf36f

Browse files
committed
Cleanup attribute nodes in 'TruffleObjectBuiltins'.
1 parent 993def5 commit 6ecf36f

File tree

1 file changed

+0
-173
lines changed

1 file changed

+0
-173
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/TruffleObjectBuiltins.java

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,14 @@
2626

2727
package com.oracle.graal.python.builtins.objects.foreign;
2828

29-
import static com.oracle.graal.python.nodes.SpecialAttributeNames.__CLASS__;
3029
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ADD__;
3130
import static com.oracle.graal.python.nodes.SpecialMethodNames.__BOOL__;
3231
import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
3332
import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELATTR__;
34-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELETE__;
3533
import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELITEM__;
3634
import static com.oracle.graal.python.nodes.SpecialMethodNames.__DIR__;
3735
import static com.oracle.graal.python.nodes.SpecialMethodNames.__FLOORDIV__;
38-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTRIBUTE__;
39-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETATTR__;
4036
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__;
41-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GET__;
4237
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GE__;
4338
import static com.oracle.graal.python.nodes.SpecialMethodNames.__GT__;
4439
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
@@ -54,7 +49,6 @@
5449
import static com.oracle.graal.python.nodes.SpecialMethodNames.__RTRUEDIV__;
5550
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETATTR__;
5651
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETITEM__;
57-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SET__;
5852
import static com.oracle.graal.python.nodes.SpecialMethodNames.__SUB__;
5953
import static com.oracle.graal.python.nodes.SpecialMethodNames.__TRUEDIV__;
6054
import static com.oracle.graal.python.runtime.exception.PythonErrorType.AttributeError;
@@ -69,14 +63,8 @@
6963
import com.oracle.graal.python.builtins.objects.PNone;
7064
import com.oracle.graal.python.builtins.objects.PNotImplemented;
7165
import com.oracle.graal.python.builtins.objects.function.PKeyword;
72-
import com.oracle.graal.python.builtins.objects.function.PythonCallable;
7366
import com.oracle.graal.python.builtins.objects.list.PList;
74-
import com.oracle.graal.python.builtins.objects.type.PythonClass;
7567
import com.oracle.graal.python.nodes.PGuards;
76-
import com.oracle.graal.python.nodes.SpecialMethodNames;
77-
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
78-
import com.oracle.graal.python.nodes.attributes.LookupInheritedAttributeNode;
79-
import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
8068
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
8169
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
8270
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
@@ -87,7 +75,6 @@
8775
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
8876
import com.oracle.graal.python.nodes.interop.PForeignToPTypeNode;
8977
import com.oracle.graal.python.nodes.interop.PTypeToForeignNode;
90-
import com.oracle.graal.python.nodes.object.GetClassNode;
9178
import com.oracle.graal.python.runtime.exception.PythonErrorType;
9279
import com.oracle.truffle.api.CompilerDirectives;
9380
import com.oracle.truffle.api.dsl.Cached;
@@ -104,8 +91,6 @@
10491
import com.oracle.truffle.api.interop.UnsupportedMessageException;
10592
import com.oracle.truffle.api.interop.UnsupportedTypeException;
10693
import com.oracle.truffle.api.nodes.Node;
107-
import com.oracle.truffle.api.profiles.BranchProfile;
108-
import com.oracle.truffle.api.profiles.ConditionProfile;
10994
import com.oracle.truffle.api.profiles.ValueProfile;
11095

11196
@CoreFunctions(extendClasses = TruffleObject.class)
@@ -802,153 +787,6 @@ protected Object doGeneric(Object callee, @SuppressWarnings("unused") Object arg
802787
}
803788
}
804789

805-
@Builtin(name = __GETATTRIBUTE__, fixedNumOfArguments = 2)
806-
@GenerateNodeFactory
807-
public abstract static class GetattributeNode extends PythonBinaryBuiltinNode {
808-
private final BranchProfile hasDescProfile = BranchProfile.create();
809-
private final BranchProfile isDescProfile = BranchProfile.create();
810-
private final BranchProfile hasValueProfile = BranchProfile.create();
811-
private final BranchProfile errorProfile = BranchProfile.create();
812-
private final ConditionProfile typeIsObjectProfile = ConditionProfile.createBinaryProfile();
813-
814-
@Child private LookupInheritedAttributeNode lookup = LookupInheritedAttributeNode.create();
815-
private final ValueProfile typeProfile = ValueProfile.createIdentityProfile();
816-
@Child private GetClassNode getObjectClassNode;
817-
@Child private GetClassNode getDataClassNode;
818-
@Child private LookupAttributeInMRONode lookupGetNode;
819-
@Child private LookupAttributeInMRONode lookupSetNode;
820-
@Child private LookupAttributeInMRONode lookupDeleteNode;
821-
@Child private CallTernaryMethodNode dispatchGet;
822-
@Child private Node attrReadNode;
823-
@Child private LookupAndCallBinaryNode getattrNode;
824-
825-
@Specialization
826-
protected Object doIt(TruffleObject object, Object key) {
827-
Object descr = lookup.execute(object, key);
828-
PythonClass dataDescClass = null;
829-
if (descr != PNone.NO_VALUE) {
830-
hasDescProfile.enter();
831-
dataDescClass = getDataClass(descr);
832-
Object delete = PNone.NO_VALUE;
833-
Object set = lookupSet(dataDescClass);
834-
if (set == PNone.NO_VALUE) {
835-
delete = lookupDelete(dataDescClass);
836-
}
837-
if (set != PNone.NO_VALUE || delete != PNone.NO_VALUE) {
838-
isDescProfile.enter();
839-
Object get = lookupGet(dataDescClass);
840-
if (get instanceof PythonCallable) {
841-
// Only override if __get__ is defined, too, for compatibility with CPython.
842-
return dispatch(object, descr, get);
843-
}
844-
}
845-
}
846-
Object value = readAttribute(object, key);
847-
if (value != PNone.NO_VALUE) {
848-
hasValueProfile.enter();
849-
return value;
850-
}
851-
if (descr != PNone.NO_VALUE) {
852-
hasDescProfile.enter();
853-
Object get = lookupGet(dataDescClass);
854-
if (get == PNone.NO_VALUE) {
855-
return descr;
856-
} else if (get instanceof PythonCallable) {
857-
return dispatch(object, descr, get);
858-
}
859-
}
860-
errorProfile.enter();
861-
return fallbackGetattr(object, key);
862-
}
863-
864-
private Object fallbackGetattr(Object object, Object key) {
865-
if (getattrNode == null) {
866-
CompilerDirectives.transferToInterpreterAndInvalidate();
867-
getattrNode = insert(LookupAndCallBinaryNode.create(SpecialMethodNames.__GETATTR__));
868-
}
869-
return getattrNode.executeObject(object, key);
870-
}
871-
872-
private Object readAttribute(TruffleObject object, Object key) {
873-
if (attrReadNode == null) {
874-
CompilerDirectives.transferToInterpreterAndInvalidate();
875-
attrReadNode = insert(Message.READ.createNode());
876-
}
877-
try {
878-
return ForeignAccess.sendRead(attrReadNode, object, key);
879-
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
880-
return PNone.NO_VALUE;
881-
}
882-
}
883-
884-
private Object dispatch(Object object, Object descr, Object get) {
885-
if (dispatchGet == null) {
886-
CompilerDirectives.transferToInterpreterAndInvalidate();
887-
dispatchGet = insert(CallTernaryMethodNode.create());
888-
}
889-
PythonClass type = getObjectClass(object);
890-
return dispatchGet.execute(get, descr, typeIsObjectProfile.profile(type == object) ? PNone.NONE : object, type);
891-
}
892-
893-
private Object lookupGet(PythonClass dataDescClass) {
894-
if (lookupGetNode == null) {
895-
CompilerDirectives.transferToInterpreterAndInvalidate();
896-
lookupGetNode = insert(LookupAttributeInMRONode.create());
897-
}
898-
return lookupGetNode.execute(dataDescClass, __GET__);
899-
}
900-
901-
private Object lookupDelete(PythonClass dataDescClass) {
902-
if (lookupDeleteNode == null) {
903-
CompilerDirectives.transferToInterpreterAndInvalidate();
904-
lookupDeleteNode = insert(LookupAttributeInMRONode.create());
905-
}
906-
return lookupDeleteNode.execute(dataDescClass, __DELETE__);
907-
}
908-
909-
private Object lookupSet(PythonClass dataDescClass) {
910-
if (lookupSetNode == null) {
911-
CompilerDirectives.transferToInterpreterAndInvalidate();
912-
lookupSetNode = insert(LookupAttributeInMRONode.create());
913-
}
914-
return lookupSetNode.execute(dataDescClass, __SET__);
915-
}
916-
917-
private PythonClass getObjectClass(Object object) {
918-
if (getObjectClassNode == null) {
919-
CompilerDirectives.transferToInterpreterAndInvalidate();
920-
getObjectClassNode = insert(GetClassNode.create());
921-
}
922-
return typeProfile.profile(getObjectClassNode.execute(object));
923-
}
924-
925-
private PythonClass getDataClass(Object descr) {
926-
if (getDataClassNode == null) {
927-
CompilerDirectives.transferToInterpreterAndInvalidate();
928-
getDataClassNode = insert(GetClassNode.create());
929-
}
930-
return getDataClassNode.execute(descr);
931-
}
932-
}
933-
934-
@Builtin(name = __GETATTR__, fixedNumOfArguments = 3)
935-
@GenerateNodeFactory
936-
public abstract static class GetattrNode extends PythonBinaryBuiltinNode {
937-
@Specialization(guards = {"isForeignObject(object)"})
938-
protected Object doIt(TruffleObject object, Object key,
939-
@Cached("createReadNode()") Node readNode) {
940-
try {
941-
return ForeignAccess.sendRead(readNode, object, key);
942-
} catch (UnknownIdentifierException | UnsupportedMessageException e) {
943-
throw raise(PythonErrorType.AttributeError, "foreign object %s has no attribute %s", object, key);
944-
}
945-
}
946-
947-
protected Node createReadNode() {
948-
return Message.READ.createNode();
949-
}
950-
}
951-
952790
@Builtin(name = __GETITEM__, fixedNumOfArguments = 2)
953791
@GenerateNodeFactory
954792
abstract static class GetitemNode extends PythonBinaryBuiltinNode {
@@ -1030,15 +868,4 @@ protected Object doIt(TruffleObject object,
1030868
}
1031869
}
1032870
}
1033-
1034-
@Builtin(name = __CLASS__, fixedNumOfArguments = 1, isGetter = true)
1035-
@GenerateNodeFactory
1036-
public abstract static class ClassNode extends PythonUnaryBuiltinNode {
1037-
@Specialization(guards = {"isForeignObject(object)"})
1038-
protected Object doIt(TruffleObject object,
1039-
@Cached("create()") GetClassNode getClassNode) {
1040-
return getClassNode.execute(object);
1041-
}
1042-
}
1043-
1044871
}

0 commit comments

Comments
 (0)