-
Notifications
You must be signed in to change notification settings - Fork 324
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
Builtins expose Enso methods #11687
base: develop
Are you sure you want to change the base?
Builtins expose Enso methods #11687
Conversation
No longer true what this test tested
@@ -543,6 +543,12 @@ boolean isObjectWithMembers(Object object, InteropLibrary interop) { | |||
if (interop.isTime(object)) { | |||
return false; | |||
} | |||
if (interop.isDuration(object)) { |
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.
Both TimeZone and Duration now have members, so we need to add these guards here.
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.
The whole EqualsXyzNode
set of @Specialize
annotation is fragile, unreadable, not fully testable and deserves a rewrite. At least that's the feeling I get every time I am changing the code.
Such a gentle change is OK, unless total rewrite is attempted.
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.
See my answer in #11687 (comment) - yes it is a mess.
@JaroslavTulach |
|
@Akirathan can you merge in the most recent |
# Conflicts: # engine/runtime-integration-tests/src/test/java/org/enso/example/PolyglotTestClass.java # engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/builtins/BuiltinsJavaInteropTest.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/BuiltinObject.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDateTime.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDuration.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoFile.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeOfDay.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoTimeZone.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ManagedResource.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Ref.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/hash/EnsoHashMap.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Array.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/ArrayLikeHelpers.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/Vector.java # engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java
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.
The idea of using static methods on Type
seems to be a great solution to all the problems we had so far. The PR is simple and unlocks a functionality that was clearly missing.
- cannot call
Ref.get
: https://github.com/enso-org/enso/pull/11577/files#r1848224116 - cannot call
File.path
on EnsoFile - cannot call
to_text
onVector
- discovered while working on Warnings displayed aftermain
exit do not use definedto_text
#11569
Can you simplify these three known workarounds in the production code as well? Then this PR will immediately be useful for Enso users!
ctx, | ||
() -> { | ||
var interop = InteropLibrary.getUncached(); | ||
var refUnwrapped = ContextUtils.unwrapValue(ctx, ref); |
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.
OK, so this is result of Ref.new 42
.
assertThat( | ||
"Ref builtin object should not have any members", | ||
interop.hasMembers(refUnwrapped), | ||
is(false)); |
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.
The Ref
object has no members.
"Ref should have a meta-object (Ref type)", | ||
interop.hasMetaObject(refUnwrapped), | ||
is(true)); | ||
var refMeta = interop.getMetaObject(refUnwrapped); |
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.
One has to ask for Ref
object's meta-object - e.g. Type
assertThat( | ||
"Ref meta-object should have a 'get' method", | ||
interop.isMemberInvocable(refMeta, "get"), | ||
is(true)); |
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.
and there is invocable method get
on the Ref
type.
"Ref meta-object should have a 'get' method", | ||
interop.isMemberInvocable(refMeta, "get"), | ||
is(true)); | ||
var res = interop.invokeMember(refMeta, "get", new Object[] {refUnwrapped}); |
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.
The method can be invoked as static method on the Ref
type with first argument being the Ref
object.
The approach to export methods as internal members of types and not on atoms/builtin objects was chosen because of #12043 - at the moment, it is not possible to implement |
Closes #11589
Pull Request Description
Builtin types expose methods via the interop protocol. In fact, all types expose methods via interop protocol.
To get and invoke a method on a builtin object via interop protocol:
Example in InvokeBuiltinMethodViaInteropTest
To get and invoke a method on a builtin object via
org.graalvm.polyglot.Value
(this can be done, e.g., in std libs in Java code):Example in BuiltinTypesExposeMethodsTest.
Important Notes
Method members are reported in Type.getMembers as internal members.
This has a side effect that in the debugger, types have method properties (but not atoms):
The first attempt to implement
hasMember
andgetMembers
onBuiltinObject
abandoned - #11687 (comment)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.