codegen: skip composable .ctor on instance interfaces#23
Open
yeelam-gordon wants to merge 1 commit intomainfrom
Open
codegen: skip composable .ctor on instance interfaces#23yeelam-gordon wants to merge 1 commit intomainfrom
yeelam-gordon wants to merge 1 commit intomainfrom
Conversation
Unsealed WinRT runtime classes expose a derived-from constructor on the
default/required instance interface whose CLR method name is literally
`.ctor`. It follows the COM aggregation pattern and is only meant to
be invoked by a host framework (in practice XAML). Codegen used to fall
through to the generic instance-method path and emit invalid syntax:
`def .ctor(self) -> None:` in Python and `.ctor(): void { ... }` in
TypeScript. Full-WinAppSDK smoke previously reported 62 affected files,
all in `Microsoft.UI.Xaml.*`.
Fix: early-return at the entry of the three per-method emitters:
- `project_instance_method` (TS)
- `generate_iface_instance_method` (Python)
- `emit_method_stub` (Python `.pyi` stub)
The `.add_method(`.ctor`, ...)` entry is still recorded in interface
registration so vtable indices and parameterized-IID computation remain
correct. Factory `.ctor(args)` (legitimate class construction) still
routes through `project_factory_method` / `generate_factory_method_invoke`
unchanged, and delegate `.ctor + Invoke` is still short-circuited to
`project_delegate` / `generate_delegate`.
Verification:
- New `tests/composable_ctor_test.rs` pins all three behaviors:
no `.ctor` declaration in TS / Python / `.pyi` output, and the
interface registration still reserves a vtable slot per method.
- Existing snapshot/cleanliness/tsc tests still pass (Uri output
unchanged).
- Full Microsoft.UI.Xaml.Controls.Button generation: 383 `.js` /
383 `.d.ts` / 383 `.py` / 383 `.pyi` files, all syntactically
valid (`python -m py_compile` and AST-parse on every file, zero
errors). 36 `.ctor` registrations preserved across the namespace.
Full fix for actually *invoking* the composable constructor still
requires implementing COM aggregation subclassing and XAML hosting --
out of scope until we take that on.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Unsealed WinRT runtime classes expose a derived-from constructor on the default/required instance interface whose CLR method name is literally
.ctor. It follows the COM aggregation pattern and is only meant to be invoked by a host framework (in practice XAML). Codegen used to fall through to the generic instance-method path and emit invalid syntax:def .ctor(self) -> None:in Python and.ctor(): void { ... }in TypeScript. Full-WinAppSDK smoke previously reported 62 affected files, all inMicrosoft.UI.Xaml.*.What changed
Early-return at the entry of the three per-method emitters:
project_instance_method(TS) --project.rsgenerate_iface_instance_method(Python) --py_method.rsemit_method_stub(Python.pyistub) --python_stub.rsThe
.add_method(.ctor, ...)entry is still recorded in interface registration so vtable indices and parameterized-IID computation remain correct. Factory.ctor(args)(legitimate class construction) still routes throughproject_factory_method/generate_factory_method_invokeunchanged, and delegate.ctor + Invokeis still short-circuited toproject_delegate/generate_delegate.Verification
tests/composable_ctor_test.rs(3 tests) pins all three behaviors: no.ctordeclaration in TS / Python /.pyioutput, and the interface registration still reserves a vtable slot per method.Microsoft.UI.Xaml.Controls.Buttongeneration: 383.js/ 383.d.ts/ 383.py/ 383.pyifiles, all syntactically valid:python -m py_compileon every.py: 0 errors / 383 filesast.parseon every.pyi: 0 errors / 383 files.ctorregistrations preserved across the namespace (vtable correctness)Out of scope
Full fix for actually invoking the composable constructor still requires implementing COM aggregation subclassing and XAML hosting -- out of scope until we take that on. This PR only stops codegen from emitting syntactically invalid output.