Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NullPointerException in --dumpGraphs & test & docs #6304

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,28 @@ lazy val `interpreter-dsl` = (project in file("lib/scala/interpreter-dsl"))
)
)

lazy val `interpreter-dsl-test` =
(project in file("engine/interpreter-dsl-test"))
.configs(Test)
.settings(
version := "0.1",
frgaalJavaCompilerSetting,
Test / fork := true,
Test / javaOptions ++= Seq(
"-Dgraalvm.locatorDisabled=true",
s"--upgrade-module-path=${file("engine/runtime/build-cache/truffle-api.jar").absolutePath}"
),
commands += WithDebugCommand.withDebug,
libraryDependencies ++= Seq(
"org.graalvm.truffle" % "truffle-api" % graalVersion % "provided",
"org.graalvm.truffle" % "truffle-dsl-processor" % graalVersion % "provided",
"junit" % "junit" % junitVersion % Test,
"com.novocode" % "junit-interface" % "0.11" % Test exclude ("junit", "junit-dep")
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
)
)
.dependsOn(`interpreter-dsl`)
.dependsOn(`runtime`)

// ============================================================================
// === Sub-Projects ===========================================================
// ============================================================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.enso.interpreter.dsl.test;

import com.oracle.truffle.api.nodes.Node;
import org.enso.interpreter.dsl.BuiltinMethod;

@BuiltinMethod(type = "InliningBuiltins", name = "in")
final class InliningBuiltinsInNode extends Node {

long execute(long a, long b) {
return a + b;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.enso.interpreter.dsl.test;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.Node;
import org.enso.interpreter.dsl.BuiltinMethod;
import org.junit.Assert;

@BuiltinMethod(type = "InliningBuiltins", name = "out")
final class InliningBuiltinsOutNode extends Node {

long execute(VirtualFrame frame, long a, long b) {
Assert.assertNotNull("VirtualFrame is always provided " + frame);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
return a + b;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.enso.interpreter.dsl.test;

import org.enso.interpreter.node.InlineableRootNode;
import org.enso.interpreter.runtime.callable.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;

public class InliningBuiltinsTest {

/** @see InliningBuiltinsInNode#execute(long, long) */
@Test
public void executeWithoutVirtualFrame() {
var fn = InliningBuiltinsInMethodGen.makeFunction(null);
if (fn.getCallTarget().getRootNode() instanceof InlineableRootNode root) {
var call = root.createDirectCallNode();
var clazz = call.getClass().getSuperclass();
assertEquals("InlinedCallNode", clazz.getSimpleName());
assertEquals("BuiltinRootNode", clazz.getEnclosingClass().getSimpleName());

var res = call.call(Function.ArgumentsHelper.buildArguments(null, null, new Object[] { null, 5L, 7L }));
assertEquals(12L, res);
} else {
fail("It is inlineable: " + fn.getCallTarget().getRootNode());
}
}

/** @see InliningBuiltinsOutNode#execute(com.oracle.truffle.api.frame.VirtualFrame, long, long) */
@Test
public void executeWithVirtualFrame() {
var fn = InliningBuiltinsOutMethodGen.makeFunction(null);
if (fn.getCallTarget().getRootNode() instanceof InlineableRootNode root) {
var call = root.createDirectCallNode();
var clazz = call.getClass().getSuperclass();
assertEquals("com.oracle.truffle.api.nodes.DirectCallNode", clazz.getName());

var res = call.call(Function.ArgumentsHelper.buildArguments(null, null, new Object[] { null, 3L, 9L }));
assertEquals(12L, res);
} else {
fail("It is inlineable: " + fn.getCallTarget().getRootNode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final boolean cloneCallTarget() {

@Override
public final CallTarget getClonedCallTarget() {
return null;
return getRootNode().getCallTarget();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** An annotation denoting a node that should be wrapped for standard library export. */
/**
* An annotation denoting a node that should be wrapped for standard library export. A subclass of
* {@code BuiltinRootNode} is generated with implementation of {@code
* InlineableRootNode#createDirectCallNode()} that either delegates to regular {@link
* DirectCallNode} (when the {@code execute} method requires {@code VirtualFrame} as one of its
* arguments) or provides a special implementation, if no {@code VirtualFrame} is needed.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface BuiltinMethod {
/** @return the language-level type of {@code this} argument. */
/** @return the language-level type of {@code self} argument. */
String type();

/** @return the language-level name of this method. */
Expand Down