Skip to content

Commit

Permalink
Fix some failing tests; remove root node comparison in MaterializeFra…
Browse files Browse the repository at this point in the history
…meNode; fix runtime compilation of SyncFrameValuesNode
  • Loading branch information
DSouzaM committed Mar 20, 2024
1 parent ed50e8f commit b2cff2d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
ARGS = []
if sys.implementation.name == 'graalpy':
ARGS = ['--python.EnableDebuggingBuiltins']
if not __graalpython__.is_native and __graalpython__.is_bytecode_dsl_interpreter:
ARGS += ['--vm.Dpython.EnableBytecodeDSLInterpreter=true']
COMMAND = [sys.executable, *ARGS, str(MODULE_PATH)]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ def test_load_default_verify_keystore():
""")
env = os.environ.copy()
env['JAVA_TOOL_OPTIONS'] = f"-Djavax.net.ssl.trustStore={curdir}/ssldata/signing_keystore.jks"
subprocess.run([sys.executable, '-c', src], env=env, check=True)

args = []
if __graalpython__.is_bytecode_dsl_interpreter:
args += ['--vm.Dpython.EnableBytecodeDSLInterpreter=true']

subprocess.run([sys.executable, *args, '-c', src], env=env, check=True)
Original file line number Diff line number Diff line change
Expand Up @@ -3095,11 +3095,11 @@ public static void doEnter(VirtualFrame frame, Object contextManager,
Object type = getClass.execute(inliningTarget, contextManager);
Object enter = lookupEnter.execute(frame, type, contextManager);
if (enter == PNone.NO_VALUE) {
throw raiseNode.get(inliningTarget).raise(AttributeError, new Object[]{T___ENTER__});
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL, type);
}
Object exit = lookupExit.execute(frame, type, contextManager);
if (exit == PNone.NO_VALUE) {
throw raiseNode.get(inliningTarget).raise(AttributeError, new Object[]{T___EXIT__});
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.N_OBJECT_DOES_NOT_SUPPORT_CONTEXT_MANAGER_PROTOCOL_EXIT, type);
}
Object result = callEnter.executeObject(frame, enter, contextManager);
exitSetter.setObject(frame, exit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import com.oracle.graal.python.runtime.PythonOptions;
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
import com.oracle.graal.python.util.PythonUtils;
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.bytecode.BytecodeLocation;
import com.oracle.truffle.api.bytecode.BytecodeNode;
import com.oracle.truffle.api.dsl.Bind;
import com.oracle.truffle.api.dsl.Cached;
Expand Down Expand Up @@ -180,13 +180,6 @@ private static void processBytecodeFrame(Frame frameToMaterialize, PFrame pyFram
return;
}
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
BytecodeDSLFrameInfo bytecodeDSLFrameInfo = (BytecodeDSLFrameInfo) info;
PBytecodeDSLRootNode rootNode = bytecodeDSLFrameInfo.getRootNode();

if (location.getRootNode() != rootNode) {
throw new AssertionError("A node that did not belong to this root node was passed as a location.");
}

if (location instanceof PBytecodeDSLRootNode) {
/**
* Sometimes we don't have a precise location (see
Expand Down Expand Up @@ -248,20 +241,45 @@ public abstract static class SyncFrameValuesNode extends Node {

public abstract void execute(PFrame pyFrame, Frame frameToSync);

@Specialization(guards = {"!pyFrame.hasCustomLocals()", "frameToSync.getFrameDescriptor() == cachedFd",
@Specialization(guards = {"!pyFrame.hasCustomLocals()",
"frameToSync.getFrameDescriptor() == cachedFd",
"variableSlotCount(cachedFd) < 32"}, limit = "1")
@ExplodeLoop
static void doSyncExploded(PFrame pyFrame, Frame frameToSync,
@Cached(value = "frameToSync.getFrameDescriptor()") FrameDescriptor cachedFd) {
MaterializedFrame target = pyFrame.getLocals();
assert cachedFd == target.getFrameDescriptor();
doCopy(cachedFd, frameToSync, target);
int slotCount = variableSlotCount(cachedFd);

if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
FrameInfo info = (FrameInfo) cachedFd.getInfo();
if (info instanceof BytecodeDSLFrameInfo bytecodeDSLFrameInfo) {
bytecodeDSLFrameInfo.getRootNode().copyLocals(frameToSync, target, slotCount);
}
} else {
for (int i = 0; i < slotCount; i++) {
PythonUtils.copyFrameSlot(frameToSync, target, i);
}
}
}

@Specialization(guards = "!pyFrame.hasCustomLocals()", replaces = "doSyncExploded")
@ExplodeLoop
static void doSync(PFrame pyFrame, Frame frameToSync) {
MaterializedFrame target = pyFrame.getLocals();
doCopy(frameToSync.getFrameDescriptor(), frameToSync, target);
FrameDescriptor fd = target.getFrameDescriptor();
int slotCount = variableSlotCount(fd);

if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
FrameInfo info = (FrameInfo) fd.getInfo();
if (info instanceof BytecodeDSLFrameInfo bytecodeDSLFrameInfo) {
bytecodeDSLFrameInfo.getRootNode().copyLocals(frameToSync, target, slotCount);
}
} else {
for (int i = 0; i < slotCount; i++) {
PythonUtils.copyFrameSlot(frameToSync, target, i);
}
}
}

@Specialization(guards = "pyFrame.hasCustomLocals()")
Expand All @@ -278,21 +296,5 @@ protected static int variableSlotCount(FrameDescriptor fd) {
}
return info.getVariableCount();
}

private static void doCopy(FrameDescriptor fd, Frame source, MaterializedFrame destination) {
FrameInfo info = (FrameInfo) fd.getInfo();
if (info == null) {
return;
}
int count = info.getVariableCount();

if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
((BytecodeDSLFrameInfo) info).getRootNode().copyLocals(source, destination, count);
} else {
for (int i = 0; i < count; i++) {
PythonUtils.copyFrameSlot(source, destination, i);
}
}
}
}
}

0 comments on commit b2cff2d

Please sign in to comment.