refactor: fix nondeterministic ordering for orphaned impls - #1933
Open
ahomescu wants to merge 2 commits into
Open
Conversation
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 01:40
4909a51 to
ae2a4ab
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 01:57
ae2a4ab to
3958028
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 02:07
3958028 to
cb4f49b
Compare
ahomescu
changed the base branch from
ahomescu/fix_reorganize_definitions/non_ascii_idents
to
ahomescu/fix_reorganize_definitions/move_impls
July 25, 2026 02:11
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 02:11
cb4f49b to
a9bb6b6
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
2 times, most recently
from
July 25, 2026 02:44
f5d0b6a to
c18365d
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 03:17
c18365d to
f7a8185
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 03:26
f7a8185 to
d48cffd
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 05:09
d48cffd to
8c90f29
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 05:33
8c90f29 to
69f3336
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 05:41
69f3336 to
b8b7cbd
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 05:42
b8b7cbd to
a4762b4
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 05:48
a4762b4 to
e12328d
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 05:53
e12328d to
87fe048
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:00
87fe048 to
8ed12c4
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:05
8ed12c4 to
e47b3f7
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:16
e47b3f7 to
4046cf7
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:26
4046cf7 to
25d529e
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:43
25d529e to
22e2e15
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:51
22e2e15 to
2d83bcd
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 29, 2026 23:18
2d83bcd to
4498dd0
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
2 times, most recently
from
July 30, 2026 00:31
a91bf17 to
cb8ad37
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
2 times, most recently
from
July 30, 2026 22:56
d88ce74 to
90c77c2
Compare
Regression test: `test_reorganize_orphaned_impl_order` (`tests/snapshots/reorganize_orphaned_impl_order.rs`). Three const-only `impl` blocks sit in one header module, each on a different self type, and all three self types are defined outside any header module. That is what keeps their entries in the `impls` map unclaimed: an entry is only removed when the self type's own declaration is individually processed, which never happens for a type defined outside the headers. All three are then appended to `pending_impls` by iterating a `HashMap`, and reattached to `stuff` in whatever order that iteration produced. The recorded snapshot is one of the six orderings; the test fails on the other five, so it currently passes about one run in six.
`remove_header_items` collected the `impl` blocks it can carry alongside a moved declaration into a `HashMap<DefId, MovedDeclImpl>`, keyed by the self type. Entries are claimed as each self type's own declaration is processed, but an `impl` whose self type is defined outside any header module is never claimed, and what is left is appended to `pending_impls` by iterating the map. `move_items` emits `pending_impls` in order, so the `impl` blocks reattached to a module came out in `HashMap` iteration order, which varies between runs. This is the same defect as the `foreign_items` map fixed in "fix nondeterministic ordering for foreign items", one level up. `impls` is now an `IndexMap`, so the leftovers are appended in the order the blocks appear in the header module, and removals use `shift_remove` so that claiming one entry does not permute the rest (`remove`/`swap_remove` would keep the output deterministic, but in an order unrelated to the source). The snapshot changes to the order the three `impl` blocks are written in.
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 30, 2026 22:58
90c77c2 to
d53027a
Compare
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.
Stack created with GitHub Stacks CLI • Give Feedback 💬