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

Encountered error Unimplemented selecting <...> during codegen #58375

Closed
ckaran opened this issue Feb 11, 2019 · 34 comments
Closed

Encountered error Unimplemented selecting <...> during codegen #58375

ckaran opened this issue Feb 11, 2019 · 34 comments
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ckaran
Copy link

ckaran commented Feb 11, 2019

Update by pnkfelix: reduction to isolated test showing regression from 1.23.0 to 1.24.0 is given in comment below.

Original bug report follows


I'm using cargo-tarpaulin to ensure that my tests using proptest are covering all cases. In the process of testing this out, I ran into the following error:

$ reset ; RUSTC_BACKTRACE=1 ; cargo tarpaulin --force-clean -l -- --no-default-features
[INFO tarpaulin] Running Tarpaulin
[INFO tarpaulin] Building project
error: internal compiler error: src/librustc/traits/codegen/mod.rs:58: Encountered error `Unimplemented` selecting `Binder(<core::char::DecodeUtf16<<std::vec::Vec<u16> as core::iter::IntoIterator>::IntoIter> as arbitrary::traits::Arbitrary>)` during codegen

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:595:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error


note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.0-nightly (d17318011 2019-02-07) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

[ERROR tarpaulin] Failed to compile tests! Error: build failed

EDIT A fairly small repository illustrating the bug can be found here.

Meta

rustc --version --verbose:

rustc 1.34.0-nightly (d17318011 2019-02-07)
binary: rustc
commit-hash: d1731801163df1d3a8d4ddfa68adac2ec833ef7f
commit-date: 2019-02-07
host: x86_64-unknown-linux-gnu
release: 1.34.0-nightly
LLVM version: 8.0

Backtrace

The only information that I got from the command is given above. If you know of better commands I can try to use, I can do so and amend this report.

@jonas-schievink jonas-schievink added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 11, 2019
@jethrogb
Copy link
Contributor

jethrogb commented Mar 2, 2019

Unable to reproduce, can't install tarpaulin:

error[E0599]: no method named `start` found for type `proc_macro2::Span` in the current scope
  --> /home/jethro/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/cargo-tarpaulin-0.7.0/src/source_analysis.rs:82:27
   |
