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

move implicit Sized predicate to end of list #86011

Merged
merged 2 commits into from
Oct 15, 2021

Conversation

tlyu
Copy link
Contributor

@tlyu tlyu commented Jun 4, 2021

In Bounds::predicates(), move the implicit Sized predicate to the
end of the generated list. This means that if there is an explicit
Sized bound, it will be checked first, and any resulting
diagnostics will have a more useful span.

Fixes #85998, at least partially. Based on #85979, but only the last 2 commits are new for this pull request. (edit: rebased) A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit Sized predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I could use some help interpreting the changes to the stderr output. It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with Sized bounds. Possibly some error reporting code is making assumptions about ordering of predicates? The diagnostics for src/test/ui/derives/derives-span-Hash-*.rs seem to have improved, no longer pointing at the type parameter identifier, but src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs became less verbose for some reason.

I also ran into an instance of #84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

@estebank this seems likely to conflict (slightly?) with your work on #85947; how would you like to resolve that?

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 4, 2021
@rust-log-analyzer

This comment has been minimized.

Comment on lines 6 to 7
|
::: $SRC_DIR/std/src/panicking.rs:LL:COL
|
LL | pub fn begin_panic<M: Any + Send>(msg: M) -> ! {
| --- required by this bound in `begin_panic`
|
= note: cannot satisfy `_: Any`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is arguably a regression.

@estebank
Copy link
Contributor

estebank commented Jun 5, 2021

A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit Sized predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I made these two changes in order to have the right spans available. I'm not sure if these changes would be enough to address what you're mentioning here.

29c8a9f#diff-0a61b538a3cec072c76fecae4635af6a12ec3256860029ac70549c2aa53ab394R1480-R1485

29c8a9f#diff-ac1e6e554bac799e1e2d3886bea8fdc0d0bf04b20d33df59f5a8e92c41987ac6R2137-R2139

It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with Sized bounds. Possibly some error reporting code is making assumptions about ordering of predicates?

It some what does. I can point you at where that is happening, but if you search for where E0282 and E0284 are emitted, you'll find them. It's fine if there are small changes, we just might have to tweak the logic there to keep whatever checks we currently have.

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs seemed to not get more verbose, things just moved around, which make sense.

I also ran into an instance of #84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

Did this happen on tests or while working on rustc? Did it happen with --keep-stage 1? If the problem is one of "we might hit this in CI" it's less concerning to me than "users will hit a new fingerprint issue in stable in 12 weeks".

@estebank
Copy link
Contributor

estebank commented Jun 5, 2021

r? @estebank
r=me after potentially addressing the src/test/ui/issues/issue-16966.stderr case, but if you find it difficult to do (I would just remove the note in every case where it is _: Something) or lack the time, we can land as is.

@rust-highfive rust-highfive assigned estebank and unassigned varkor Jun 5, 2021
@tlyu
Copy link
Contributor Author

tlyu commented Jun 6, 2021

Thanks for the review! I'll be taking a closer look at the things you pointed out and will probably reply in more detail soon.

I also ran into an instance of #84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

Did this happen on tests or while working on rustc? Did it happen with --keep-stage 1? If the problem is one of "we might hit this in CI" it's less concerning to me than "users will hit a new fingerprint issue in stable in 12 weeks".

I opened issue #86013 with more details. Basically, when I either applied or reverted the patches in this PR, the fingerprints changed and I got the ICE on a specific UI test case. For what it's worth, I built the stage1 compiler and libstd using ./x.py build -i, and did not encounter ICEs while building the compiler itself.

As for whether this will cause fingerprint errors when this lands in stable? I'm not sure I know enough about the details of incremental compilation. Do we have some way of invalidating incremental compilation caches when there are internal changes to the compiler? (I hope so.) If so, how is this done? Is it part of the release process? Automatically according to the commit-hash stored during build?

@tlyu
Copy link
Contributor Author

tlyu commented Jun 6, 2021

src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs seemed to not get more verbose, things just moved around, which make sense.

if you compare
https://github.com/rust-lang/rust/pull/86011/files#diff-06109f234a5a60a647998669551ba82a0a549f34b4741bd5da4a449afbbe14a6L13
with
https://github.com/rust-lang/rust/pull/86011/files#diff-06109f234a5a60a647998669551ba82a0a549f34b4741bd5da4a449afbbe14a6R37
you'll notice (A, B, <A as Foo>::Bar) got deleted from the error message.

For issue-16966, I found this area to be somewhat suspicious:

if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
self.emit_inference_failure_err(body_id, span, subst, vec![], ErrorCode::E0282)
.emit();
return;
}

and I'm attempting to investigate. It maybe that the type inference ambiguity causes a bunch of simultaneous errors and we previously happened to get the Sized trait predicate first, outputting the more terse error E0282 instead of E0283.

@tlyu
Copy link
Contributor Author

tlyu commented Jun 8, 2021

What I thought was the "obvious" approach to quieting the new E0283 in issue-16966 has some nontrivial fallout. Maybe the smallest change to the diagnostics is what we already have in this pull request? Do you think we need to make additional changes in this pull request?

I tried to see what would happen if I made this block in maybe_report_ambiguity() either always or never execute:

if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
self.emit_inference_failure_err(body_id, span, subst, vec![], ErrorCode::E0282)
.emit();
return;
}

I wound up with these outputs from the UI tests:
always:
always-E0282.txt
never:
never-E0282.txt

The "never" approach generates a lot more diffs in the stderr output than the "always" approach. (51 failures with "never", vs 19 failures with "always")

A quick glance at the output from the "always" approach shows that the diffs are largely making some vague verbose diagnostics less verbose.

My guess (partially confirmed by disabling some of the verbosity suppression) is that in the case of issue-16966, the type inference ambiguity was causing every trait bound to not be satisfied, and prior to my changes, we were luckily hitting Sized first and ending up with E0282, but are now getting E0283 because the first unsatisfied bound is no longer Sized.

Any opinions on whether the deleted verbosity with "always" was at all helpful? It sounds like you might be concerned that the E0283 now appearing with issue-16966 is too verbose? If so, how do you feel about the existing instances of E0283 verbosity that are deleted in the "always" approach?

@estebank
Copy link
Contributor

estebank commented Jun 9, 2021

At a very quick glance, it seems like the always case removes a bunch of useful suggestions, while the never case is just more verbose and perhaps slightly misleading...

I'll try to take a look at this PR with fresh eyes tomorrow, but I think we might want to merge as is.

@tlyu
Copy link
Contributor Author

tlyu commented Jun 13, 2021

@estebank

Did this happen on tests or while working on rustc? Did it happen with --keep-stage 1? If the problem is one of "we might hit this in CI" it's less concerning to me than "users will hit a new fingerprint issue in stable in 12 weeks".

I wrote an update in #86013 (comment)

It seems unlikely to affect users of released versions because invalidation of the incremental caches seems to honor changes in the commit hash.

@tlyu
Copy link
Contributor Author

tlyu commented Jun 16, 2021

Opened #86371 with some discouraging findings. Maybe the better approach is to detect whether we are dealing with violating an implicit Sized bound, and adjust the span to point at any explicit Sized bound that happens to be present, instead of to the type parameter name.

@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 5, 2021
@bors
Copy link
Contributor

bors commented Jul 16, 2021

☔ The latest upstream changes (presumably #84623) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank
Copy link
Contributor

@tlyu can you rebase? After that r=me, but I would still like to somehow fix src/test/ui/issues/issue-16966.stderr.

@tlyu tlyu force-pushed the correct-sized-bound-spans branch from 6676902 to 6d851c8 Compare July 20, 2021 19:52
@tlyu
Copy link
Contributor Author

tlyu commented Jul 21, 2021

@estebank Rebase done. I looked at #16966 and the change in the stderr in this PR isn't a necessarily a regression of the substance of that issue, which is about duplication of error messages. (The change in src/test/ui/issues/issue-16966.stderr is more (potentially-useless) verbosity than there used to be, but there's no repetition.)

I think there's a big rabbit hole here of various error reporting heuristics that use the failure to satisfy the implicit Sized constraint as a way of suppressing excess verbosity. I'm not sure what to do about them, because in theory, the ordering of trait bounds should be irrelevant to type checking results, right?

@bors
Copy link
Contributor

bors commented Jul 28, 2021

☔ The latest upstream changes (presumably #87540) made this pull request unmergeable. Please resolve the merge conflicts.

@tlyu tlyu force-pushed the correct-sized-bound-spans branch from 6d851c8 to 19f32a9 Compare July 28, 2021 23:46
@tlyu
Copy link
Contributor Author

tlyu commented Jul 28, 2021

Rebased again.

@bors
Copy link
Contributor

bors commented Aug 3, 2021

☔ The latest upstream changes (presumably #87628) made this pull request unmergeable. Please resolve the merge conflicts.

@camelid
Copy link
Member

camelid commented Aug 20, 2021

triage: @tlyu could you rebase again? Then perhaps ping estebank to let them know the PR is ready to be approved. Thanks!

@tlyu tlyu force-pushed the correct-sized-bound-spans branch from 19f32a9 to c07f5c4 Compare October 8, 2021 23:51
@tlyu
Copy link
Contributor Author

tlyu commented Oct 8, 2021

Rebased again. A UI test is currently failing because of #89639, but I confirmed that also occurs on master.

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot 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 Oct 8, 2021
@estebank
Copy link
Contributor

Looking at the output after the rebase, I am much more comfortable landing this as is. Apologies for the delay in landing this!

@bors r+

@bors
Copy link
Contributor

bors commented Oct 14, 2021

📌 Commit c07f5c4 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 14, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 15, 2021
…stebank

move implicit `Sized` predicate to end of list

In `Bounds::predicates()`, move the implicit `Sized` predicate to the
end of the generated list. This means that if there is an explicit
`Sized` bound, it will be checked first, and any resulting
diagnostics will have a more useful span.

Fixes rust-lang#85998, at least partially. ~~Based on rust-lang#85979, but only the last 2 commits are new for this pull request.~~ (edit: rebased) A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit `Sized` predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I could use some help interpreting the changes to the stderr output. It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with `Sized` bounds. Possibly some error reporting code is making assumptions about ordering of predicates? The diagnostics for src/test/ui/derives/derives-span-Hash-*.rs seem to have improved, no longer pointing at the type parameter identifier, but src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs became less verbose for some reason.

I also ran into an instance of rust-lang#84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

`@estebank` this seems likely to conflict (slightly?) with your work on rust-lang#85947; how would you like to resolve that?
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 15, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#86011 (move implicit `Sized` predicate to end of list)
 - rust-lang#89821 (Add a strange test for `unsafe_code` lint.)
 - rust-lang#89859 (add dedicated error variant for writing the discriminant of an uninhabited enum variant)
 - rust-lang#89870 (Suggest Box::pin when Pin::new is used instead)
 - rust-lang#89880 (Use non-checking TLS relocation in aarch64 asm! sym test.)
 - rust-lang#89885 (add long explanation for E0183)
 - rust-lang#89894 (Remove unused dependencies from rustc_const_eval)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 36a1076 into rust-lang:master Oct 15, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 15, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 18, 2021
…ans, r=estebank"

This reverts commit 36a1076, reversing
changes made to e1e9319.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 18, 2021
Revert rust-lang#86011 to fix an incorrect bound check

This reverts commit 36a1076, reversing
changes made to e1e9319.

Fixes rust-lang#89935
r? `@estebank`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Oct 19, 2021
Revert rust-lang#86011 to fix an incorrect bound check

This reverts commit 36a1076, reversing
changes made to e1e9319.

Fixes rust-lang#89935
r? `@estebank`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 19, 2021
Revert rust-lang#86011 to fix an incorrect bound check

This reverts commit 36a1076, reversing
changes made to e1e9319.

Fixes rust-lang#89935
r? ``@estebank``
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 19, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#86479 (Automatic exponential formatting in Debug)
 - rust-lang#87404 (Add support for artifact size profiling)
 - rust-lang#87769 (Alloc features cleanup)
 - rust-lang#88789 (remove unnecessary bound on Zip specialization impl)
 - rust-lang#88860 (Deduplicate panic_fmt)
 - rust-lang#90009 (Make more `From` impls `const` (libcore))
 - rust-lang#90018 (Fix rustdoc UI for very long type names)
 - rust-lang#90025 (Revert rust-lang#86011 to fix an incorrect bound check)
 - rust-lang#90036 (Remove border-bottom from most docblocks.)
 - rust-lang#90060 (Update RELEASES.md)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this pull request Oct 22, 2021
…ans, r=estebank"

This reverts commit 36a1076, reversing
changes made to e1e9319.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 22, 2021
…ulacrum

[beta] backports

*  Don't emit a warning for empty rmeta files. rust-lang#90072
*  Erase late-bound regions before computing vtable debuginfo name. rust-lang#90050
*  Fix wrong niche calculation when 2+ niches are placed at the start rust-lang#90040
*  Revert rust-lang#86011 to fix an incorrect bound check rust-lang#90025
*  Fix macro_rules! duplication when reexported in the same module rust-lang#89867
* Bump cargo to include rust-lang/cargo#9979 - Fix fetching git repos after a force push.

r? `@Mark-Simulacrum`
@tlyu tlyu deleted the correct-sized-bound-spans branch November 16, 2021 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

E0277 wrong span in diagnostic with explicit Sized bound