-
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
Encapsulating array-like data and operations into a single package #7544
Merged
Merged
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
2201637
Moving all array-like data classes into the same package
JaroslavTulach b7efd8d
Unifying configuration of WithDebugCommand with annotation processors
JaroslavTulach 22f9714
Hiding ArrayProxy as package private class
JaroslavTulach d4c1140
Let Meta*Test pass OK
JaroslavTulach 91204f4
Enso objects shall extend EnsoObject
JaroslavTulach 8974b3c
ArraySlice doesn't have to be public
JaroslavTulach 58d661c
Less methods in Array
JaroslavTulach db95190
Replacing Array public methods with ArrayLikeLengthNode
JaroslavTulach e7c297e
ArrayLikeAtNode unifies access to index
JaroslavTulach 8fc5995
Hiding all public methods of Vector
JaroslavTulach cc9df48
Fixing runtime/bench
JaroslavTulach 0d64ede
Hiding Array.getItems() from public
JaroslavTulach 5c7b9cd
Renaming to ArrayLikeCoerceToArrayNode
JaroslavTulach 4d80810
Renaming to ArrayLikeCopyToArrayNode
JaroslavTulach f128f8b
Simplifying Flatten with the help of ArrayLikeAtNode and ArrayLikeLen…
JaroslavTulach 660a938
Reformatting Java code
JaroslavTulach 63941a6
Removing check for UnsupportedMessageException
JaroslavTulach 359a608
Avoid querying length until really needed
JaroslavTulach 7d9026f
Insert the newly created node before it is used
JaroslavTulach 1dd97a8
Simplify various builtins and make Array package private
JaroslavTulach b5f5fdd
Undo b7efd8d
JaroslavTulach 4c3e383
Making Vector package private class
JaroslavTulach d098ae5
WIP: Speeding up ArrayProxyBenchmarks.sumOverVectorBackedByDelegating…
JaroslavTulach 56aabdf
Let's call it VectorLong so it ends next to Vector alphabetically
JaroslavTulach d68ab5b
Recognize also double[]
JaroslavTulach abe16a7
Refactoring into many specialized innerclasses
JaroslavTulach 0433105
Specialize length and at from Double and Long vectors
JaroslavTulach 6181b10
Create pure EnsoOnly vector from values that need no conversions
JaroslavTulach 3c439ae
Place Warnings into Vector.Generic
JaroslavTulach 685580a
Turning ArrayBuilder into a builtin
JaroslavTulach 33b1cb6
Support for Vector_Builder.appendTo
JaroslavTulach ba8931b
Merging with #7525
JaroslavTulach fcad022
Documenting signatures of Array_Like_Helpers functions
JaroslavTulach 2af6be8
Reformatted
JaroslavTulach 232eb1c
Removing needless Javadoc
JaroslavTulach 3c99eeb
It's a fallback specification
JaroslavTulach 3ce8e17
Avoid shouldNotReachHere. Use panics from ArrayPanics.
JaroslavTulach 969d8b2
One method less
JaroslavTulach 9bfa61e
Removing useless documentation
JaroslavTulach 24309fc
Using @Fallback to negate previous specializations
JaroslavTulach dca7e99
Throw IAE, convert asGuestValue, convert to Illegal_Argument
JaroslavTulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
18 changes: 18 additions & 0 deletions
18
distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Array_Like_Helpers.enso
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import project.Any.Any | ||
import project.Data.Array.Array | ||
import project.Data.Numbers.Integer | ||
|
||
## PRIVATE | ||
The builtin cannot throw `Illegal_Argument` as that type cannot be a | ||
builtin, because they do not support default arguments in constructors. | ||
So a wrapper is used which will translate a Java exception into the Enso | ||
one. This indirection may be removed once the following story is done: | ||
https://www.pivotaltracker.com/n/projects/2539304/stories/183817602 | ||
JaroslavTulach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
new_array_proxy_builtin : Integer -> (Integer -> Any) -> Array | ||
new_array_proxy_builtin length at = @Builtin_Method "Array_Like_Helpers.new_array_proxy_builtin" | ||
|
||
length array_like = @Builtin_Method "Array_Like_Helpers.length" | ||
JaroslavTulach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
at array_like index = @Builtin_Method "Array_Like_Helpers.at" | ||
|
||
vector_to_array array_like = @Builtin_Method "Array_Like_Helpers.vector_to_array" | ||
vector_from_function = @Builtin_Method "Array_Like_Helpers.vector_from_function" | ||
JaroslavTulach marked this conversation as resolved.
Show resolved
Hide resolved
|
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
4 changes: 1 addition & 3 deletions
4
...ime/src/bench/java/org/enso/interpreter/bench/benchmarks/semantic/IfVsCaseBenchmarks.java
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
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
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
5 changes: 3 additions & 2 deletions
5
...ne/runtime/src/main/java/org/enso/interpreter/node/controlflow/caseexpr/BranchResult.java
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
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
40 changes: 18 additions & 22 deletions
40
...me/src/main/java/org/enso/interpreter/node/expression/builtin/immutable/AtVectorNode.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,39 @@ | ||
package org.enso.interpreter.node.expression.builtin.immutable; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.interop.InteropLibrary; | ||
import com.oracle.truffle.api.interop.InvalidArrayIndexException; | ||
import com.oracle.truffle.api.interop.UnsupportedMessageException; | ||
import com.oracle.truffle.api.nodes.Node; | ||
import org.enso.interpreter.dsl.BuiltinMethod; | ||
import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode; | ||
import org.enso.interpreter.runtime.EnsoContext; | ||
import org.enso.interpreter.runtime.data.Vector; | ||
import org.enso.interpreter.runtime.data.vector.ArrayLikeAtNode; | ||
import org.enso.interpreter.runtime.data.vector.ArrayLikeLengthNode; | ||
import org.enso.interpreter.runtime.error.DataflowError; | ||
import org.enso.interpreter.runtime.error.WarningsLibrary; | ||
|
||
@BuiltinMethod( | ||
type = "Vector", | ||
type = "Array_Like_Helpers", | ||
name = "at", | ||
description = "Returns an element of Vector at the specified index.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably needs an update as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What kind of update would you suggest, @hubertp? |
||
public class AtVectorNode extends Node { | ||
private @Child InteropLibrary interop = InteropLibrary.getFactory().createDispatched(3); | ||
private @Child WarningsLibrary warnings = WarningsLibrary.getFactory().createDispatched(3); | ||
private @Child HostValueToEnsoNode convert = HostValueToEnsoNode.build(); | ||
private @Child ArrayLikeAtNode at = ArrayLikeAtNode.create(); | ||
private @Child ArrayLikeLengthNode length; | ||
|
||
Object execute(Vector self, long index) { | ||
Object execute(Object arrayLike, long index) { | ||
try { | ||
return readElement(self, index); | ||
} catch (UnsupportedMessageException e) { | ||
CompilerDirectives.transferToInterpreter(); | ||
throw new IllegalStateException(e); | ||
long actualIndex = index < 0 ? index + len(arrayLike) : index; | ||
return at.executeAt(arrayLike, actualIndex); | ||
} catch (InvalidArrayIndexException e) { | ||
var len = len(arrayLike); | ||
var ctx = EnsoContext.get(this); | ||
var payload = ctx.getBuiltins().error().makeIndexOutOfBounds(index, len); | ||
return DataflowError.withoutTrace(payload, this); | ||
} | ||
} | ||
|
||
private Object readElement(Vector self, long index) throws UnsupportedMessageException { | ||
try { | ||
long actualIndex = index < 0 ? index + self.length(interop) : index; | ||
return self.readArrayElement(actualIndex, interop, warnings, convert); | ||
} catch (InvalidArrayIndexException e) { | ||
EnsoContext ctx = EnsoContext.get(this); | ||
return DataflowError.withoutTrace( | ||
ctx.getBuiltins().error().makeIndexOutOfBounds(index, self.length(interop)), this); | ||
private long len(Object arrayLike) { | ||
if (length == null) { | ||
CompilerDirectives.transferToInterpreterAndInvalidate(); | ||
length = insert(ArrayLikeLengthNode.create()); | ||
} | ||
return length.executeLength(arrayLike); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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 is the reason for this ignored field?
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.
Removing the
Value ignore
constructor turnsArray_Proxy
into a singleton and fails:I decided to add a constructor to "silent" this tests.
The proper fix is to remove the
type Array_Proxy
altogether, I think. It is not atype
anyway. It is just a place for thenew
andfrom_proxy_object
methods. However I happily leave this for @jdunkerley, @radeusgd and for another pull request.