6060import com .oracle .graal .python .builtins .objects .PNone ;
6161import com .oracle .graal .python .builtins .objects .cell .CellBuiltins ;
6262import com .oracle .graal .python .builtins .objects .cell .PCell ;
63+ import com .oracle .graal .python .builtins .objects .foreign .ForeignObjectBuiltins .ForeignGetattrNode ;
6364import com .oracle .graal .python .builtins .objects .frame .PFrame ;
6465import com .oracle .graal .python .builtins .objects .function .PArguments ;
6566import com .oracle .graal .python .builtins .objects .function .PKeyword ;
9596import com .oracle .graal .python .nodes .function .builtins .PythonUnaryBuiltinNode ;
9697import com .oracle .graal .python .nodes .function .builtins .PythonVarargsBuiltinNode ;
9798import com .oracle .graal .python .nodes .object .GetClassNode ;
99+ import com .oracle .graal .python .nodes .object .IsForeignObjectNode ;
98100import com .oracle .graal .python .runtime .exception .PException ;
99101import com .oracle .graal .python .runtime .exception .PythonErrorType ;
100102import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
@@ -423,7 +425,7 @@ public abstract static class GetattributeNode extends GetAttrBuiltinNode {
423425 @ Child private ReadAttributeFromObjectNode readFromDict = ReadAttributeFromObjectNode .createForceType ();
424426 @ Child private CallSlotDescrGet callGetSlotNode ;
425427 @ Child private GetTypeNode getType ;
426- @ Child private GetObjectNode getObject ;
428+ @ Child private GetObjectNode getObject = GetObjectNodeGen . create () ;
427429 @ Child private ObjectBuiltins .GetAttributeNode objectGetattributeNode ;
428430 @ Child private GetMroNode getMroNode ;
429431 @ Child private IsSameTypeNode isSameTypeNode ;
@@ -444,7 +446,9 @@ Object get(VirtualFrame frame, SuperObject self, Object attr,
444446 @ Cached GetObjectTypeNode getObjectType ,
445447 @ Cached CastToTruffleStringCheckedNode castToTruffleStringNode ,
446448 @ Cached InlinedConditionProfile hasDescrGetProfile ,
447- @ Cached InlinedConditionProfile getObjectIsStartObjectProfile ) {
449+ @ Cached InlinedConditionProfile getObjectIsStartObjectProfile ,
450+ @ Cached IsForeignObjectNode isForeignObjectNode ,
451+ @ Cached ForeignGetattrNode foreignGetattrNode ) {
448452 Object startType = getObjectType .execute (inliningTarget , self );
449453 if (startType == null ) {
450454 return genericGetAttr (frame , self , attr );
@@ -465,12 +469,13 @@ Object get(VirtualFrame frame, SuperObject self, Object attr,
465469 getType = insert (GetTypeNodeGen .create ());
466470 }
467471
472+ Object type = getType .executeCached (self );
468473 PythonAbstractClass [] mro = getMro (startType );
469474 /* No need to check the last one: it's gonna be skipped anyway. */
470475 int i = 0 ;
471476 int n = mro .length ;
472477 for (i = 0 ; i + 1 < n ; i ++) {
473- if (isSameType (getType . executeCached ( self ) , mro [i ])) {
478+ if (isSameType (type , mro [i ])) {
474479 break ;
475480 }
476481 }
@@ -493,22 +498,28 @@ Object get(VirtualFrame frame, SuperObject self, Object attr,
493498 CompilerDirectives .transferToInterpreterAndInvalidate ();
494499 callGetSlotNode = insert (CallSlotDescrGet .create ());
495500 }
496- if (getObject == null ) {
497- CompilerDirectives .transferToInterpreterAndInvalidate ();
498- getObject = insert (GetObjectNodeGen .create ());
499- }
501+ Object object = getObject .executeCached (self );
500502 Object obj ;
501- if (getObjectIsStartObjectProfile .profile (inliningTarget , getObject . executeCached ( self ) == startType )) {
503+ if (getObjectIsStartObjectProfile .profile (inliningTarget , object == startType )) {
502504 obj = PNone .NO_VALUE ;
503505 } else {
504- obj = self . getObject () ;
506+ obj = object ;
505507 }
506508 res = callGetSlotNode .executeCached (frame , resSlots .tp_descr_get (), res , obj , startType );
507509 }
508510 return res ;
509511 }
510512 }
511513
514+ Object object = getObject .executeCached (self );
515+ if (isForeignObjectNode .execute (inliningTarget , object )) {
516+ try {
517+ return foreignGetattrNode .execute (inliningTarget , object , stringAttr );
518+ } catch (PException e ) {
519+ // continue to genericGetAttr()
520+ }
521+ }
522+
512523 return genericGetAttr (frame , self , stringAttr );
513524 }
514525
0 commit comments