Skip to content

bindgen: surface base-class _Impl trait requirements for composable hierarchies#4416

Draft
Copilot wants to merge 5 commits into
masterfrom
copilot/add-impl-trait-requirements
Draft

bindgen: surface base-class _Impl trait requirements for composable hierarchies#4416
Copilot wants to merge 5 commits into
masterfrom
copilot/add-impl-trait-requirements

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

Fix windows-bindgen to emit _Impl super-trait bounds for default interfaces of derived classes (composable hierarchies), so implementers don't need to manually list every base class.

  • Promote Class::default_interface and Class::bases to pub
  • Add Interface::base_class_default_interfaces that walks the owning class's bases and returns each base's default interface
  • Extend Interface::write so the _Impl trait for an exclusive default interface picks up base classes' default _Impl traits as super-trait bounds
  • Gate the inherited bound on config.should_implement(base, …) so configurations that emit the derived _Impl but omit a base _Impl (e.g. --implements Derived without selecting the bases) fall back to windows_core::IUnknownImpl instead of referencing an un-emitted trait name
  • Add rdl fixture class_hierarchy_impl (3-level hierarchy: BaseMiddleLeaf) verifying generated IMiddle_Impl: IBase_Impl and ILeaf_Impl: IMiddle_Impl + IBase_Impl
  • Add rdl fixture class_hierarchy_impl_partial that selects only Test.ILeaf via implements, locking in the IUnknownImpl fallback when bases are not selected
  • Regenerate crates/tests/winrt/composable/src/bindings.rs so its checked-in bindings reflect the new bounds (CI's git diff --exit-code after build.rs regen)
  • All 323 bindgen/rdl fixtures pass; parallel_validation clean

Copilot AI changed the title [WIP] Add impl trait requirements for composable type hierarchies bindgen: surface base-class _Impl trait requirements for composable hierarchies May 15, 2026
Copilot AI requested a review from kennykerr May 15, 2026 06:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates windows-bindgen to surface base-class default-interface implementation requirements in generated _Impl traits for composable class hierarchies, reducing the need for implementers to manually enumerate every base class in implementation scaffolding.

Changes:

  • Extend bindgen _Impl super-trait bounds for exclusive default interfaces to include base classes’ default _Impl traits.
  • Add a new RDL bindgen fixture (class_hierarchy_impl) validating _Impl trait super-trait chaining across a 3-level class hierarchy.
  • Regenerate the WinRT composable test bindings to reflect the new emitted bounds.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/libs/bindgen/src/types/interface.rs Adds base-class default interface discovery and wires it into _Impl super-trait requirements.
crates/libs/bindgen/src/types/class.rs Exposes default_interface and bases for use by interface codegen.
crates/tests/libs/bindgen/data/bindgen/class_hierarchy_impl/input.rdl New fixture input defining a 3-level class hierarchy with exclusive default interfaces.
crates/tests/libs/bindgen/data/bindgen/class_hierarchy_impl/fixture.toml New fixture configuration enabling implementation scaffolding output.
crates/tests/libs/bindgen/data/bindgen/class_hierarchy_impl/expected.rs Golden output asserting the new _Impl super-trait bounds.
crates/tests/winrt/composable/src/bindings.rs Updated generated bindings to include new _Impl trait super-trait bounds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +101 to +110
// their `_Impl` traits. This means implementing the default interface of a derived class
// automatically pulls in the obligation to implement the default interfaces of its base
// classes, without the caller having to list every base in `#[implement(...)]`.
for extra in self.base_class_default_interfaces(config.reader) {
if !required_interfaces
.iter()
.any(|existing| existing.def == extra.def)
{
required_interfaces.push(extra);
}
@kennykerr
Copy link
Copy Markdown
Collaborator

@copilot review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 15, 2026

@copilot review feedback

Good catch. Fixed in ffa2e56: the base default interfaces are only added to required_interfaces (and thus to the _Impl super-trait bound) when config.should_implement returns true for the base, so --implements Derived without the bases falls back to windows_core::IUnknownImpl instead of referencing an un-emitted _Impl trait. Added a class_hierarchy_impl_partial rdl fixture that selects only Test.ILeaf via implements, verifying the fallback (pub trait ILeaf_Impl: windows_core::IUnknownImpl).

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.

windows-bindgen should add impl trait requirements for composable type hiearchies

3 participants