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

ICE: unwrap on an Err PlaceBuilder #87987

Closed
ehuss opened this issue Aug 12, 2021 · 4 comments · Fixed by #88039
Closed

ICE: unwrap on an Err PlaceBuilder #87987

ehuss opened this issue Aug 12, 2021 · 4 comments · Fixed by #88039
Assignees
Labels
A-closures Area: Closures (`|…| { … }`) A-edition-2021 Area: The 2021 edition 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.

Comments

@ehuss
Copy link
Contributor

ehuss commented Aug 12, 2021

Encountered an ICE when building yew 0.18.0 on edition 2021. I have roughly narrowed it down to the following (can probably be reduced further). Seems to be an issue with closure captures.

Code

// Build with edition 2021
use std::rc::Rc;

#[derive(Clone, PartialEq)]
struct Props {
    field_1: u32,
    field_2: u32,
}

#[derive(Clone, Debug, PartialEq)]
struct Node;

#[derive(Clone)]
struct NodeRef(Rc<Node>);

enum VNode {
    VRef(Node),
}

impl VNode {
    fn first_node(&self) -> Node {
        match self {
            VNode::VRef(node) => node.clone(),
        }
    }
}

impl NodeRef {
    fn get(&self) -> Option<Node> {
        Some(self.0.as_ref().clone())
    }
}

struct Properties;

fn main() {
    let test_node = Node;
    let test_node_ref = NodeRef(Rc::new(test_node));
    let check_node_ref = |vnode: VNode| {
        assert_eq!(vnode.first_node(), test_node_ref.get().unwrap());
    };

    let props = Props {
        field_1: 1,
        field_2: 1,
    };
    let props_2 = props.clone();

    check_node_ref(VNode::VRef({
        {
            let _ = |__yew_props: Props| {
                let _: Props = props_2;
            };
            props_2;
        }
        Node
    }));
}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (ccffcafd5 2021-08-11)
binary: rustc
commit-hash: ccffcafd55e58f769d4b0efc0064bf65e76998e4
commit-date: 2021-08-11
host: x86_64-apple-darwin
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

thread 'rustc' panicked at 'called Result::unwrap() on an Err value: PlaceBuilder { base: Upvar { var_hir_id: HirId { owner: DefId(0:16 ~ foo[602f]::main), local_id: 106 }, closure_def_id: DefId(0:18 ~ foo[602f]::main::{closure#1}), closure_kind: Fn }, projection: [] }', compiler/rustc_mir_build/src/build/expr/as_place.rs:306:69

Backtrace

stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_mir_build::build::expr::as_place::PlaceBuilder::into_place
   4: rustc_mir_build::build::matches::simplify::<impl rustc_mir_build::build::Builder>::simplify_candidate
   5: rustc_mir_build::build::matches::<impl rustc_mir_build::build::Builder>::lower_match_tree
   6: rustc_mir_build::build::matches::<impl rustc_mir_build::build::Builder>::place_into_pattern
   7: rustc_mir_build::build::matches::<impl rustc_mir_build::build::Builder>::expr_into_pattern
   8: rustc_mir_build::build::block::<impl rustc_mir_build::build::Builder>::ast_block_stmts
   9: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  10: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  11: rustc_data_structures::stack::ensure_sufficient_stack
  12: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  13: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  14: rustc_data_structures::stack::ensure_sufficient_stack
  15: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  16: rustc_mir_build::build::construct_fn
  17: rustc_infer::infer::InferCtxtBuilder::enter
  18: rustc_mir_build::build::mir_built
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  20: rustc_data_structures::stack::ensure_sufficient_stack
  21: rustc_query_system::query::plumbing::get_query_impl
  22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_built
  23: rustc_mir::transform::check_unsafety::unsafety_check_result
  24: core::ops::function::FnOnce::call_once
  25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  26: rustc_data_structures::stack::ensure_sufficient_stack
  27: rustc_query_system::query::plumbing::force_query_with_job
  28: rustc_query_system::query::plumbing::get_query_impl
  29: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  30: <rustc_mir::transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
  31: rustc_mir::transform::check_unsafety::unsafety_check_result
  32: core::ops::function::FnOnce::call_once
  33: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  34: rustc_data_structures::stack::ensure_sufficient_stack
  35: rustc_query_system::query::plumbing::force_query_with_job
  36: rustc_query_system::query::plumbing::get_query_impl
  37: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  38: rustc_mir::transform::mir_const
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::get_query_impl
  42: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  43: rustc_mir::transform::mir_promoted
  44: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  45: rustc_data_structures::stack::ensure_sufficient_stack
  46: rustc_query_system::query::plumbing::get_query_impl
  47: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  48: rustc_mir::borrow_check::mir_borrowck
  49: core::ops::function::FnOnce::call_once
  50: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  51: rustc_data_structures::stack::ensure_sufficient_stack
  52: rustc_query_system::query::plumbing::force_query_with_job
  53: rustc_query_system::query::plumbing::get_query_impl
  54: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  55: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  56: rustc_interface::passes::analysis
  57: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  58: rustc_data_structures::stack::ensure_sufficient_stack
  59: rustc_query_system::query::plumbing::force_query_with_job
  60: rustc_query_system::query::plumbing::get_query_impl
  61: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  62: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  63: rustc_span::with_source_map
  64: rustc_interface::interface::create_compiler_and_run
  65: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.56.0-nightly (ccffcafd5 2021-08-11) running on x86_64-apple-darwin

