Skip to content

Commit 01e7d58

Browse files
committed
[GR-69321] Fix bad compilations with settrace
PullRequest: graalpython/3984
2 parents 6918807 + da22a8d commit 01e7d58

File tree

7 files changed

+180
-140
lines changed

7 files changed

+180
-140
lines changed

.github/workflows/downstream-tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ jobs:
3434
3535
- name: Install CMake (Darwin)
3636
if: ${{ matrix.os.platform == 'darwin' && matrix.name == 'pybind11' }}
37-
run: brew install cmake
37+
run: |
38+
if brew list cmake >/dev/null 2>&1; then
39+
echo "cmake already installed"
40+
else
41+
brew install cmake
42+
fi
3843
3944
- name: Install Rust toolchain
4045
if: ${{ matrix.name == 'pyo3' || matrix.name == 'pydantic-core' || matrix.name == 'jiter' }}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/FrameBuiltins.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ Object getUpdating(VirtualFrame frame, PFrame self,
306306
PFrame pyFrame = materializeNode.executeOnStack(false, true, frame);
307307
assert pyFrame == self;
308308
}
309-
return getFrameLocalsNode.execute(inliningTarget, self);
309+
Object locals = getFrameLocalsNode.execute(inliningTarget, self);
310+
self.setLocalsAccessed(true);
311+
return locals;
310312
}
311313
}
312314

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/frame/PFrame.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public final class PFrame extends PythonBuiltinObject {
8686
public static final int NO_JUMP = -2;
8787
private int jumpDestLine = DISALLOW_JUMPS;
8888
private Object localTraceFun = null;
89+
private boolean localsAccessed;
8990

9091
private boolean traceLine = true;
9192

@@ -119,6 +120,14 @@ public void setJumpDestLine(int jumpDestLine) {
119120
this.jumpDestLine = jumpDestLine;
120121
}
121122

123+
public boolean localsAccessed() {
124+
return localsAccessed;
125+
}
126+
127+
public void setLocalsAccessed(boolean localsAccessed) {
128+
this.localsAccessed = localsAccessed;
129+
}
130+
122131
// TODO: frames: this is a large object, think about how to make this
123132
// smaller
124133
public static final class Reference {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 149 additions & 94 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.oracle.graal.python.nodes.bytecode_dsl.PBytecodeDSLRootNode;
5656
import com.oracle.graal.python.runtime.PythonOptions;
5757
import com.oracle.graal.python.runtime.object.PFactory;
58+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5859
import com.oracle.truffle.api.bytecode.BytecodeNode;
5960
import com.oracle.truffle.api.dsl.Bind;
6061
import com.oracle.truffle.api.dsl.Cached;
@@ -206,7 +207,7 @@ private static void copyLocalsArray(Frame localFrame, PRootNode root, PDict loca
206207
BytecodeNode bytecodeNode = bytecodeDSLRootNode.getBytecodeNode();
207208
for (int i = 0; i < namesArray.length; i++) {
208209
TruffleString varname = namesArray[i];
209-
Object value = PyDictGetItem.executeUncached(localsDict, varname);
210+
Object value = getDictItemUncached(localsDict, varname);
210211
if (deref) {
211212
PCell cell = (PCell) bytecodeNode.getLocalValue(0, localFrame, offset + i);
212213
cell.setRef(value);
@@ -217,7 +218,7 @@ private static void copyLocalsArray(Frame localFrame, PRootNode root, PDict loca
217218
} else {
218219
for (int i = 0; i < namesArray.length; i++) {
219220
TruffleString varname = namesArray[i];
220-
Object value = PyDictGetItem.executeUncached(localsDict, varname);
221+
Object value = getDictItemUncached(localsDict, varname);
221222
if (deref) {
222223
PCell cell = (PCell) localFrame.getObject(offset + i);
223224
cell.setRef(value);
@@ -228,6 +229,11 @@ private static void copyLocalsArray(Frame localFrame, PRootNode root, PDict loca
228229
}
229230
}
230231

232+
@TruffleBoundary
233+
private static Object getDictItemUncached(PDict localsDict, TruffleString varname) {
234+
return PyDictGetItem.executeUncached(localsDict, varname);
235+
}
236+
231237
@NeverDefault
232238
public static GetFrameLocalsNode create() {
233239
return GetFrameLocalsNodeGen.create();

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,9 @@ public abstract static class SyncFrameValuesNode extends Node {
236236
public abstract void execute(PFrame pyFrame, Frame frameToSync);
237237

238238
@Specialization(guards = {"!pyFrame.hasCustomLocals()",
239-
"frameToSync.getFrameDescriptor() == cachedFd",
240-
"variableSlotCount(cachedFd) < 32"}, limit = "1")
239+
"frameToSync.getFrameDescriptor() == cachedFd"}, limit = "1")
241240
@ExplodeLoop
242-
static void doSyncExploded(PFrame pyFrame, Frame frameToSync,
241+
static void doSyncCached(PFrame pyFrame, Frame frameToSync,
243242
@Cached(value = "frameToSync.getFrameDescriptor()") FrameDescriptor cachedFd) {
244243
MaterializedFrame target = pyFrame.getLocals();
245244
assert cachedFd == target.getFrameDescriptor();
@@ -252,30 +251,14 @@ static void doSyncExploded(PFrame pyFrame, Frame frameToSync,
252251
rootNode.getBytecodeNode().copyLocalValues(0, frameToSync, target, 0, slotCount);
253252
}
254253
} else {
255-
for (int i = 0; i < slotCount; i++) {
256-
PythonUtils.copyFrameSlot(frameToSync, target, i);
257-
}
254+
frameToSync.copyTo(0, target, 0, slotCount);
258255
}
259256
}
260257

261-
@Specialization(guards = "!pyFrame.hasCustomLocals()", replaces = "doSyncExploded")
258+
@Specialization(guards = "!pyFrame.hasCustomLocals()", replaces = "doSyncCached")
262259
@ExplodeLoop
263260
static void doSync(PFrame pyFrame, Frame frameToSync) {
264-
MaterializedFrame target = pyFrame.getLocals();
265-
FrameDescriptor fd = target.getFrameDescriptor();
266-
int slotCount = variableSlotCount(fd);
267-
268-
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
269-
FrameInfo info = (FrameInfo) fd.getInfo();
270-
if (info instanceof BytecodeDSLFrameInfo bytecodeDSLFrameInfo) {
271-
PBytecodeDSLRootNode rootNode = bytecodeDSLFrameInfo.getRootNode();
272-
rootNode.getBytecodeNode().copyLocalValues(0, frameToSync, target, 0, slotCount);
273-
}
274-
} else {
275-
for (int i = 0; i < slotCount; i++) {
276-
PythonUtils.copyFrameSlot(frameToSync, target, i);
277-
}
278-
}
261+
doSyncCached(pyFrame, frameToSync, frameToSync.getFrameDescriptor());
279262
}
280263

281264
@Specialization(guards = "pyFrame.hasCustomLocals()")

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@
9292
import com.oracle.truffle.api.TruffleOptions;
9393
import com.oracle.truffle.api.dsl.GeneratedBy;
9494
import com.oracle.truffle.api.dsl.NodeFactory;
95-
import com.oracle.truffle.api.frame.Frame;
96-
import com.oracle.truffle.api.frame.MaterializedFrame;
9795
import com.oracle.truffle.api.interop.InteropLibrary;
9896
import com.oracle.truffle.api.interop.UnsupportedMessageException;
9997
import com.oracle.truffle.api.memory.ByteArraySupport;
@@ -742,24 +740,6 @@ public static Unsafe initUnsafe() {
742740
}
743741
}
744742

745-
public static void copyFrameSlot(Frame frameToSync, MaterializedFrame target, int slot) {
746-
if (frameToSync.isObject(slot)) {
747-
target.setObject(slot, frameToSync.getObject(slot));
748-
} else if (frameToSync.isInt(slot)) {
749-
target.setInt(slot, frameToSync.getInt(slot));
750-
} else if (frameToSync.isLong(slot)) {
751-
target.setLong(slot, frameToSync.getLong(slot));
752-
} else if (frameToSync.isBoolean(slot)) {
753-
target.setBoolean(slot, frameToSync.getBoolean(slot));
754-
} else if (frameToSync.isDouble(slot)) {
755-
target.setDouble(slot, frameToSync.getDouble(slot));
756-
} else if (frameToSync.isFloat(slot)) {
757-
target.setFloat(slot, frameToSync.getFloat(slot));
758-
} else if (frameToSync.isByte(slot)) {
759-
target.setByte(slot, frameToSync.getByte(slot));
760-
}
761-
}
762-
763743
public static TruffleString[] objectArrayToTruffleStringArray(Node inliningTarget, Object[] array, CastToTruffleStringNode cast) {
764744
if (array.length == 0) {
765745
return EMPTY_TRUFFLESTRING_ARRAY;

0 commit comments

Comments
 (0)