Repository navigation
mpgen: Allow wrapped interfaces to inherit from unwrapped interfaces #377
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
Open
ryanofsky
wants to merge
1
commit into
bitcoin-core:master
Choose a base branch
from
ryanofsky:pr/methodkey
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
In commit 08f72b0: mpgen: Key ProxyMethod and method traits by interface type
I was wondering what happens if the c++ subclass adds an overload of an inherited method.
FooCallbackalready declarescall(int). I added these two lines toExtendedCallbackin test/foo.hThis makes both
FooCallback::call(int)andExtendedCallback::call(double)visible throughExtendedCallback.Previously, the inherited method used
&FooCallback::call, which identifiescall(int). The new mapping uses&ExtendedCallback::call, where both overloads are visible.With these lines added mptest fails to build with:
Could we select the c++ class before taking the method pointer? I worked up this possible solution in gen.cpp
There might be a better solution to this, but the reasoning here is that, where the receiving c++ class derives publicly and unambiguously from the declaring class, we can preserve the old base lookup. Here,
ImplbecomesFooCallback, avoiding the additional overload.For unrelated c++ classes, the condition is false and we retain the receiving class’s lookup. This selection would only be emitted for inherited methods with a wrapped base and unwrapped bases keep the direct lookup.
With the proposed fix, mptest builds with the added overload. I haven’t found a current Bitcoin Core interface affected by this, and the ambiguity doesn’t arise when the inherited and added methods have distinct c++ names. But the PR does break a previously working libmultiprocess arrangement
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.
re: #377 (comment)
Wow this is an interesting thing to test. My first instinct is that it's good for this to trigger an error because interfaces wrapped by libmultiprocess already have a bunch of restrictions and one listed there is "Interface methods should not be overloaded" (because capnproto doesn't support method overloading, and this helps it be more language-independent).
But maybe overloading could be good to support in a derived class, and I"m thinking in particular of cases where base class may be wrapped and exposed over IPC and derived class is an unwrapped normal c++ class inheriting from some implementation of the interface. This type of class should be free to have its own methods without the same restrictions. I'm assuming this does not work today, so would not want to add support for that here, but I think the change you suggested could make sense as a followup especially if there is a motivating use-case.
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.
Thanks for pointing out that restriction. I hadn’t accounted for it when testing the wrapped
ExtendedCallbackcase. Agreed that this doesn’t need to expand the scope of this PR.I also tried the unwrapped subclass case you mentioned; a normal c++ subclass inheriting from an implementation, adding a local overload, and being passed through the wrapped base interface. That builds and passes the ipc test, so that particular arrangement already appears to work.