Skip to content

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

Merged
bors merged 1 commit into
rust-lang:masterfrom
wesleywiser:optimizations_handle_specialization
Dec 30, 2019
Merged

Fix Instance::resolve() incorrectly returning specialized instances#67662
bors merged 1 commit into
rust-lang:masterfrom
wesleywiser:optimizations_handle_specialization

Conversation

@wesleywiser

Copy link
Copy Markdown
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-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 27, 2019
@wesleywiser
wesleywiserforce-pushed the optimizations_handle_specialization branch from 9cb8cb7 to d88a745CompareDecember 27, 2019 15:32
Comment threadsrc/test/ui/consts/trait_specialization.rs Outdated
Comment threadsrc/test/ui/consts/trait_specialization.rs Outdated
@wesleywiser
wesleywiserforce-pushed the optimizations_handle_specialization branch 2 times, most recently from 8525d2d to 4cfd5c4CompareDecember 27, 2019 16:46
Comment threadsrc/test/mir-opt/inline/inline-specialization.rs Outdated
Comment threadsrc/test/ui/consts/trait_specialization.rs Outdated
@anp

anp commented Dec 27, 2019

Copy link
Copy Markdown
Contributor

@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.
Fixesrust-lang#66901
@wesleywiser
wesleywiserforce-pushed the optimizations_handle_specialization branch from 4cfd5c4 to 25a8b5dCompareDecember 27, 2019 18:04
@wesleywiser

Copy link
Copy Markdown
MemberAuthor

Force pushed

@wesleywiser

Copy link
Copy Markdown
MemberAuthor

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

@anp

anp commented Dec 27, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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

@wesleywiser

Copy link
Copy Markdown
MemberAuthor

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

anp commented Dec 27, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 27, 2019

Copy link
Copy Markdown
Collaborator

📌 Commit 25a8b5d has been approved by oli-obk

@borsbors 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:masterDec 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
Copy Markdown
Contributor

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().

Comment threadsrc/librustc_mir/transform/const_prop.rs
Comment threadsrc/librustc_mir/transform/inline.rs
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.
Fixesrust-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.
Fixesrust-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.
Fixesrust-lang#68855
r? @eddyb
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: 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

@wesleywiser@anp@oli-obk@bors@eddyb@rust-highfive