Skip to content

Commit b4bc279

Browse files
[GR-30326] Frame read/write access needs to pass through DSL execute dispatch.
PullRequest: graalpython/1722
2 parents da4903c + 61148be commit b4bc279

17 files changed

+75
-155
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ModuleRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ public Object execute(VirtualFrame frame) {
9494
public void initializeFrame(VirtualFrame frame) {
9595
addClosureCellsToLocals(frame);
9696
if (doc != null) {
97-
getWriteModuleDoc().writeObject(frame, doc);
97+
getWriteModuleDoc().executeObject(frame, doc);
9898
}
9999
if (hasAnnotations()) {
100-
getWriteAnnotations().writeObject(frame, new PDict(lookupLanguageReference(PythonLanguage.class).get()));
100+
getWriteAnnotations().executeObject(frame, new PDict(lookupLanguageReference(PythonLanguage.class).get()));
101101
}
102102
}
103103

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/SetAttributeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static SetAttributeNode create(String key, ExpressionNode object, Express
8787
}
8888

8989
@Override
90-
public final void writeObject(VirtualFrame frame, Object value) {
90+
public final void executeObject(VirtualFrame frame, Object value) {
9191
executeVoid(frame, getObject().execute(frame), value);
9292
}
9393

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/cell/WriteLocalCellNode.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ public static WriteLocalCellNode create(FrameSlot frameSlot, ExpressionNode read
6161
return WriteLocalCellNodeGen.create(frameSlot, readLocal, right);
6262
}
6363

64-
@Override
65-
public void writeObject(VirtualFrame frame, Object value) {
66-
executeWithValue(frame, value);
67-
}
68-
69-
public abstract void executeWithValue(VirtualFrame frame, Object value);
64+
public abstract void executeObject(VirtualFrame frame, Object value);
7065

7166
@Specialization
7267
void writeObject(VirtualFrame frame, Object value,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/classes/ReadClassAttributeNode.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Object read(VirtualFrame frame,
133133
}
134134
}
135135

136-
private static class WriteClassAttributeCellNode extends StatementNode implements WriteNode {
136+
private static final class WriteClassAttributeCellNode extends StatementNode implements WriteNode {
137137
@Child private WriteNode writeCellLocal;
138138
@Child private WriteNode writeNsItem;
139139
@Child private ExpressionNode right;
@@ -148,15 +148,34 @@ public ExpressionNode getRhs() {
148148
return right;
149149
}
150150

151-
public void writeObject(VirtualFrame frame, Object value) {
152-
writeCellLocal.writeObject(frame, value);
153-
writeNsItem.writeObject(frame, value);
151+
public void executeObject(VirtualFrame frame, Object value) {
152+
writeCellLocal.executeObject(frame, value);
153+
writeNsItem.executeObject(frame, value);
154154
}
155155

156156
@Override
157157
public void executeVoid(VirtualFrame frame) {
158-
Object value = right.execute(frame);
159-
writeObject(frame, value);
158+
executeObject(frame, right.execute(frame));
159+
}
160+
161+
public void executeBoolean(VirtualFrame frame, boolean value) {
162+
writeCellLocal.executeBoolean(frame, value);
163+
writeNsItem.executeBoolean(frame, value);
164+
}
165+
166+
public void executeInt(VirtualFrame frame, int value) {
167+
writeCellLocal.executeInt(frame, value);
168+
writeNsItem.executeInt(frame, value);
169+
}
170+
171+
public void executeLong(VirtualFrame frame, long value) {
172+
writeCellLocal.executeLong(frame, value);
173+
writeNsItem.executeLong(frame, value);
174+
}
175+
176+
public void executeDouble(VirtualFrame frame, double value) {
177+
writeCellLocal.executeDouble(frame, value);
178+
writeNsItem.executeDouble(frame, value);
160179
}
161180
}
162181
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/ForNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ protected boolean doIntegerIterator(VirtualFrame frame, PIntegerIterator iterato
109109
profiledIterator.setExhausted();
110110
return false;
111111
}
112-
((WriteNode) target).writeInt(frame, profiledIterator.next());
112+
((WriteNode) target).executeInt(frame, profiledIterator.next());
113113
return true;
114114
}
115115

@@ -120,7 +120,7 @@ protected boolean doLongIterator(VirtualFrame frame, PLongSequenceIterator itera
120120
iterator.setExhausted();
121121
return false;
122122
}
123-
((WriteNode) target).writeLong(frame, iterator.next());
123+
((WriteNode) target).executeLong(frame, iterator.next());
124124
return true;
125125
}
126126

@@ -131,7 +131,7 @@ protected boolean doDoubleIterator(VirtualFrame frame, PDoubleSequenceIterator i
131131
iterator.setExhausted();
132132
return false;
133133
}
134-
((WriteNode) target).writeDouble(frame, iterator.next());
134+
((WriteNode) target).executeDouble(frame, iterator.next());
135135
return true;
136136
}
137137

@@ -141,7 +141,7 @@ protected boolean doIterator(VirtualFrame frame, Object object,
141141
@Cached("create()") IsBuiltinClassProfile errorProfile,
142142
@Cached PRaiseNode raise) {
143143
try {
144-
((WriteNode) target).writeObject(frame, next.execute(frame, object));
144+
((WriteNode) target).executeObject(frame, next.execute(frame, object));
145145
return true;
146146
} catch (PException e) {
147147
e.expectStopIteration(errorProfile, raise, object);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/DestructuringAssignmentNode.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ public static DestructuringAssignmentNode create(ExpressionNode rhs, ReadNode[]
7373
return DestructuringAssignmentNodeGen.create(rhs, slots, starredIndex, assignments);
7474
}
7575

76-
public abstract void executeWith(VirtualFrame frame, Object rhsValue);
76+
public abstract void executeObject(VirtualFrame frame, Object rhsValue);
7777

7878
@Override
7979
public final void executeVoid(VirtualFrame frame) {
8080
Object rhsValue = rhs.execute(frame);
81-
executeWith(frame, rhsValue);
81+
executeObject(frame, rhsValue);
8282
}
8383

8484
public final void writeObject(VirtualFrame frame, Object rhsValue) {
85-
executeWith(frame, rhsValue);
85+
executeObject(frame, rhsValue);
8686
}
8787

8888
public ExpressionNode getRhs() {
@@ -128,7 +128,7 @@ private void writeSequenceStorage(VirtualFrame frame, SequenceStorage sequenceSt
128128
} else {
129129
for (int i = 0; i < slots.length; i++) {
130130
Object value = getItemNode.execute(frame, sequenceStorage, i);
131-
slots[i].writeObject(frame, value);
131+
slots[i].executeObject(frame, value);
132132
}
133133
}
134134
}
@@ -217,7 +217,7 @@ void doExploded(VirtualFrame frame, SequenceStorage storage, WriteNode[] slots,
217217
CompilerAsserts.partialEvaluationConstant(starredLength);
218218
Object[] array = consumeStarredItems(frame, storage, starredLength, getItemNode, starredIndex);
219219
assert starredLength == array.length;
220-
slots[starredIndex].writeObject(frame, factory().createList(array));
220+
slots[starredIndex].executeObject(frame, factory().createList(array));
221221
performAssignmentsAfterStar(frame, storage, starredIndex + starredLength, getItemNode, slots, starredIndex);
222222
}
223223
}
@@ -239,10 +239,10 @@ void doGeneric(VirtualFrame frame, SequenceStorage storage, WriteNode[] slots, i
239239
for (int i = 0; i < starredLength; i++) {
240240
array[i] = getItemNode.execute(frame, storage, pos++);
241241
}
242-
slots[starredIndex].writeObject(frame, factory().createList(array));
242+
slots[starredIndex].executeObject(frame, factory().createList(array));
243243
for (int i = starredIndex + 1; i < slots.length; i++) {
244244
Object value = getItemNode.execute(frame, storage, pos++);
245-
slots[i].writeObject(frame, value);
245+
slots[i].executeObject(frame, value);
246246
}
247247
}
248248
}
@@ -251,7 +251,7 @@ void doGeneric(VirtualFrame frame, SequenceStorage storage, WriteNode[] slots, i
251251
private static void writeSlots(VirtualFrame frame, SequenceStorage storage, SequenceStorageNodes.GetItemNode getItemNode, WriteNode[] slots, int starredIndex) {
252252
for (int i = 0; i < starredIndex; i++) {
253253
Object value = getItemNode.execute(frame, storage, i);
254-
slots[i].writeObject(frame, value);
254+
slots[i].executeObject(frame, value);
255255
}
256256
}
257257

@@ -270,7 +270,7 @@ private static void performAssignmentsAfterStar(VirtualFrame frame, SequenceStor
270270
int starredIndex) {
271271
for (int i = starredIndex + 1, pos = startPos; i < slots.length; i++, pos++) {
272272
Object value = getItemNode.execute(frame, sequenceStorage, pos);
273-
slots[i].writeObject(frame, value);
273+
slots[i].executeObject(frame, value);
274274
}
275275
}
276276

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/WriteGlobalNode.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,6 @@ public static WriteGlobalNode create(String attributeId, ExpressionNode rhs) {
7373
return WriteGlobalNodeGen.create(attributeId, rhs);
7474
}
7575

76-
public void writeBoolean(VirtualFrame frame, boolean value) {
77-
executeWithValue(frame, value);
78-
}
79-
80-
public void writeInt(VirtualFrame frame, int value) {
81-
executeWithValue(frame, value);
82-
}
83-
84-
public void writeLong(VirtualFrame frame, long value) {
85-
executeWithValue(frame, value);
86-
}
87-
88-
public void writeDouble(VirtualFrame frame, double value) {
89-
executeWithValue(frame, value);
90-
}
91-
92-
public void writeObject(VirtualFrame frame, Object value) {
93-
executeWithValue(frame, value);
94-
}
95-
96-
public abstract void executeWithValue(VirtualFrame frame, boolean value);
97-
98-
public abstract void executeWithValue(VirtualFrame frame, int value);
99-
100-
public abstract void executeWithValue(VirtualFrame frame, long value);
101-
102-
public abstract void executeWithValue(VirtualFrame frame, double value);
103-
104-
public abstract void executeWithValue(VirtualFrame frame, Object value);
105-
10676
private static PDict getGlobalsDict(VirtualFrame frame) {
10777
return (PDict) PArguments.getGlobals(frame);
10878
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/WriteLocalVariableNode.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.oracle.truffle.api.dsl.Specialization;
3333
import com.oracle.truffle.api.frame.FrameSlot;
3434
import com.oracle.truffle.api.frame.VirtualFrame;
35-
import com.oracle.truffle.api.nodes.NodeCost;
3635
import com.oracle.truffle.api.nodes.NodeInfo;
3736

3837
@NodeInfo(shortName = "write_local")
@@ -68,38 +67,28 @@ public final Object getIdentifier() {
6867
}
6968

7069
@Specialization(guards = "isBooleanKind(frame, frameSlot)")
71-
@Override
72-
public void writeBoolean(VirtualFrame frame, boolean value) {
70+
void writeBoolean(VirtualFrame frame, boolean value) {
7371
frame.setBoolean(frameSlot, value);
7472
}
7573

7674
@Specialization(guards = "isIntegerKind(frame, frameSlot)")
77-
@Override
78-
public void writeInt(VirtualFrame frame, int value) {
75+
void writeInt(VirtualFrame frame, int value) {
7976
frame.setInt(frameSlot, value);
8077
}
8178

8279
@Specialization(guards = "isLongKind(frame, frameSlot)")
83-
@Override
84-
public void writeLong(VirtualFrame frame, long value) {
80+
void writeLong(VirtualFrame frame, long value) {
8581
frame.setLong(frameSlot, value);
8682
}
8783

8884
@Specialization(guards = "isDoubleKind(frame, frameSlot)")
89-
@Override
90-
public void writeDouble(VirtualFrame frame, double value) {
85+
void writeDouble(VirtualFrame frame, double value) {
9186
frame.setDouble(frameSlot, value);
9287
}
9388

9489
@Specialization(replaces = {"writeBoolean", "writeInt", "writeDouble", "writeLong"})
95-
@Override
96-
public void writeObject(VirtualFrame frame, Object value) {
90+
void writeObject(VirtualFrame frame, Object value) {
9791
FrameSlotGuards.ensureObjectKind(frame, frameSlot);
9892
frame.setObject(frameSlot, value);
9993
}
100-
101-
@Override
102-
public NodeCost getCost() {
103-
return NodeCost.NONE;
104-
}
10594
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/WriteNameNode.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -80,42 +80,12 @@ protected void writeLocal(VirtualFrame frame, Object value,
8080
}
8181

8282
@Specialization(guards = "!hasLocals(frame)")
83-
protected void writeGlobal(VirtualFrame frame, Object value,
83+
protected static void writeGlobal(VirtualFrame frame, Object value,
8484
@Cached("create(attributeId)") WriteGlobalNode setItem) {
85-
setItem.executeWithValue(frame, value);
85+
setItem.executeObject(frame, value);
8686
}
8787

88-
public void writeBoolean(VirtualFrame frame, boolean value) {
89-
executeWithValue(frame, value);
90-
}
91-
92-
public void writeInt(VirtualFrame frame, int value) {
93-
executeWithValue(frame, value);
94-
}
95-
96-
public void writeLong(VirtualFrame frame, long value) {
97-
executeWithValue(frame, value);
98-
}
99-
100-
public void writeDouble(VirtualFrame frame, double value) {
101-
executeWithValue(frame, value);
102-
}
103-
104-
public void writeObject(VirtualFrame frame, Object value) {
105-
executeWithValue(frame, value);
106-
}
107-
108-
public abstract void executeWithValue(VirtualFrame frame, boolean value);
109-
110-
public abstract void executeWithValue(VirtualFrame frame, int value);
111-
112-
public abstract void executeWithValue(VirtualFrame frame, long value);
113-
114-
public abstract void executeWithValue(VirtualFrame frame, double value);
115-
116-
public abstract void executeWithValue(VirtualFrame frame, Object value);
117-
118-
public String getAttributeId() {
88+
public final String getAttributeId() {
11989
return attributeId;
12090
}
12191
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/frame/WriteNode.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,13 @@ public interface WriteNode extends NodeInterface {
3333

3434
ExpressionNode getRhs();
3535

36-
default void writeBoolean(VirtualFrame frame, boolean value) {
37-
writeObject(frame, value);
38-
}
36+
void executeBoolean(VirtualFrame frame, boolean value);
3937

40-
default void writeInt(VirtualFrame frame, int value) {
41-
writeObject(frame, value);
42-
}
38+
void executeInt(VirtualFrame frame, int value);
4339

44-
default void writeLong(VirtualFrame frame, long value) {
45-
writeObject(frame, value);
46-
}
40+
void executeLong(VirtualFrame frame, long value);
4741

48-
default void writeDouble(VirtualFrame frame, double value) {
49-
writeObject(frame, value);
50-
}
42+
void executeDouble(VirtualFrame frame, double value);
5143

52-
void writeObject(VirtualFrame frame, Object value);
44+
void executeObject(VirtualFrame frame, Object value);
5345
}

0 commit comments

Comments
 (0)