Python tests: check that the registration order doesn't depend on the fragment link order - #43
Open
Fedr wants to merge 4 commits into
Open
Python tests: check that the registration order doesn't depend on the fragment link order#43Fedr wants to merge 4 commits into
Fedr wants to merge 4 commits into
Conversation
adalisk-emikhaylov
added a commit
that referenced
this pull request
Aug 7, 2026
adalisk-emikhaylov
added a commit
that referenced
this pull request
Aug 7, 2026
…rden the deterministic type sort The Aliases: docstring lines were emitted in the iteration order of Registry::type_aliases, which follows the static-init (= link) order of the fragment TUs, so they could still differ between two builds of identical source - sort them, and load the aliases themselves in sorted order too (when two alias spellings map to the same Python name, the winner used to depend on that iteration order). Also tie-break exact type-name collisions in the topological sort by the mangled typeid name (std::sort is unstable, so equal keys would keep layout-dependent order), include <algorithm>/<cstring> explicitly instead of transitively, and drop the inner sorted_rdeps that shadowed the buffer meant to be reused across iterations.
…ation test/check_py_registration_order.sh builds a small input as 4 fragments, links the same objects in two different orders, and requires the resulting modules to have identical type registration order, alias registration, docstrings, and injected __init__ overload order. The aliases in the input are deliberately spread across the file so that they land in different fragments.
Fedr
force-pushed
the
deterministic-type-order
branch
from
August 7, 2026 17:07
036c171 to
adc7e99
Compare
Only the link-order regression check remains in this branch.
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.
Adds a regression check for the deterministic registration order of the Python bindings, locking in the guarantees introduced by 236ba96 (deterministic topological type sort) and f2764c5 (deterministic alias ordering).
What it checks
The types and aliases are registered by static initializers, so their registration order across the fragment TUs follows the link order, and until the two commits above the bindings visibly depended on it: relinking the same objects in a different order moved the
__init__overloads injected from conversion operators (which affects pybind11's overload resolution), and shuffled theAliases:docstring lines.test/check_py_registration_order.sh:test/order_check/input/MR/order.h— 8 classes with conversion operators into oneTargetclass, plus 5 type aliases of it, deliberately spread across the file so that they land in different fragments (adjacent declarations would end up in the same fragment and could never shuffle);0 1 2 3and0 3 2 1;MRBIND_DEBUG=2type/alias registration log,Target's docstring, and its__init__overload list to be identical.Status
MRBIND_DEBUG=2dump is byte-identical between the two link orders.Aliases:docstring line; before 236ba96 also on the type registration order and the injected__init__overload positions:The branch history keeps the earlier implementation commits (now superseded by the master ones and reverted), so the net diff is just the check and its input.