-
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
Use ArraySlice to slice a Vector #3724
Conversation
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java
Show resolved
Hide resolved
13973fb
to
19bbb0c
Compare
abfc064
to
151c749
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.
Looks good to me overall, just a few small comments and a question on implementation that would be good if can be answered before merge.
if (CompilerDirectives.inInterpreter()) { | ||
if (!InteropLibrary.getUncached().hasArrayElements(storage)) { | ||
throw new IllegalStateException("Vector needs array-like delegate, but got: " + storage); | ||
} | ||
} |
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 think I don't understand why this check is performed only in the interpreter. Won't this affect semantics depending on optimization levels?
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.
Anyway, if left as-is I think it would be beneficial to add a short comment explaining why this is only checked in interpreter.
Unless there is some obvious reason that every Truffle developer should understand immediately, I think such an explanation will help future developers understand this decision.
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.
We could do the check as assert
. Asserts are ignored when Truffle does its PE compilation. We just need to make sure we run our tests with -ea
.
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.
Why can't the check be there always?
@Builtin.Specialize | ||
@Builtin.WrapException(from = UnsupportedMessageException.class, to = PanicException.class) | ||
public final Vector slice(long start, long end, InteropLibrary interop) | ||
throws UnsupportedMessageException { |
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.
In what circumstances is UnsupportedMessageException
thrown?
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.
Only if the backing storage no longer can answer the interop.getArraySize
call - shouldn't happen.
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.
Not bad. If that works, it can go in. There is VectorBenchmarks.java
- consider adding a sliced
check in there.
if (CompilerDirectives.inInterpreter()) { | ||
if (!InteropLibrary.getUncached().hasArrayElements(storage)) { | ||
throw new IllegalStateException("Vector needs array-like delegate, but got: " + storage); | ||
} | ||
} |
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.
We could do the check as assert
. Asserts are ignored when Truffle does its PE compilation. We just need to make sure we run our tests with -ea
.
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArraySlice.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Vector.java
Show resolved
Hide resolved
Parameters of type InteropLibrary are currently correctly generated only when annotated with `Builtin.Specialized`. Should eventually get rid of this limitation and merge the logic into both variants.
151c749
to
0df33f0
Compare
Each builtin `makeFunction` method has to be currently registered for reflection. Adding registration of `SliceVectorMethodGen` to make following example work ag ```bash enso$ sbt engine-runner-native/buildNativeImage enso$ ./runner --run engine/runner-native/src/test/resources/Factorial.enso 6 ``` # Important Notes Regression caused by #3724 - Once the above code is executed in the CI, we'll discover such breakages before integration.
[ci no changelog needed]
Pull Request Description
Use an
ArraySlice
to sliceVector
.Avoids memory copying for the slice function.
Important Notes
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.