Skip to content

Commit 1a32ef4

Browse files
committed
Minor: missing profiles, remove dead code, simplify assertion in addOperatorsToBuiltin
1 parent 1c4ee9a commit 1a32ef4

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/deque/DequeBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ static void rotate(PDeque self, int n) {
671671
@GenerateUncached
672672
public abstract static class DequeLenNode extends LenBuiltinNode {
673673
@Specialization
674-
static int doIt(Object self) {
675-
return ((PDeque) self).getSize();
674+
static int doGeneric(PDeque self) {
675+
return self.getSize();
676676
}
677677
}
678678

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/getsetdescriptor/GetSetDescriptorTypeBuiltins.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import com.oracle.truffle.api.dsl.Specialization;
7777
import com.oracle.truffle.api.frame.VirtualFrame;
7878
import com.oracle.truffle.api.nodes.Node;
79+
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
7980
import com.oracle.truffle.api.strings.TruffleString;
8081

8182
/**
@@ -165,11 +166,13 @@ abstract static class DescrSet extends DescrSetBuiltinNode {
165166
@Specialization(guards = "!isNoValue(value)")
166167
static void doDescriptorSet(VirtualFrame frame, Object descr, Object obj, Object value,
167168
@Bind("this") Node inliningTarget,
169+
@Shared @Cached InlinedConditionProfile isGetSetDescrProfile,
168170
@Shared @Cached DescriptorCheckNode descriptorCheckNode,
169171
@Cached DescrSetNode setNode) {
170172
Object type;
171173
Object name;
172-
if (descr instanceof GetSetDescriptor getSet) {
174+
if (isGetSetDescrProfile.profile(inliningTarget, descr instanceof GetSetDescriptor)) {
175+
GetSetDescriptor getSet = (GetSetDescriptor) descr;
173176
type = getSet.getType();
174177
name = getSet.getName();
175178
} else if (descr instanceof HiddenAttrDescriptor hidden) {
@@ -183,13 +186,15 @@ static void doDescriptorSet(VirtualFrame frame, Object descr, Object obj, Object
183186
}
184187

185188
@Specialization(guards = "isNoValue(value)")
186-
static void doDescriptorDel(VirtualFrame frame, Object descr, Object obj, Object value,
189+
static void doDescriptorDel(VirtualFrame frame, Object descr, Object obj, @SuppressWarnings("unused") Object value,
187190
@Bind("this") Node inliningTarget,
191+
@Shared @Cached InlinedConditionProfile isGetSetDescrProfile,
188192
@Shared @Cached DescriptorCheckNode descriptorCheckNode,
189193
@Cached DescrDeleteNode deleteNode) {
190194
Object type;
191195
Object name;
192-
if (descr instanceof GetSetDescriptor getSet) {
196+
if (isGetSetDescrProfile.profile(inliningTarget, descr instanceof GetSetDescriptor)) {
197+
GetSetDescriptor getSet = (GetSetDescriptor) descr;
193198
type = getSet.getType();
194199
name = getSet.getName();
195200
} else if (descr instanceof HiddenAttrDescriptor hidden) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperBuiltins.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ private Object genericGetAttr(VirtualFrame frame, Object object, Object attr) {
436436
@Specialization
437437
Object get(VirtualFrame frame, SuperObject self, Object attr,
438438
@Bind("this") Node inliningTarget,
439-
@Cached GetClassNode getClassNode,
440439
@Cached GetObjectSlotsNode getSlotsNode,
441440
@Cached TruffleString.EqualNode equalNode,
442441
@Cached GetObjectTypeNode getObjectType,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TpSlots.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,20 @@ public static void setSlots(PythonAbstractClass klass, TpSlots slots) {
801801
}
802802
}
803803

804-
public static void addOperatorsToBuiltin(Map<TruffleString, BoundBuiltinCallable<?>> builtins, Python3Core core, PythonBuiltinClassType type) {
805-
TpSlots slots = type.getDeclaredSlots();
806-
804+
private static boolean checkNoMagicOverrides(PythonBuiltinClassType type) {
807805
// Check that no one is trying to define magic methods directly
808806
// If the assertion fires: you should define @Slot instead of @Builtin
809807
// We do not look in MRO, we may have already called addOperatorsToBuiltin on super
810808
var readAttr = ReadAttributeFromObjectNode.getUncachedForceType();
811-
assert readAttr.execute(type, T___BOOL__) == PNone.NO_VALUE;
812-
assert readAttr.execute(type, T___LEN__) == PNone.NO_VALUE;
813-
assert readAttr.execute(type, T___GET__) == PNone.NO_VALUE;
814-
assert readAttr.execute(type, T___SET__) == PNone.NO_VALUE;
815-
assert readAttr.execute(type, T___DELETE__) == PNone.NO_VALUE;
809+
for (TruffleString name : SPECIAL2SLOT.keySet()) {
810+
assert readAttr.execute(type, name) == PNone.NO_VALUE : name;
811+
}
812+
return true;
813+
}
814+
815+
public static void addOperatorsToBuiltin(Map<TruffleString, BoundBuiltinCallable<?>> builtins, Python3Core core, PythonBuiltinClassType type) {
816+
TpSlots slots = type.getDeclaredSlots();
817+
assert checkNoMagicOverrides(type);
816818

817819
// Similar to CPython:add_operators
818820
for (var slotDefGroup : SLOTDEFS.entrySet()) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ static int doOthers(Frame frame, Node inliningTarget, Object object,
143143
if (slots.sq_length() != null) {
144144
return callSlotLenNode.execute((VirtualFrame) frame, inliningTarget, slots.sq_length(), object);
145145
}
146-
hasNoSqLenBranch.enter(inliningTarget);
147146
throw raiseError(object, inliningTarget, raiseNode, slots);
148147
}
149148

0 commit comments

Comments
 (0)