Skip to content

[mypyc] Recompile dependents when a class's native_class or @trait changes - #22136

Open
rheard wants to merge 1 commit into
python:masterfrom
rheard:fix-mypyc-1232
Open

rheard wants to merge 1 commit into
python:masterfrom
rheard:fix-mypyc-1232

Conversation

@rheard

@rheard rheard commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes mypyc/mypyc#1232.

With separate compilation, adding @mypyc_attr(native_class=False) to a class between builds, or removing it, didn't recompile the modules that use the class if its module already imported mypyc_attr. Mypy doesn't record the decorator, so the module's interface hash didn't change. The stale modules then failed to compile against the class's new export table ('CPyDef_a___C': is not a member of 'export_table_a'). @trait had the same problem, and there the result was a segfault: the trait's module looked for a trait vtable that the stale subclasses didn't have.

This is the follow-up mentioned in #22128, using the same approach. MypycPlugin.report_config_data now returns (name, is_ext_class, is_trait, is_decorated) for each class in the module, in place of the list of decorated class names that #22128 added, and mypy includes the plugin config data in the interface hash. When the cache is written, these come from the tree, using the same is_extension_class, is_trait and is_decorated_class calls as build_type_map. When the cache is checked, the module hasn't been parsed yet, so they come from the cached IR.

The new tests turn each decorator on and off. A step in the middle changes only native.py and checks that other, which then has a non-native class or a trait, stays fresh, so a mismatch between the write and check paths would show up.

Other mypyc_attr flags that affect subclasses in other modules, such as serializable, have the same gap. I left them out since they'd mean repeating how prepare_class_def derives them, but I can add them here if you'd like.

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.

Separate compilation doesn't recompile modules that use a class when @mypyc_attr(native_class=False) or @trait is added

1 participant