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

type parameter out of range when substituting #101465

Closed
Tracked by #5977
xxchan opened this issue Sep 5, 2022 · 2 comments · Fixed by #101604
Closed
Tracked by #5977

type parameter out of range when substituting #101465

xxchan opened this issue Sep 5, 2022 · 2 comments · Fixed by #101604
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@xxchan
Copy link
Contributor

xxchan commented Sep 5, 2022

Code

// It's complicated and I will try to minimize it later...

The source code is here https://github.com/risingwavelabs/risingwave/blob/xxchan/bump/src/storage/src/hummock/state_store.rs#L445

The error can be seen here https://buildkite.com/risingwavelabs/pull-request/builds/7684#01830ff8-131b-4859-b1f7-c715704e5540

risingwavelabs/risingwave#5119

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `(): store::IterFutureTrait`
#1 [typeck] type-checking `hummock::state_store::<impl at src/storage/src/hummock/state_store.rs:445:1: 445:35>::iter`
#2 [type_of] computing type of `hummock::state_store::<impl at src/storage/src/hummock/state_store.rs:445:1: 445:35>::GetFuture::{opaque#0}`
#3 [check_mod_item_types] checking item types in module `hummock::state_store`
#4 [analysis] running analysis passes on this crate
end of query stack

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (289279de1 2022-09-04)
binary: rustc
commit-hash: 289279de116707f28cf9c18e4bbb8c6ec84ad75b
commit-date: 2022-09-04
host: aarch64-apple-darwin
release: 1.65.0-nightly
LLVM version: 15.0.0

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:632:9: type parameter `I/#2` (I/2) out of range when substituting, substs=[()]
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/289279de116707f28cf9c18e4bbb8c6ec84ad75b/compiler/rustc_errors/src/lib.rs:1465:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug::<&alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: <rustc_middle::ty::subst::SubstFolder>::type_param_out_of_range
   8: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
   9: <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle::ty::subst::SubstFolder>
  10: <rustc_middle::ty::Ty as rustc_middle::ty::fold::TypeSuperFoldable>::super_fold_with::<rustc_middle::ty::subst::SubstFolder>
  11: <rustc_middle::ty::PredicateKind as rustc_middle::ty::fold::TypeFoldable>::try_fold_with::<rustc_middle::ty::subst::SubstFolder>
  12: <rustc_middle::ty::subst::SubstFolder as rustc_middle::ty::fold::FallibleTypeFolder>::try_fold_binder::<rustc_middle::ty::PredicateKind>
  13: <rustc_trait_selection::traits::select::SelectionContext>::impl_or_trait_obligations
  14: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
  15: <rustc_infer::infer::InferCtxt>::probe::<core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, <rustc_trait_selection::traits::select::SelectionContext>::evaluation_probe<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}>::{closure#0}>
  16: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_stack
  17: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<<rustc_trait_selection::traits::select::SelectionContext>::in_task<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}::{closure#2}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#0}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
  18: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_anon_task::<rustc_middle::ty::context::TyCtxt, <rustc_trait_selection::traits::select::SelectionContext>::in_task<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}::{closure#2}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#0}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
  19: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
  20: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_predicate_recursively
  21: <rustc_infer::infer::InferCtxt>::probe::<core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, <rustc_trait_selection::traits::select::SelectionContext>::evaluation_probe<<rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation::{closure#0}>::{closure#0}>
  22: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation
  23: <rustc_infer::infer::InferCtxtBuilder>::enter_with_canonical::<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_traits::evaluate_obligation::evaluate_obligation::{closure#0}>
  24: rustc_traits::evaluate_obligation::evaluate_obligation
  25: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task_impl<rustc_middle::ty::context::TyCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#0}, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
  26: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
  27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>>
  28: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::evaluate_obligation, rustc_query_impl::plumbing::QueryCtxt>
  29: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
  30: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  31: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  32: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_must_hold_modulo_regions
  33: <rustc_typeck::check::fn_ctxt::FnCtxt>::opt_suggest_box_span
  34: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_match::{closure#0}
  35: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  36: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  37: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  38: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  39: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  40: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  41: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  42: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  43: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  44: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  45: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  46: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  47: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  48: rustc_typeck::check::check::check_fn
  49: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  50: rustc_typeck::check::typeck
  51: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
  52: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  53: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck, rustc_query_impl::plumbing::QueryCtxt>
  54: <rustc_typeck::collect::type_of::find_opaque_ty_constraints_for_tait::ConstraintLocator>::check
  55: rustc_hir::intravisit::walk_item::<rustc_typeck::collect::type_of::find_opaque_ty_constraints_for_tait::ConstraintLocator>
  56: rustc_typeck::collect::type_of::find_opaque_ty_constraints_for_tait
  57: rustc_typeck::collect::type_of::type_of
  58: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId, rustc_middle::ty::Ty>
  59: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, rustc_middle::ty::Ty>>
  60: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::type_of, rustc_query_impl::plumbing::QueryCtxt>
  61: rustc_typeck::check::check::check_opaque
  62: rustc_typeck::check::check::check_item_type
  63: rustc_typeck::check::check::check_mod_item_types
  64: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, ()>
  65: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  66: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
  67: <rustc_middle::hir::map::Map>::for_each_module::<rustc_typeck::check_crate::{closure#6}::{closure#0}>
  68: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#6}>
  69: rustc_typeck::check_crate
  70: rustc_interface::passes::analysis
  71: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  72: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  73: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  74: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  75: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  76: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  77: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  78: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
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.65.0-nightly (289279de1 2022-09-04) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C lto=off -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `(): store::IterFutureTrait`
#1 [typeck] type-checking `hummock::state_store::<impl at src/storage/src/hummock/state_store.rs:445:1: 445:35>::iter`
#2 [type_of] computing type of `hummock::state_store::<impl at src/storage/src/hummock/state_store.rs:445:1: 445:35>::GetFuture::{opaque#0}`
#3 [check_mod_item_types] checking item types in module `hummock::state_store`
#4 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `risingwave_storage`

@xxchan xxchan 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 5, 2022
@compiler-errors
Copy link
Member

compiler-errors commented Sep 6, 2022

Minimized:

#![feature(trait_alias)]

struct B;

struct C;

trait Tr2<S> = Into<S>;

fn foo2<T: Tr2<()>>() {}

fn foo() -> impl Sized {
    let x = foo2::<_>();

    match true {
        true => B,
        false => C,
    }
}

The logic in opt_suggest_box_span is super broken. First, we're calling it on non-error paths (which is probably inefficient), it's throwing away the non-Self substs on the predicates it's checking, it doesn't really make sense why it works at all1 since it's trying to check literally all pending predicates in the FulfillmentContext, etc.... 😕 I am going to totally rewrite that logic.

@rustbot claim

1. This is probably because this has gone through a couple of impl Trait rewrites and refactors...

@xxchan
Copy link
Contributor Author

xxchan commented Sep 13, 2022

Thanks for your incredible work! The ICE doesn't occur in our code anymore.

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. glacier ICE tracked in rust-lang/glacier. 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.

3 participants