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/non_ascii_idents
branch
from
July 25, 2026 01:40
bc1e9f1 to
fdec068
Compare
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/non_ascii_idents
branch
from
July 25, 2026 01:57
fdec068 to
c4f8d6f
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/non_ascii_idents
branch
from
July 25, 2026 02:07
c4f8d6f to
b6501c7
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/move_impls
branch
from
July 25, 2026 02:16
8e0fdc6 to
bc21f43
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/move_impls
branch
2 times, most recently
from
July 25, 2026 03:17
9b9adb2 to
96ca5e6
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/move_impls
branch
from
July 25, 2026 03:26
96ca5e6 to
0739482
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/move_impls
branch
from
July 25, 2026 05:09
0739482 to
2fca703
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/move_impls
branch
from
July 25, 2026 05:33
2fca703 to
52cf39f
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/move_impls
branch
from
July 25, 2026 05:41
52cf39f to
1ff0704
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/move_impls
branch
from
July 25, 2026 05:42
1ff0704 to
1f4904f
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/move_impls
branch
from
July 25, 2026 05:48
1f4904f to
f675e52
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/move_impls
branch
from
July 25, 2026 05:53
f675e52 to
90c2469
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/move_impls
branch
from
July 25, 2026 06:00
90c2469 to
af56551
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/move_impls
branch
from
July 25, 2026 06:05
af56551 to
dd20965
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/move_impls
branch
from
July 25, 2026 06:16
dd20965 to
8a12703
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/move_impls
branch
from
July 25, 2026 06:26
8a12703 to
9f50992
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/move_impls
branch
from
July 25, 2026 06:43
9f50992 to
ac05fb9
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:43
25d529e to
22e2e15
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/move_impls
branch
from
July 25, 2026 06:51
ac05fb9 to
8257d5e
Compare
ahomescu
force-pushed
the
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
branch
from
July 25, 2026 06:51
22e2e15 to
2d83bcd
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 💬