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

Fix Instance::resolve() incorrectly returning specialized instances #67662

Merged

Conversation

wesleywiser
Copy link
Member

We only want to return specializations when Reveal::All is passed, not
when Reveal::UserFacing is. Resolving this fixes several issues with
the ConstProp, SimplifyBranches, and Inline MIR optimization
passes.

Fixes #66901

Rebased on top of #67631

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 27, 2019
@wesleywiser wesleywiser force-pushed the optimizations_handle_specialization branch from 9cb8cb7 to d88a745 Compare December 27, 2019 15:32
@wesleywiser wesleywiser force-pushed the optimizations_handle_specialization branch 2 times, most recently from 8525d2d to 4cfd5c4 Compare December 27, 2019 16:46
@anp
Copy link
Member

anp commented Dec 27, 2019

@oli-obk I assume that closing #67631 implies this should also fix the test failure I have in #67137, but rebasing onto @wesleywiser's branch still yields a failure for me :(.

We only want to return specializations when `Reveal::All` is passed, not
when `Reveal::UserFacing` is. Resolving this fixes several issues with
the `ConstProp`, `SimplifyBranches`, and `Inline` MIR optimization
passes.

Fixes rust-lang#66901
@wesleywiser wesleywiser force-pushed the optimizations_handle_specialization branch from 4cfd5c4 to 25a8b5d Compare December 27, 2019 18:04
@wesleywiser
Copy link
Member Author

Force pushed

@wesleywiser
Copy link
Member Author

Hi @anp do you have the error details so I can look at them?

@anp
Copy link
Member

anp commented Dec 27, 2019

It's the same error that highfive reports:

------------------------------------------
stderr:
------------------------------------------
warning: due to multiple output types requested, the explicitly specified output file name will be adapted for each output type

warning: struct is never constructed: `PrintName`
  --> /usr/local/google/home/adamperry/c/rust/src/test/mir-opt/retain-never-const.rs:10:8
   |
10 | struct PrintName<T>(T);
   |        ^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: associated const is never used: `VOID`
  --> /usr/local/google/home/adamperry/c/rust/src/test/mir-opt/retain-never-const.rs:13:5
   |
13 |     const VOID: ! = panic!();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^

warning: function is never used: `no_codegen`
  --> /usr/local/google/home/adamperry/c/rust/src/test/mir-opt/retain-never-const.rs:16:4
   |
16 | fn no_codegen<T>() {
   |    ^^^^^^^^^^

error: any use of this value will cause an error
  --> /usr/local/google/home/adamperry/c/rust/src/test/mir-opt/retain-never-const.rs:13:21
   |
13 |     const VOID: ! = panic!();
   |     ----------------^^^^^^^^-
   |                     |
   |                     the evaluated program panicked at 'explicit panic', /usr/local/google/home/adamperry/c/rust/src/test/mir-opt/retain-never-const.rs:13:21
   |
   = note: `#[deny(const_err)]` on by default
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0080]: erroneous constant used
  --> /usr/local/google/home/adamperry/c/rust/src/test/mir-opt/retain-never-const.rs:17:13
   |
17 |     let _ = PrintName::<T>::VOID;
   |             ^^^^^^^^^^^^^^^^^^^^ referenced constant has errors

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0080`.

------------------------------------------

failures:
    [mir-opt] mir-opt/retain-never-const.rs

test result: FAILED. 73 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

@oli-obk
Copy link
Contributor

oli-obk commented Dec 27, 2019

I guess we still need my PR for backwards compatibility of @anp's PR. I'll reopen

@wesleywiser
Copy link
Member Author

I have no idea why your PR would change that test's behavior but I wonder if we shouldn't have #[warn(const_err)] on that test.

@anp
Copy link
Member

anp commented Dec 27, 2019

I think oli said at one point that it would be a breaking change to allow const prop to surface this error?

@oli-obk
Copy link
Contributor

oli-obk commented Dec 27, 2019

error[E0080]: erroneous constant used

this is the problem, the use of the broken constant inside a never used function should not cause a hard error.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 27, 2019

@bors r+

@bors
Copy link
Contributor

bors commented Dec 27, 2019

📌 Commit 25a8b5d has been approved by oli-obk

@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 Dec 27, 2019
@bors bors merged commit 25a8b5d into rust-lang:master Dec 30, 2019
let eligible = if !resolved_item.defaultness.is_default() {
true
} else if param_env.reveal == traits::Reveal::All {
!trait_ref.needs_subst()
Copy link
Member

Choose a reason for hiding this comment

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

You might want an assert that !trait_ref.needs_infer().

Centril added a commit to Centril/rust that referenced this pull request Mar 24, 2020
Use Reveal::All in MIR optimizations

Resolves some code review feedback in rust-lang#67662.

Fixes rust-lang#68855

r? @eddyb
Centril added a commit to Centril/rust that referenced this pull request Mar 24, 2020
Use Reveal::All in MIR optimizations

Resolves some code review feedback in rust-lang#67662.

Fixes rust-lang#68855

r? @eddyb
Centril added a commit to Centril/rust that referenced this pull request Mar 24, 2020
Use Reveal::All in MIR optimizations

Resolves some code review feedback in rust-lang#67662.

Fixes rust-lang#68855

r? @eddyb
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specialization does not work correctly during constant evaluation.
6 participants