Skip to content

Using stable iteration order for user_provided_types writeback#151949

Open
paradoxicalguy wants to merge 2 commits intorust-lang:mainfrom
paradoxicalguy:stable-iteration-order
Open

Using stable iteration order for user_provided_types writeback#151949
paradoxicalguy wants to merge 2 commits intorust-lang:mainfrom
paradoxicalguy:stable-iteration-order

Conversation

@paradoxicalguy
Copy link
Contributor

@paradoxicalguy paradoxicalguy commented Feb 1, 2026

fixes issue #73501

this PR fixes a source of MIR non-determinism described in issue #73501 by applying a stable iteration order when writing user_provided_types from the function context into TypechResults during writeback phase.

previously these entries were done by using .extend() on user_provided_types, an unstable iteration order leading to DefId drift because of randomness causing MIR differences between local runs and CI,
switching to items_in_stable_order() ensures deterministic insertion without changing semantics because it sorts items by ItemLocalId before inserting them.

tests ran:

  • ./x.py test tests/mir-opt now produces a stable result across repeated runs

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 1, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2026

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@dianne
Copy link
Contributor

dianne commented Feb 4, 2026

🤔 user type annotations are stored in an UnordMap, so whatever's consuming it after writeback really shouldn't be depending on ordering, right? If changing the insertion order changes anything, that's pretty suspicious; I'd imagine it means something else is doing something wrong. LocalTableInContextMut::extend takes UnordItems specifically because it should be order-independent.

Also, judging by the CI failure that prompted it, the problem in #73501 looks like DefIds not being reproducible between different rustc builds, not a problem with nondeterministic iteration order. How does this address that?

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 4, 2026

I agree with dianne's analysis

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 4, 2026

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 4, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 4, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@paradoxicalguy
Copy link
Contributor Author

thanks for the feedback @dianne
i need to investigate this further, i will trace through and update this PR after finding the root cause or any progression in this area

@rustbot
Copy link
Collaborator

rustbot commented Feb 4, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot
Copy link
Collaborator

rustbot commented Feb 4, 2026

⚠️ Warning ⚠️

  • The following commits have merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

    You can start a rebase with the following commands:

    $ # rebase
    $ git pull --rebase https://github.com/rust-lang/rust.git main
    $ git push --force-with-lease
    

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Feb 4, 2026
@paradoxicalguy
Copy link
Contributor Author

@dianne @BoxyUwU
i tried to reproduce this issue locally but the generated mir remained perfectly identical across all local tests, suggesting the root cause might be architecture difference or isolated to CI environments.
and you're right this isn't a correct fix, closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants