Skip to content
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

Support on_problems=Problem_Behavior.Report_Warning and Map_Error wrapping in Vector.map #8595

Merged
merged 239 commits into from
Jan 16, 2024

Conversation

GregoryTravis
Copy link
Contributor

@GregoryTravis GregoryTravis commented Dec 19, 2023

Pull Request Description

Implements Warnings.get_all wrap_errors=True which wraps warnings attached to values inside vectors with Map_Error, which includes the position of the value within the vector. See the documentation for more details.

get_all wrap_errors=True does not change the warnings that are attached to values -- it wraps them before returning them to the caller, but does not change the original warnings attached to the values.

Wrapped warnings only appear attached to the vector itself. The values inside the vector do not have their warnings wrapped.

Warning propagation is not changed at all; Warnings.get_all (with default wrap_errors=False) behaves as before. get_all wrap_errors=True is meant to be used primarily by the IDE, although it can be used anywhere this wrapping is desired.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

CHANGELOG.md Outdated
@@ -599,6 +599,7 @@
- [Support for loading big Excel files.][8403]
- [Added new `Filter_Condition`s - `Equal_Ignore_Case`, `Is_Nan`, `Is_Infinite`
and `Is_Finite`.][8539]
- Support `on_problems=Problem_Behavior.Report_Warning` in `Vector.map`.][8595]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Support `on_problems=Problem_Behavior.Report_Warning` in `Vector.map`.][8595]
- [Support `on_problems=Problem_Behavior.Report_Warning` in `Vector.map`.][8595]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Describes an error attached to a value within a `Vector`. The `index` field
contains the index into the `Vector` at which the error occurred.

If a value is a nested within multiple `Vector`s, its warnings are wrapped
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If a value is a nested within multiple `Vector`s, its warnings are wrapped
If a value is nested within multiple `Vector`s, its warnings are wrapped

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

GregoryTravis and others added 2 commits January 9, 2024 13:27
…ke_Helpers.enso

Co-authored-by: Radosław Waśko <radoslaw.wasko@enso.org>
@GregoryTravis GregoryTravis added CI: Clean build required CI runners will be cleaned before and after this PR is built. and removed CI: Clean build required CI runners will be cleaned before and after this PR is built. labels Jan 9, 2024
@@ -307,8 +307,6 @@ public Object invokeWarnings(

if (result instanceof DataflowError) {
return result;
} else if (result instanceof WithWarnings withWarnings) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is already handled by WithWarnings.wrap.

docs/semantics/wrapped-errors.md Outdated Show resolved Hide resolved
@@ -164,6 +164,13 @@ spec =
obj1 . should_not_equal <| JS_Object.from_pairs [["a", 43], ["b", 123]]
obj1 . should_not_equal <| JS_Object.from_pairs [["a", 42], ["b", JS_Object.from_pairs [["c",1], ["d",3]]]]

Test.specify "should be able to set values" <|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of #8630, which will be merged first.

docs/semantics/wrapped-errors.md Outdated Show resolved Hide resolved
@@ -617,7 +617,8 @@ private boolean generateWarningsCheck(
+ " = withWarnings.getValue();");
out.println(
" gatheredWarnings ="
+ " gatheredWarnings.prepend(withWarnings.getReassignedWarningsAsRope(bodyNode));");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

test/Benchmarks/src/Vector/Map_Error_Benchmark.enso Outdated Show resolved Hide resolved
test/Benchmarks/src/Vector/Map_Error_Benchmark.enso Outdated Show resolved Hide resolved
Describes an error attached to a value within a `Vector`. The `index` field
contains the index into the `Vector` at which the error occurred.

If a value is a nested within multiple `Vector`s, its warnings are wrapped
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

CHANGELOG.md Outdated
@@ -599,6 +599,7 @@
- [Support for loading big Excel files.][8403]
- [Added new `Filter_Condition`s - `Equal_Ignore_Case`, `Is_Nan`, `Is_Infinite`
and `Is_Finite`.][8539]
- Support `on_problems=Problem_Behavior.Report_Warning` in `Vector.map`.][8595]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that a lot of thought and work has been put into this PR. Let's get it in! I'd update the description of the PR (as that usually gets copied to Git commit description). I'd somehow point readers to docs/semantics/wrapped-errors.md as that contains great explanation of the overall design.

not a wrapping error, it is returned unchanged.
unwrap : Any -> Any
unwrap error_value =
Panic.catch No_Such_Conversion handler=_->error_value <|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting use of conversion. Convert to Wrapped_Error and then use inner_error. I can see that the Error.unwrap method is applied recursively to strip off all the wrappers. Consider adding @Tail_Call annotation to turn it into a loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


builder.group "warnings_get_all_wrapped_"+vector_type options group_builder->
group_builder.specify "no_warnings" <|
Warning.get_all_wrapped data.no_warnings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the get_all_wrapped function defined? Aren't we supposed to use get_all wrap_errors=True?

Implements Warnings.get_all_wrapped which wraps warnings

If we shall be using get_all wrap_errors=True then I'd like to point out the pull request description is outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


## Catching Wrapped Errors

Wrapped errors are "transparent" to `Error.catch`. That is, if you attempt to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


## Implementing Error Wrappers

An error wrapper is a regular Enso value that has a conversion to `Wrapped_Error`. For example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@GregoryTravis
Copy link
Contributor Author

GregoryTravis commented Jan 12, 2024

I can see that a lot of thought and work has been put into this PR. Let's get it in! I'd update the description of the PR (as that usually gets copied to Git commit description). I'd somehow point readers to docs/semantics/wrapped-errors.md as that contains great explanation of the overall design.

Done.

This PR is blocked by the error "Invariant contract violation for receiver Nothing" when runtime assertions are turned on. I am unable to reproduce it with a single test, or under the debugger. Discussion here:

https://discord.com/channels/401396655599124480/1194662721958969364/1194662721958969364

Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

Looks like that eventually violates Truffle invariants and was lurking
around.
"interop.isMetaObject(metaLeft)",
"!interop.isNull(metaRight)",
"interop.isMetaObject(metaRight)"
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know how to reproduce the problem?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run stdlib test/Tests with assertions on. I haven't been able to reduce it to something small yet.

@hubertp
Copy link
Contributor

hubertp commented Jan 15, 2024

@GregoryTravis
This failure looks legit?

 INFO ide_ci::program::command: npmℹ️ Checking formatting...
 INFO ide_ci::program::command: npm⚠️ [warn] docs/semantics/README.md
 INFO ide_ci::program::command: npm⚠️ [warn] docs/semantics/wrapped-errors.md
 INFO ide_ci::program::command: npm⚠️ [warn] Code style issues found in 2 files. Run Prettier to fix.

@JaroslavTulach are you OK with merging it with my workaround? @Akirathan will create a PR with a smaller case but I don't think it makes sense to block this work because it is unrelated to Greg's change.

@Akirathan
Copy link
Member

are you OK with merging it with my workaround?

@hubertp yes, go ahead. I have created a separate PR for this specific issue in #8764

@GregoryTravis GregoryTravis added the CI: Ready to merge This PR is eligible for automatic merge label Jan 15, 2024
@mergify mergify bot merged commit f2cb1f0 into develop Jan 16, 2024
29 checks passed
@mergify mergify bot deleted the 8371-element-direct branch January 16, 2024 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support on_problems=Problem_Behavior.Report_Warning and Map_Error wrapping in Vector.map
6 participants