-
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
Improved polyglot Date support #3559
Conversation
b764759
to
4c98949
Compare
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso
Outdated
Show resolved
Hide resolved
111a003
to
69320d4
Compare
Great. Thanks for the use-case.
I've got that part working in JaroslavTulach@a4edf9f however that is unlikely the preferred solution - it requires one to know the type of the
The problem is that My workaround patch fixes that by having two conversion methods. The other one requests Solution exists, but it is very ugly. Maybe we are not doing the conversions correctly! Also most of the current To get a solution quickly, I believe we shall explore e9b0800 - e.g. obtain |
Without e9b0800 I am getting following output when I execute the test:
with the e9b0800 change the should serialise dates with format error goes away:
however another problem appears should be able to compare columns and table - e.g. the solution has some collateral damage which has to be avoided - done in f16d07e |
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Time/Date.enso
Outdated
Show resolved
Hide resolved
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.
This is a step backwards, away from proper date support: now every single date object will get wrapped eagerly, instead of being wrapped on demand. Bad for performance, bad for semantics (since now we always mangle polyglot dates even if no such need exists), I can't see a single thing this is actually good for. Also, still only focused on dates, meaning we'll get 4x the mess when trying to support the whole set of time-like types. The right way to do this is to follow the lead of Text
– convert on-demand, and expose methods normally, like for any other builtin.
Which leads me to another point: I was told by the Truffle team that Env.asGuestValue
is discouraged and poised for deprecation. Therefore introducing new uses into the codebase should be motivated by a tangible difficulty of implementing another solution. And with Hubert's changes to builtin objects, doing it right is trivial.
engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java
Outdated
Show resolved
Hide resolved
@ExportMessage | ||
boolean isMemberInvocable(String member, @CachedLibrary(limit="1") InteropLibrary delegate) { | ||
if ( | ||
"has_type".equals(member) || |
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'd expect a piece of documentation which describes how has_type
works (unless I missed it) and how its semantics differ from Java.is_instance
. As otherwise, I don't understand why the change is made and what it means.
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.
As we have discussed with @JaroslavTulach, there seems to be no good place to document this has_type
method, because it is added essentially to any Java type extending Throwable
.
But IIRC only if the Throwable is caught, ones created with new
may not necessarily have it - @JaroslavTulach is that the case? That's how I currently understand the wrapping mechanism - that it happens only at 'catch-site' - but I may be wrong. Thus, that may too be worth clarifying.
Thus, there is no Enso supertype common for exceptions that we could attach the doc to.
Because of that, we have decided the best course of action may be to add a has_type
(or a similar name) method to the type Polyglot_Error cause
Atom which would then delegate to the underlying wrapped exception's has_type
implementation. Then the base has_type
extension will not be directly documented, but all of its behaviour can be explained in the Polyglot_Error.has_type
"facade".
Does that sound good?
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.
because it is added essentially to any Java type extending Throwable
No, not really. One has to construct Polyglot_Error
atom via Error.makePolyglotError
- then the first argument is AbstractTruffleException
instance which responds to has_type
invokeMember
message.
there is no Enso supertype common for exceptions that we could attach the doc to.
No, there is not any common super type. The first argument of Polyglot_Error
is of type Dynamic
.
Polyglot_Error.has_type
sounds OKish.
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.
However, will it simplify anything? If there is:
internal_pattern = maybe_java_pattern.map_error case _ of
Polyglot_Error err ->
if err.has_type PatternSyntaxException . not then err else
Regex.Syntax_Error err.getMessage
other -> other
how shall one invoke Polyglot_Error.has_type
instance method?
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 guess you'd need
internal_pattern = maybe_java_pattern.map_error error-> case error of
Polyglot_Error cause ->
if error.has_type PatternSyntaxException . not then error else
Regex.Syntax_Error cause.getMessage
other -> other
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.
At the end I got a better idea: ec0b51d - there is Any.is_a
, so let's reuse that method! It may not be absolutely perfect, but it avoids defining new method name and supports following usecase:
polyglot java import PatternSyntaxException
# ...
if error.is_a PatternSyntaxException....
Polemic: Looking at Meta.enso
I see:
is_a : Any -> Any -> Boolean
is_a value typ = if typ == Any then True else
if is_error value then typ == Base.Error else
case value of
# ....
Base.Polyglot -> typ == Base.Polyglot
my goal with this is_a
implementation is to reuse getMetaObject. In case we get a guest object representing Java host object then getMetaObject
will return the guest object representing Java class - e.g. exactly the one we get by doing polyglot java import PatternSyntaxException
. Then following code seems natural:
polyglot java import PatternSyntaxException
# ...
if error.is_a PatternSyntaxException....
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/Context.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/enso/interpreter/node/expression/builtin/interop/generic/GetMembersNode.java
Show resolved
Hide resolved
std-bits/table/src/main/java/org/enso/table/formatting/DateFormatter.java
Show resolved
Hide resolved
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.
- requests made by James and Radek
engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Error.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Error.java
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/EnsoDate.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Hubert Plociniczak <hubert.plociniczak@gmail.com>
2c1e85c
to
9fbcd1c
Compare
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.
It's all right. One thing that should be noted is that we should get rid of Time_Utils
ASAP – migrate everything to builtins instead. We can do it in a separate issue tho.
Pull Request Description
Significantly improves the polyglot Date support (as introduced by #3374). It enhances the
Date_Spec
to run it in four flavors:The code is then improved by necessary modifications to make the
Date_Spec
pass.Important Notes
James has requested in #181755990 - e.g. Review and improve InMemory Table support for Dates, Times, DateTimes, BigIntegers the following program to work:
the program works with here in provided changes and prints
27
as of today.@jdunkerley has provided tests for proper behavior of date in
Table
andColumn
. Those tests are working as of f16d07e. One just needs to acceptList<Value>
and then queryValue
forisDate()
when needed.Last round of changes is related to exception handling. 8b686b1 makes sure
makePolyglotError
accepts only polyglot values. Then it wraps plain Java exceptions intoWrapPlainException
withhas_type
method - 60da5e7 - the remaining changes in the PR are only trying to get all tests working in the new setup.The support for
Time
isn't part of this PR yet.Checklist
Please include the following checklist in your PR: