Skip to content

Commit

Permalink
PanicException can only accept interop values
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jul 16, 2022
1 parent ebb0dd0 commit 8b686b1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.Node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
description = "Gets the current execution stacktrace.")
public class GetStackTraceNode extends Node {
Array execute(Object self) {
var exception = new PanicException(null, this);
var exception = new PanicException("Stacktrace", this);
TruffleStackTrace.fillIn(exception);
return stackTraceToArray(exception);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.enso.interpreter.node.expression.constant;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.TruffleObject;
import org.enso.interpreter.node.ExpressionNode;
import org.enso.interpreter.runtime.error.PanicException;

/** Throws a runtime panic containing a statically-known payload. */
public class ErrorNode extends ExpressionNode {
private final Object payload;
private final TruffleObject payload;

private ErrorNode(Object payload) {
private ErrorNode(TruffleObject payload) {
this.payload = payload;
}

Expand All @@ -29,7 +30,7 @@ public Object executeGeneric(VirtualFrame frame) {
* @param payload the payload carried by exceptions thrown in the course of this node's execution.
* @return a new instance of this node.
*/
public static ErrorNode build(Object payload) {
public static ErrorNode build(TruffleObject payload) {
return new ErrorNode(payload);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.enso.interpreter.runtime.error;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.exception.AbstractTruffleException;
import com.oracle.truffle.api.interop.*;
Expand All @@ -25,6 +26,10 @@ public class PanicException extends AbstractTruffleException {
*/
public PanicException(Object payload, Node location) {
super(location);
if (!InteropLibrary.isValidValue(payload)) {
CompilerDirectives.transferToInterpreter();
throw new IllegalArgumentException("Only interop values are supported: " + payload);
}
this.payload = payload;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import org.enso.interpreter.runtime.callable.argument.{
ArgumentDefinition,
CallArgument
}
import org.enso.interpreter.runtime.callable.atom.Atom
import org.enso.interpreter.runtime.callable.atom.AtomConstructor
import org.enso.interpreter.runtime.callable.function.{
FunctionSchema,
Expand Down Expand Up @@ -1170,7 +1171,7 @@ class IrToTruffle(
* @return a runtime node representing the error.
*/
def processError(error: IR.Error): RuntimeExpression = {
val payload: AnyRef = error match {
val payload: Atom = error match {
case Error.InvalidIR(_, _, _) =>
throw new CompilerError("Unexpected Invalid IR during codegen.")
case err: Error.Syntax =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ List<String> toCatchClause(List<MethodParameter> methodParameters, Map<String, I
return List.of(
" } catch (" + from + " e) {",
" Builtins builtins = Context.get(this).getBuiltins();",
" throw new PanicException(e, this);"
" throw new PanicException(e.getMessage(), this);"
);
} else {
return List.of(
Expand Down

0 comments on commit 8b686b1

Please sign in to comment.