Skip to content

Commit eff5432

Browse files
committed
Simplify guards in PyObjetGetMethod
1 parent d3c89a5 commit eff5432

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetMethod.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.oracle.truffle.api.dsl.Bind;
6666
import com.oracle.truffle.api.dsl.Cached;
6767
import com.oracle.truffle.api.dsl.Cached.Shared;
68+
import com.oracle.truffle.api.dsl.Fallback;
6869
import com.oracle.truffle.api.dsl.GenerateUncached;
6970
import com.oracle.truffle.api.dsl.ImportStatic;
7071
import com.oracle.truffle.api.dsl.Specialization;
@@ -105,18 +106,8 @@ protected static boolean isObjectGetAttribute(Object lazyClass) {
105106
return getattributeSlot == BuiltinMethodDescriptors.OBJ_GET_ATTRIBUTE && getattrSlot == PNone.NO_VALUE;
106107
}
107108

108-
@Specialization(guards = {"!isForeignObjectNode.execute(receiver)", "!isObjectGetAttribute(lazyClass)"}, limit = "1")
109-
static Object getGenericAttr(Frame frame, Object receiver, TruffleString name,
110-
@SuppressWarnings("unused") @Shared("isForeign") @Cached IsForeignObjectNode isForeignObjectNode,
111-
@SuppressWarnings("unused") @Shared("getClassNode") @Cached GetClassNode getClass,
112-
@SuppressWarnings("unused") @Bind("getClass.execute(receiver)") Object lazyClass,
113-
@Cached PyObjectGetAttr getAttr) {
114-
return new BoundDescriptor(getAttr.execute(frame, receiver, name));
115-
}
116-
117-
@Specialization(guards = {"!isForeignObjectNode.execute(receiver)", "isObjectGetAttribute(lazyClass)", "name == cachedName"}, limit = "1")
109+
@Specialization(guards = {"isObjectGetAttribute(lazyClass)" /* Implies not foreign */, "name == cachedName"}, limit = "1")
118110
static Object getFixedAttr(VirtualFrame frame, Object receiver, @SuppressWarnings("unused") TruffleString name,
119-
@SuppressWarnings("unused") @Shared("isForeign") @Cached IsForeignObjectNode isForeignObjectNode,
120111
@SuppressWarnings("unused") @Shared("getClassNode") @Cached GetClassNode getClass,
121112
@Bind("getClass.execute(receiver)") Object lazyClass,
122113
@SuppressWarnings("unused") @Cached("name") TruffleString cachedName,
@@ -173,9 +164,8 @@ static Object getFixedAttr(VirtualFrame frame, Object receiver, @SuppressWarning
173164
}
174165

175166
// No explicit branch profiling when we're looking up multiple things
176-
@Specialization(guards = {"!isForeignObjectNode.execute(receiver)", "isObjectGetAttribute(lazyClass)"}, replaces = "getFixedAttr", limit = "1")
167+
@Specialization(guards = "isObjectGetAttribute(lazyClass)" /* Implies not foreign */, replaces = "getFixedAttr", limit = "1")
177168
static Object getDynamicAttr(Frame frame, Object receiver, TruffleString name,
178-
@SuppressWarnings("unused") @Shared("isForeign") @Cached IsForeignObjectNode isForeignObjectNode,
179169
@SuppressWarnings("unused") @Shared("getClassNode") @Cached GetClassNode getClass,
180170
@Bind("getClass.execute(receiver)") Object lazyClass,
181171
@Cached LookupAttributeInMRONode.Dynamic lookupNode,
@@ -217,7 +207,7 @@ static Object getDynamicAttr(Frame frame, Object receiver, TruffleString name,
217207
throw raiseNode.raise(AttributeError, ErrorMessages.OBJ_P_HAS_NO_ATTR_S, receiver, name);
218208
}
219209

220-
@Specialization(guards = "isForeignObjectNode.execute(receiver)", limit = "3")
210+
@Specialization(guards = "isForeignObjectNode.execute(receiver)", limit = "1")
221211
Object getForeignMethod(VirtualFrame frame, Object receiver, TruffleString name,
222212
@SuppressWarnings("unused") @Cached IsForeignObjectNode isForeignObjectNode,
223213
@Cached TruffleString.ToJavaStringNode toJavaString,
@@ -238,4 +228,10 @@ Object getForeignMethod(VirtualFrame frame, Object receiver, TruffleString name,
238228
return new BoundDescriptor(getAttr.execute(frame, receiver, name));
239229
}
240230
}
231+
232+
@Fallback
233+
static Object getGenericAttr(Frame frame, Object receiver, TruffleString name,
234+
@Cached PyObjectGetAttr getAttr) {
235+
return new BoundDescriptor(getAttr.execute(frame, receiver, name));
236+
}
241237
}

0 commit comments

Comments
 (0)