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

Promote broken values instead of ignoring them #11777

Merged
merged 30 commits into from
Dec 19, 2024

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Dec 5, 2024

Pull Request Description

Partially fixes #5430 by propagating DataflowErrors found during statement execution out of the method.

Important Notes

This change may affect behavior of existing methods that ignore DataflowError as discussed here.

Checklist

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

@JaroslavTulach JaroslavTulach changed the title Currently a DataflowError may get lost in a middle of block statements Propagate DataflowError in middle of block instead of ignoring it Dec 5, 2024
for (ExpressionNode statement : statements) {
statement.executeGeneric(frame);
var result = statement.executeGeneric(frame);
if (result != nothing) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not get rid of this if statement and use simply just if (result instanceof DataflowError err). If it is an instance of DataflowError, it cannot be nothing.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed this seems redundant, can we remove it, or is there some reason that we don't see here?

Copy link
Member Author

@JaroslavTulach JaroslavTulach Dec 5, 2024

Choose a reason for hiding this comment

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

The reason is the other part of #5430:

We don't need to solve it in this PR. Just my 2 Kč explanation of the != Nothing check. In any case, that's for another PR.

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented Dec 5, 2024

There are two failed tests in standard libraries:

This is the kind of errors we can expect if we enable this DataflowError propagation. Can you fix the tests easily, @GregoryTravis, @radeusgd?

Btw. this change makes the Decimal_Spec error go away:

diff --git test/Base_Tests/src/Data/Decimal_Spec.enso test/Base_Tests/src/Data/Decimal_Spec.enso
index 3465ce9cd8..6e3a463b82 100644
--- test/Base_Tests/src/Data/Decimal_Spec.enso
+++ test/Base_Tests/src/Data/Decimal_Spec.enso
@@ -487,7 +487,7 @@ add_specs suite_builder =
             (Decimal.from_integer 7297927982888383 . multiply  (Decimal.from_integer 828737) (Math_Context.new 6)) . should_equal (Decimal.from_integer 6048060000000000000000 )
             (Decimal.new "893872388.3535345" . multiply  (Decimal.new "72374727737.23434535") (Math_Context.new 14)) . should_equal (Decimal.new "64693770738918000000")
 
-            (Decimal.new "909678645268840" . divide (Decimal.new "28029830") (Math_Context.new 6)) . should_equal (Decimal.new "32453900 ")
+            _ = (Decimal.new "909678645268840" . divide (Decimal.new "28029830") (Math_Context.new 6)) . should_equal (Decimal.new "32453900 ")
             (Decimal.new "384456406.7860325392609633764" . divide (Decimal.new "24556.125563546") (Math_Context.new 7)) . should_equal (Decimal.new "15656.23")
 
             (Decimal.from_integer 3948539458034580838458034803485 . add (Decimal.from_integer 237957498573948579387495837459837) (Math_Context.new 20)) . should_equal (Decimal.from_integer 241906038031983160230000000000000)

e.g. exactly as expected it is enough to add a dummy assignment and the problem goes away. I assume you want to do a better fix @GregoryTravis - please integrate it into my branch, so it gets green.

diff --git test/Base_Tests/src/Data/Time/Date_Range_Spec.enso test/Base_Tests/src/Data/Time/Date_Range_Spec.enso
index b2b469ae1c..22843aa6cb 100644
--- test/Base_Tests/src/Data/Time/Date_Range_Spec.enso
+++ test/Base_Tests/src/Data/Time/Date_Range_Spec.enso
@@ -157,7 +157,7 @@ add_specs suite_builder =
                 r.partition p . should_equal (r.to_vector.partition p)
                 r.all p . should_equal (r.to_vector.all p)
                 r.any p . should_equal (r.to_vector.any p)
-                r.find p . should_equal (r.to_vector.find p)
+                _ = r.find p . should_equal (r.to_vector.find p)
                 r.index_of p . should_equal (r.to_vector.index_of p)
                 r.last_index_of p . should_equal (r.to_vector.last_index_of p)
                 count_mondays acc date =
@@ -170,7 +170,7 @@ add_specs suite_builder =
                 r.partition fc . should_equal (r.to_vector.partition fc)
                 r.all fc . should_equal (r.to_vector.all fc)
                 r.any fc . should_equal (r.to_vector.any fc)
-                r.find fc . should_equal (r.to_vector.find fc)
+                _ = r.find fc . should_equal (r.to_vector.find fc)
                 r.index_of fc . should_equal (r.to_vector.index_of fc)
                 r.last_index_of fc . should_equal (r.to_vector.last_index_of fc)

same for Date_Range_Spec @radeusgd.

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

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

Santa came early this year! 🎄
I'm so happy to finally see this change - deep down I knew we may be losing something due to the unhandled errors disappearing into the void. And you confirmed my suspicions. Thankfully that isn't that many errors and they look relatively harmless. But I'm happy that from now on I can keep writing code with the peace of mind that errors will go on unnoticed.

Also we can now remove most instances of if_not_error - yay! 🎉 It was basically a workaround for ensuring error propagation. I guess we want to keep the function because it is still useful when we want to control the propagation with 'more precision'. But in numerous cases it should be no longer needed and we can remove a lot of unnecessary indentation from the code.

I submitted commits that fix should_equal silently breaking if expected value provided is dataflow error (in that case should_fail_with is expected). I will add a commit fixing the Date_Range_Spec tests in a moment.

@JaroslavTulach
Copy link
Member Author

we want to keep the function because ...

... we already published first customer releases and we are dedicated to backward compatibility, right?

@JaroslavTulach
Copy link
Member Author

Engine benchmarks run is fine - looks like nobody writes benchmarks for errors ;-) I also glanced StdLib benchmarks run and found nothing suspicious.

@JaroslavTulach
Copy link
Member Author

@radeusgd, @GregoryTravis there are still failures in stdlib tests:

Can you fix them?

Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

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

Approving the libs bits.

@GregoryTravis
Copy link
Contributor

Can you fix them?

I will look at these, after the release.

@radeusgd
Copy link
Member

radeusgd commented Dec 17, 2024

I think I have fixed all the test failures in stdlib, let's see what the CI says.

I also scheduled a run of the nightly CI: https://github.com/enso-org/enso/actions/runs/12378958829 - not sure if Snowflake will run as it has failing tests on develop but we can at least see if there are no more failures than expected.

GitHub
Enso Analytics is a self-service data prep and analysis platform designed for data teams. - Extra Nightly Tests · 434ba8a

Copy link
Member Author

@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.

Thank you guys for fixing the test failures. Radek, I don't like the rhs_error_check "friend API situation". We shouldn't be cheating like this (at least not in my PR ;-).

p.first != p.second
"; first difference at index " + diff.to_text + " "
False -> "; lengths differ (" + self.length.to_text + " != " + that.length.to_text + ") "
Any.should_equal self that frames_to_skip=0 = rhs_error_check that <|
Copy link
Member Author

Choose a reason for hiding this comment

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

Finally I see it. This wraps the original code in rhs_error_check helper function. It doesn't change API of Any.should_equal (it is not easy to see that when argument definition is mixed with code on the same line). As a result of the additional function call, the frames shift and thus 4+frame_to_skip. The rest remains unchanged.

@@ -294,15 +297,20 @@ Error.should_equal self that frames_to_skip=0 =
1.00000001 . should_equal 1.00000002 epsilon=0.0001
Number.should_equal : Float -> Float -> Integer -> Spec_Result
Number.should_equal self that epsilon=0 frames_to_skip=0 =
matches = case that of
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is way easier of parse, we the function signature clearly stays unaffected.

test/Table_Tests/src/Util.enso Outdated Show resolved Hide resolved
@JaroslavTulach JaroslavTulach changed the title Propagate DataflowError in middle of block instead of ignoring it Promote broken values instead of ignoring them Dec 19, 2024
@JaroslavTulach JaroslavTulach added CI: No changelog needed Do not require a changelog entry for this PR. CI: Keep up to date Automatically update this PR to the latest develop. CI: Ready to merge This PR is eligible for automatic merge labels Dec 19, 2024
@mergify mergify bot merged commit 014b562 into develop Dec 19, 2024
35 of 37 checks passed
@mergify mergify bot deleted the wip/jtulach/PropagateDataflowError5430 branch December 19, 2024 11:59
MrFlashAccount pushed a commit that referenced this pull request Dec 19, 2024
Partially fixes #5430 by propagating `DataflowError`s found during statement execution out of the method.

# Important Notes
This change [may affect behavior](https://github.com/enso-org/enso/pull/11673/files#r1871128327) of existing methods that ignore `DataflowError` as [discussed here](https://github.com/enso-org/enso/pull/11673/files#r1871128327).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Keep up to date Automatically update this PR to the latest develop. CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid discarded (error) values in runtime
5 participants