note: compiler flags: -Z unstable-options -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [mir_built] building MIR for `main::{closure#1}`
#1 [unsafety_check_result] unsafety-checking `main::{closure#1}`
#2 [unsafety_check_result] unsafety-checking `main`
#3 [mir_const] processing MIR for `main`
#4 [mir_promoted] processing `main`
#5 [mir_borrowck] borrow-checking `main`
#6 [analysis] running analysis passes on this crate
end of query stack

cc @rust-lang/wg-rfc-2229

@ehuss ehuss added 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. C-bug Category: This is a bug. labels Aug 12, 2021
@m-ou-se m-ou-se added A-closures Area: Closures (`|…| { … }`) A-edition-2021 Area: The 2021 edition labels Aug 12, 2021
@roxelo
Copy link
Member

roxelo commented Aug 13, 2021

The code can be further simplified to:

fn main() {
    let props = Props {
        field_1: 1,
        field_2: 1,
    };
    let props_2 = props.clone();

    let _ = |__yew_props: Props| {
        let _: Props = props_2;
    };
}

The issue seems to be around using type annotation. If a type annotation is included, the right hand side of the let statement should always be read.

fn main() {
    let props = Props {
        field_1: 1,
        field_2: 1,
    };
    let props_2 = props.clone();

    let _ = |__yew_props: Props| {
        let _ = props_2; // No ICE when we remove the type annotation
    };
}

@arora-aman
Copy link
Member

let _: Props = props_2; Is there a runtime check/ is MIR generated for checking if props_2 as Props is valid?

Because if that's the case then we need props_2 to be caputred.

@roxelo
Copy link
Member

roxelo commented Aug 15, 2021

@rustbot claim
I should have a fix later tonight

@ehuss
Copy link
Contributor Author

ehuss commented Aug 17, 2021

@roxelo We found another instance of this PlaceBuilder ICE that still fails with #88039 included:

#![feature(capture_disjoint_fields)]

fn foo<MsU>(handler: impl FnOnce() -> MsU + Clone + 'static) {
    Box::new(move |value| {
        (|_| handler.clone()())(value);
        None
    }) as Box<dyn Fn(i32) -> Option<i32>>;
}

fn main() {}

Found trying to migrate seed 0.8.0.

Let me know if you need any more information.

camsteffen added a commit to camsteffen/rust that referenced this issue Aug 19, 2021
RFC2229 Only compute place if upvars can be resolved

Closes rust-lang#87987

This PR fixes an ICE when trying to unwrap an Err. This error appears when trying to convert a PlaceBuilder into Place when upvars can't yet be resolved. We should only try to convert a PlaceBuilder into Place if upvars can be resolved.

r? `@nikomatsakis`
@bors bors closed this as completed in 7611fe4 Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-edition-2021 Area: The 2021 edition 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants