Repository navigation
region_obligations not empty #51649
Copy link
Copy link
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️NLL-completeWorking towards the "valid code works" goalWorking towards the "valid code works" goal
Milestone
Description
when compiling syn v0.14.2 with rustc 1.28.0-nightly (523097979 2018-06-18) and compiler flags: -Z borrowck=mir -Z polonius, the compiler panicked.
thread 'main' panicked at 'region_obligations not empty: [
(
NodeId(
16596
),
RegionObligation(sub_region='_#1r, sup_type=T)
)
]', librustc/infer/mod.rs:1057:9
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:71
at libstd/sys_common/backtrace.rs:59
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:211
3: std::panicking::default_hook
at libstd/panicking.rs:227
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
at libstd/panicking.rs:515
6: std::panicking::continue_panic_fmt
at libstd/panicking.rs:426
7: std::panicking::begin_panic_fmt
at libstd/panicking.rs:413
8: rustc::infer::InferCtxt::take_and_reset_region_constraints
9: rustc_mir::borrow_check::nll::type_check::TypeChecker::prove_trait_ref
10: rustc_mir::borrow_check::nll::type_check::TypeVerifier::sanitize_place
11: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_rvalue
12: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_mir
13: rustc_mir::borrow_check::nll::type_check::type_check_internal
14: rustc_mir::borrow_check::nll::compute_regions
15: rustc_mir::borrow_check::do_mir_borrowck
16: rustc::ty::context::GlobalCtxt::enter_local
17: rustc_mir::borrow_check::mir_borrowck
18: rustc::ty::query::__query_compute::mir_borrowck
19: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_borrowck<'tcx>>::compute
20: rustc::dep_graph::graph::DepGraph::with_task_impl
21: rustc::ty::context::tls::with_related_context
22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
24: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
25: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::{{closure}}
26: rustc::util::common::time
27: rustc::ty::context::tls::enter_context
28: <std::thread::local::LocalKey<T>>::with
29: rustc::ty::context::TyCtxt::create_and_enter
30: rustc_driver::driver::compile_input
31: rustc_driver::run_compiler_with_pool
32: <scoped_tls::ScopedKey<T>>::set
33: syntax::with_globals
34: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
35: __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:105
36: rustc_driver::run
37: rustc_driver::main
38: std::rt::lang_start::{{closure}}
39: std::panicking::try::do_call
at libstd/rt.rs:59
at libstd/panicking.rs:310
40: __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:105
41: std::rt::lang_start_internal
at libstd/panicking.rs:289
at libstd/panic.rs:392
at libstd/rt.rs:58
42: main
43: __libc_start_main
44: <unknown>
query stack during panic:
#0 [mir_borrowck] processing `<punctuated::Punctuated<T, P> as std::ops::Index<usize>>::index`
end of query stack
error: internal compiler error: unexpected panic
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️NLL-completeWorking towards the "valid code works" goalWorking towards the "valid code works" goal
Activity
thelearnerofcode commentedon Jun 20, 2018
I get a similar error when compiling actix-web with the same arguments:
KodrAus commentedon Jun 20, 2018
I can repro this with
rustc 1.28.0-nightly (f28c7aef7 2018-06-19)with the following:cargo buildresults in:jice-nospam commentedon Jun 26, 2018
Reproduced on 1.28.0-nightly (2a1c4ee 2018-06-25) running on x86_64-unknown-linux-gnu.
compiler flags : -C debuginfo=2 -C incremental --crate-type lib
jonhoo commentedon Jun 27, 2018
I don't think
unimplemented!()is even necessary:nikomatsakis commentedon Jun 28, 2018
I think I know the problem, but my old minimizations were no longer reproducing. Thanks all for the test cases. I'll try to get this fixed ASAP.
nikomatsakis commentedon Jun 28, 2018
I can't reproduce the ICE on master (but I can with nightly) — however, I suspect there is still a bug here. Gonna dig a bit deeper.
jonhoo commentedon Jun 28, 2018
Latest
masterfixes both the minimization and the full codebase issue for me 👍nikomatsakis commentedon Jun 28, 2018
OK so let me leave some notes on what's going wrong. As I thought, the ICE is gone, but the underlying problem remains. Explaining the problem, I fear, is a bit complex.
First: in some parts, the NLL type checker uses a kind of gruesome hack to extract its constraints. Essentially, it is building on the old inference context, which accumulates various region constraints in a format designed for the old lexical solver. NLL hijacks this by running the type-check, generating those old-style constraints, and then "taking" them and converting them to the new format. We do this "take" operation frequently so that we can isolate where in the program the constraint arose. So we do something like this to process some point
P:(Since my latest PR, we are doing this a lot less, and instead we are using queries to do this isolation; this is much better. But anyway.)
There is however an implicit assumption that the constriants we get from
take_constraintsall arose as part ofprocess(infcx, P)-- but what if there were constriants recorded before we started? Constraints that never got "taken"? This is precisely the problem we are seeing -- before, it was resulting in an ICE, but now we are not checking.If you add this diff, though, you will start to see ICEs again:
nikomatsakis commentedon Jun 28, 2018
So what code is causing these wayward region obligations? The answer is that a very early part of the NLL process is causing the problem. Specifically, when we are creating the universal regions table:
rust/src/librustc_mir/borrow_check/nll/mod.rs
Lines 64 to 65 in e3bf634
During that process, we compute the implied bounds from the argument types:
rust/src/librustc_mir/borrow_check/nll/universal_regions.rs
Lines 686 to 687 in e3bf634
That code winds up (in some weird cases involving associated types) having to solve some obligations:
rust/src/librustc/infer/outlives/bounds.rs
Lines 76 to 112 in e3bf634
Solving those obligations may produce the region-obligations that are causing us trouble. But if you look carefully at that code, you'll notice a weird thing: these obligations that we are solving are basically the requirements that are needed for types to be well-formed. But we should already be guaranteeing that the types are WF (I can't, anyway, think of an exception off the top of my head... my comment suggests that there may have been one...)
I think my preference here would be to make a (canonicalized) query for computing the implied region bounds from a ty. This query would be invoked from
librustc_typeckand also, later, from NLL MIR. It would also resolve all of these nested obligations as needed. The expectation here would be that there are no errors that result — typically we can't do a good job reporting errors from queries.That said, we should first check whether this is "dead code" here (that is, the error reporting code):
rust/src/librustc/infer/outlives/bounds.rs
Line 154 in e3bf634
nikomatsakis commentedon Jun 29, 2018
So this ICE doesn't occur on master, therefore I'm going to defer it, but the code is still kinda wrong. I may try to fix it in "spare time". I haven't yet finishd my essay series on the best fix yet, so I could start there. :)
nikomatsakis commentedon Jun 29, 2018
I'd like to see this fixed by the RC though.
tmandry commentedon Jul 1, 2018
I checked this; it only occurs if there are other (already reported) errors in the program. I was only able to trigger this in a single test. Without any error handling, it has the same behavior.
compile-fail/impl-trait/where-allowed.rs
Auto merge of #51959 - tmandry:make-implied-outlives-query, r=nikomat…
assert no region obligations on entering custom type op