Skip to content

Test recursive dispatch using visitor pattern. #3365

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

Merged
merged 1 commit into from
Oct 22, 2021

Conversation

dyershov
Copy link
Contributor

Description

Implemented unit test aims at replicating BUG #3357. The implementation defines abstract C++ class that performs an operation on abstract member Data class and sends the result to a visitor. A trampoline class is used to bind Adder python class. Additionally two algorithms that use previously defined abstractions to perform operation on two or three objects. These algorithms are tested using a concrete python implementation. The recursive dispatch of overloaded operator fails in the case of algorithm that uses three objects. When calling a visitor indirectly from lambda function inside overloaded operation, the expected functionality is restored.

Suggested changelog entry:

- implement tests for recursive dispatch using visitor pattern

@dyershov dyershov changed the title tests: test recursive dispatch in order to replicate BUG #3357 Test recursive dispatch using visitor pattern. Oct 15, 2021
@dyershov
Copy link
Contributor Author

@rwgk Tagging you in this PR as per #3357 (comment).

Apologies for CI failing. I have to learn how to run checks locally so that I can fix things.

@dyershov dyershov force-pushed the BUG-3357/recursive-dispatch-test branch 3 times, most recently from 56edf9b to 12eb9dc Compare October 15, 2021 03:19
@henryiii
Copy link
Collaborator

Try nox, maybe with pipx run nox if you have pipx installed, or just with nox if you have that installed. That should run all the possible tests, and pre-commit too. You can select as well, see nox -l.

@dyershov dyershov force-pushed the BUG-3357/recursive-dispatch-test branch from 9e23ee4 to 17cd089 Compare October 16, 2021 14:06
@dyershov
Copy link
Contributor Author

dyershov commented Oct 16, 2021

Thanks @henryiii! Running nox didn't show failures in windows build. I'm suspecting, based on the comment for DispatchIssue, pure virtual functions here somehow not allowed in windows. I can fix it if it is causing problems.

@Skylion007 Skylion007 closed this Oct 18, 2021
@Skylion007 Skylion007 reopened this Oct 18, 2021
@Skylion007 Skylion007 closed this Oct 19, 2021
@Skylion007 Skylion007 reopened this Oct 19, 2021
@Skylion007
Copy link
Collaborator

@dyershov The failing test is a flake so this looks good.

Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

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

Thanks for the great test! (And sorry it took so long to respond; oversight.)

@Skylion007 Skylion007 merged commit 076c89f into pybind:master Oct 22, 2021
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Oct 22, 2021
@dyershov
Copy link
Contributor Author

@Skylion007, @rwgk, and @henryiii , no need to worry about the response time. Thank you all for the great project! Without it a lot of what I do would be very difficult in not impossible to achieve. Looking forward for possible resolution on this issue.

# lambda is a workaround, which adds extra frame to the
# current CPython thread. Removing lambda reveals the bug
# [https://github.com/pybind/pybind11/issues/3357]
(lambda: visitor(Data(first.value + second.value)))()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't the lambda have not been here, and the test marked with xfail? It's not a segfault, right?

Copy link
Collaborator

@rwgk rwgk Oct 24, 2021

Choose a reason for hiding this comment

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

Maybe an additional test.
I think it's important to keep this test (with the extra lambda) indefinitely. We want to be sure it doesn't break, even after the bug is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also thought about two tests: one expected to fail, another with a workaround. I can create another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

May be nice ... but at the moment it doesn't buy as anything tangible (the existing comments are very clear) and it'll be an organic minor part of the work fixing the bug. I'd just leave it for later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Though, it would be fun to try and learn more about xfail.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Up to you! I'll vote to merge if you send the PR.

@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants