-
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
Accept Array-like objects seamlessly in builtins #3817
Merged
mergify
merged 7 commits into
develop
from
wip/hubert/builtins-array-conversion-183266964
Oct 25, 2022
Merged
Accept Array-like objects seamlessly in builtins #3817
mergify
merged 7 commits into
develop
from
wip/hubert/builtins-array-conversion-183266964
Oct 25, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubertp
changed the title
Accept Array-like objects seamlesly in builtins
Accept Array-like objects seamlessly in builtins
Oct 20, 2022
hubertp
force-pushed
the
wip/hubert/builtins-array-conversion-183266964
branch
from
October 20, 2022 14:40
ed5340b
to
e2207aa
Compare
JaroslavTulach
approved these changes
Oct 21, 2022
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.
Great.
...time/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CoerceArrayNode.java
Outdated
Show resolved
Hide resolved
radeusgd
reviewed
Oct 24, 2022
Most of the time, rather than defining the type of the parameter of the builtin, we want to accept every Array-like object i.e. Vector, Array, polyglot Array etc. Rather than writing all possible combinations, and likely causing bugs on the way anyway as we already saw, one should use `CoerceArrayNode` to convert to Java's `Object[]`. Added various test cases to illustrate the problem.
Co-authored-by: Jaroslav Tulach <jaroslav.tulach@enso.org>
Moved location-dependent test cases out of Meta spec. That way we don't have to update them every single time we add new test to Meta.
hubertp
force-pushed
the
wip/hubert/builtins-array-conversion-183266964
branch
from
October 25, 2022 10:04
ea23daa
to
a4b8913
Compare
hubertp
added
CI: Ready to merge
This PR is eligible for automatic merge
and removed
CI: Ready to merge
This PR is eligible for automatic merge
labels
Oct 25, 2022
radeusgd
approved these changes
Oct 25, 2022
radeusgd
reviewed
Oct 25, 2022
...time/src/main/java/org/enso/interpreter/node/expression/builtin/mutable/CoerceArrayNode.java
Outdated
Show resolved
Hide resolved
…ion/builtin/mutable/CoerceArrayNode.java Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org>
mergify
bot
deleted the
wip/hubert/builtins-array-conversion-183266964
branch
October 25, 2022 12:44
hubertp
added a commit
that referenced
this pull request
Jan 4, 2023
Most of the problems with accessing `ArrayOverBuffer` have been resolved by using `CoerceArrayNode` (#3817). In `Array.sort` we still however specialized on Array which wasn't compatible with `ArrayOverBuffer`. Added a specialization to `Array.sort` to deal with that case. Because one cannot use a custom comparator with primitive (Java) arrays there is a conversion needed. It's a necessary penalty if we want to keep `ArrayOverBuffer` around. Also fixed an example in `Array.enso` by providing a default argument.
3 tasks
hubertp
added a commit
that referenced
this pull request
Jan 8, 2023
Most of the problems with accessing `ArrayOverBuffer` have been resolved by using `CoerceArrayNode` (#3817). In `Array.sort` we still however specialized on Array which wasn't compatible with `ArrayOverBuffer`. Added a specialization to `Array.sort` to deal with that case. Because one cannot use a custom comparator with primitive (Java) arrays there is a conversion needed. It's a necessary penalty if we want to keep `ArrayOverBuffer` around. Also fixed an example in `Array.enso` by providing a default argument.
hubertp
added a commit
that referenced
this pull request
Jan 9, 2023
Most of the problems with accessing `ArrayOverBuffer` have been resolved by using `CoerceArrayNode` (#3817). In `Array.sort` we still however specialized on Array which wasn't compatible with `ArrayOverBuffer`. Added a specialization to `Array.sort` to deal with that case. Because one cannot use a custom comparator with primitive (Java) arrays there is a conversion needed. It's a necessary penalty if we want to keep `ArrayOverBuffer` around. Also fixed an example in `Array.enso` by providing a default argument.
mergify bot
pushed a commit
that referenced
this pull request
Jan 9, 2023
…s the Array (#4022) Most of the problems with accessing `ArrayOverBuffer` have been resolved by using `CoerceArrayNode` (#3817). In `Array.sort` we still however specialized on Array which wasn't compatible with `ArrayOverBuffer`. Similarly sorting JS or Python arrays wouldn't work. Added a specialization to `Array.sort` to deal with that case. A generic specialization (with `hasArrayElements`) not only handles `ArrayOverBuffer` but also polyglot arrays coming from JS or Python. We could have an additional specialization for `ArrayOverBuffer` only (removed in the last commit) that returns `ArrayOverBuffer` rather than `Array` although that adds additional complexity which so far is unnecessary. Also fixed an example in `Array.enso` by providing a default argument.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Most of the time, rather than defining the type of the parameter of the builtin, we want to accept every Array-like object i.e. Vector, Array, polyglot Array etc.
Rather than writing all possible combinations, and likely causing bugs on the way anyway as we already saw, one should use
CoerceArrayNode
to convert to Java'sObject[]
.Added various test cases to illustrate the problem.
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.