Skip to content

ICE with new borrowck and macros #6304

Closed

Description

@alexcrichton

This code (attempted to whittle down as much as possible) yields an ICE:

struct Foo {
  a: int
}

pub enum Bar {
  Bar1, Bar2(int, ~Bar),
}

impl Foo {
  fn elaborate_stm(&mut self, s: ~Bar) -> ~Bar {
    macro_rules! declare(
      ($id:expr, $rest:expr) => ({
        self.check_id($id);
        ~Bar2($id, $rest)
      })
    );
    match s {
      ~Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
      _ => fail!()
    }
  }

  fn check_id(&mut self, s: int) { fail!() }
}
$ RUST_LOG=rustc=1,::rt::backtrace rustc --test ./foo.rs
./foo.rs:23:25: 23:26 warning: unused variable: `s`
./foo.rs:23   fn check_id(&mut self, s: int) { fail!() }
                                           ^
rust: task failed at 'assertion failed: region_maps.scopes_intersect(old_loan.kill_scope, new_loan.kill_scope)', /Users/alex/code/rust-src/
src/librustc/middle/borrowck/check_loans.rs:174
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/alex/code/rust-src/src/librustc/rustc.rc:353
rust: domain main @0x7f8924017810 root task failed
rust: domain main @0x7f8924017810 root task failed

Activity

  1. alexcrichton commented on May 7, 2013

    @alexcrichton
    MemberAuthor

    As I'm bringing one of my projects up to date, I'm getting this error a lot. Pretty much anything which uses macros and somehow uses some mutability inside causes this ICE.

  2. nikomatsakis commented on May 8, 2013

    @nikomatsakis
    Contributor

    I'll take a look.

  3. emberian commented on Jul 3, 2013

    @emberian
    Contributor

    Backtrace

    #0  upcall_fail (expr=0x7fffe48c5de0 "assertion failed: region_maps.scopes_intersect(old_loan.kill_scope, new_loan.kill_scope)", 
        file=0x7ffff6877450 <str67452> "/home/cmr/hacking/rust/src/librustc/middle/borrowck/check_loans.rs", line=181) at ../src/rt/rust_upcall.cpp:127
    #1  0x00007ffff78c1eac in sys::begin_unwind_::_89e154cd0915671::_07 () from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #2  0x00007ffff78c1ad2 in sys::__extensions__::fail_with::anon::anon::expr_fn_21919 () from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #3  0x00007ffff78c1a01 in str::as_buf_21914::_f8c6f4a6f9cb738::_07 () from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #4  0x00007ffff78c1a8c in sys::__extensions__::fail_with::anon::expr_fn_21917 () from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #5  0x00007ffff78c1a01 in str::as_buf_21914::_f8c6f4a6f9cb738::_07 () from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #6  0x00007ffff782bf1b in sys::__extensions__::meth_10068::fail_with::_d96679812a86c367::_07 ()
       from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #7  0x00007ffff6610e8c in middle::borrowck::check_loans::__extensions__::meth_67539::report_error_if_loans_conflict::_7a7bbb95dbe43ed::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #8  0x00007ffff661087a in middle::borrowck::check_loans::__extensions__::check_for_conflicting_loans::anon::expr_fn_67532 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #9  0x00007ffff660ef92 in middle::borrowck::check_loans::__extensions__::meth_67420::each_issued_loan::_a8f64f5878cbbed::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #10 0x00007ffff661022b in middle::borrowck::check_loans::__extensions__::meth_67513::check_for_conflicting_loans::_da3080ceacf4c36f::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #11 0x00007ffff660ba89 in middle::borrowck::check_loans::check_loans_in_expr::_c19a735d2f695f4::_07 ()
    ---Type <return> to continue, or q <return> to quit---
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #12 0x00007ffff6239cea in visit::visit_expr_27456::_c1574f318f1f1a6::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #13 0x00007ffff660b7c9 in middle::borrowck::check_loans::check_loans_in_expr::_c19a735d2f695f4::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #14 0x00007ffff623a4d4 in visit::visit_exprs_27459::_b96d71a127b74940::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #15 0x00007ffff6238eb4 in visit::visit_expr_27456::_c1574f318f1f1a6::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #16 0x00007ffff660b7c9 in middle::borrowck::check_loans::check_loans_in_expr::_c19a735d2f695f4::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #17 0x00007ffff6239961 in visit::visit_expr_27456::_c1574f318f1f1a6::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #18 0x00007ffff660b7c9 in middle::borrowck::check_loans::check_loans_in_expr::_c19a735d2f695f4::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #19 0x00007ffff6234adb in visit::visit_expr_opt_27065::_719f6211725a297::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #20 0x00007ffff6233fb4 in visit::visit_block_26910::_2945d7bc2771dfd::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #21 0x00007ffff660df58 in middle::borrowck::check_loans::check_loans_in_block::_535c1a3589f6e3::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #22 0x00007ffff623954a in visit::visit_expr_27456::_c1574f318f1f1a6::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #23 0x00007ffff660b7c9 in middle::borrowck::check_loans::check_loans_in_expr::_c19a735d2f695f4::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    ---Type <return> to continue, or q <return> to quit---
    #24 0x00007ffff6234adb in visit::visit_expr_opt_27065::_719f6211725a297::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #25 0x00007ffff6233fb4 in visit::visit_block_26910::_2945d7bc2771dfd::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #26 0x00007ffff660df58 in middle::borrowck::check_loans::check_loans_in_block::_535c1a3589f6e3::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #27 0x00007ffff6240023 in visit::visit_arm_27993::_fe1ea04ccc534::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #28 0x00007ffff623fe6c in visit::default_visitor_27605::anon::expr_fn_27991 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #29 0x00007ffff6239464 in visit::visit_expr_27456::_c1574f318f1f1a6::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #30 0x00007ffff660b7c9 in middle::borrowck::check_loans::check_loans_in_expr::_c19a735d2f695f4::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #31 0x00007ffff6234adb in visit::visit_expr_opt_27065::_719f6211725a297::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #32 0x00007ffff6233fb4 in visit::visit_block_26910::_2945d7bc2771dfd::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #33 0x00007ffff660df58 in middle::borrowck::check_loans::check_loans_in_block::_535c1a3589f6e3::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #34 0x00007ffff660035d in middle::borrowck::check_loans::check_loans::_78399e2f71ef86d::_07 ()
       from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #35 0x00007ffff665a0de in middle::borrowck::borrowck_fn::_b7106e69c6c155e3::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #36 0x00007ffff623f465 in visit::visit_method_helper_27933::_ccd15c8939a283f7::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #37 0x00007ffff623f164 in visit::visit_item_27804::_72d5616277254d51::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    ---Type <return> to continue, or q <return> to quit---
    #38 0x00007ffff623e11c in visit::default_visitor_27605::anon::expr_fn_27802 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #39 0x00007ffff623d913 in visit::visit_mod_27738::_180342e1b369096::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #40 0x00007ffff623d748 in visit::default_visitor_27605::anon::expr_fn_27736 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #41 0x00007ffff65f0f1a in visit::visit_crate_65814::_85b5b27c66c5cece::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #42 0x00007ffff6655025 in middle::borrowck::check_crate::_66a2ce23a87e3a87::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #43 0x00007ffff682f9c1 in driver::driver::compile_rest::anon::expr_fn_93289 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #44 0x00007ffff682d083 in driver::driver::compile_rest::_e58f61c4387ba8b7::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #45 0x00007ffff6861854 in __morestack () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #46 0x00007ffff682ffbc in driver::driver::compile_upto::_af4a64d82884294::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #47 0x00007ffff6830355 in driver::driver::compile_input::_2d802f44a752fd9a::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #48 0x00007ffff684f793 in run_compiler::_7449a6c8ce585463::_07 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #49 0x00007ffff686157e in main::anon::expr_fn_97271 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #50 0x00007ffff685f027 in monitor::anon::expr_fn_97096 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #51 0x00007ffff685693b in task::__extensions__::try_95957::anon::expr_fn_96395 () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #52 0x00007ffff6861854 in __morestack () from /home/cmr/.local/bin/../lib/librustc-d3cb8c2ccd84a7a7-0.7.so
    #53 0x00007ffff7894961 in task::spawn::spawn_raw_oldsched::make_child_wrapper::anon::expr_fn_18373 ()
       from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    #54 0x00007ffff790ad7c in __morestack () from /home/cmr/.local/bin/../lib/libstd-6c65cf4b443341b1-0.7.so
    ---Type <return> to continue, or q <return> to quit---
    #55 0x00007ffff5e54e43 in task_start_wrapper (a=0x7fffec20dcb0) at ../src/rt/rust_task.cpp:164
    #56 0x0000000000000000 in ?? ()
    
  4. nikomatsakis commented on Jul 3, 2013

    @nikomatsakis
    Contributor

    Obviously I failed to take a look.

  5. DaGenix commented on Jul 27, 2013

    @DaGenix

    I ran into this as well and didn't find this issue until I'd already come up with code to reproduce it. In case its helpful, here is the code I ended up with:

    fn test(x: &[u8]) {
    }
    
    macro_rules! impl_buffer( ($name:ident, $size:expr) => (
        impl $name {
            fn run(&mut self, in: &[u8]) {
                let mut i = 0;
                while in.len() - i >= $size {
                    test(in.slice(i, i + $size));
                    i += $size;
                }
            }
        }
    ))
    
    pub struct Buffer;
    impl_buffer!(Buffer, 64)

    At least in my case, there is an easy workaround. The following works fine:

    fn test(x: &[u8]) {
    }
    
    macro_rules! impl_buffer( ($name:ident, $size:expr) => (
        impl $name {
            fn run(&mut self, in: &[u8]) {
                let size = $size;
                let mut i = 0;
                while in.len() - i >= size {
                    test(in.slice(i, i + size));
                    i += $size;
                }
            }
        }
    ))
    
    pub struct Buffer;
    impl_buffer!(Buffer, 64)
  6. added 3 commits that reference this issue on Sep 7, 2013
    32c4d9b
  7. added a commit that references this issue on Sep 10, 2013
    a5ad4c3
  8. added a commit that references this issue on Sep 10, 2013
    753d8c2
  9. added a commit that references this issue on Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions