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

Improve TCO in the presence of warnings #7116

Merged
merged 3 commits into from
Jun 26, 2023

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Jun 23, 2023

Pull Request Description

Partially revert #6849, which introduced a regression in TCO in the presence of warnings. Rather than modifying the tail call status, TailCallException now propagates the extracted warnings and appends them to the final result.

Closes #7093

Important Notes

Compared to the previous attempt we don't pay the penalty of adding the warnings or even checking for them because it is being dealt in a separate specialization.

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.

Partially revert #6849, which
introduced a regression in TCO in the presence of warnings.
Rather than modifying the tail call status, `TailCallException` now
propagates the extracted warnings and appends them to the final result.
Compare to the previous attempt we don't pay the penalty of adding the
warnings or even checking for them because it is being dealt in a
separate specialization.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Jun 23, 2023
vec = Vector.new 10000 (i-> i+1)
elem1 = Warning.attach "WARNING1" 998
vec.contains 998 . should_equal True
res1 = vec.contains elem1
Copy link
Member

Choose a reason for hiding this comment

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

Is this the line that was causing stack overflow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is the example from the ticket.

@@ -277,7 +287,7 @@ public Object invokeWarnings(
invokeFunctionNode.getSchema(),
invokeFunctionNode.getDefaultsExecutionMode(),
invokeFunctionNode.getArgumentsExecutionMode()));
childDispatch.setTailStatus(TailStatus.NOT_TAIL);
childDispatch.setTailStatus(getTailStatus());
Copy link
Member

@JaroslavTulach JaroslavTulach Jun 24, 2023

Choose a reason for hiding this comment

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

In the test below... what node behavior this change affects?

The warning in the test is attached to an argument, not to self, so I don't see how this change can be triggered and make a difference?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh you mean why I change it in InvokeCallableNode when the fix was only necessary in InvokeMethodNode, right?
I'm reverting the previous change for all three cases and replacing it with the same approach i.e. warnings propagation via TailCallException.
It does not appear that we have any test case exercising this case specifically.

Warning[] warnings,
@Cached(value = "createLoopNode()") LoopNode loopNode) {
Object result = dispatch(function, callerInfo, state, arguments, loopNode);
return WithWarnings.appendTo(EnsoContext.get(this), result, warnings);
Copy link
Member

Choose a reason for hiding this comment

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

This looks correct. If there are warnings, remove them, handle all the tail calls and attach them again. Not sure how that can be triggered by the test however?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how that can be triggered by the test however?

I'm not sure how to convince you other than running it with debugger attached and putting the breakpoint yourself.

Copy link
Member

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

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

Just minor nitpicks

test/Tests/src/Semantic/Warnings_Spec.enso Outdated Show resolved Hide resolved
test/Tests/src/Semantic/Warnings_Spec.enso Outdated Show resolved Hide resolved
extracted = warnings.getWarnings(warning, null);
callable = warnings.removeWarnings(warning);
} catch (UnsupportedMessageException e) {
throw CompilerDirectives.shouldNotReachHere(e);
Copy link
Member

Choose a reason for hiding this comment

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

Just a side note: Eventually, we should probably align the exceptions we are throwing from the nodes in the engine. In most places it is IllegalStateException, but sometimes it is also CompilerDirectives.shouldNotReachHere. We should provide a proper wrapper for these exceptions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I've had the same observation a while ago ;)

@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Jun 26, 2023
@mergify mergify bot merged commit ae4666c into develop Jun 26, 2023
@mergify mergify bot deleted the wip/hubert7093-fix-tco-for-warnings branch June 26, 2023 12:38
@hubertp hubertp mentioned this pull request May 1, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

TCO is not properly applied when function encounters a value with warnings attached
6 participants