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

rustc crash with type alias of impl trait #63677

Closed
shootingsyh opened this issue Aug 18, 2019 · 9 comments · Fixed by #63934
Closed

rustc crash with type alias of impl trait #63677

shootingsyh opened this issue Aug 18, 2019 · 9 comments · Fixed by #63934
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@shootingsyh
Copy link

shootingsyh commented Aug 18, 2019

I cannot provide a simple repro yet. But what I did is mostly define a type alias of an impl trait and use it as generic parameter of another type. And here is the stack trace

error: internal compiler error: src/librustc/traits/coherence.rs:523: ty_is_local invoked on unexpected type: TimerStream

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:643:9
stack backtrace:
   0:        0x1106295e2 - std::panicking::default_hook::{{closure}}::hab1ab34f1ce96caa
   1:        0x1106292ad - std::panicking::default_hook::h64b790c24fa7fc49
   2:        0x10f34ca03 - rustc::util::common::panic_hook::h5f0c42b9b5f5c860
   3:        0x110629ea1 - std::panicking::rust_panic_with_hook::hb4f2ed402a5c2512
   4:        0x10f6fef51 - std::panicking::begin_panic::hc70c89798bac02e9
   5:        0x10f718a1e - rustc_errors::Handler::bug::h5baeb98a8a0678a0
   6:        0x10f03e62b - rustc::util::bug::opt_span_bug_fmt::{{closure}}::h6d481064c64d9070
   7:        0x10f038d46 - rustc::ty::context::tls::with_opt::{{closure}}::heed197f8ba0676ae
   8:        0x10f038514 - rustc::ty::context::tls::with_context_opt::hec55cd2ecdfd7b1e
   9:        0x10f038542 - rustc::ty::context::tls::with_opt::hcb84b0e0c6e44f43
  10:        0x10f03e548 - rustc::util::bug::opt_span_bug_fmt::h36d0f65a1fdc8719
  11:        0x10f03e49b - rustc::util::bug::bug_fmt::h82ba15a6bd0a15f1
  12:        0x10f01420a - rustc::traits::coherence::ty_is_local_constructor::h114dccfe228be3db
  13:        0x10f013f6d - rustc::traits::coherence::ty_is_local::hebc4f08163a8f32c
  14:        0x10f0139cb - rustc::traits::coherence::orphan_check_trait_ref::ha29c20ab5632e1a2
  15:        0x10f0135e2 - rustc::traits::coherence::trait_ref_is_knowable::he4651b1a389892b5
  16:        0x10f3295a7 - rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache::hef619078f305ea6c
  17:        0x10ee02e33 - rustc::dep_graph::graph::DepGraph::with_anon_task::h9c7fbd897a8b74af
  18:        0x10f329039 - rustc::traits::select::SelectionContext::candidate_from_obligation::h91204ae0cd40ca57
  19:        0x10f32838d - rustc::traits::select::SelectionContext::evaluate_stack::hdccb6e4735e69c64
  20:        0x10ee02a9b - rustc::dep_graph::graph::DepGraph::with_anon_task::h1983365f787ed581
  21:        0x10f326dac - rustc::traits::select::SelectionContext::evaluate_predicate_recursively::hbbad24ee512cbcfa
  22:        0x10f3259e3 - rustc::traits::select::SelectionContext::evaluate_predicates_recursively::h6b77f200c3916542
  23:        0x10effc467 - rustc::infer::InferCtxt::probe::h46c73949432589d0
  24:        0x10f328420 - rustc::traits::select::SelectionContext::evaluate_stack::hdccb6e4735e69c64
  25:        0x10ee02a9b - rustc::dep_graph::graph::DepGraph::with_anon_task::h1983365f787ed581
  26:        0x10f326dac - rustc::traits::select::SelectionContext::evaluate_predicate_recursively::hbbad24ee512cbcfa
  27:        0x10effd017 - rustc::infer::InferCtxt::probe::h9b9c357204ffa5a5
  28:        0x10f366558 - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::hc4c9d32f4ddb802a
  29:        0x10f3014b6 - <core::slice::Iter<T> as core::iter::traits::iterator::Iterator>::try_fold::h08089fe9896ed2ce
  30:        0x10f2cdc11 - <core::iter::adapters::chain::Chain<A,B> as core::iter::traits::iterator::Iterator>::try_fold::h15c19b5ccfa88730
  31:        0x10f01300b - rustc::traits::coherence::overlap::hfed74e82ba05c75e
  32:        0x10e266e58 - rustc::ty::context::GlobalCtxt::enter_local::h49b342d271f1b96c
  33:        0x10e2fd172 - rustc::traits::coherence::overlapping_impls::h14e3a1cc484a2e15
  34:        0x10e149785 - <rustc_typeck::coherence::inherent_impls_overlap::InherentOverlapChecker as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item::haa87c78d85f603c3
  35:        0x10e148b6b - rustc_typeck::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check::h5714823a4b6013ef
  36:        0x10e15b342 - rustc::ty::query::__query_compute::crate_inherent_impls_overlap_check::hec25e21ca4400cff
  37:        0x10e19206b - rustc::dep_graph::graph::DepGraph::with_task_impl::hdb035c1d37fe2a13
  38:        0x10e241a26 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hc5bc0d0da4f194ab
  39:        0x10e304300 - rustc_typeck::coherence::check_coherence::he7286af5c662a030
  40:        0x10e15c9ad - rustc::util::common::time::h2a7c97de8a318682
  41:        0x10e30512c - rustc_typeck::check_crate::hd110f4e4742d4bb0
  42:        0x10dcadd12 - rustc_interface::passes::analysis::h3fd78df98efc9ff0
  43:        0x10dbb4bae - rustc::ty::query::__query_compute::analysis::h353a45c1e4e47295
  44:        0x10dbc520b - rustc::dep_graph::graph::DepGraph::with_task_impl::hb88490dc2932c48f
  45:        0x10dbcf865 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h30f3db9b52216656
  46:        0x10dbeb2d7 - rustc::ty::context::tls::enter_global::h2b05f3b892a0fe2a
  47:        0x10dbd530c - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::hef054cc95c28e706
  48:        0x10dd03e5c - rustc_interface::passes::create_global_ctxt::{{closure}}::hc6fa2edd634a5176
  49:        0x10dbd61f4 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h04de03e7b31bec3d
  50:        0x10dc08664 - std::thread::local::LocalKey<T>::with::h6300b72366cd4201
  51:        0x10dc0fa82 - scoped_tls::ScopedKey<T>::set::h95306a0884a1982c
  52:        0x10dc408e5 - syntax::with_globals::ha28675c52e11d2e2
  53:        0x10dbb0e47 - std::sys_common::backtrace::__rust_begin_short_backtrace::hf20192de0d0e5526
  54:        0x11063927f - __rust_maybe_catch_panic
  55:        0x10dbd8b67 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h520e25e0f997e8ef
  56:        0x11060d13e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h8743b96d38f43bdd
  57:        0x11063808e - std::sys::unix::thread::Thread::new::thread_start::hf6abe31b14f3b029
  58:     0x7fff711f12eb - _pthread_body
  59:     0x7fff711f4249 - _pthread_start
query stack during panic:
#0 [crate_inherent_impls_overlap_check] check for overlap between inherent impls defined in this crate
#1 [analysis] running analysis passes on this crate
end of query stack
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.39.0-nightly (2111aed0a 2019-08-17) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden
@Centril Centril added A-trait-system Area: Trait system A-type-system Area: Type system F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` 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. requires-nightly This issue requires a nightly compiler in some way. labels Aug 18, 2019
@jonas-schievink jonas-schievink added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example C-bug Category: This is a bug. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Aug 18, 2019
@Aaron1011
Copy link
Member

@shootingsyh: Are you able to provide the repository that reproduces this?

@shootingsyh
Copy link
Author

Sorry it’s still under very early developing, so I haven’t open it. I’m trying to figure out a repro though

@shootingsyh
Copy link
Author

shootingsyh commented Aug 19, 2019

Still cannot find a simple repro. I decided to public my work at https://github.com/shootingsyh/rxstream, and here is patch of my local change:
patch2.txt (Updated with correct patch)

Apply the patch, cargo build with the nightly version, it will crash like that.
Sorry I cannot isolate the issue further. And I'm too new for rust, and this issue happens quite a while ago, almost forgot what I was doing there...

cc @Aaron1011

@hellow554
Copy link
Contributor

@shootingsyh

error[E0583]: file not found for module `overlapped_time_buffer`
 --> src/operators/transform/mod.rs:6:9
  |
6 | pub mod overlapped_time_buffer;
  |         ^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: name the file either overlapped_time_buffer.rs or overlapped_time_buffer/mod.rs inside the directory "src/operators/transform"

If I remove that pub mod (and resolve the other issues) it doesn't ICE on my machine. :/

@shootingsyh
Copy link
Author

shootingsyh commented Aug 19, 2019

@hellow554 how did you get this error? use cargo build?
BTW, did you get the local change patch.txt applied? The patch is where I use the impl trait thing.
https://github.com/rust-lang/rust/files/3518790/patch2.txt (Updated with correct patch)

@hellow554
Copy link
Contributor

@shootingsyh

cd $(mktemp -d)
git clone https://github.com/shootingsyh/rxstream
cd rxstream
wget https://github.com/rust-lang/rust/files/3514385/patch.txt
patch -p1 < patch.txt
cargo build

@shootingsyh
Copy link
Author

Hmmm, sorry didn't add the src/operators/transform/overlapped_time_buffer.rs file into my diff...
Here is the updated patch. Also updated the previous comments and issue
patch2.txt

@hellow554
Copy link
Contributor

hellow554 commented Aug 20, 2019

This is small-ish, I'm not sure if it can be simplified further:

#![feature(type_alias_impl_trait)]

pub trait Trait {}
pub struct S1<T>(T);
pub struct S2<T>(T);

pub type T1 = impl Trait;
pub type T2 = S1<T1>;
pub type T3 = S2<T2>;

impl<T> Trait for S1<T> {}
impl<T: Trait> S2<T> {}
impl T3 {}

pub fn use_t1() -> T1 { S1(()) }

(I Hope the names don't confuse you ;) )

@hellow554

This comment has been minimized.

@rustbot rustbot removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Aug 20, 2019
Aaron1011 added a commit to Aaron1011/rust that referenced this issue Sep 18, 2019
Fixes rust-lang#63677

This commit treats all opaque types as 'remote' with respect to
coherence checking, instead of causing an ICE. This ensures that opaque
types cannot ever 'leak' information about the underlying type (e.g.
whether or not it is a local or remote type)
Centril added a commit to Centril/rust that referenced this issue Sep 24, 2019
… r=nikomatsakis

Fix coherence checking for impl trait in type aliases

**UPDATE**: This PR now treats all opaque types as remote. The original description appears below, but is no longer accurate.

Fixes rust-lang#63677

[RFC 2071](rust-lang/rfcs#2071) (impl-trait-existential-types) does not explicitly state how `type_alias_impl_trait` should interact with coherence. However, there's only one choice which makes sense - coherence should look at the underlying type (i.e. the *"defining"* type of the `impl Trait`) of the type alias, just like we do for non-`impl Trait` type aliases.

Specifically, `impl Trait` type aliases that resolve to a local type should be treated like a local type with respect to coherence (e.g. `impl Trait` type aliases which resolve to a foreign type should be treated as a foreign type, and those that resolve to a local type should be treated as a local type).

Since neither inherent impls nor direct trait impl (i.e. `impl MyType` or `impl MyTrait for MyType`) are allowed for type aliases, this usually does not come up. Before we ever attempt to do coherence checking, we will have errored out if an `impl Trait` type alias was used directly in an `impl` clause.

However, during trait selection, we sometimes need to prove bounds like `T: Sized` for some type `T`. If `T` is an impl trait type alias, this requires to know the coherence behavior for `impl Trait` type aliases when we perform coherence checking.

Note: Since determining the underlying type of an `impl Trait` type alias requires us to perform body type checking, this commit causes us to type check some bodies easier than we otherwise would have. However, since this is done through a query, this shouldn't cause any problems

For completeness, I've added an additional test of the coherence-related behavior of `impl Trait` type aliases.

cc rust-lang#63063
@bors bors closed this as completed in 33e1dd7 Sep 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

Successfully merging a pull request may close this issue.

6 participants