-
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
Create static wrappers for builtin types #4077
Create static wrappers for builtin types #4077
Conversation
I think we will have to face something like that at some point anyway, am I right @JaroslavTulach ? I think this is related to this Discord discussion where I notice that Truffle assertions do not allow |
Nothing is exceptional! #4074 provides special exceptions for |
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.
Except the doubts with "_static"
suffix, I don't see any problem. Nice.
engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java
Outdated
Show resolved
Hide resolved
f4fc619
to
15f23d3
Compare
@radeusgd so you are OK with the PR? I'd rather keep the |
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.
Looks good, I'd appreciate adding one more test to clarify how the statics work in an edge case which is unclear to me currently.
Error.to_text . should_equal "Error" | ||
Error.to_text Error . should_equal "Error" |
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 get where this is coming from, but it is quite surprising. Should the Error
argument be supported anymore?
Other than that - I'd like to see a test like
x = Error
x.to_text . should_equal "???"
What will this print? Will it be Error
or a function now? Would be great to have a test documenting this behaviour, as it's non obvious.
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.
What will this print? Will it be Error or a function now?
The latter. OK, I will add case.
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.
Hmm, is this definitely the way it is supposed to work? Shouldn't the static approach only work for static references to the types?
Anyway, even if not, I'm not suggesting to do anything about it in the current PR.
Thanks for adding the test, documenting the currently expected behaviour.
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 would even argue this now works as it should have worked to be begin with. Let's take further discussion offline.
#3764 introduced static wrappers for instance methods. Except it had a limitation to only be allowed for types with at least a single constructor. That excluded builtin types as well which, by default, don't have them. This limitation is problematic for Array/Vector consolidation and makes builtin types somehow second-citizens. This change lifts the limitation for builtin types only. Note that we do not want to share the implementatin of the generated builtin methods. At the same time due to the additional argument we have to adjust the starting index of the arguments. This change avoids messing with the existing dispatch logic, to avoid unnecessary complexity. As a result it is now possible to call builtin types' instance methods, statically: ``` arr = Array.new_1 42 Array.length arr ``` That would previously lead to missing method exception in runtime. The only exception is `Nothing`. Primarily because it requires `Nothing` to have a proper eigentype (`Nothing.type`) which would messed up a lot of existing logic.
15f23d3
to
63bb9b4
Compare
Pull Request Description
#3764 introduced static wrappers for instance methods. Except it had a limitation to only be allowed for types with at least a single constructor.
That excluded builtin types as well which, by default, don't have them. This limitation is problematic for Array/Vector consolidation and makes builtin types somehow second-citizens.
This change lifts the limitation for builtin types only. Note that we do want to share the implementation of the generated builtin methods. At the same time due to the additional argument we have to adjust the starting index of the arguments.
This change avoids messing with the existing dispatch logic, to avoid unnecessary complexity.
As a result it is now possible to call builtin types' instance methods, statically:
That would previously lead to missing method exception in runtime.
Important Notes
The only exception is
Nothing
. Primarily because it requiresNothing
to have a proper eigentype (Nothing.type
) which would messed up a lot of existing logic for no obvious benefit (no more calling offoo=Nothing
in parameters being one example).Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.