Skip to content

Commit dc3b6c6

Browse files
committed
Avoid subclasses in WriteAttributeToObjectNode
* Using the correct subclass is prone to errors. * Subclasses prevent host inlining.
1 parent dc57688 commit dc3b6c6

File tree

7 files changed

+86
-167
lines changed

7 files changed

+86
-167
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextBuiltins.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,19 +1014,19 @@ abstract static class PyObjectSetAttrNode extends PNodeWithContext {
10141014

10151015
@Specialization
10161016
static void doBuiltinClass(PythonBuiltinClass object, TruffleString key, Object value,
1017-
@Exclusive @Cached(value = "createForceType()", inline = false) WriteAttributeToObjectNode writeAttrNode) {
1017+
@Exclusive @Cached WriteAttributeToObjectNode writeAttrNode) {
10181018
writeAttrNode.execute(object, key, value);
10191019
}
10201020

10211021
@Specialization
10221022
static void doNativeClass(PythonNativeClass object, TruffleString key, Object value,
1023-
@Exclusive @Cached(value = "createForceType()", inline = false) WriteAttributeToObjectNode writeAttrNode) {
1023+
@Exclusive @Cached WriteAttributeToObjectNode writeAttrNode) {
10241024
writeAttrNode.execute(object, key, value);
10251025
}
10261026

10271027
@Specialization(guards = {"!isPythonBuiltinClass(object)"})
10281028
static void doObject(PythonObject object, TruffleString key, Object value,
1029-
@Exclusive @Cached(inline = false) WriteAttributeToPythonObjectNode writeAttrToPythonObjectNode) {
1029+
@Exclusive @Cached WriteAttributeToPythonObjectNode writeAttrToPythonObjectNode) {
10301030
writeAttrToPythonObjectNode.execute(object, key, value);
10311031
}
10321032
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCArrayTypeBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private static void createGetSet(PythonLanguage language, Object type, NodeFacto
135135
PBuiltinFunction getter = PFactory.createBuiltinFunction(language, name, type, 1, flags, rawCallTarget);
136136
GetSetDescriptor callable = PFactory.createGetSetDescriptor(language, getter, getter, name, type, false);
137137
callable.setAttribute(T___DOC__, toTruffleStringUncached(builtin.doc()));
138-
WriteAttributeToObjectNode.getUncached(true).execute(type, name, callable);
138+
WriteAttributeToObjectNode.getUncached().execute(type, name, callable);
139139
}
140140

141141
@Builtin(name = "raw", minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true, doc = "value")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/LazyPyCSimpleTypeBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private static void addClassMethod(PythonLanguage language, Object type, NodeFac
132132
PBuiltinFunction function = PFactory.createBuiltinFunction(language, name, type, 1, flags, callTarget);
133133
PDecoratedMethod classMethod = PFactory.createClassmethodFromCallableObj(language, function);
134134
function.setAttribute(T___DOC__, builtinDoc);
135-
WriteAttributeToObjectNode.getUncached(true).execute(type, name, classMethod);
135+
WriteAttributeToObjectNode.getUncached().execute(type, name, classMethod);
136136
}
137137

138138
@ImportStatic(CDataTypeBuiltins.class)

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/StructSequence.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public static void initType(PythonContext context, PythonAbstractClass klass, De
182182
unnamedFields++;
183183
}
184184
}
185-
WriteAttributeToObjectNode writeAttrNode = WriteAttributeToObjectNode.getUncached(true);
185+
WriteAttributeToObjectNode writeAttrNode = WriteAttributeToObjectNode.getUncached();
186186
if (klass instanceof PythonManagedClass managedClass) {
187187
/*
188188
* The methods and slots are already set for each PBCT, but we need to store the field
@@ -220,7 +220,7 @@ public static void initType(PythonContext context, PythonAbstractClass klass, De
220220
private static void copyMethod(PythonLanguage language, PythonAbstractClass klass, TruffleString name, PythonBuiltinClass template) {
221221
PBuiltinFunction templateMethod = (PBuiltinFunction) template.getAttribute(name);
222222
PBuiltinFunction method = PFactory.createBuiltinFunction(language, templateMethod, klass);
223-
WriteAttributeToObjectNode.getUncached(true).execute(klass, name, method);
223+
WriteAttributeToObjectNode.getUncached().execute(klass, name, method);
224224
}
225225

226226
private static void createMember(PythonLanguage language, Object klass, TruffleString name, TruffleString doc, int idx) {
@@ -230,7 +230,7 @@ private static void createMember(PythonLanguage language, Object klass, TruffleS
230230
if (doc != null) {
231231
callable.setAttribute(T___DOC__, doc);
232232
}
233-
WriteAttributeToObjectNode.getUncached(true).execute(klass, name, callable);
233+
WriteAttributeToObjectNode.getUncached().execute(klass, name, callable);
234234
}
235235

236236
private static class GetStructMemberNode extends PRootNode {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ static void set(VirtualFrame frame, Object object, Object keyObject, Object valu
622622
@Bind Node inliningTarget,
623623
@Cached CastToTruffleStringChecked0Node castKeyNode,
624624
@Cached ObjectNodes.GenericSetAttrNode genericSetAttrNode,
625-
@Cached("createForceType()") WriteAttributeToObjectNode write) {
625+
@Cached WriteAttributeToObjectNode write) {
626626
TruffleString key = castKeyNode.cast(inliningTarget, keyObject, ATTR_NAME_MUST_BE_STRING);
627627
genericSetAttrNode.execute(inliningTarget, frame, object, key, value, write);
628628
}
@@ -633,7 +633,7 @@ void setBuiltin(Object object, Object key, Object value) {
633633
if (PythonContext.get(this).isInitialized()) {
634634
throw PRaiseNode.raiseStatic(this, TypeError, ErrorMessages.CANT_SET_ATTRIBUTE_R_OF_IMMUTABLE_TYPE_N, PyObjectReprAsTruffleStringNode.executeUncached(key), object);
635635
} else {
636-
set(null, object, key, value, null, CastToTruffleStringChecked0Node.getUncached(), ObjectNodes.GenericSetAttrNode.getUncached(), WriteAttributeToObjectNode.getUncached(true));
636+
set(null, object, key, value, null, CastToTruffleStringChecked0Node.getUncached(), ObjectNodes.GenericSetAttrNode.getUncached(), WriteAttributeToObjectNode.getUncached());
637637
}
638638
}
639639

@@ -953,7 +953,7 @@ static Object getModule(PythonClass cls, @SuppressWarnings("unused") PNone value
953953

954954
@Specialization(guards = "!isNoValue(value)")
955955
static Object setModule(PythonClass cls, Object value,
956-
@Cached WriteAttributeToObjectNode writeAttrNode) {
956+
@Shared @Cached WriteAttributeToObjectNode writeAttrNode) {
957957
writeAttrNode.execute(cls, T___MODULE__, value);
958958
return PNone.NONE;
959959
}
@@ -991,13 +991,13 @@ static Object getModule(PythonAbstractNativeObject cls, @SuppressWarnings("unuse
991991
static Object setNative(PythonAbstractNativeObject cls, Object value,
992992
@Bind Node inliningTarget,
993993
@Shared @Cached GetTypeFlagsNode getFlags,
994-
@Cached("createForceType()") WriteAttributeToObjectNode writeAttr,
994+
@Shared @Cached WriteAttributeToObjectNode writeAttrNode,
995995
@Shared @Cached PRaiseNode raiseNode) {
996996
long flags = getFlags.execute(cls);
997997
if ((flags & TypeFlags.HEAPTYPE) == 0) {
998998
throw raiseNode.raise(inliningTarget, TypeError, ErrorMessages.CANT_SET_N_S, cls, T___MODULE__);
999999
}
1000-
writeAttr.execute(cls, T___MODULE__, value);
1000+
writeAttrNode.execute(cls, T___MODULE__, value);
10011001
return PNone.NONE;
10021002
}
10031003

0 commit comments

Comments
 (0)