-
Notifications
You must be signed in to change notification settings - Fork 323
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
Type in Truffle Node breaks GraalVM semantics #6809
Comments
@kustosz suggests to share |
Surprisingly when the type is not a builtin, but a regular type defined in source, it holds its identity: diff --git engine/runtime/src/test/java/org/enso/interpreter/test/SharedEngineTest.java engine/runtime/src/test/java/org/enso/interpreter/test/SharedEngineTest.java
index c1815ce6b2..9825872fd1 100644
--- engine/runtime/src/test/java/org/enso/interpreter/test/SharedEngineTest.java
+++ engine/runtime/src/test/java/org/enso/interpreter/test/SharedEngineTest.java
@@ -2,7 +2,6 @@ package org.enso.interpreter.test;
import java.io.ByteArrayOutputStream;
import java.nio.file.Paths;
-
import org.enso.polyglot.RuntimeOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
@@ -40,11 +39,17 @@ public class SharedEngineTest extends TestBase {
private final Source typeCase = Source.newBuilder("enso", """
from Standard.Base import Vector, Text, Number
+ type Own
+ Value c
+
+ init x = Own.Value x
+
check x = case x of
_ : Vector -> 1
_ : Text -> 2
_ : Number -> 3
- _ -> 4
+ _ : Own -> 4
+ _ -> 5
""",
"type_case.enso"
).buildLiteral();
@@ -56,8 +61,21 @@ public class SharedEngineTest extends TestBase {
assertEquals(2, r.asInt());
}
+ @Test
+ public void ownTypeCaseFirstRun() {
+ var init = this.ctx.eval(typeCase).invokeMember("eval_expression", "init");
+ var ownValue = init.execute("Hi");
+ var fn = this.ctx.eval(typeCase).invokeMember("eval_expression", "check");
+ var r = fn.execute(ownValue);
+ assertEquals(4, r.asInt());
+ }
+
@Test
public void typeCaseSecondRun() {
typeCaseFirstRun();
}
+ @Test
+ public void ownTypeCaseSecondRun() {
+ ownTypeCaseFirstRun();
+ }
} Both |
Jaroslav Tulach reports a new STANDUP for yesterday (2023-08-08): Progress: - SharedEngineTest & EnsoContext: #7493
Next Day: Python interop & bugfixes |
What is the difference between code and data in Truffle? Code is supposed to live longer and be more immutable than data. In short:
com.oracle.truffle.api.nodes.Node
TruffleObject
subclassesIn order for
Node
to live longer, be immutable, be reusable, , it is forbidden to reference data fromNode
. Rather than thatNode
shall reference a "general shape of data". See the difference between Function - the data and FunctionSchema - something embedded inNode
s. Global data are stored inEnsoContext
- includingType
instances.There is at least few violations of this rule that needs to be fixed:
It is necessary to replace such references with one level of indirection - the actual
Type
must be obtained fromEnsoContext
- theNode
can only hold something to discover the type effectively.There is a branch wip/jtulach/NoTypeInNodePlease_6809 which contains a failing test. The test creates one
Engine
and uses the sameSource
in two differentContext
s. Using the same engine & source means there is just one instance of AST nodes shared between the two contexts. TheCatchTypeBranchNode
embedsType
from the first context, so the first execution succeeds, but second fails as theType
forText
is different.The text was updated successfully, but these errors were encountered: