Skip to content

refactor: fix nondeterministic ordering for orphaned impls #1933

Open
ahomescu wants to merge 2 commits into
ahomescu/fix_reorganize_definitions/move_implsfrom
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls
Open

refactor: fix nondeterministic ordering for orphaned impls #1933
ahomescu wants to merge 2 commits into
ahomescu/fix_reorganize_definitions/move_implsfrom
ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls

Conversation

@ahomescu

Copy link
Copy Markdown
Contributor

Stack created with GitHub Stacks CLIGive Feedback 💬

@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/non_ascii_idents branch from bc1e9f1 to fdec068 Compare July 25, 2026 01:40
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 4909a51 to ae2a4ab Compare July 25, 2026 01:40
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/non_ascii_idents branch from fdec068 to c4f8d6f Compare July 25, 2026 01:57
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from ae2a4ab to 3958028 Compare July 25, 2026 01:57
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/non_ascii_idents branch from c4f8d6f to b6501c7 Compare July 25, 2026 02:07
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 3958028 to cb4f49b Compare July 25, 2026 02:07
@ahomescu
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
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from cb4f49b to a9bb6b6 Compare July 25, 2026 02:11
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 8e0fdc6 to bc21f43 Compare July 25, 2026 02:16
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch 2 times, most recently from f5d0b6a to c18365d Compare July 25, 2026 02:44
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch 2 times, most recently from 9b9adb2 to 96ca5e6 Compare July 25, 2026 03:17
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from c18365d to f7a8185 Compare July 25, 2026 03:17
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 96ca5e6 to 0739482 Compare July 25, 2026 03:26
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from f7a8185 to d48cffd Compare July 25, 2026 03:26
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 0739482 to 2fca703 Compare July 25, 2026 05:09
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from d48cffd to 8c90f29 Compare July 25, 2026 05:09
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 2fca703 to 52cf39f Compare July 25, 2026 05:33
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 8c90f29 to 69f3336 Compare July 25, 2026 05:33
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 52cf39f to 1ff0704 Compare July 25, 2026 05:41
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 69f3336 to b8b7cbd Compare July 25, 2026 05:41
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 1ff0704 to 1f4904f Compare July 25, 2026 05:42
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from b8b7cbd to a4762b4 Compare July 25, 2026 05:42
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 1f4904f to f675e52 Compare July 25, 2026 05:48
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from a4762b4 to e12328d Compare July 25, 2026 05:48
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from f675e52 to 90c2469 Compare July 25, 2026 05:53
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from e12328d to 87fe048 Compare July 25, 2026 05:53
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 90c2469 to af56551 Compare July 25, 2026 06:00
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 87fe048 to 8ed12c4 Compare July 25, 2026 06:00
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from af56551 to dd20965 Compare July 25, 2026 06:05
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 8ed12c4 to e47b3f7 Compare July 25, 2026 06:05
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from dd20965 to 8a12703 Compare July 25, 2026 06:16
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from e47b3f7 to 4046cf7 Compare July 25, 2026 06:16
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 8a12703 to 9f50992 Compare July 25, 2026 06:26
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 4046cf7 to 25d529e Compare July 25, 2026 06:26
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from 9f50992 to ac05fb9 Compare July 25, 2026 06:43
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 25d529e to 22e2e15 Compare July 25, 2026 06:43
ahomescu added 2 commits July 24, 2026 23:51
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
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/move_impls branch from ac05fb9 to 8257d5e Compare July 25, 2026 06:51
@ahomescu
ahomescu force-pushed the ahomescu/fix_reorganize_definitions/deterministic_orphaned_impls branch from 22e2e15 to 2d83bcd Compare July 25, 2026 06:51
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.

1 participant