-
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
Vector should preserve warnings #3938
Vector should preserve warnings #3938
Conversation
engine/runtime/src/main/java/org/enso/interpreter/node/callable/SequenceLiteralNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/ArrayRope.java
Outdated
Show resolved
Hide resolved
4a1678b
to
c645b67
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.
This is certainly step towards better implementation of WithWarnings
. I left few questions inline - mostly related to multi-dimensional arrays.
* @return the associated warnings | ||
*/ | ||
@GenerateLibrary.Abstract(ifExported = {"hasWarnings"}) | ||
public Warning[] getWarnings(Object receiver, Node location) 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.
Wouldn't it be easier to return any polyglot object that hasArrayElements
? That might save few conversions/wrappings 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.
Can't do, it seems. Warnings need to be sorted later with per-creation timestamp
Warning[] valuesWarnings = warningsLibrary.getWarnings(value, null); | ||
allWarnings = new Warning[valuesWarnings.length + warningsArr.length]; | ||
System.arraycopy(warningsArr, 0, allWarnings, 0, warningsArr.length); | ||
System.arraycopy(valuesWarnings, 0, allWarnings, warningsArr.length, valuesWarnings.length); |
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.
Here we are trying hard to create Warning[]
and then we are going to convert it back to TruffleObject
I assume.
public static Array getAll(Object value, WarningsLibrary warnings) { | ||
if (warnings.hasWarnings(value)) { | ||
try { | ||
return new Array((Object[]) warnings.getWarnings(value, null)); |
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.
Here we take the array and wrap it again into TruffleObject
. Maybe ArrayRope
itself could be a TruffleObject
?
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.
My main concern is that we have a contract on returning Warnings in a specific order. I think it is a topic worth exploring but potentially in a separate PR.
engine/runtime/src/main/java/org/enso/interpreter/node/callable/InvokeMethodNode.java
Show resolved
Hide resolved
...e/src/main/java/org/enso/interpreter/node/expression/builtin/text/util/ExpectStringNode.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java
Outdated
Show resolved
Hide resolved
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/Array.java
Outdated
Show resolved
Hide resolved
Checked the benchmarks and they look OK |
c645b67
to
fed4ead
Compare
When Vector was created via a sequence literal, we simply dropped any associated any warnings associated with it. This change propagates Warnings during the creation of the Vector. Ideally, it would be sufficient to propagate warnings from the individual elements to the underlying storage but doesn't go well with `Vector.fromArray`.
Added a WarningsLibrary that exposes `hasWarnings` and `getWarnings` messages. That way we can have a single storage that defines how to extract warnings from an Array and the others just delegate to it. This simplifies logic added to sequence literals to handle warnings.
Since warnings are no longer automatically extracted from Array-like structures, we delay the operation until an actual polyglot method call is performed. Discovered a bug in `Warning.detach_selected_warnings` which was missing any usage or tests.
Previously, accessing an element of an Array-like structure would only return warnings of that element or of the structure itself. Now, accessing an element also returns warnings from all its elements as well.
8b731f6
to
fc0b232
Compare
Pull Request Description
When Vector was created via a sequence literal, we simply dropped any associated any warnings associated with it.
Similarly doing any mapping on a Vector with warnings would create a new Vector with warnings now missing.
Rather than ducktaping every creation of
Array
/Vector
/whatever
so that they propagate warnings, decided to address the problem at the root. Array-like structures no longer remove warnings from values. Instead, whoever uses the values should ensure, if necessary, that they are gone. This was mostly problematic for polyglot calls.Added a
WarningsLibrary
that exposeshasWarnings
,getWarnings
andremoveWarnings
to deal with warnings-related logic. This is primarily used in Vector which delegates all calls to the underlying storage but can be used in any collection.Bonus points: warnings now survive multi-dimensional Vectors.
Important note
This PR addresses:
(initially the solution was very limited as it only addressed the former).
While working on polyglot calls discovered by accident that
Warning.detach_selected_warnings
was buggy and not tested. This is now fixed.Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide build
and./run ide watch
.