-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-codegenArea: Code generationArea: Code generationA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-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.
Description
This is ICE happens when I call ROnce::new
from the abi_stable crate in const contexts in dependent crates/doctests,
but not when using the ROnce::NEW
associated constant.
Reproducing
It can be reproduced using a doctest in the playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=27b35d06267adeacb7334388600c96be
It can also be reproduced by cloning this repository,and then build lib_1.
Code
The code for the linked repositories is :
lib_0:
pub struct VTable{
state:extern fn(),
}
impl VTable{
pub const fn vtable()->&'static VTable{
Self::VTABLE
}
const VTABLE: &'static VTable =
&VTable{state};
}
extern fn state(){ }
lib_1:
use lib_0::VTable;
static ICE_ICE:&'static VTable=VTable::vtable();
Error
This is the error message:
Compiling lib_1 v0.1.0 (/home/matias/Documents/eclipse_workspace/tmp/const_fn_ice/lib_1)
warning: static item is never used: `ICE_ICE`
--> src/lib.rs:3:1
|
3 | static ICE_ICE:&'static VTable=VTable::vtable();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
error: internal compiler error: src/librustc_mir/monomorphize/collector.rs:778: Cannot create local mono-item for DefId(15:17 ~ lib_0[ce77]::state[0])
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:644:9
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.tiyicn.workers.dev-1ecc6299db9ec823/backtrace-0.3.34/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:47
3: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:36
4: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:200
5: std::panicking::default_hook
at src/libstd/panicking.rs:214
6: rustc::util::common::panic_hook
7: core::ops::function::Fn::call
8: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:481
9: std::panicking::begin_panic
10: rustc_errors::Handler::bug
11: rustc::util::bug::opt_span_bug_fmt::{{closure}}
12: rustc::ty::context::tls::with_opt::{{closure}}
13: rustc::ty::context::tls::with_context_opt
14: rustc::ty::context::tls::with_opt
15: rustc::util::bug::opt_span_bug_fmt
16: rustc::util::bug::bug_fmt
17: rustc_mir::monomorphize::collector::should_monomorphize_locally
18: rustc_mir::monomorphize::collector::collect_miri
19: rustc_mir::monomorphize::collector::collect_miri
20: rustc_mir::monomorphize::collector::collect_const
21: rustc_mir::monomorphize::collector::collect_items_rec
22: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
23: rustc::util::common::time
24: rustc_mir::monomorphize::collector::collect_crate_mono_items
25: rustc::util::common::time
26: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
27: rustc::ty::query::__query_compute::collect_and_partition_mono_items
28: rustc::dep_graph::graph::DepGraph::with_task_impl
29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
30: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
31: rustc::ty::query::__query_compute::exported_symbols
32: rustc::dep_graph::graph::DepGraph::with_task_impl
33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
34: rustc_metadata::encoder::EncodeContext::encode_crate_root
35: rustc::dep_graph::graph::DepGraph::with_ignore
36: rustc_metadata::encoder::encode_metadata
37: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
38: rustc::ty::context::TyCtxt::encode_metadata
39: rustc_interface::passes::encode_and_write_metadata
40: rustc::util::common::time
41: rustc_interface::passes::start_codegen
42: rustc::ty::context::tls::enter_global
43: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
44: rustc_interface::passes::create_global_ctxt::{{closure}}
45: rustc_interface::passes::BoxedGlobalCtxt::enter
46: rustc_interface::queries::Query<T>::compute
47: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
48: rustc_interface::interface::run_compiler_in_existing_thread_pool
49: std::thread::local::LocalKey<T>::with
50: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
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.38.0-nightly (435236b88 2019-08-01) running on i686-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `lib_1`.
DutchGhost
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Centril commentedon Aug 2, 2019
cc @oli-obk
oli-obk commentedon Aug 3, 2019
I think we have another issue open for another symptom of this bug but I can't find it. Basically the problem is that we fail to recognize that the allocation containing the function pointer came from another crate and thus was already collected. Since we don't realize we don't need to collect the alloc, we do so and try to collect the function pointers in it.
Maybe we can cause the same bug by having a const fn return a function pointer and then storing that in a constant.
rodrimati1992 commentedon Aug 3, 2019
These also produce the same error(when running doctests):
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=86bbb9d2551e5ca2b3de324f60697376
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=afe32351c0a8161c52d2320489a22095
Error:
oli-obk commentedon Aug 3, 2019
OK, so essentially it boils down to "don't try to monomorphize functions that can't be monomorphized locally, and assume they have been monomorphized upstream". Going for that logic will fix all of the ICEs we've had at this site, but also turn hypothetical compiler bugs that were ICEs into linker errors (undefined reference)
oli-obk commentedon Aug 4, 2019
cc @rust-lang/compiler I see no other way (see previous post) to prevent the collector from trying to collect function pointers in constants if the function comes from a different crate, without breaking the case where we need to collect the function pointer because the function comes from the local crate.
We may have local constants with function pointers to functions from other crates and constants with references to constants from other crates that contain function pointers. So there's no use in checking where the constant came from. Const eval could theoretically return a list of created function pointers, but that would just be a complicated way of subverting the ICE.
We can make sure to just silence the ICE in the constant case, to ensure it still catches bugs in the regular case.
Opinions?
4 remaining items
oli-obk commentedon Aug 9, 2019
Impl instructions:
rust/src/librustc/middle/reachable.rs
Line 37 in 813a3a5
constness
field. If it's const,return true;
rust/src/librustc/middle/reachable.rs
Line 45 in 813a3a5
impl_item
'snode
field (https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/struct.ImplItem.html#structfield.node) forMethod
and fetch theFnHeader
from that variant.Rollup merge of rust-lang#63582 - JohnTitor:fix-ice-63226, r=oli-obk
Rollup merge of rust-lang#63582 - JohnTitor:fix-ice-63226, r=oli-obk
Auto merge of #63592 - Centril:rollup-7c6dg3e, r=Centril
michaelwoerister commentedon Aug 16, 2019
Nice! Thanks @oli-obk for writing up the instructions and @JohnTitor for implementing them!
librustc_mir/monomorphize/collector.rs:776:
Cannot create local mono-item for DefId #60363