Skip to content

Commit 2f06132

Browse files
committed
minor improvements and fixes
1 parent 1cbe4a6 commit 2f06132

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,13 @@ private Object getId(PythonObject obj) {
755755
if (readId == null) {
756756
CompilerDirectives.transferToInterpreterAndInvalidate();
757757
readId = insert(ReadAttributeFromObjectNode.create());
758-
writeId = insert(WriteAttributeToObjectNode.create());
759758
}
760759
Object id = readId.execute(obj, ID_KEY);
761760
if (id == NO_VALUE) {
761+
if (writeId == null) {
762+
CompilerDirectives.transferToInterpreterAndInvalidate();
763+
writeId = insert(WriteAttributeToObjectNode.create());
764+
}
762765
id = getContext().getNextGlobalId();
763766
writeId.execute(obj, ID_KEY, id);
764767
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
6363
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6464
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
65+
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
66+
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6567
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6668
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6769
import com.oracle.truffle.api.CompilerDirectives;
@@ -255,7 +257,7 @@ private HashingStorageNodes.GetItemNode getGetItemNode() {
255257

256258
@Builtin(name = __GETITEM__, fixedNumOfArguments = 2)
257259
@GenerateNodeFactory
258-
public abstract static class GetItemNode extends PythonBuiltinNode {
260+
public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
259261
@Specialization
260262
Object getItem(PDict self, Object key,
261263
@Cached("create()") HashingStorageNodes.GetItemNode getItemNode,
@@ -297,7 +299,7 @@ Object run(Object self, Object key,
297299

298300
@Builtin(name = __SETITEM__, fixedNumOfArguments = 3)
299301
@GenerateNodeFactory
300-
public abstract static class SetItemNode extends PythonBuiltinNode {
302+
public abstract static class SetItemNode extends PythonTernaryBuiltinNode {
301303
@Specialization
302304
Object run(PDict self, Object key, Object value,
303305
@Cached("create()") HashingStorageNodes.SetItemNode setItemNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/MappingproxyBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4848
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
4949
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
50+
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
5051
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
5152
import com.oracle.truffle.api.CompilerDirectives;
5253
import com.oracle.truffle.api.dsl.Cached;
@@ -144,7 +145,7 @@ private HashingStorageNodes.GetItemNode getGetItemNode() {
144145

145146
@Builtin(name = __GETITEM__, fixedNumOfArguments = 2)
146147
@GenerateNodeFactory
147-
public abstract static class GetItemNode extends PythonBuiltinNode {
148+
public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
148149
@Specialization
149150
Object getItem(PMappingproxy self, Object key,
150151
@Cached("create()") HashingStorageNodes.GetItemNode getItemNode) {
@@ -158,7 +159,7 @@ Object getItem(PMappingproxy self, Object key,
158159

159160
@Builtin(name = __SETITEM__, fixedNumOfArguments = 3)
160161
@GenerateNodeFactory
161-
public abstract static class SetItemNode extends PythonBuiltinNode {
162+
public abstract static class SetItemNode extends PythonTernaryBuiltinNode {
162163
@Specialization
163164
@SuppressWarnings("unused")
164165
Object run(PMappingproxy self, Object key, Object value) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
5858
import com.oracle.graal.python.builtins.objects.function.PKeyword;
5959
import com.oracle.graal.python.builtins.objects.function.PythonCallable;
60-
import com.oracle.graal.python.builtins.objects.mappingproxy.PMappingproxy;
6160
import com.oracle.graal.python.builtins.objects.type.PythonClass;
6261
import com.oracle.graal.python.nodes.SpecialMethodNames;
6362
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
@@ -87,7 +86,6 @@
8786
import com.oracle.truffle.api.nodes.UnexpectedResultException;
8887
import com.oracle.truffle.api.profiles.BranchProfile;
8988
import com.oracle.truffle.api.profiles.ConditionProfile;
90-
import com.oracle.truffle.api.profiles.ValueProfile;
9189

9290
@CoreFunctions(extendClasses = PythonObject.class)
9391
public class ObjectBuiltins extends PythonBuiltins {
@@ -224,16 +222,15 @@ private LookupAndCallBinaryNode getCallEqNode() {
224222

225223
@Builtin(name = __GETATTRIBUTE__, fixedNumOfArguments = 2)
226224
@GenerateNodeFactory
227-
public abstract static class GetattributeNode extends PythonBinaryBuiltinNode {
225+
public abstract static class GetAttributeNode extends PythonBinaryBuiltinNode {
228226
private final BranchProfile hasDescProfile = BranchProfile.create();
229227
private final BranchProfile isDescProfile = BranchProfile.create();
230228
private final BranchProfile hasValueProfile = BranchProfile.create();
231229
private final BranchProfile errorProfile = BranchProfile.create();
232230
private final ConditionProfile typeIsObjectProfile = ConditionProfile.createBinaryProfile();
233231

234232
@Child private LookupAttributeInMRONode.Dynamic lookup = LookupAttributeInMRONode.Dynamic.create();
235-
private final ValueProfile typeProfile = ValueProfile.createIdentityProfile();
236-
@Child private GetClassNode getObjectClassNode;
233+
@Child private GetClassNode getObjectClassNode = GetClassNode.create();
237234
@Child private GetClassNode getDataClassNode;
238235
@Child private LookupAttributeInMRONode lookupGetNode;
239236
@Child private LookupAttributeInMRONode lookupSetNode;
@@ -244,7 +241,7 @@ public abstract static class GetattributeNode extends PythonBinaryBuiltinNode {
244241

245242
@Specialization
246243
protected Object doIt(Object object, Object key) {
247-
PythonClass type = getObjectClass(object);
244+
PythonClass type = getObjectClassNode.execute(object);
248245
Object descr = lookup.execute(type, key);
249246
PythonClass dataDescClass = null;
250247
if (descr != PNone.NO_VALUE) {
@@ -338,14 +335,6 @@ private Object lookupSet(PythonClass dataDescClass) {
338335
return lookupSetNode.execute(dataDescClass);
339336
}
340337

341-
private PythonClass getObjectClass(Object object) {
342-
if (getObjectClassNode == null) {
343-
CompilerDirectives.transferToInterpreterAndInvalidate();
344-
getObjectClassNode = insert(GetClassNode.create());
345-
}
346-
return typeProfile.profile(getObjectClassNode.execute(object));
347-
}
348-
349338
private PythonClass getDataClass(Object descr) {
350339
if (getDataClassNode == null) {
351340
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)