Skip to content

Commit

Permalink
Auto merge of #123165 - oli-obk:no_ord_def_id3, r=cjgillot
Browse files Browse the repository at this point in the history
Stop sorting `Span`s' `SyntaxContext`, as that is incompatible with incremental

work towards #90317

Luckily no one actually needed these to be sorted, so it didn't even affect diagnostics. I'm guessing they'd have been sorted by creation time anyway, so it wouldn't really have mattered.

r? `@cjgillot`
  • Loading branch information
bors committed Jun 21, 2024
2 parents d40f30e + 4239a73 commit 25c9f2c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 32 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4762,6 +4762,7 @@ dependencies = [
name = "rustc_span"
version = "0.0.0"
dependencies = [
"derivative",
"indexmap",
"itoa",
"md-5",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
# tidy-alphabetical-start
derivative = "2.2.0"
indexmap = { version = "2.0.0" }
itoa = "1.0"
md5 = { package = "md-5", version = "0.10.0" }
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ use std::hash::Hash;
use tracing::{debug, trace};

/// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks".
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct SyntaxContext(u32);

// To ensure correctness of incremental compilation,
// `SyntaxContext` must not implement `Ord` or `PartialOrd`.
// See https://github.com/rust-lang/rust/issues/90317.
impl !Ord for SyntaxContext {}
impl !PartialOrd for SyntaxContext {}

#[derive(Debug, Encodable, Decodable, Clone)]
pub struct SyntaxContextData {
outer_expn: ExpnId,
Expand Down
39 changes: 8 additions & 31 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,46 +467,23 @@ impl FileName {
/// `SpanData` is public because `Span` uses a thread-local interner and can't be
/// sent to other threads, but some pieces of performance infra run in a separate thread.
/// Using `Span` is generally preferred.
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[derive(Clone, Copy, Hash, PartialEq, Eq, derivative::Derivative)]
#[derivative(PartialOrd, Ord)]
pub struct SpanData {
pub lo: BytePos,
pub hi: BytePos,
/// Information about where the macro came from, if this piece of
/// code was created by a macro expansion.
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
// `SyntaxContext` does not implement `Ord`.
// The other fields are enough to determine in-file order.
pub ctxt: SyntaxContext,
#[derivative(PartialOrd = "ignore", Ord = "ignore")]
// `LocalDefId` does not implement `Ord`.
// The other fields are enough to determine in-file order.
pub parent: Option<LocalDefId>,
}

// Order spans by position in the file.
impl Ord for SpanData {
fn cmp(&self, other: &Self) -> Ordering {
let SpanData {
lo: s_lo,
hi: s_hi,
ctxt: s_ctxt,
// `LocalDefId` does not implement `Ord`.
// The other fields are enough to determine in-file order.
parent: _,
} = self;
let SpanData {
lo: o_lo,
hi: o_hi,
ctxt: o_ctxt,
// `LocalDefId` does not implement `Ord`.
// The other fields are enough to determine in-file order.
parent: _,
} = other;

(s_lo, s_hi, s_ctxt).cmp(&(o_lo, o_hi, o_ctxt))
}
}

impl PartialOrd for SpanData {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl SpanData {
#[inline]
pub fn span(&self) -> Span {
Expand Down

0 comments on commit 25c9f2c

Please sign in to comment.