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

Rollup of 9 pull requests #126949

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
114dd20
Un-unsafe the `StableOrd` trait
eggyal Jun 12, 2024
a264bff
Mark assoc tys live only if the trait is live
mu001999 Jun 18, 2024
dd557d8
Add a test demonstrating that RPITITs cant use precise capturing
compiler-errors Jun 20, 2024
c39b86a
Fix a span in `parse_ty_bare_fn`.
nnethercote Jun 17, 2024
0e73e70
Ensure careful consideration is given by impls
eggyal Jun 22, 2024
594fa01
not use offset when there is not ends with brace
bvanjoi Jun 23, 2024
a2298a6
Do not ICE when suggesting dereferencing closure arg
estebank Jun 24, 2024
6521c39
Deny use<> for RPITITs
compiler-errors Jun 20, 2024
553a690
Specify target specific linker for riscv64gc-gnu job
Hoverbear Jun 24, 2024
26677eb
don't suggest awaiting type expr patterns
SparkyPotato Jun 24, 2024
8016940
Tweak a confusing comment in `create_match_candidates`
Zalathar Jun 24, 2024
83a7b8f
Rollup merge of #126326 - eggyal:ununsafe-StableOrd, r=michaelwoerister
compiler-errors Jun 25, 2024
50c1fda
Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix
compiler-errors Jun 25, 2024
f9a58c6
Rollup merge of #126724 - nnethercote:fix-parse_ty_bare_fn-span, r=co…
compiler-errors Jun 25, 2024
0e91505
Rollup merge of #126746 - compiler-errors:no-rpitit, r=oli-obk
compiler-errors Jun 25, 2024
f841558
Rollup merge of #126868 - bvanjoi:fix-126764, r=davidtwco
compiler-errors Jun 25, 2024
6c39e85
Rollup merge of #126884 - estebank:issue-125634, r=Nadrieril
compiler-errors Jun 25, 2024
7f8ba07
Rollup merge of #126915 - SparkyPotato:fix-126903, r=compiler-errors
compiler-errors Jun 25, 2024
72965db
Rollup merge of #126916 - ferrocene:hoverbear/riscv64gc-gnu-specify-l…
compiler-errors Jun 25, 2024
a765000
Rollup merge of #126926 - Zalathar:candidate-per-arm, r=Nadrieril
compiler-errors Jun 25, 2024
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
Prev Previous commit
Next Next commit
Ensure careful consideration is given by impls
Added an associated `const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED`
to the `StableOrd` trait to ensure that implementors carefully consider
whether the trait's contract is upheld, as incorrect implementations can
cause miscompilations.
  • Loading branch information
eggyal committed Jun 22, 2024
commit 0e73e7095ae7aa7ead69c4ba7ba002560ef118fa
6 changes: 4 additions & 2 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,13 @@ pub struct Size {
raw: u64,
}