82 |             for i in span.start().line..(span.end().line + 1) {
   |                           ^^^^^
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `start`, perhaps you need to implement it:
           candidate #1: `statemachine::StateData`

@jethrogb
Copy link
Contributor

jethrogb commented Mar 2, 2019

If you are able to run it, can you run the command verbosely to extract the entire rustc command line? If you then run that command line yourself, does that also ICE?

@ckaran
Copy link
Author

ckaran commented Mar 5, 2019

@jethrogb Here is what I have. Note that I ran git clean -xdf to get rid of all generated files before running any of these commands, so they are as clean as I can make them. If you want me to use some other commands, please give me the exact commands, and I can run them for you.

$ reset ; RUSTC_BACKTRACE=1 ; cargo tarpaulin --force-clean --line --verbose -- --no-default-features
[INFO tarpaulin] Running Tarpaulin
[DEBUG tarpaulin] Cleaning project
[INFO tarpaulin] Building project
warning: dependency (pyo3) specified without providing a local path, Git repository, or version to use. This will be considered an error in future versions
warning: unused manifest key: dependencies.pyo3.pyo3
    Updating crates.io index
   Compiling proc-macro2 v0.4.27                                                                                                                                                                                                       
   Compiling memchr v2.2.0                                                                                                                                                                                                             
   Compiling autocfg v0.1.2                                                                                                                                                                                                            
   Compiling libc v0.2.50                                                                                                                                                                                                              
   Compiling spin v0.5.0                                                                                                                                                                                                               
   Compiling rand_core v0.4.0                                                                                                                                                                                                          
   Compiling unicode-xid v0.1.0                                                                                                                                                                                                        
   Compiling regex v1.1.2                                                                                                                                                                                                              
   Compiling ucd-util v0.1.3                                                                                                                                                                                                           
   Compiling utf8-ranges v1.0.2                                                                                                                                                                                                        
   Compiling proc-macro-hack-impl v0.4.1                                                                                                                                                                                               
   Compiling cfg-if v0.1.7                                                                                                                                                                                                             
   Compiling version_check v0.1.5                                                                                                                                                                                                      
   Compiling byteorder v1.3.1                                                                                                                                                                                                          
   Compiling remove_dir_all v0.5.1                                                                                                                                                                                                     
   Compiling num-traits v0.2.6                                                                                                                                                                                                         
   Compiling fnv v1.0.6                                                                                                                                                                                                                
   Compiling quick-error v1.2.2                                                                                                                                                                                                        
   Compiling bit-vec v0.5.0                                                                                                                                                                                                            
   Compiling bitflags v1.0.4                                                                                                                                                                                                           
   Compiling rand_pcg v0.1.2                                                                                                                                                                                                           
   Compiling rand_chacha v0.1.1                                                                                                                                                                                                        
   Compiling rand v0.6.5                                                                                                                                                                                                               
   Compiling lazy_static v1.3.0                                                                                                                                                                                                        
   Compiling rand_core v0.3.1                                                                                                                                                                                                          
   Compiling rand_jitter v0.1.3                                                                                                                                                                                                        
   Compiling regex-syntax v0.6.5                                                                                                                                                                                                       
   Compiling proc-macro-hack v0.4.1                                                                                                                                                                                                    
   Compiling bit-set v0.5.0                                                                                                                                                                                                            
   Compiling rand_xorshift v0.1.1                                                                                                                                                                                                      
   Compiling rand_isaac v0.1.1                                                                                                                                                                                                         
   Compiling rand_hc v0.1.0                                                                                                                                                                                                            
   Compiling thread_local v0.3.6                                                                                                                                                                                                       
   Compiling rand_os v0.1.3                                                                                                                                                                                                            
   Compiling wait-timeout v0.1.5                                                                                                                                                                                                       
   Compiling quote v0.6.11                                                                                                                                                                                                             
   Compiling mashup-impl v0.1.9                                                                                                                                                                                                        
   Compiling aho-corasick v0.6.10                                                                                                                                                                                                      
   Compiling syn v0.15.27                                                                                                                                                                                                              
   Compiling mashup v0.1.9                                                                                                                                                                                                             
   Compiling tempfile v3.0.7                                                                                                                                                                                                           
   Compiling rusty-fork v0.2.1                                                                                                                                                                                                         
   Compiling proptest v0.9.1                                                                                                                                                                                                           
   Compiling pyo3 v0.6.0-alpha.4                                                                                                                                                                                                       
error: internal compiler error: src/librustc/traits/codegen/mod.rs:58: Encountered error `Unimplemented` selecting `Binder(<core::char::DecodeUtf16<<std::vec::Vec<u16> as core::iter::IntoIterator>::IntoIter> as arbitrary::traits::Arbitrary>)` during codegen
                                                                                                                                                                                                                                       
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:620:9                                                                                                                                                                
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.                                                                                                                                                         
error: aborting due to previous error                                                                                                                                                                                                  
                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                       
note: the compiler unexpectedly panicked. this is a bug.                                                                                                                                                                               
                                                                                                                                                                                                                                       
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports                                                                                                                      
                                                                                                                                                                                                                                       
note: rustc 1.35.0-nightly (a9da8fc9c 2019-03-04) running on x86_64-unknown-linux-gnu                                                                                                                                                  
                                                                                                                                                                                                                                       
note: compiler flags: -C debuginfo=2 -C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2 --crate-type lib                                                                                               
                                                                                                                                                                                                                                       
note: some of the compiler flags provided by cargo are hidden                                                                                                                                                                          
                                                                                                                                                                                                                                       
error: Could not compile `proptest`.                                                                                                                                                                                                   
warning: build failed, waiting for other jobs to finish...
[ERROR tarpaulin] Failed to compile tests! Error: build failed 

Meta

$ rustc --version --verbose
rustc 1.35.0-nightly (a9da8fc9c 2019-03-04)
binary: rustc
commit-hash: a9da8fc9c267c08cfdb8cf5b39da14f154d12939
commit-date: 2019-03-04
host: x86_64-unknown-linux-gnu
release: 1.35.0-nightly
LLVM version: 8.0

$ uname -a
Linux EMANE 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release --all
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic

@jethrogb
Copy link
Contributor

jethrogb commented Mar 5, 2019

@ckaran I was hoping running tarpaulin verbosely would provide some more info, but unfortunately it doesn't really... Can you provide instructions on how to reproduce (including tarpaulin install) on a clean system, or docker container, or something like that?

@ckaran
Copy link
Author

ckaran commented Mar 7, 2019

@jethrogb Did you get my last comment? I did as you asked yesterday, adding it as a comment, along with a ridiculously long copied chunk of standard out from re-running tarpaulin (it turns out you need to set RUST_LOG=trace to get output from tarpaulin), but I don't see the comment here any more. I'm hoping that this is just something temporary with GitHub; if not, let me know, and I can re-run everything and make it a part of my repository so you can see exactly what I did.

@jethrogb
Copy link
Contributor

jethrogb commented Mar 7, 2019

@ckaran no I got nothing. Sounds like GitHub ate your comment unfortunately.

@ckaran
Copy link
Author

ckaran commented Mar 7, 2019

@jethrogb OK, I don't have time at the moment, but I'll work on putting something together in my repo that outlines shows what I'm seeing. RUST_LOG=trace generates an absolutely enormous amount of output, but I think that without doing that, you won't be able to see what I'm seeing, so that is what I'll do.

@ckaran
Copy link
Author

ckaran commented Mar 12, 2019

@jethrogb I've updated the repository at https://github.com/ckaran/rustc_issue_report_58375 with the output from RUST_LOG=trace RUST_BACKTRACE=full cargo tarpaulin >> build_output.txt 2>&1. The resulting output is quite verbose; I hope that it will be of help to you. More details can be found in the update second of the README.md for the repository.

If that still doesn't work for you, everything I've done is within a virtual machine; as soon as I can figure out how to get a ~13 GB file to you, I could send it to you so you could play around with it and see what I'm seeing.

@jethrogb
Copy link
Contributor

Can you run it again but with strace?

strace -etrace=execve -s 10000 -v -f cargo tarpaulin >> build_output.txt 2>&1

@ckaran
Copy link
Author

ckaran commented Mar 15, 2019

@jethrogb Done. Pull the latest commit from the repository. Thank you for looking into this!

@jethrogb
Copy link
Contributor

Reproduced by doing

RUSTFLAGS="-C relocation-model=dynamic-no-pic -C link-dead-code -C opt-level=0 -C debuginfo=2" cargo +nightly build --features bit-set,break-dead-code,byteorder,default,fork,num-traits,quick-error,rand,regex-syntax,rusty-fork,std,tempfile,timeout

in crate proptest version 0.9.1

@jethrogb
Copy link
Contributor

possible dupe of #57131 or #52478

@jethrogb
Copy link
Contributor

Significantly reduced reproduction in ckaran/rustc_issue_report_58375#1 . I would like it to be smaller still, though.

@jethrogb
Copy link
Contributor

Also was able to reproduce on Rust 1.24.0, so it's at least not a recent regression. https://github.com/jethrogb/rustc_issue_report_58375/tree/1.24.0 . Since this blows up on DecodeUtf16 and I need DecodeUtf16: Debug, this test case requires at least 1.24.0.

@ckaran
Copy link
Author

ckaran commented Mar 18, 2019

@jethrogb I left a comment on your PR to my repository, but I'm going to leave the same comment here, so that others can read the thread and know what we talked about (mea culpa for not commenting here originally!)

Based on what you've said above, it appears that what you pushed fully reproduces the problem for you, correct? If so, I'll merge the PR. Do you want me to leave the repository up until the regression is fixed, or is there a better place to put the code?

Were you able to install tarpaulin and see the same results as well?

@jethrogb
Copy link
Contributor

jethrogb commented Mar 18, 2019

This is a regression from 1.23.0 to 1.24.0

Fully reduced:

pub struct DecodeUtf16<I: Iterator<Item = u16>>(I);

pub trait Arbitrary {
    type Strategy;
    fn arbitrary_with() -> Self::Strategy;
    fn arbitrary() {}
}

impl Arbitrary for DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter> {
    type Strategy = Self;
    fn arbitrary_with() -> Self::Strategy {
        unimplemented!()
    }
}

Compile with --crate-type lib -C link-dead-code

Now that we have a reduced test case can someone from the compiler team look at this? @nikomatsakis

@jethrogb
Copy link
Contributor

@jonas-schievink can you update the issue labels as appropriate?

@jonas-schievink jonas-schievink added I-nominated regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Mar 20, 2019
@pnkfelix
Copy link
Member

injected between nightly-2018-01-04 and nightly-2018-01-05

@pnkfelix
Copy link
Member

Here are the PR's from that time frame:

% git log 0a3761e63..8e7a609e6 --format=oneline --author=bors
8e7a609e635b728eba65d471c985ab462dc4cfc7 Auto merge of #46916 - michaelwoerister:generate-dead-code-plz, r=alexcrichton
4cd918c4caf90ef87d687c02f23b06c581054de3 Auto merge of #47147 - projektir:to_ptr_cast, r=eddyb
78f24d86b84882a02c15f27768e831d0342a3f5d Auto merge of #47124 - estebank:loan-paths, r=nikomatsakis
608aae904b14efd09b4f95d9f4c3f030e6a34f95 Auto merge of #47132 - cramertj:impl-trait-camel-case, r=nikomatsakis

I think #46916 looks quite relevant.

@pnkfelix
Copy link
Member

(Although I don't think #46916 necessarily injected the bug; it may have just exposed a pre-existing bug.)

@pnkfelix
Copy link
Member

triage: marking P-high.

@pnkfelix pnkfelix added the P-high High priority label Mar 21, 2019
@pnkfelix
Copy link
Member

assigning to @aturon for initial investigation.

@pnkfelix
Copy link
Member

removing nomination now that this is assigned.

@ckaran
Copy link
Author

ckaran commented Apr 11, 2019

@aturon Have you figured out anything about this bug?

@djc
Copy link
Contributor

djc commented Apr 28, 2019

Any news? Since the assignment more than a month ago, there seems to have been zero updates or progress. For a stable-to-stable regression, I would have expected more priority. @nikomatsakis (as compiler team lead), should this be reassigned?

@pnkfelix
Copy link
Member

pnkfelix commented May 2, 2019

Unassigning from @aturon, with intent to assign to someone else at today's rustc meeting.

@djc
Copy link
Contributor

djc commented Jun 20, 2019

I've been looking at the reduced test case and trying to see if I can determine the root cause. It would make sense if #46916 has caused this regression; it looks like the compiler is selecting an impl for some piece of code but not finding a matching impl. It seems likely this is because the impl itself was removed for being unused, except clearly some code referencing it is clearly still alive -- I'm guessing #46916 revived the latter part but not the former part. I've been trying to figure out which part of the code might be cleaning out unused trait impls, but this is my first time hacking the compiler so that will likely take me some time.

alessandrod added a commit to alessandrod/nuts that referenced this issue Jul 5, 2019
Proptest seems to be hitting this rust-lang/rust#58375
@alessandrod
Copy link
Contributor

I ran into this a couple of days ago trying to enable code coverage for https://github.com/alessandrod/nuts so I decided to take a stab at it. This is the first time I look at the compiler so apologies if what follows is inaccurate and a waste of your time. 🙏

I took @jethrogb's test case and reduced it a bit further: (I've also made a test case for it: https://github.com/alessandrod/rust/blob/12e230759447b37ed7a0fc18f971caaa10b869e6/src/test/run-pass/issue-58375-monomorphize-default-impls.rs)

pub struct DecodeUtf16<I>(I);

pub trait Arbitrary {
    fn arbitrary() {}
}

pub trait A {
    type Item;
}

impl A for u8 {
    type Item = char;
}

impl Arbitrary for DecodeUtf16<<u8 as A>::Item>  {
}

Poking around I noticed that when the last impl is "instantiated" (sorry I know the terminology is inaccurate), <u8 as A>::Item is normalized to char, so the impl becomes DecodeUtf16<char>.

Then the eager monomorphizing collector (tm) code enabled by -C link-dead-code, when trying to add the default method Arbitrary::arbitrary to the impl, does this:

let substs = InternalSubsts::for_item(tcx, method.def_id, |param, _| {
match param.kind {
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
GenericParamDefKind::Type { .. } |
GenericParamDefKind::Const => {
trait_ref.substs[param.index as usize]
}
}
});
let instance = ty::Instance::resolve(tcx,
ty::ParamEnv::reveal_all(),
method.def_id,
substs).unwrap();

Those substs aren't normalized tho, so the code effectively looks up DecodeUtf16<<u8 as A>::Item> which can't be found and hence the panic.

Normalizing does seem to fix the bug: alessandrod@12e2307

I haven't created a pull request because this is all still well beyond my pay grade. I've ran the tests locally tho and to my surprise everything seems to pass. Hope this helps!

@djc
Copy link
Contributor

djc commented Jul 8, 2019

@alessandrod great work! The best way to get this reviewed is probably to post this as a PR anyway -- just mention in the description that this is your first and reviewers will no doubt treat you gently.

@pnkfelix
Copy link
Member

nominating for discussion at compiler meeting

if @alessandrod or someone else puts up a PR with the proposed fix before the next compiler meeting, great! But if no PR goes up, then the team should at least discuss the solution put forth there.

(And, maybe, whether the existing APi's could be revised to make these kinds of bugs harder to run into? Just a stray thought on my part...)

bors added a commit that referenced this issue Jul 18, 2019
Normalize type parameters in create_mono_items_for_default_impls.

Fix for #58375. I've added a test in `src/tests/run-pass` to reproduce the bug, not sure that's the best place for it.

See #58375 (comment) for more context.
@djc
Copy link
Contributor

djc commented Jul 20, 2019

Looks like this has been fixed. Thanks, @alessandrod!

@neoeinstein
Copy link
Contributor

If fixed, should this issue now be closed?

@nikomatsakis
Copy link
Contributor

Closing, thanks!

@ckaran
Copy link
Author

ckaran commented Aug 19, 2019

Thank you @alessandrod for fixing this! I finally had the chance to test this on latest nightly, and it works! Now I just have to fix the (large) number of holes in my test cases...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants