Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incr.comp.: Fix potential unstable Fingerprint error for BorrowCheckResult #98924

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ fn do_mir_borrowck<'a, 'tcx>(
// Compute non-lexical lifetimes.
let nll::NllOutput {
regioncx,
opaque_type_values,
mut opaque_type_values,
polonius_input,
polonius_output,
opt_closure_req,
Expand Down Expand Up @@ -437,6 +437,12 @@ fn do_mir_borrowck<'a, 'tcx>(

let tainted_by_errors = mbcx.emit_errors();

// Since `BorrowCheckResult` is a query result, let's make sure that its `concrete_opaque_types`
// field is in deterministic order.
// Note, that this is not the best solution. It would be better to use a collection type
// that does not expose its internal order at all once that's available (see #63713).
opaque_type_values.sort_deterministically(&infcx.tcx.create_stable_hashing_context());

let result = BorrowCheckResult {
concrete_opaque_types: opaque_type_values,
closure_requirements: opt_closure_req,
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_data_structures/src/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::iter::FromIterator;
use std::slice::Iter;
use std::vec::IntoIter;

use crate::stable_hasher::{HashStable, StableHasher};
use crate::stable_hasher::{HashStable, StableHasher, ToStableHashKey};

/// A map type implemented as a vector of pairs `K` (key) and `V` (value).
/// It currently provides a subset of all the map operations, the rest could be added as needed.
Expand Down Expand Up @@ -190,5 +190,14 @@ where
}
}

impl<K, V> VecMap<K, V> {
pub fn sort_deterministically<HCX>(&mut self, hcx: &HCX)
where
K: ToStableHashKey<HCX>,
{
self.0.sort_by_cached_key(|(k, _)| k.to_stable_hash_key(hcx));
}
}

#[cfg(test)]
mod tests;