From 94212194da03033b0b62f503072e35c41ad03e5f Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 5 Jul 2022 12:20:32 +0200 Subject: [PATCH] incr.comp.: Fix potential unstable Fingerprint error for BorrowCheckResult. --- compiler/rustc_borrowck/src/lib.rs | 8 +++++++- compiler/rustc_data_structures/src/vec_map.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 7d6f37340c2bb..05b8d3fe17953 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -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, @@ -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, diff --git a/compiler/rustc_data_structures/src/vec_map.rs b/compiler/rustc_data_structures/src/vec_map.rs index 86be0bd8775d7..08c3674d7117b 100644 --- a/compiler/rustc_data_structures/src/vec_map.rs +++ b/compiler/rustc_data_structures/src/vec_map.rs @@ -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. @@ -190,5 +190,14 @@ where } } +impl VecMap { + pub fn sort_deterministically(&mut self, hcx: &HCX) + where + K: ToStableHashKey, + { + self.0.sort_by_cached_key(|(k, _)| k.to_stable_hash_key(hcx)); + } +} + #[cfg(test)] mod tests;