Skip to content

Commit 8a832a0

Browse files
committed
Refactor according to gates.
- Fix: `IsNotTypeSlot` check in `PyObjectLookupAttr` contained a boolean logic error which led to viewing every attribute not named "mro" as a non-type-slot attribute. It has now been converted into the easier readable `IsTypeSlot`. - Update: For the comparison to the string constant marker `NOT_SET` an object identity check is applicable (as argued in previous commits), the `Object.equals()` check which implements this without the compiler warning of a String comparison with `==` needs to be moved behind a Truffle boundary.
1 parent e091a56 commit 8a832a0

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import com.oracle.graal.python.nodes.util.CannotCastException;
8383
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
8484
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
85+
import com.oracle.graal.python.util.PythonUtils;
8586
import com.oracle.truffle.api.dsl.Cached;
8687
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8788
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -202,7 +203,6 @@ public abstract static class CSVListDialectsNode extends PythonBuiltinNode {
202203
@Specialization
203204
PList listDialects(VirtualFrame frame, PythonModule module,
204205
@Cached ReadAttributeFromObjectNode readNode,
205-
@CachedLibrary(limit = "1") HashingStorageLibrary library,
206206
@Cached ListNodes.ConstructListNode constructListNode) {
207207

208208
Object dialects = readNode.execute(module, "_dialects");
@@ -543,9 +543,8 @@ private String getCharOrNone(String attribute, Object valueObj, String defaultVa
543543
if (valueObj == PNone.NO_VALUE) {
544544
return defaultValue;
545545
}
546-
if (valueObj == PNone.NONE || valueObj == NOT_SET) {
546+
if (valueObj == PNone.NONE || PythonUtils.equals(valueObj, NOT_SET)) {
547547
return NOT_SET;
548-
549548
}
550549

551550
return getChar(attribute, valueObj, defaultValue, getType, castToJavaStringNode);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ protected static final boolean isBuiltinTypeType(Object type) {
122122
return type == PythonBuiltinClassType.PythonClass;
123123
}
124124

125-
protected static final boolean isNotTypeSlot(String name) {
126-
final int length = name.length();
127-
return length < 3 || (length > 3 && name.charAt(0) != '_') || !name.equals("mro");
125+
protected static final boolean isTypeSlot(String name) {
126+
return SpecialMethodSlot.canBeSpecial(name) || name.equals("mro");
128127
}
129128

130129
// simple version that needs no calls and only reads from the object directly
@@ -179,7 +178,7 @@ static final Object doBuiltinModule(VirtualFrame frame, Object object, String na
179178
// difference for type.__getattribute__ over object.__getattribute__ is that it looks for a
180179
// __get__ method on the value and invokes it if it is callable.
181180
@SuppressWarnings("unused")
182-
@Specialization(guards = {"isTypeGetAttribute(type)", "isBuiltinTypeType(type)", "isNotTypeSlot(name)"}, limit = "1")
181+
@Specialization(guards = {"isTypeGetAttribute(type)", "isBuiltinTypeType(type)", "!isTypeSlot(name)"}, limit = "1")
183182
static final Object doBuiltinTypeType(VirtualFrame frame, Object object, String name,
184183
@Cached GetClassNode getClass,
185184
@Bind("getClass.execute(object)") Object type,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ public static boolean bufferHasRemaining(ByteBuffer buffer) {
586586
return buffer.hasRemaining();
587587
}
588588

589+
@TruffleBoundary(allowInlining = true)
590+
public static boolean equals(Object a, Object b) {
591+
return a.equals(b);
592+
}
593+
589594
@TruffleBoundary
590595
public static <E> ArrayDeque<E> newDeque() {
591596
return new ArrayDeque<>();

0 commit comments

Comments
 (0)