-
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
Implement hasLanguage interop message for all enso objects #11538
base: develop
Are you sure you want to change the base?
Conversation
- Also, EnsoObject exports hasLanguage and getLanguage interop messages. - BranchRecord converted to class
Quick note: I believe there are other ways to enforce the contract while keeping |
EnsoObject
to abstract classhasLanguage
interop message for all enso objects
hasLanguage
interop message for all enso objects
|
||
/** All non-primitive Enso types extends from {@code EnsoObject}. */ | ||
public interface EnsoObject extends TruffleObject {} | ||
@ExportLibrary(InteropLibrary.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the goal is to provide default implementation of hasLanguage
and getLanguage
message for all Enso interop objects - e.g. those who implement EnsoObject
interface.
- I would hope there is a better pattern to achieve this than converting to
abstract class
- I don't like the
toDisplayString
to be defined, but unimplemented
Let's see if Truffle API offers some better alternative to achieve such a default common implementation of some ExportLibrary
messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if Truffle API offers some better alternative to achieve such a default common implementation of some ExportLibrary messages?
I tried to leave EnsoObject
as an interface, annotate it with @ExportLibrary(InteropLibrary.class)
, and implement hasLanguage
and getLanguage
as default methods. But @ExportMessage
on default method on interface does not work - the Truffle DSL processor fails with an error. Any ideas are welcome.
As for toDisplayString
implementation - that is required by Truffle DSL, because if you export one of getLanguage
or hasLanguage
messages, then, toDisplayString
is abstract and has to be implemented. However, I am still not sure what is the proper way to define it here, in EnsoObject
.
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java
Outdated
Show resolved
Hide resolved
An approach with leaving diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java
index ce60158116..eb65b641b2 100644
--- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java
+++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoObject.java
@@ -1,6 +1,15 @@
package org.enso.interpreter.runtime.data;
import com.oracle.truffle.api.interop.TruffleObject;
+import com.oracle.truffle.api.library.DynamicDispatchLibrary;
+import com.oracle.truffle.api.library.ExportLibrary;
+import com.oracle.truffle.api.library.ExportMessage;
/** All non-primitive Enso types extends from {@code EnsoObject}. */
-public interface EnsoObject extends TruffleObject {}
+@ExportLibrary(DynamicDispatchLibrary.class)
+public interface EnsoObject extends TruffleObject {
+ @ExportMessage
+ Class<?> dispatch() {
+ return LanguageForEnsoObject.class;
+ }
+}
diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/LanguageForEnsoObject.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/LanguageForEnsoObject.java
index cfd3eda4c0..6114f01e0e 100644
--- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/LanguageForEnsoObject.java
+++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/LanguageForEnsoObject.java
@@ -1,8 +1,10 @@
package org.enso.interpreter.runtime.data;
+import com.oracle.truffle.api.interop.InteropLibrary;
+import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.library.ExportLibrary;
-@ExportLibrary()
-public final class LanguageForEnsoObject {
-
+@ExportLibrary(value = InteropLibrary.class, receiverType = EnsoObject.class)
+public final class LanguageForEnsoObject implements TruffleObject {
+ // TODO: Export hasLanguage and getLanguage methods
} This patch fails to compile because Truffle DSL processor fails with errror: "@ExportLibrary is not supported for interfaces". And the receiver type must export TL;DR; |
With the exception of toDisplayString message.
It is not automatically delegated because it is implemented in the super type.
Blocks #11468
Pull Request Description
This PR implements the Truffle contract that all the Enso objects must export
hasLanguage
andgetLanguage
messages. By refactoringEnsoObject
from an interface to an abstract class.Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
or the Snowflake database integration, a run of the Extra Tests has been scheduled.