Closed
Labels
A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Description
When dereferencing a boxed Iterator trait object I get an internal compiler error (only on nightly).
Here is a minimal example: (playground link)
fn ice(x: Box<dyn Iterator<Item=()>>) {
*x
}
fn main() {}This should result in a type error, as indeed it does if I swap out dyn Iterator<Item=()> with dyn std::fmt::Debug.
Instead, it results in the following error when compiled with nightly (rustc src/main.rs):
thread 'rustc' panicked at 'index out of bounds: the len is 527 but the index is 527', /rustc/e2f221c75932de7a29845c8d6f1f73536ad00c41/src/libcore/slice/mod.rs:2455:10
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: unexpected panic
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.33.0-nightly (e2f221c75 2019-01-15) running on x86_64-unknown-linux-gnu
Meta
Output from rustc --version --verbose:
rustc 1.33.0-nightly (e2f221c75 2019-01-15)
binary: rustc
commit-hash: e2f221c75932de7a29845c8d6f1f73536ad00c41
commit-date: 2019-01-15
host: x86_64-unknown-linux-gnu
release: 1.33.0-nightly
LLVM version: 8.0
Metadata
Metadata
Assignees
Labels
A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyArea: Name/path resolution done by `rustc_resolve` specificallyI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Activity
estebank commentedon Jan 16, 2019
sapphire-arches commentedon Jan 16, 2019
I think I just ran into this bug as well. It's repros in the 2018-12-31 nightly.
hellow554 commentedon Jan 17, 2019
The bug was introduced in nightly-2018-12-21, so somewhere between 790f4c5...09d6ab9
LukasKalbertodt commentedon Jan 17, 2019
This could possibly be the same bug as #57216. At least the stack trace and panic message is very similar.
pnkfelix commentedon Jan 17, 2019
triage: P-high; assigning to self.
pnkfelix commentedon Jan 18, 2019
This was injected by #54252
cc @arielb1
pnkfelix commentedon Jan 18, 2019
(the ICE seems like it may have been injected by commit be2bb4f specifically.)
pnkfelix commentedon Jan 21, 2019
I have been looking at this more. I am not 100% certain I understand the steps that are leading to the ICE, but here are some notes and hypotheses based on adding some
debug!statements to various points in the compiler and reading the resulting logs:vid) named_#527tand eventually attempting a lookup based on that inference variable on aneq_relationstable with only 527 entries._#527t) during one of the extensions and then attempting to do a lookup based on that leaked state.vid_#527t. I cannot be certain which of the four is leaky._#527tfalling latest in the control flow (i.e. appear later in the log) are underneath the execution ofprobe_for_lev_candidatewhen it is searching for a candidate similar torfold._#527t(that falls a little earlier in the control flow) comes from.pick_methodinvocation for self_ty:&mut (dyn std::iter::Iterator<Item=()> + 'static))method_name:Some(rfold#0)and return_type:Some(()). (There's thatrfoldagain.)rust/src/librustc_typeck/check/method/probe.rs
Lines 1046 to 1051 in 0974bdc
rust/src/librustc_typeck/check/method/probe.rs
Lines 1069 to 1072 in 0974bdc
pnkfelix commentedon Jan 21, 2019
(also, am I wrong in feeling my eyebrows go up when I observe that the compiler is attempting to search for candidates similar to the method name
rfoldwhen it is trying to construct a diagnostic for this code? I guess I shouldn't worry too much yet, since diagnostic generation need not be considered a hot path. But it still struck me as odd.)pnkfelix commentedon Jan 21, 2019
Anyway, just to narrow the search space for the bug, I'm going to hack
probe_for_lev_candidateso that it never attempts to search beyond an empty set. That should allow me to identify whether the problematicvid_#527tis arising from the initial probe, or if it is arising from a probe underneathprobe_for_lev_candidate.Update: No, this probably won't suffice: the ICE is itself arising, I think, during the execution of
probe_for_lev_candidate. So I suspect changing that method to only search an empty vector (or otherwise failing to call it, etc) will just mask the bug here.pnkfelix commentedon Jan 22, 2019
Okay, i think I have a hint at the problem
More debug log inspection has led me to conclude that the problematic
vid_#527tis part of the inherent candidates attached to theProbeContext.Look at this code:
rust/src/librustc_typeck/check/method/probe.rs
Lines 507 to 517 in 0974bdc
During the execution of:
rust/src/librustc_typeck/check/method/probe.rs
Line 516 in 0974bdc
is when the
vid_#527tis created and then pushed (as part of a candidate) onto the inherent candidates list attached toself. But then the callback forself.fcx.probe(|_| { ... })returns, and as part of exiting theprobecall, it does a rollback, which pops off the entries for the newly created inference variables_#527tand_#528t.Sometime well after this point, we attempt to look at the inherent candidates (during
probe_for_lev_candidate) and that's when we try to do a look up based on#_527t, but its effectively a dangling pointer into theeq_relationstable at that point.So, I am pretty sure the code for the
ty::Dynamiccase infn assemble_probeis in error here. Or at least, its behavior doesn't match my understanding of how the probes are meant to be used.Now my question is: How to fix this?
pnkfelix commentedon Jan 22, 2019
Okay well as an experiment, I have tried just removing the wrapping call to
self.fcx.probe(|_| { ... }), and so far ... nothing breaks? (And it resolves this particular instance of the bug, at least....)pnkfelix commentedon Jan 22, 2019
(this bug wasn't fixed in time for the nightly-to-beta promotion and so its now affecting beta)
Auto merge of #57835 - pnkfelix:issue-57673-remove-leaky-nested-probe…
pnkfelix commentedon Jan 23, 2019
PR #57835 fixes this problem and has been nominated for beta-backport.
However, @arielb1 thinks that it is an insufficient solution and says they hope to have a better approach up soonish.
Thus, we might not want to do an eager backport of PR #57835, since it would probably be nicer to make a single backport that includes both the effect of that PR as well as the hypothetical PR to be provided by @arielb1
pnkfelix commentedon Jan 31, 2019
visiting for triage: PR #57885 is a related follow-up to #57835. We'll hopefully discuss the hypothetical backport of PR #57835 at the T-compiler meeting today.
pnkfelix commentedon Feb 14, 2019
visiting for triage. PR #57885 was beta-nominated and beta-accepted. If I recall correctly PR #57835 is a prerequisite for landing PR #57885. So I'll make sure a backport gets posted for both of those in the near future.
pnkfelix commentedon Feb 21, 2019
closing bug now that PRs #57835 and #57885 have landed in beta-channel.