Skip to content

Deduplicate method tables in jl_foreach_reachable_mtable#61221

Merged
maleadt merged 2 commits intomasterfrom
tb/mt_visit_twice
Mar 6, 2026
Merged

Deduplicate method tables in jl_foreach_reachable_mtable#61221
maleadt merged 2 commits intomasterfrom
tb/mt_visit_twice

Conversation

@maleadt
Copy link
Member

@maleadt maleadt commented Mar 3, 2026

When a custom method table is defined in one package and imported by another, jl_foreach_reachable_mtable visits the same table twice (once per module binding). This causes extext methods to be collected and serialized twice, and on loading, jl_method_table_activate asserts because dispatch_status was already set by the first activation.

Add an htable to track visited method tables and skip duplicates.

@maleadt maleadt added bugfix This change fixes an existing bug backport 1.12 Change should be backported to release-1.12 backport 1.13 Change should be backported to release-1.13 labels Mar 3, 2026
@maleadt maleadt requested a review from vtjnash March 4, 2026 09:39
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

LGTM. We used to have some check that mt->module == v && mt->name == name (just like module visitor), but I guess that was lost in refactoring

maleadt and others added 2 commits March 5, 2026 07:37
When a custom method table is defined in one package and imported by
another, jl_foreach_reachable_mtable visits the same table twice (once
per module binding). This causes extext methods to be collected and
serialized twice, and on loading, jl_method_table_activate asserts
because dispatch_status was already set by the first activation.

Add an htable to track visited method tables and skip duplicates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@maleadt maleadt force-pushed the tb/mt_visit_twice branch from 1aea422 to c9237d8 Compare March 5, 2026 06:37
@maleadt
Copy link
Member Author

maleadt commented Mar 5, 2026

Ah yes, found it in https://github.com/JuliaLang/julia/pull/58131/changes#diff-9a718f382a240acdbe9d0bdbc3ffb521f67af0e62b2ba8c8594b8faa65c78014L799
I've pushed the simplification like how the code originally was, or do prefer the explicit htable vesion?

@maleadt maleadt merged commit 91b4d72 into master Mar 6, 2026
8 checks passed
@maleadt maleadt deleted the tb/mt_visit_twice branch March 6, 2026 07:33
maleadt added a commit that referenced this pull request Mar 6, 2026
When a custom method table is defined in one package and imported by
another, jl_foreach_reachable_mtable visits the same table twice (once
per module binding). This causes extext methods to be collected and
serialized twice, and on loading, jl_method_table_activate asserts
because dispatch_status was already set by the first activation.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
maleadt added a commit that referenced this pull request Mar 6, 2026
When a custom method table is defined in one package and imported by
another, jl_foreach_reachable_mtable visits the same table twice (once
per module binding). This causes extext methods to be collected and
serialized twice, and on loading, jl_method_table_activate asserts
because dispatch_status was already set by the first activation.

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@maleadt maleadt removed backport 1.12 Change should be backported to release-1.12 backport 1.13 Change should be backported to release-1.13 labels Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This change fixes an existing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants