Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Compiler crash when using a storage with a hasher that implement ReversibleStorageHasher #11674

Closed
2 tasks done
gdnathan opened this issue Jun 15, 2022 · 3 comments
Closed
2 tasks done
Labels
J2-unconfirmed Issue might be valid, but it’s not yet known.

Comments

@gdnathan
Copy link

gdnathan commented Jun 15, 2022

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Description of bug

When i try to use a storage with a hasher that implement ReversibleStorageHasher, so i can use .iter() on my storage, the copmiler crash (lsp crash, cargo crash...). More details in the steps to reproduce

Steps to reproduce

Ok, so here are the steps:

1 - Have a structure thatlook like this:

#[derive(Clone, Encode, Decode, TypeInfo, Debug, PartialEq, Eq)]
pub struct Subscription<T: Config> {
    pub frequency: u32, // block number
    pub amount: BalanceOf<T>,
    pub remaining_payments: Option<u32>,
    pub beneficiary: T::AccountId,
}

2 - have a storage that look like this:

	#[pallet::storage]
	#[pallet::getter(fn subscriptions)]
	pub type Subscriptions<T: Config> =
		StorageMap<_, Blake2_128Concat, u32, (Subscription<T>, T::AccountId), OptionQuery>;

3 - use this [storage].iter().for_each() and deconstruct like this, in the on_initialize() function of hooks, with those steps:

	#[pallet::hooks]
	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
		fn on_initialize(n: T::BlockNumber) -> Weight {
// deconstruct like this: (key, (subscription, acc))
			Subscriptions::<T>::iter().for_each(|(key, (subscription, acc))| {
// convert n with n.into()
				if n.into() % subscription.frequency == 0 {
					T::Currency::transfer(
// use the acc veriable (acc.clone() have the same result)
						&acc,
						&subscription.beneficiary,
						subscription.amount,
						ExistenceRequirement::AllowDeath,
					);
				}
			});
			0
		}
	}

Thoses are the conditions to make the bug happen. Here is what it does on a cargo check:

error: internal compiler error: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs:856:33: unexpected path: def=frame_support::pallet_prelude::StorageMap su
bsts=[_, _, _, _, _, _, _] path=Path { span: src/lib.rs:83:4: 83:22 (#0), res: Def(TyAlias, DefId(0:98 ~ pallet_template[c980]::pallet::Subscriptions)), segments: [PathSe
gment { ident: Subscriptions#0, hir_id: Some(HirId { owner: DefId(0:102 ~ pallet_template[c980]::pallet::{impl#0}::on_initialize), local_id: 6 }), res: Some(Err), args: S
ome(GenericArgs { args: [Type(Ty { hir_id: HirId { owner: DefId(0:102 ~ pallet_template[c980]::pallet::{impl#0}::on_initialize), local_id: 4 }, kind: Path(Resolved(None,
Path { span: src/lib.rs:83:20: 83:21 (#0), res: Def(TyParam, DefId(0:101 ~ pallet_template[c980]::pallet::{impl#0}::T)), segments: [PathSegment { ident: T#0, hir_id: Some
(HirId { owner: DefId(0:102 ~ pallet_template[c980]::pallet::{impl#0}::on_initialize), local_id: 5 }), res: Some(Def(TyParam, DefId(0:101 ~ pallet_template[c980]::pallet:
:{impl#0}::T))), args: None, infer_args: false }] })), span: src/lib.rs:83:20: 83:21 (#0) })], bindings: [], parenthesized: false, span_ext: src/lib.rs:83:19: 83:22 (#0)
}), infer_args: false }] }

thread 'rustc' panicked at 'Box', /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/compiler/rustc_errors/src/lib.rs:1334:9
stack backtrace:
0: 0x7fcaf689e09d - std::backtrace_rs::backtrace::libunwind::trace::h2ce9f27fb9fd1403
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7fcaf689e09d - std::backtrace_rs::backtrace::trace_unsynchronized::hcf641bbcae785061
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7fcaf689e09d - std::sys_common::backtrace::_print_fmt::h99b2b1d03ebfca25
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/sys_common/backtrace.rs:66:5
3: 0x7fcaf689e09d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h50c88e784ce953c7
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/sys_common/backtrace.rs:45:22
4: 0x7fcaf68f9e2c - core::fmt::write::h293792f10574f121
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/core/src/fmt/mod.rs:1196:17
5: 0x7fcaf688f791 - std::io::Write::write_fmt::h2e8c395507ba7a71
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/io/mod.rs:1654:15
6: 0x7fcaf68a0d75 - std::sys_common::backtrace::_print::h03874fe9c21d2c8b
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/sys_common/backtrace.rs:48:5
7: 0x7fcaf68a0d75 - std::sys_common::backtrace::print::h9734f26823bd11c4
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/sys_common/backtrace.rs:35:9
8: 0x7fcaf68a0d75 - std::panicking::default_hook::{{closure}}::h59b4d6b1bb2ff70c
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/panicking.rs:295:22
9: 0x7fcaf68a0a96 - std::panicking::default_hook::h43a12be5c3cdc286
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/panicking.rs:314:9
10: 0x7fcaf70fa7c1 - rustc_driver[a1318164c6967ebc]::DEFAULT_HOOK::{closure#0}::{closure#0}
11: 0x7fcae6307863 - <alloc::boxed::Box<F,A> as core::ops::function::Fn>::call::he027f8d12636695f
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/alloc/src/boxed.rs:1965:9
12: 0x7fcae62d9f9d - proc_macro::bridge::client::::enter::{{closure}}::{{closure}}::h75e3df1c0c78089b
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/proc_macro/src/bridge/client.rs:339:21
13: 0x7fcaf68a144a - std::panicking::rust_panic_with_hook::h75ebd6bac4dfc1b4
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/panicking.rs:702:17
14: 0x7fcaf81ba461 - std[60aa6a7d54c33ec5]::panicking::begin_panic::<rustc_errors[2e564758a48a66d]::ExplicitBug>::{closure#0}
15: 0x7fcaf81b9f96 - std[60aa6a7d54c33ec5]::sys_common::backtrace::_rust_end_short_backtrace::<std[60aa6a7d54c33ec5]::panicking::begin_panic<rustc_errors[2e564758a
48a66d]::ExplicitBug>::{closure#0}, !>
16: 0x7fcaf812ca06 - std[60aa6a7d54c33ec5]::panicking::begin_panic::<rustc_errors[2e564758a48a66d]::ExplicitBug>
17: 0x7fcaf80db426 - std[60aa6a7d54c33ec5]::panic::panic_any::<rustc_errors[2e564758a48a66d]::ExplicitBug>
18: 0x7fcaf80dafe5 - <rustc_errors[2e564758a48a66d]::HandlerInner>::bug::<&alloc[8cb8c49cdcd99c11]::string::String>
19: 0x7fcaf80daac0 - <rustc_errors[2e564758a48a66d]::Handler>::bug::<&alloc[8cb8c49cdcd99c11]::string::String>
20: 0x7fcaf81b2cad - rustc_middle[2d4819d2380380d9]::ty::context::tls::with_opt::<rustc_middle[2d4819d2380380d9]::util::bug::opt_span_bug_fmt<rustc_span[fd79c104f28
193cb]::span_encoding::Span>::{closure#0}, ()>
21: 0x7fcaf81b3af6 - rustc_middle[2d4819d2380380d9]::util::bug::opt_span_bug_fmt::<rustc_span[fd79c104f28193cb]::span_encoding::Span>
22: 0x7fcaf81b3a73 - rustc_middle[2d4819d2380380d9]::util::bug::bug_fmt
23: 0x7fcaf808192f - <rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVisitor>::path_inferred_subst_iter
24: 0x7fcaf8081eba - <rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir[9cb4d6c40c3b996f]::intravisit::Visi
tor>::visit_expr
25: 0x7fcaf8081d4f - <rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir[9cb4d6c40c3b996f]::intravisit::Visi
tor>::visit_expr
26: 0x7fcaf80a8e12 - rustc_hir[9cb4d6c40c3b996f]::intravisit::walk_expr::<rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVisi
tor>
27: 0x7fcaf8081d64 - <rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir[9cb4d6c40c3b996f]::intravisit::Visi
tor>::visit_expr
28: 0x7fcaf80a58d7 - rustc_hir[9cb4d6c40c3b996f]::intravisit::walk_block::<rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVis
itor>
29: 0x7fcaf8081d64 - <rustc_infer[6b6cb99105ac010b]::infer::error_reporting::need_type_info::FindInferSourceVisitor as rustc_hir[9cb4d6c40c3b996f]::intravisit::Visi
tor>::visit_expr
30: 0x7fcaf804b3b4 - <rustc_infer[6b6cb99105ac010b]::infer::InferCtxt>::emit_inference_failure_err
31: 0x7fcaf7f97c3b - <rustc_infer[6b6cb99105ac010b]::infer::InferCtxt as rustc_trait_selection[e287d650b5ee650d]::traits::error_reporting::InferCtxtPrivExt>::maybe

report_ambiguity
32: 0x7fcaf7f8b8e7 - <rustc_infer[6b6cb99105ac010b]::infer::InferCtxt as rustc_trait_selection[e287d650b5ee650d]::traits::error_reporting::InferCtxtExt>::report_ful
fillment_errors
33: 0x7fcaf86f18e6 - <rustc_infer[6b6cb99105ac010b]::infer::InferCtxtBuilder>::enter::<&rustc_middle[2d4819d2380380d9]::ty::context::TypeckResults, <rustc_typeck[37
6f1d0dc7e323a8]::check::inherited::InheritedBuilder>::enter<rustc_typeck[376f1d0dc7e323a8]::check::typeck_with_fallback<rustc_typeck[376f1d0dc7e323a8]::check::typeck::{cl
osure#0}>::{closure#1}, &rustc_middle[2d4819d2380380d9]::ty::context::TypeckResults>::{closure#0}>
34: 0x7fcaf8687f5a - rustc_typeck[376f1d0dc7e323a8]::check::typeck
35: 0x7fcaf97568a0 - <rustc_query_system[fedac00cf566d235]::dep_graph::graph::DepGraph<rustc_middle[2d4819d2380380d9]::dep_graph::dep_node::DepKind>>::with_task::<r
ustc_middle[2d4819d2380380d9]::ty::context::TyCtxt, rustc_span[fd79c104f28193cb]::def_id::LocalDefId, &rustc_middle[2d4819d2380380d9]::ty::context::TypeckResults>
36: 0x7fcaf8c7a0d0 - rustc_query_system[fedac00cf566d235]::query::plumbing::try_execute_query::<rustc_query_impl[221041185e76cafc]::plumbing::QueryCtxt, rustc_query
_system[fedac00cf566d235]::query::caches::DefaultCache<rustc_span[fd79c104f28193cb]::def_id::LocalDefId, &rustc_middle[2d4819d2380380d9]::ty::context::TypeckResults>>
37: 0x7fcaf8c5061e - <rustc_query_impl[221041185e76cafc]::Queries as rustc_middle[2d4819d2380380d9]::ty::query::QueryEngine>::typeck
38: 0x7fcaf86880ef - rustc_typeck[376f1d0dc7e323a8]::check::typeck
39: 0x7fcaf97568a0 - <rustc_query_system[fedac00cf566d235]::dep_graph::graph::DepGraph<rustc_middle[2d4819d2380380d9]::dep_graph::dep_node::DepKind>>::with_task::<r
ustc_middle[2d4819d2380380d9]::ty::context::TyCtxt, rustc_span[fd79c104f28193cb]::def_id::LocalDefId, &rustc_middle[2d4819d2380380d9]::ty::context::TypeckResults>
40: 0x7fcaf8c7a0d0 - rustc_query_system[fedac00cf566d235]::query::plumbing::try_execute_query::<rustc_query_impl[221041185e76cafc]::plumbing::QueryCtxt, rustc_query
_system[fedac00cf566d235]::query::caches::DefaultCache<rustc_span[fd79c104f28193cb]::def_id::LocalDefId, &rustc_middle[2d4819d2380380d9]::ty::context::TypeckResults>>
41: 0x7fcaf8c5061e - <rustc_query_impl[221041185e76cafc]::Queries as rustc_middle[2d4819d2380380d9]::ty::query::QueryEngine>::typeck
42: 0x7fcaf87491d8 - <rustc_middle[2d4819d2380380d9]::hir::map::Map>::par_body_owners::<rustc_typeck[376f1d0dc7e323a8]::check::typeck_item_bodies::{closure#0}>
43: 0x7fcaf95137bc - rustc_typeck[376f1d0dc7e323a8]::check::typeck_item_bodies
44: 0x7fcaf9775f73 - <rustc_query_system[fedac00cf566d235]::dep_graph::graph::DepGraph<rustc_middle[2d4819d2380380d9]::dep_graph::dep_node::DepKind>>::with_task::<r
ustc_middle[2d4819d2380380d9]::ty::context::TyCtxt, (), ()>
45: 0x7fcaf9825035 - rustc_query_system[fedac00cf566d235]::query::plumbing::try_execute_query::<rustc_query_impl[221041185e76cafc]::plumbing::QueryCtxt, rustc_query
_system[fedac00cf566d235]::query::caches::DefaultCache<(), ()>>
46: 0x7fcaf984f2d1 - rustc_query_system[fedac00cf566d235]::query::plumbing::get_query::<rustc_query_impl[221041185e76cafc]::queries::typeck_item_bodies, rustc_query
_impl[221041185e76cafc]::plumbing::QueryCtxt>
47: 0x7fcaf9548873 - <rustc_session[df45cd53ed1d3a9]::session::Session>::time::<(), rustc_typeck[376f1d0dc7e323a8]::check_crate::{closure#7}>
48: 0x7fcaf9530bbb - rustc_typeck[376f1d0dc7e323a8]::check_crate
49: 0x7fcaf92f1117 - rustc_interface[c88ea67dfb7c9d24]::passes::analysis
50: 0x7fcaf9771855 - <rustc_query_system[fedac00cf566d235]::dep_graph::graph::DepGraph<rustc_middle[2d4819d2380380d9]::dep_graph::dep_node::DepKind>>::with_task::<r
ustc_middle[2d4819d2380380d9]::ty::context::TyCtxt, (), core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>
51: 0x7fcaf981a49d - rustc_query_system[fedac00cf566d235]::query::plumbing::try_execute_query::<rustc_query_impl[221041185e76cafc]::plumbing::QueryCtxt, rustc_query
_system[fedac00cf566d235]::query::caches::DefaultCache<(), core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>>
52: 0x7fcaf986188e - rustc_query_system[fedac00cf566d235]::query::plumbing::get_query::<rustc_query_impl[221041185e76cafc]::queries::analysis, rustc_query_impl[2210
41185e76cafc]::plumbing::QueryCtxt>
53: 0x7fcaf92ae4a7 - <rustc_interface[c88ea67dfb7c9d24]::passes::QueryContext>::enter::<rustc_driver[a1318164c6967ebc]::run_compiler::{closure#1}::{closure#2}::{clo
sure#3}, core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>
54: 0x7fcaf929865f - <rustc_interface[c88ea67dfb7c9d24]::interface::Compiler>::enter::<rustc_driver[a1318164c6967ebc]::run_compiler::{closure#1}::{closure#2}, core[
fe29770e84ba6932]::result::Result<core[fe29770e84ba6932]::option::Option<rustc_interface[c88ea67dfb7c9d24]::queries::Linker>, rustc_errors[2e564758a48a66d]::ErrorGuarante
ed>>
55: 0x7fcaf92c1caf - rustc_span[fd79c104f28193cb]::with_source_map::<core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>, rus
tc_interface[c88ea67dfb7c9d24]::interface::create_compiler_and_run<core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>, rustc_drive
r[a1318164c6967ebc]::run_compiler::{closure#1}>::{closure#1}>
56: 0x7fcaf92994f2 - <scoped_tls[355245919de37a4a]::ScopedKey<rustc_span[fd79c104f28193cb]::SessionGlobals>>::set::<rustc_interface[c88ea67dfb7c9d24]::interface::ru
n_compiler<core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>, rustc_driver[a1318164c6967ebc]::run_compiler::{closure#1}>::{closur
e#0}, core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>
57: 0x7fcaf92aeb2f - std[60aa6a7d54c33ec5]::sys_common::backtrace::_rust_begin_short_backtrace::<rustc_interface[c88ea67dfb7c9d24]::util::run_in_thread_pool_with_g
lobals<rustc_interface[c88ea67dfb7c9d24]::interface::run_compiler<core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>, rustc_driver
[a1318164c6967ebc]::run_compiler::{closure#1}>::{closure#0}, core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>::{closure#0}, cor
e[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>
58: 0x7fcaf92aec99 - <<std[60aa6a7d54c33ec5]::thread::Builder>::spawn_unchecked
<rustc_interface[c88ea67dfb7c9d24]::util::run_in_thread_pool_with_globals<rustc_inte
rface[c88ea67dfb7c9d24]::interface::run_compiler<core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>, rustc_driver[a1318164c6967ebc
]::run_compiler::{closure#1}>::{closure#0}, core[fe29770e84ba6932]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>::{closure#0}, core[fe29770e84ba693
2]::result::Result<(), rustc_errors[2e564758a48a66d]::ErrorGuaranteed>>::{closure#1} as core[fe29770e84ba6932]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
59: 0x7fcaf68ab373 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::ha38232abee92310c
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/alloc/src/boxed.rs:1951:9
60: 0x7fcaf68ab373 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::h742906562c32a5b2
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/alloc/src/boxed.rs:1951:9
61: 0x7fcaf68ab373 - std::sys::unix::thread::Thread::new::thread_start::h441cb532d7888bf2
at /rustc/7466d5492b2d28d2ba5114dbe71511a6502ac822/library/std/src/sys/unix/thread.rs:108:17
62: 0x7fcaf648c54d -
63: 0x7fcaf6511874 - clone
64: 0x0 -

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.63.0-nightly (7466d5492 2022-06-08) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [typeck] type-checking pallet::<impl at src/lib.rs:81:2: 99:3>::on_initialize
#1 [typeck] type-checking pallet::<impl at src/lib.rs:81:2: 99:3>::on_initialize::{closure#0}
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: could not compile pallet-template

@github-actions github-actions bot added the J2-unconfirmed Issue might be valid, but it’s not yet known. label Jun 15, 2022
@nazar-pc
Copy link
Contributor

You should probably report this into rustc instead

@bkchr
Copy link
Member

bkchr commented Jun 15, 2022

Yep, this is a rustc bug, not Substrate related. Going to close the issue.

@bkchr bkchr closed this as completed Jun 15, 2022
@gdnathan
Copy link
Author

Okay, thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J2-unconfirmed Issue might be valid, but it’s not yet known.
Projects
None yet
Development

No branches or pull requests

3 participants