Skip to content

Commit

Permalink
Quick-fix for Error.to_text CCE (#3357)
Browse files Browse the repository at this point in the history
This is just a quick fix addressing an issue which was making debugging problematic.

The proper solution to the broader issue described at #1538 (comment) still needs to be done.
  • Loading branch information
radeusgd committed Mar 24, 2022
1 parent edadca1 commit 85a5770
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
@@ -1,25 +1,40 @@
package org.enso.interpreter.node.expression.builtin.error;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.nodes.Node;
import org.enso.interpreter.dsl.AcceptsError;
import org.enso.interpreter.dsl.BuiltinMethod;
import org.enso.interpreter.runtime.callable.atom.Atom;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.error.DataflowError;

@BuiltinMethod(type = "Error", name = "to_text", description = "Convert an error to text.")
public class ErrorToTextNode extends Node {
public abstract class ErrorToTextNode extends Node {
private static final int DISPATCH_CACHE = 3;
private @Child InteropLibrary displays =
InteropLibrary.getFactory().createDispatched(DISPATCH_CACHE);
private @Child InteropLibrary strings =
InteropLibrary.getFactory().createDispatched(DISPATCH_CACHE);

public Text execute(DataflowError _this) {
static ErrorToTextNode build() {
return ErrorToTextNodeGen.create();
}

public abstract Text execute(@AcceptsError Object _this);

@Specialization
public Text doDataflowError(DataflowError _this) {
try {
return Text.create(strings.asString(displays.toDisplayString(_this)));
} catch (UnsupportedMessageException ignored) {
throw new IllegalStateException("Unreachable");
}
}

@Specialization
public Text doAtom(Atom _this) {
return Text.create("Error");
}
}
Expand Up @@ -102,12 +102,12 @@ class RuntimeVisualisationsTest
}

def receive: Option[Api.Response] =
receiveTimeout(10)
receiveTimeout(20)

def receiveTimeout(timeoutSeconds: Int): Option[Api.Response] =
Option(messageQueue.poll(timeoutSeconds.toLong, TimeUnit.SECONDS))

def receive(n: Int, timeoutSeconds: Int = 10): List[Api.Response] =
def receive(n: Int, timeoutSeconds: Int = 20): List[Api.Response] =
Iterator
.continually(receiveTimeout(timeoutSeconds))
.take(n)
Expand Down Expand Up @@ -1902,7 +1902,7 @@ class RuntimeVisualisationsTest
Api.Request(requestId, Api.PushContextRequest(contextId, item1))
)
val pushContextResponses =
context.receive(n = 4, timeoutSeconds = 60)
context.receive(n = 4, timeoutSeconds = 90)
pushContextResponses should contain allOf (
Api.Response(requestId, Api.PushContextResponse(contextId)),
TestMessages.error(
Expand Down
4 changes: 4 additions & 0 deletions test/Tests/src/Semantic/Error_Spec.enso
Expand Up @@ -54,6 +54,10 @@ spec =
Test.specify "should implement to_display_text" <|
Error.throw Nothing . to_display_text . should_equal "Error: Nothing"

Test.specify "should implement to_text" <|
Error.throw Nothing . to_text . should_equal "(Error: Nothing)"
Error.to_text . should_equal "Error"

Test.specify "should be able to be mapped" <|
error = Error.throw 42
regular = 10
Expand Down

0 comments on commit 85a5770

Please sign in to comment.