// Ord is implement as just comparing numerical values and numerical values
// are not changed by (de-)serialization.
#[cfg(feature = "nightly")]
impl StableOrd for Size {
const CAN_USE_UNSTABLE_SORT: bool = true;

// `Ord` is implemented as just comparing numerical values and numerical values
// are not changed by (de-)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

// This is debug-printed a lot in larger structs, don't waste too much space there
Expand Down
50 changes: 43 additions & 7 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,21 @@ pub trait ToStableHashKey<HCX> {
/// The associated constant `CAN_USE_UNSTABLE_SORT` denotes whether
/// unstable sorting can be used for this type. Set to true if and
/// only if `a == b` implies `a` and `b` are fully indistinguishable.
///
/// **Be careful when implementing this trait, as an incorrect
/// implementation can cause miscompilation!**
pub trait StableOrd: Ord {
const CAN_USE_UNSTABLE_SORT: bool;

/// Marker to ensure that implementors have carefully considered
/// whether their `Ord` implementation obeys this trait's contract.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: ();
}

impl<T: StableOrd> StableOrd for &T {
const CAN_USE_UNSTABLE_SORT: bool = T::CAN_USE_UNSTABLE_SORT;

// Ordering of a reference is exactly that of the referent, and since
// the ordering of the referet is stable so must be the ordering of the
// reference.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

/// This is a companion trait to `StableOrd`. Some types like `Symbol` can be
Expand Down Expand Up @@ -295,6 +301,10 @@ macro_rules! impl_stable_traits_for_trivial_type {

impl $crate::stable_hasher::StableOrd for $t {
const CAN_USE_UNSTABLE_SORT: bool = true;

// Encoding and decoding doesn't change the bytes of trivial types
// and `Ord::cmp` depends only on those bytes.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
};
}
Expand Down Expand Up @@ -332,6 +342,10 @@ impl<CTX> HashStable<CTX> for Hash128 {

impl StableOrd for Hash128 {
const CAN_USE_UNSTABLE_SORT: bool = true;

// Encoding and decoding doesn't change the bytes of `Hash128`
// and `Ord::cmp` depends only on those bytes.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<CTX> HashStable<CTX> for ! {
Expand Down Expand Up @@ -397,6 +411,10 @@ impl<T1: HashStable<CTX>, T2: HashStable<CTX>, CTX> HashStable<CTX> for (T1, T2)

impl<T1: StableOrd, T2: StableOrd> StableOrd for (T1, T2) {
const CAN_USE_UNSTABLE_SORT: bool = T1::CAN_USE_UNSTABLE_SORT && T2::CAN_USE_UNSTABLE_SORT;

// Ordering of tuples is a pure function of their elements' ordering, and since
// the ordering of each element is stable so must be the ordering of the tuple.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3)
Expand All @@ -416,6 +434,10 @@ where
impl<T1: StableOrd, T2: StableOrd, T3: StableOrd> StableOrd for (T1, T2, T3) {
const CAN_USE_UNSTABLE_SORT: bool =
T1::CAN_USE_UNSTABLE_SORT && T2::CAN_USE_UNSTABLE_SORT && T3::CAN_USE_UNSTABLE_SORT;

// Ordering of tuples is a pure function of their elements' ordering, and since
// the ordering of each element is stable so must be the ordering of the tuple.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4)
Expand All @@ -439,6 +461,10 @@ impl<T1: StableOrd, T2: StableOrd, T3: StableOrd, T4: StableOrd> StableOrd for (
&& T2::CAN_USE_UNSTABLE_SORT
&& T3::CAN_USE_UNSTABLE_SORT
&& T4::CAN_USE_UNSTABLE_SORT;

// Ordering of tuples is a pure function of their elements' ordering, and since
// the ordering of each element is stable so must be the ordering of the tuple.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] {
Expand Down Expand Up @@ -533,6 +559,10 @@ impl<CTX> HashStable<CTX> for str {

impl StableOrd for &str {
const CAN_USE_UNSTABLE_SORT: bool = true;

// Encoding and decoding doesn't change the bytes of string slices
// and `Ord::cmp` depends only on those bytes.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<CTX> HashStable<CTX> for String {
Expand All @@ -542,10 +572,12 @@ impl<CTX> HashStable<CTX> for String {
}
}

// String comparison only depends on their contents and the
// contents are not changed by (de-)serialization.
impl StableOrd for String {
const CAN_USE_UNSTABLE_SORT: bool = true;

// String comparison only depends on their contents and the
// contents are not changed by (de-)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<HCX> ToStableHashKey<HCX> for String {
Expand All @@ -571,9 +603,11 @@ impl<CTX> HashStable<CTX> for bool {
}
}

// sort order of bools is not changed by (de-)serialization.
impl StableOrd for bool {
const CAN_USE_UNSTABLE_SORT: bool = true;

// sort order of bools is not changed by (de-)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<T, CTX> HashStable<CTX> for Option<T>
Expand All @@ -591,9 +625,11 @@ where
}
}

// the Option wrapper does not add instability to comparison.
impl<T: StableOrd> StableOrd for Option<T> {
const CAN_USE_UNSTABLE_SORT: bool = T::CAN_USE_UNSTABLE_SORT;

// the Option wrapper does not add instability to comparison.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<T1, T2, CTX> HashStable<CTX> for Result<T1, T2>
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir/src/hir_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ impl ItemLocalId {
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
}

// Ord is implement as just comparing the ItemLocalId's numerical
// values and these are not changed by (de-)serialization.
impl StableOrd for ItemLocalId {
const CAN_USE_UNSTABLE_SORT: bool = true;

// `Ord` is implemented as just comparing the ItemLocalId's numerical
// values and these are not changed by (de-)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_query_system/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ impl<HCX> ToStableHashKey<HCX> for WorkProductId {
impl StableOrd for WorkProductId {
// Fingerprint can use unstable (just a tuple of `u64`s), so WorkProductId can as well
const CAN_USE_UNSTABLE_SORT: bool = true;

// `WorkProductId` sort order is not affected by (de)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

// Some types are used a lot. Make sure they don't unintentionally get bigger.
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,11 @@ pub enum OutputType {
DepInfo,
}

// Trivial C-Style enums have a stable sort order across compilation sessions.
impl StableOrd for OutputType {
const CAN_USE_UNSTABLE_SORT: bool = true;

// Trivial C-Style enums have a stable sort order across compilation sessions.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

impl<HCX: HashStableContext> ToStableHashKey<HCX> for OutputType {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ impl Default for DefPathHash {
}
}

// `DefPathHash` sort order is not affected (de)serialization.
impl StableOrd for DefPathHash {
const CAN_USE_UNSTABLE_SORT: bool = true;

// `DefPathHash` sort order is not affected by (de)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}

/// A [`StableCrateId`] is a 64-bit hash of a crate name, together with all
Expand Down
Loading