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

Propagate py::multiple_inheritance to all children #3650

Merged
merged 2 commits into from
Jan 27, 2022

Conversation

virtuald
Copy link
Contributor

Description

This builds on the tests split from #3665 into #3649, which should probably be merged first.

This started with a comment that @Skylion007 made on my tests for #3635, and I realized the fix was straightforward. Previously, you had to mark any child of a class that participated in multiple inheritance with py::multiple_inheritance, even if the child derived from a single base. Now, pybind11 can autodetect this in most cases.

I'm not confident this is quite the right fix. It's not clear to me what the difference between simple_type and simple_ancestors are, and I wonder if the purpose of simple_type has evolved over time as it's only used in one place.

A different fix might be to change type_caster_base's simple_type check to simple_ancestors, but then simple type wouldn't be used anywhere?

... actually, I just realized this change makes simple_type and simple_ancestors identical? Simple ancestors is only used for registering/deregistering instances.

It's late here, I'll sleep on it. There must be a subtle side effect of simple_type that I'm just missing and that the tests don't currently cover.

Suggested changelog entry:

* ``py::multiple_inheritance`` is now only needed when C++ bases are hidden from pybind11

}
else if (rec.bases.size() == 1) {
auto parent_tinfo = get_type_info((PyTypeObject *) rec.bases[0].ptr());
tinfo->simple_ancestors = parent_tinfo->simple_ancestors;
// a child of a non-simple type can never be a simple type
tinfo->simple_type = parent_tinfo->simple_type;
}

Copy link
Collaborator

@Skylion007 Skylion007 Jan 26, 2022

Choose a reason for hiding this comment

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

According to the documentation and our testing for the TypeInfo type, a type with non simple_ancestors can never be a simple type. We should add an assert somewhere that verifies this:

Suggested change
// a simple type can never have non-simple ancestors
assert(!tinfo->simple_type || tinfo->simple_ancestors));

@henryiii henryiii closed this Jan 26, 2022
@henryiii henryiii reopened this Jan 26, 2022
@rwgk
Copy link
Collaborator

rwgk commented Jan 26, 2022

@jagerman for comment, who I believe was the main author of the multiple inheritance code.

@rwgk
Copy link
Collaborator

rwgk commented Jan 26, 2022

I'll try to get this through the global testing asap (hopefully the 12:00 batch, in ~2 hours).

@rwgk
Copy link
Collaborator

rwgk commented Jan 26, 2022

This PR is now in the global testing pipeline (12:00 batch), after first testing manually with ASAN.

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.

The global testing went fine. Results are a bit noisy again, but after looking through I'm convinced we're good to go ahead.

@rwgk rwgk merged commit ec81e8e into pybind:master Jan 27, 2022
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label Jan 27, 2022
@rwgk
Copy link
Collaborator

rwgk commented Jan 27, 2022

This is also on the smart_holder branch now. Thanks again!

Skylion007 added a commit to Skylion007/pybind11 that referenced this pull request Jan 28, 2022
@virtuald virtuald deleted the mi-propagate branch January 28, 2022 16:52
Skylion007 added a commit that referenced this pull request Jan 31, 2022
* Fix optimization bug introduced in #3650

* Add simple Python extension test for MVF

* Improve comments

* Clarify comment

* Clarify another comment

* Add test docstring

* Fix typo
@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label Feb 2, 2022
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