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

ICE in StableHasher #89118

Closed
joshlf opened this issue Sep 20, 2021 · 12 comments · Fixed by #89480
Closed

ICE in StableHasher #89118

joshlf opened this issue Sep 20, 2021 · 12 comments · Fixed by #89480
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been 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.
Milestone

Comments

@joshlf
Copy link
Contributor

joshlf commented Sep 20, 2021

Code

The code in question is from this change in Fuchsia.

In order to reproduce, first download Fuchsia and then build.

Once that's done, perform the following steps from inside the Fuchsia repository:

# Download a recent known-good version
$ git fetch https://fuchsia.googlesource.com/fuchsia refs/changes/03/583203/4 && git checkout FETCH_HEAD

# Use Netstack3 (if you're not on x86_64, substitute your target for `x64`)
$ fx set core.x64 --with //src/connectivity/network/netstack3:bin --cargo-toml-gen

# Do a full build as a prerequisite for the next step
$ fx build && fx build build/rust:cargo_toml_gen

# Generate a `Cargo.toml` file for Netstack3
$ fx gen-cargo //src/connectivity/network/netstack3:bin

# Check out the problematic code
$ git fetch https://fuchsia.googlesource.com/fuchsia refs/changes/09/583209/1 && git checkout FETCH_HEAD

# Try to build Netstack3
$ cd src/connectivity/network/netstack3 && cargo check --target x86_64-fuchsia

Meta

Version from error output:

