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

Stop sorting Spans' SyntaxContext, as that is incompatible with incremental #123165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 28, 2024

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 28, 2024
@@ -460,21 +460,21 @@ impl Ord for SpanData {
let SpanData {
lo: s_lo,
hi: s_hi,
ctxt: s_ctxt,
ctxt: _,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@oli-obk oli-obk Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2024
@oli-obk oli-obk added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 2, 2024
@petrochenkov
Copy link
Contributor

Is it hard to remove PartialOrd from Span and use some explicit location_only_ordering_hygiene_is_ignored method instead?
If the change affects SyntaxContext only, then the cure seems to be worse than the disease.

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 3, 2024

@rustbot author

I'll explore that, but I think at least borrowck uses it to sort its diagnostics

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 3, 2024
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 19, 2024

Is it hard to remove PartialOrd from Span and use some explicit location_only_ordering_hygiene_is_ignored method instead? If the change affects SyntaxContext only, then the cure seems to be worse than the disease.

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 SpanSortedByBytePos wrapper struct, everything else is too annoying. See https://github.com/rust-lang/rust/compare/master...oli-obk:rust:no_ord_span?expand=1 for a hacky way towards that

@rustbot
Copy link
Collaborator

rustbot commented Apr 19, 2024

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants