Repository navigation
Stop sorting Spans' SyntaxContext, as that is incompatible with incremental - #123165
Conversation
| lo: s_lo, | ||
| hi: s_hi, | ||
| ctxt: s_ctxt, | ||
| ctxt: _, |
There was a problem hiding this comment.
This needs a comment for macro expansions.
Side note: this Ord impl is not consistent with the derived impl for PartialEq. Should we fix the latter?
There was a problem hiding this comment.
What do you think about ensuring that for equal (including the sort-ignored fields) SpanDatas we just return Ordering::Equal, and only sort the others?
There was a problem hiding this comment.
That's not consistent either.
The a == b implies partial_cmp(a, b) == Some(Equal) direction is easy. We have it without adding a special case.
The converse is harder: if s_lo == o_lo && s_hi == o_hi we get Some(Equal), but s_ctxt may not be o_ctxt.
There was a problem hiding this comment.
Maybe Spans should just be PartialOrd, but not Ord. I'll try if we can get away with just removing Ord
Edit: ah no, we need Ord for sort and friends.
Yea, idk how to solve this in a way that makes everything work out, except go full in with https://github.com/rust-lang/rust/compare/master...oli-obk:rust:no_ord_span?expand=1, no matter how annoying it is
|
Is it hard to remove |
|
@rustbot author I'll explore that, but I think at least borrowck uses it to sort its diagnostics |
I tried it, but sorting spans is used all over the compiler, even if we added convenience helpers for it, the right way would be to replace most of these spans with a |
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
@bors r+ rollup=never |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (25c9f2c): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResults (secondary -2.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 694.36s -> 694.089s (-0.04%) |
`Span` and `SpanData` encode four fields: `lo`/`hi`, `ctxt`, and `parent`. `ctxt` and `parent` have unorderable types. Both types ignore `ctxt` and `parent` for `PartialOrd`/`Ord`. But their `PartialEq`/`Eq` impls do *not* ignore those fields. This eq/ord inconsistency is a bug. It was introduced in rust-lang#123165. The idea of ordering spans in general is dubious, because of `ctxt` and `parent`. But the idea of ordering spans just with `lo`/`hi` is fine. Therefore, this commit does the following. - Removes the `PartialOrd`/`Ord` impls for `Span`/`SpanData` - Adds a `Span::lo_hi` method which can be used in lots of places where span locations are involved in sorting. E.g. `xs.sort_by_key(|span| span.lo_hi())` - Adds `OrdSpan`, a newtype around `Span` that impls `PartialEq`/`Eq`/`PartialOrd`/`Ord` using `lo_hi`. This is for storing spans in ordered types like `BTreeMap<OrdSpan, T>`. Note also that some `sort`+`dedup` combinations might not remove all duplicates with the old eq/ord inconsistency. These now all do the right thing, which could affect some error messages, though in practice nothing in the test suite is affected.
`Span` and `SpanData` encode four fields: `lo`/`hi`, `ctxt`, and `parent`. `ctxt` and `parent` have unorderable types. Both types ignore `ctxt` and `parent` for `PartialOrd`/`Ord`. But their `PartialEq`/`Eq` impls do *not* ignore those fields. This eq/ord inconsistency is a bug. It was introduced in rust-lang#123165. The idea of ordering spans in general is dubious, because of `ctxt` and `parent`. But the idea of ordering spans just with `lo`/`hi` is fine. Therefore, this commit does the following. - Removes the `PartialOrd`/`Ord` impls for `Span`/`SpanData` - Adds a `Span::lo_hi` method which can be used in lots of places where span locations are involved in sorting. E.g. `xs.sort_by_key(|span| span.lo_hi())` - Adds `OrdSpan`, a newtype around `Span` that impls `PartialEq`/`Eq`/`PartialOrd`/`Ord` using `lo_hi`. This is for storing spans in ordered types like `BTreeMap<OrdSpan, T>`. Note also that some `sort`+`dedup` combinations might not remove all duplicates with the old eq/ord inconsistency. These now all do the right thing, which could affect some error messages, though in practice nothing in the test suite is affected.
`Span` and `SpanData` encode four fields: `lo`/`hi`, `ctxt`, and `parent`. `ctxt` and `parent` have unorderable types. Both types ignore `ctxt` and `parent` for `PartialOrd`/`Ord`. But their `PartialEq`/`Eq` impls do *not* ignore those fields. This eq/ord inconsistency is a bug. It was introduced in rust-lang#123165. The idea of ordering spans in general is dubious, because of `ctxt` and `parent`. But the idea of ordering spans just with `lo`/`hi` is fine. Therefore, this commit does the following. - Removes the `PartialOrd`/`Ord` impls for `Span`/`SpanData` - Adds a `Span::lo_hi` method which can be used in lots of places where span locations are involved in sorting. E.g. `xs.sort_by_key(|span| span.lo_hi())` - Adds `OrdSpan`, a newtype around `Span` that impls `PartialEq`/`Eq`/`PartialOrd`/`Ord` using `lo_hi`. This is for storing spans in ordered types like `BTreeMap<OrdSpan, T>`. Note also that some `sort`+`dedup` combinations might not remove all duplicates with the old eq/ord inconsistency. These now all do the right thing, which could affect some error messages, though in practice nothing in the test suite is affected.
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