rustc 1.56.0-nightly (1f94abcda 2021-08-06) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: compiler/rustc_middle/src/ich/impls_ty.rs:94:17: StableHasher: unexpected region RePlaceholder(Placeholder { universe: U4, name: BrNamed(DefId(0:199 ~ netstack3[e4ac]::bindings::ethernet_worker::EthernetWorker::'a), 'a) })

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1046:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt::{{closure}}
   6: rustc_middle::ty::context::tls::with_opt
   7: rustc_middle::util::bug::opt_span_bug_fmt
   8: rustc_middle::util::bug::bug_fmt
   9: rustc_middle::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext> for rustc_middle::ty::sty::RegionKind>::hash_stable
  10: <rustc_middle::ty::TyS as rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext>>::hash_stable
  11: std::thread::local::LocalKey<T>::with
  12: <rustc_middle::ty::TyS as rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext>>::hash_stable
  13: std::thread::local::LocalKey<T>::with
  14: rustc_middle::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext> for rustc_middle::ty::sty::Binder<T>>::hash_stable
  15: <T as rustc_query_system::dep_graph::dep_node::DepNodeParams<Ctxt>>::to_fingerprint
  16: rustc_query_system::query::plumbing::get_query_impl
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::diagnostic_hir_wf_check
  18: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
  19: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  20: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  21: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  22: rustc_infer::infer::InferCtxtBuilder::enter
  23: rustc_typeck::check::wfcheck::check_item_well_formed
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::force_query_with_job
  27: rustc_query_system::query::plumbing::get_query_impl
  28: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_item_well_formed
  29: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::intravisit::Visitor>::visit_item
  30: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  31: rustc_data_structures::sync::par_for_each_in
  32: rustc_session::session::Session::track_errors
  33: rustc_typeck::check_crate
  34: rustc_interface::passes::analysis
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::force_query_with_job
  38: rustc_query_system::query::plumbing::get_query_impl
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  40: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  41: rustc_span::with_source_map
  42: rustc_interface::interface::create_compiler_and_run
  43: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.56.0-nightly (1f94abcda 2021-08-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z panic_abort_tests -C embed-bitcode=no -C debuginfo=2 -C incremental -C panic=abort -C link-arg=--pack-dyn-relocs=relr -C link-args=-zstack-size=0x200000 -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/out/default/gen/zircon/public/sysroot/cpp/lib -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/out/default/x64-shared/gen/zircon/public/lib/fdio -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/out/default/x64-shared/gen/zircon/public/lib/syslog -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/out/default/x64-shared/gen/zircon/public/lib/trace-engine -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/prebuilt/third_party/clang/linux-x64/lib/clang/14.0.0/x86_64-fuchsia/lib -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/out/default -C link-arg=-L/usr/local/google/home/joshlf/workspace/fuchsia/out/default/user.vdso_x64 -C link-arg=--sysroot=/usr/local/google/home/joshlf/workspace/fuchsia/out/default/gen/zircon/public/sysroot/cpp -C link-arg=/usr/local/google/home/joshlf/workspace/fuchsia/out/default/user.libc_x64/obj/zircon/system/ulib/c/crt1.Scrt1.cc.o --crate-type bin

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

query stack during panic:
#0 [check_item_well_formed] checking that `bindings::ethernet_worker::<impl at src/bindings/ethernet_worker.rs:47:1: 112:2>` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack
@joshlf joshlf added C-bug Category: This is a bug. 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. labels Sep 20, 2021
@jackh726
Copy link
Member

Easy fix here. I saw this at one point in #85499, but it went away with in the final version of that PR, so I had assumed that as the code evolved, this wouldn't get hit.

Anyways, to fix, just make the RePlaceholder arm be RePlaceholder(p) => p.hash_stable(hcx, hasher) here.

@jackh726 jackh726 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Sep 20, 2021
@nerandell
Copy link

@rustbot claim

@jackh726
Copy link
Member

Any way we can get an MCVE for this? Seems like an important test case for normalization under binders.

@rustbot ping icebreakers-cleanup-crew

@rustbot
Copy link
Collaborator

rustbot commented Sep 21, 2021

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Sep 21, 2021
@camelid
Copy link
Member

camelid commented Sep 21, 2021

Easy fix here. I saw this at one point in #85499, but it went away with in the final version of that PR, so I had assumed that as the code evolved, this wouldn't get hit.

@jackh726 does that mean this is a stable-to-beta regression? If so, could you add that label (and the 1.56 milestone) to this issue so we can track it better?

@jackh726
Copy link
Member

@camelid good question, I don't know. If this indeed is directly caused by #85499, then it would be, yes.

Can somebody check this? I don't personally have the time to right now.

@Mark-Simulacrum Mark-Simulacrum added this to the 1.56.0 milestone Sep 21, 2021
@joshlf
Copy link
Contributor Author

joshlf commented Sep 21, 2021

@jackh726

Any way we can get an MCVE for this? Seems like an important test case for normalization under binders.

I would have no idea how to do that for the change that caused the issue. I was deep in the middle of tearing my hair out trying to figure out why a certain trait (in a very hairy mess of traits) wasn't implemented. I was confused enough as it was without the ICE 😂 MCVE would be great, but I unfortunately can't provide one starting from the offending change. Perhaps someone else can create a snippet tabula rasa based on where the ICE occurred?

the8472 added a commit to the8472/rust that referenced this issue Sep 21, 2021
@hellow554
Copy link
Contributor

hellow554 commented Sep 24, 2021

This is a terrible MCVE, but it works and panics with two ICE:

trait BufferMut {}
struct Ctx<D>(D);

trait BufferUdpStateContext<B> {}
impl<B: BufferMut, C> BufferUdpStateContext<B> for C {}

trait StackContext
where
    Ctx<()>: for<'a> BufferUdpStateContext<&'a ()>,
{
    type Dispatcher;
}

trait TimerContext {
    type Handler;
}
impl<C> TimerContext for C
where
    C: StackContext,
{
    type Handler = Ctx<C::Dispatcher>;
}

struct EthernetWorker<C>(C)
where
    Ctx<()>: for<'a> BufferUdpStateContext<&'a ()>;
impl<C> EthernetWorker<C> {}

fn main() {}

After fiddling a bit more with this, the culprit is indeed that BufferMut is not implemented for &'a ().

@jackh726
Copy link
Member

@hellow554 wow! You rock!

@joshlf
Copy link
Contributor Author

joshlf commented Sep 24, 2021

Wow, fantastic work, @hellow554 !

@jackh726 jackh726 added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections labels Sep 30, 2021
@jackh726
Copy link
Member

This is fixed on nightly, just needs a test (#89118 (comment)) in higher-ranked-type-bounds/normalize-under-binders

@camelid camelid added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Oct 2, 2021
@hameerabbasi
Copy link
Contributor

@rustbot claim

@rustbot rustbot assigned hameerabbasi and unassigned nerandell Oct 3, 2021
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…ckh726

Add test for issue 89118.

This PR adds a test for issue 89118.

Closes rust-lang#89118.
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…ckh726

Add test for issue 89118.

This PR adds a test for issue 89118.

Closes rust-lang#89118.
Manishearth added a commit to Manishearth/rust that referenced this issue Oct 5, 2021
…ckh726

Add test for issue 89118.

This PR adds a test for issue 89118.

Closes rust-lang#89118.
@bors bors closed this as completed in 25cc28e Oct 5, 2021
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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants