bindgen: surface base-class _Impl trait requirements for composable hierarchies#4416
bindgen: surface base-class _Impl trait requirements for composable hierarchies#4416Copilot wants to merge 5 commits into
_Impl trait requirements for composable hierarchies#4416Conversation
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/ab690217-de3d-467a-b2a5-054290f688e8 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
_Impl trait requirements for composable hierarchies
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/702910cb-5f28-424a-acf6-264e617f168f Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
There was a problem hiding this comment.
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
_Implsuper-trait bounds for exclusive default interfaces to include base classes’ default_Impltraits. - Add a new RDL bindgen fixture (
class_hierarchy_impl) validating_Impltrait 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.
| // 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); | ||
| } |
|
@copilot review feedback |
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/d7dc0bc6-90f2-44a0-8003-2ec93bb85658 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Good catch. Fixed in ffa2e56: the base default interfaces are only added to |
Fix windows-bindgen to emit
_Implsuper-trait bounds for default interfaces of derived classes (composable hierarchies), so implementers don't need to manually list every base class.Class::default_interfaceandClass::basestopubInterface::base_class_default_interfacesthat walks the owning class's bases and returns each base's default interfaceInterface::writeso the_Impltrait for an exclusive default interface picks up base classes' default_Impltraits as super-trait boundsconfig.should_implement(base, …)so configurations that emit the derived_Implbut omit a base_Impl(e.g.--implements Derivedwithout selecting the bases) fall back towindows_core::IUnknownImplinstead of referencing an un-emitted trait nameclass_hierarchy_impl(3-level hierarchy:Base←Middle←Leaf) verifying generatedIMiddle_Impl: IBase_ImplandILeaf_Impl: IMiddle_Impl + IBase_Implclass_hierarchy_impl_partialthat selects onlyTest.ILeafviaimplements, locking in theIUnknownImplfallback when bases are not selectedcrates/tests/winrt/composable/src/bindings.rsso its checked-in bindings reflect the new bounds (CI'sgit diff --exit-codeafter build.rs regen)