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

Overflow in span subtraction / astencode #23115

Closed
Manishearth opened this issue Mar 6, 2015 · 23 comments
Closed

Overflow in span subtraction / astencode #23115

Manishearth opened this issue Mar 6, 2015 · 23 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Manishearth
Copy link
Member

https://travis-ci.org/GuillaumeGomez/rust-GSL/builds/53335854


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/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'arithmetic operation overflowed', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/codemap.rs:73

stack backtrace:
   1:     0x7fd52b3bcf6f - sys::backtrace::write::h2f046b875b210aadOBA
   2:     0x7fd52b3e7c82 - panicking::on_panic::h792ac47fb8c07faehHJ
   3:     0x7fd52b31cf2a - rt::unwind::begin_unwind_inner::hbffac672008352c8knJ
   4:     0x7fd52b31d641 - rt::unwind::begin_unwind_fmt::hbe64affaa986f482VlJ
   5:     0x7fd52b3e7807 - rust_begin_unwind
   6:     0x7fd52b433114 - panicking::panic_fmt::h81cd96819f02da8dIZs
   7:     0x7fd52b42f53d - panicking::panic::h8ea414638b29b322UXs
   8:     0x7fd5286f98ac - codemap::BytePos.Sub::sub::h13c0a0f10f07c348YWB
   9:     0x7fd529035ec0 - middle::astencode::DecodeContext<'a, 'b, 'tcx>::tr_span::hdd7910e968f71d01FCa
  10:     0x7fd52904679c - fold::noop_fold_expr::h1258022642513463166
  11:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  12:     0x7fd529049c9e - fold::noop_fold_expr::closure.66610
  13:     0x7fd5290469e1 - fold::noop_fold_expr::h1258022642513463166
  14:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  15:     0x7fd529049c9e - fold::noop_fold_expr::closure.66610
  16:     0x7fd529046bbe - fold::noop_fold_expr::h1258022642513463166
  17:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  18:     0x7fd529049c4b - fold::noop_fold_expr::closure.66605
  19:     0x7fd52904e0a4 - fold::noop_fold_local::closure.66836
  20:     0x7fd52904da97 - fold::noop_fold_decl::closure.66833
  21:     0x7fd52904bc9b - fold::Folder::fold_stmt::closure.66763
  22:     0x7fd52904b553 - fold::noop_fold_block::closure.66714
  23:     0x7fd52904b208 - iter::FlatMap<I, U, F>.Iterator::next::h9223681505759829108
  24:     0x7fd52904a9cf - vec::Vec<T>.FromIterator<T>::from_iter::h13016817088923062838
  25:     0x7fd52904a295 - fold::noop_fold_block::closure.66623
  26:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658
  27:     0x7fd529047873 - fold::noop_fold_expr::h1258022642513463166
  28:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  29:     0x7fd529049c4b - fold::noop_fold_expr::closure.66605
  30:     0x7fd52904a327 - fold::noop_fold_block::closure.66623
  31:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658
  32:     0x7fd529047873 - fold::noop_fold_expr::h1258022642513463166
  33:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  34:     0x7fd52904c176 - fold::Folder::fold_stmt::closure.66763
  35:     0x7fd52904b553 - fold::noop_fold_block::closure.66714
  36:     0x7fd52904b208 - iter::FlatMap<I, U, F>.Iterator::next::h9223681505759829108
  37:     0x7fd52904a9cf - vec::Vec<T>.FromIterator<T>::from_iter::h13016817088923062838
  38:     0x7fd52904a295 - fold::noop_fold_block::closure.66623
  39:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658
  40:     0x7fd529046f87 - fold::noop_fold_expr::h1258022642513463166
  41:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  42:     0x7fd52904bb9b - fold::Folder::fold_stmt::closure.66763
  43:     0x7fd52904b553 - fold::noop_fold_block::closure.66714
  44:     0x7fd52904b208 - iter::FlatMap<I, U, F>.Iterator::next::h9223681505759829108
  45:     0x7fd52904a9cf - vec::Vec<T>.FromIterator<T>::from_iter::h13016817088923062838
  46:     0x7fd52904a295 - fold::noop_fold_block::closure.66623
  47:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658
  48:     0x7fd529047873 - fold::noop_fold_expr::h1258022642513463166
  49:     0x7fd5290464a3 - ptr::P<T>::map::h4462110055941524197
  50:     0x7fd529049c4b - fold::noop_fold_expr::closure.66605
  51:     0x7fd52904a327 - fold::noop_fold_block::closure.66623
  52:     0x7fd529049e32 - fold::noop_fold_block::h14827012078068820658
  53:     0x7fd529069f57 - fold::noop_fold_method::closure.67217
  54:     0x7fd5290696c5 - fold::noop_fold_method::h2920979874065131956
  55:     0x7fd529038abb - middle::astencode::decode_inlined_item::h674342a5ff4e1a27Pqa
  56:     0x7fd52a9f81ff - trans::inline::instantiate_inline::closure.39610
  57:     0x7fd529427c2b - metadata::decoder::maybe_get_item_ast::h6b38702aa8f07983PDi
  58:     0x7fd52922aec6 - metadata::csearch::maybe_get_item_ast::hf5174e6ae59eb7b5o3k
  59:     0x7fd52a9f6a5d - trans::inline::instantiate_inline::h6a8d7203fac7c299bid
  60:     0x7fd52aa45d85 - trans::callee::trans_fn_ref_with_substs::h85a6252d422343b2qng
  61:     0x7fd52aa4452e - trans::callee::trans_fn_ref::h7eebc758d7f24cf00bg
  62:     0x7fd52aa5b344 - trans::meth::trans_method_callee::h175c0aff2b6fe67998x
  63:     0x7fd52aa59a19 - trans::callee::trans_call_inner::h18244630176801372264
  64:     0x7fd52aa638e9 - trans::expr::trans_rvalue_dps_unadjusted::h62a8f691df1cee3cqCi
  65:     0x7fd52aa154e6 - trans::expr::trans_into::h3bbb0e210c9fb401Vph
  66:     0x7fd52aa14684 - trans::controlflow::trans_stmt_semi::hd74052e320e3d8baK6d
  67:     0x7fd52aa15fc0 - trans::controlflow::trans_block::h4b526e186a057814x7d
  68:     0x7fd52aa640de - trans::expr::trans_rvalue_dps_unadjusted::h62a8f691df1cee3cqCi
  69:     0x7fd52aa154e6 - trans::expr::trans_into::h3bbb0e210c9fb401Vph
  70:     0x7fd52aa14684 - trans::controlflow::trans_stmt_semi::hd74052e320e3d8baK6d
  71:     0x7fd52aa15fc0 - trans::controlflow::trans_block::h4b526e186a057814x7d
  72:     0x7fd52aaed3b1 - trans::base::trans_closure::h194b7ad0474e43a46mt
  73:     0x7fd52a9fe948 - trans::base::trans_fn::h5416ef5d9cea730bZxt
  74:     0x7fd52a9fa6e1 - trans::base::trans_item::h2af153dd6f7fd52bRVt
  75:     0x7fd52aaf674c - trans::base::trans_crate::h5cb53f6b3e2377862Ru
  76:     0x7fd52b9f7613 - driver::phase_4_translate_to_llvm::h60575195b9fa298dENa
  77:     0x7fd52b9d305b - driver::compile_input::h9772b425fd1776fdNba
  78:     0x7fd52ba97697 - run_compiler::h17c28dbe4dd58e3bV5b
  79:     0x7fd52ba952c9 - thunk::F.Invoke<A, R>::invoke::h3041729087284544127
  80:     0x7fd52ba93f40 - rt::unwind::try::try_fn::h11775082019993619070
  81:     0x7fd52b457e38 - rust_try_inner
  82:     0x7fd52b457e25 - rust_try
  83:     0x7fd52ba946df - thunk::F.Invoke<A, R>::invoke::h10556879288050829464
  84:     0x7fd52b3d29b5 - sys::thread::thread_start::hfe8c2cac3ec4afcdr8E
  85:     0x7fd52520fe99 - start_thread
  86:     0x7fd52af8a4bc - <unknown>

Offending code:


impl Sub for BytePos {
    type Output = BytePos;

    fn sub(self, rhs: BytePos) -> BytePos {
        BytePos((self.to_usize() - rhs.to_usize()) as u32)
    }
}

and the code calling it:

    pub fn tr_span(&self, span: Span) -> Span {
        let imported_filemaps = &self.cdata.codemap_import_info[..];

        let filemap_index = {
            // Optimize for the case that most spans within a translated item
            // originate from the same filemap.
            let last_filemap_index = self.last_filemap_index.get();

            if span.lo >= imported_filemaps[last_filemap_index].original_start_pos &&
               span.hi <= imported_filemaps[last_filemap_index].original_end_pos {
                last_filemap_index
            } else {
                let mut a = 0;
                let mut b = imported_filemaps.len();

                while b - a > 1 {
                    let m = (a + b) / 2;
                    if imported_filemaps[m].original_start_pos > span.lo {
                        b = m;
                    } else {
                        a = m;
                    }
                }

                self.last_filemap_index.set(a);
                a
            }
        };

        let lo = (span.lo - imported_filemaps[filemap_index].original_start_pos) +
                  imported_filemaps[filemap_index].translated_filemap.start_pos;
        let hi = (span.hi - imported_filemaps[filemap_index].original_start_pos) +
                  imported_filemaps[filemap_index].translated_filemap.start_pos;

        codemap::mk_sp(lo, hi)
    }

We might want a bounds check there (resolving to 0?), but there seems to be something broken in the astencode code too.

cc @GuillaumeGomez @pnkfelix

@pnkfelix
Copy link
Member

pnkfelix commented Mar 6, 2015

exciting! Another entry for the bug log.

@isurakka
Copy link

isurakka commented Mar 7, 2015

Got similar error but with different caller.

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/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'arithmetic operation overflowed', C:/bot/slave/nightly-dist-rustc-win-64/build/src/libsyntax\codemap.rs:73

stack backtrace:
   1:         0x7121a6fc - sys::backtrace::write::h0dbbf7b67c297decSVA
   2:         0x71235b08 - rt::unwind::register::h77e3f3d90b03e98dXpJ
   3:         0x711833b7 - rt::unwind::begin_unwind_inner::h12ceb964528c2b96mnJ
   4:         0x71183b7b - rt::unwind::begin_unwind_fmt::ha1e3b759bf51a254XlJ
   5:         0x7123573a - rust_begin_unwind
   6:         0x7124c2a9 - panicking::panic_fmt::h55855a4db6daddf2IZs
   7:         0x712488e1 - panicking::panic::h4d7abbe447750a26UXs
   8:           0x51260e - codemap::BytePos.Sub::sub::hb4e9bb288333e96exYB
   9:           0xbd7f48 - middle::astencode::_&'a DecodeContext<'b, 'c, 'tcx>.ast_map..FoldOps::new_span::h2c2deff2e015ae41qqa
  10:           0xbe824a - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  11:           0xbe7f77 - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  12:           0xbeb70f - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  13:           0xbe848b - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  14:           0xbe7f77 - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  15:           0xbeb6dc - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  16:           0xbebd41 - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  17:           0xbeb859 - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  18:           0xc0a706 - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  19:           0xc09ea2 - middle::astencode::rbml..Doc<'a>.doc_decoder_helpers::opt_child::hc02538a1a994b8cb7Tb
  20:           0xbdaa0b - middle::astencode::decode_inlined_item::h4b5ecdf19d937b3aPqa
  21:         0x635f1b0a - trans::base::_InsnCtxt.Drop::drop::h23e8c6aa94978b9eYmr
  22:           0xfa1efe - metadata::decoder::maybe_get_item_ast::hc63081888c5999fbPDi
  23:           0xdbd1a5 - metadata::csearch::maybe_get_item_ast::h01114cd4d0fa035fo3k
  24:         0x635f03fd - back::write::run_assembler::h9b10d62e3415d47666c
  25:         0x6363cd69 - trans::common::ExprOrMethodCall...std..fmt..Debug::fmt::h2639905fc5fb8c20SAl
  26:         0x6363c087 - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  27:         0x63638848 - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  28:         0x6364ea25 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  29:         0x6365b6fb - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  30:         0x6360e087 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  31:         0x6360ee02 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  32:         0x636dea2a - trans::base::FindNestedReturn.Visitor<'v>::visit_expr::h820ae59272a71f02HTs
  33:         0x635f7ffd - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  34:         0x635f92c0 - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  35:         0x6363cf14 - trans::common::ExprOrMethodCall...std..fmt..Debug::fmt::h2639905fc5fb8c20SAl
  36:         0x6363b5bb - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  37:         0x63638a5e - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  38:         0x6364ea25 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  39:         0x6365b6fb - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  40:         0x6360e087 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  41:         0x63716b3d - trans::_match::ReassignmentChecker.euv..Delegate<'tcx>::mutate::h460f09245e4f2e80ZGw
  42:         0x6360d4e2 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::push_ast_cleanup_scope::h2e3d819ba03b0988SJJ
  43:         0x6360eb63 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  44:         0x636dea2a - trans::base::FindNestedReturn.Visitor<'v>::visit_expr::h820ae59272a71f02HTs
  45:         0x635f7ffd - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  46:         0x635f942c - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  47:         0x6363cf14 - trans::common::ExprOrMethodCall...std..fmt..Debug::fmt::h2639905fc5fb8c20SAl
  48:         0x6363b5bb - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  49:         0x63638a5e - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  50:         0x6364ea25 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  51:         0x6365b6fb - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  52:         0x6360e087 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  53:         0x6360ee02 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  54:         0x636dea2a - trans::base::FindNestedReturn.Visitor<'v>::visit_expr::h820ae59272a71f02HTs
  55:         0x635f7ffd - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  56:         0x635f942c - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  57:         0x6363cf14 - trans::common::ExprOrMethodCall...std..fmt..Debug::fmt::h2639905fc5fb8c20SAl
  58:         0x6363b5bb - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  59:         0x63651b84 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  60:         0x63650293 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  61:         0x63659f70 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  62:         0x63658d8e - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  63:         0x6360f77f - trans::expr::Dest...std..cmp..PartialEq::eq::ha661cb7533fe26abOmh
  64:         0x6366fc5d - trans::common::erase_regions::RegionEraser<'a, 'tcx>.TypeFolder<'tcx>::fold_substs::hcee31f2ecd0cd8c3Zvk
  65:         0x63658e76 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  66:         0x6360e0a8 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  67:         0x6360ee02 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  68:         0x636dea2a - trans::base::FindNestedReturn.Visitor<'v>::visit_expr::h820ae59272a71f02HTs
  69:         0x635f7ffd - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  70:         0x635f942c - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  71:         0x6363cf14 - trans::common::ExprOrMethodCall...std..fmt..Debug::fmt::h2639905fc5fb8c20SAl
  72:         0x6363b5bb - trans::context::CrateContext<'b, 'tcx>::tn::head2a03b8133cd76d7l
  73:         0x63651b84 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  74:         0x63650293 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  75:         0x63659f70 - trans::common::ExprOrMethodCall...std..cmp..PartialEq::ne::h90e475dde6fd53b6BDl
  76:         0x6360e087 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  77:         0x63716b3d - trans::_match::ReassignmentChecker.euv..Delegate<'tcx>::mutate::h460f09245e4f2e80ZGw
  78:         0x6360d4e2 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::push_ast_cleanup_scope::h2e3d819ba03b0988SJJ
  79:         0x6360eb63 - trans::cleanup::FunctionContext<'blk, 'tcx>.CleanupMethods<'blk, 'tcx>::pop_and_trans_ast_cleanup_scope::hac8b50cc79571f06wTJ
  80:         0x636dea2a - trans::base::FindNestedReturn.Visitor<'v>::visit_expr::h820ae59272a71f02HTs
  81:         0x635f7ffd - trans::context::CrateContext<'b, 'tcx>::sess::h1bfe1f4cd70e1d25w4l
  82:         0x635f4d8b - trans::context::CrateContext<'b, 'tcx>::stats::h974340237ce9f5d56fm

rustc 1.0.0-nightly (b0746ff19 2015-03-05) (built 2015-03-06)

@Manishearth
Copy link
Member Author

new_span is just a wrapper around tr_span, so it's the same bug :)

(hopefully)

@Manishearth
Copy link
Member Author

@isurakka What was the code you were compiling?

Perhaps the following lines:

        let lo = (span.lo - imported_filemaps[filemap_index].original_start_pos) +
                  imported_filemaps[filemap_index].translated_filemap.start_pos;
        let hi = (span.hi - imported_filemaps[filemap_index].original_start_pos) +
                  imported_filemaps[filemap_index].translated_filemap.start_pos;

should be

        let lo = (span.lo + imported_filemaps[filemap_index].original_start_pos) -
                    imported_filemaps[filemap_index].translated_filemap.start_pos;
        let hi = (span.hi + imported_filemaps[filemap_index].original_start_pos) -
                    imported_filemaps[filemap_index].translated_filemap.start_pos;

That would explain why this underflow didn't break anything before. I've never seen an underflowed span in rustc output.

The function was introduced in #22235, @michaelwoerister do you think that the above fix is enough?

@isurakka
Copy link

isurakka commented Mar 7, 2015

I was compiling glium.

@michaelwoerister
Copy link
Member

@Manishearth Normally this should not make a difference, since at this point span.lo should always be greater than or equal to imported_filemaps[filemap_index].original_start_pos. It would be interesting to see what the span and filemap in question look like.

Anyway, I actually would not swap the additions and subtractions here. It would probably get rid of the underflow, but we actually want to fail immediately here instead of hiding the error. Something has to be wrong with either the input data (span and/or filemap) or with the binary search determining the filemap index.

@Manishearth
Copy link
Member Author

It would probably get rid of the underflow, but we actually want to fail immediately here instead of hiding the error

Yeah, that's what I was unsure of. I might have a look at this later (not now, busy)

@michaelwoerister
Copy link
Member

@Manishearth That would be great. I won't have time to look into this until Wednesday.
@pnkfelix It looks like a legitimate entry for your list :)

@michaelwoerister
Copy link
Member

I've taken a short look at this but I'm having a hard time reproducing the ICE.

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 8, 2015
@pavlo-v-chernykh
Copy link

Hi, guys,

I faced with the same issue when tried to use "pub use"ed structs in my integration test

src/lib.rs

#[macro_use]
mod lexer;
#[macro_use]
pub mod expr;
#[macro_use]
mod parser;
mod scope;

pub use parser::Parser;
pub use scope::Scope;

tests/lib.rs

#[macro_use]
extern crate lust;

use lust::{Parser, Scope};

#[test]
fn test_macro_expansion() {
    let ref mut scope = Scope::new_std();
    let input = "(def m (macro (a) '(+ 1 ~a)))";
    let expr = Parser::new(input.chars())
        .parse().ok().unwrap()
        .expand(scope).ok().unwrap()
        .eval(scope).ok().unwrap();
....

Line

let expr = Parser::new(input.chars())

causes a backtrace

thread 'rustc' panicked at 'arithmetic operation overflowed', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/codemap.rs:73

stack backtrace:
   1:        0x10a831d2b - sys::backtrace::write::ha860f032f06dd89afCC
   2:        0x10a85ab0d - panicking::on_panic::h6a18b44186bb57afDsI
   3:        0x10a77aa77 - rt::unwind::begin_unwind_inner::hd2534fa4a37f06f1EbI
   4:        0x10a77b24e - rt::unwind::begin_unwind_fmt::hf8a9b93d4166a152faI
   5:        0x10a85a5cd - rust_begin_unwind
   6:        0x10a8aa325 - panicking::panic_fmt::hbdadebd7eca0abecESs
   7:        0x10a8a22e4 - panicking::panic::h90cda9aae43785b6bRs
   8:        0x109ee8aaf - codemap::BytePos.Sub::sub::ha963a332df6226d2X7y
   9:        0x107732970 - middle::astencode::DecodeContext<'a, 'b, 'tcx>::tr_span::h41b6adfd5f25b283UBa
  10:        0x107744af4 - fold::noop_fold_expr::h16033087652823088353
  11:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  12:        0x107748335 - fold::noop_fold_expr::closure.65783
  13:        0x107744d2a - fold::noop_fold_expr::h16033087652823088353
  14:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  15:        0x107748335 - fold::noop_fold_expr::closure.65783
  16:        0x107744c23 - fold::noop_fold_expr::h16033087652823088353
  17:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  18:        0x107748335 - fold::noop_fold_expr::closure.65783
  19:        0x107744d2a - fold::noop_fold_expr::h16033087652823088353
  20:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  21:        0x107748335 - fold::noop_fold_expr::closure.65783
  22:        0x107744d2a - fold::noop_fold_expr::h16033087652823088353
  23:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  24:        0x107748335 - fold::noop_fold_expr::closure.65783
  25:        0x107744d2a - fold::noop_fold_expr::h16033087652823088353
  26:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  27:        0x107748335 - fold::noop_fold_expr::closure.65783
  28:        0x107744d2a - fold::noop_fold_expr::h16033087652823088353
  29:        0x107744815 - ptr::P<T>::map::h6010855507994973922
  30:        0x1077482d2 - fold::noop_fold_expr::closure.65778
  31:        0x107748b40 - fold::noop_fold_block::closure.65796
  32:        0x10774853a - fold::noop_fold_block::h7304960027847516833
  33:        0x107767d9a - fold::noop_fold_impl_item::closure.66351
  34:        0x10776769d - fold::noop_fold_impl_item::h7368773820276733676
  35:        0x10773573f - middle::astencode::decode_inlined_item::hb675d3182a90b087vqa
  36:        0x1072fdb0c - trans::inline::instantiate_inline::closure.39507
  37:        0x107b5bf3f - metadata::decoder::maybe_get_item_ast::h6ba2addb84791b678eg
  38:        0x107941a68 - metadata::csearch::maybe_get_item_ast::h4a190184b359c7080Ei
  39:        0x1072fc36b - trans::inline::instantiate_inline::hefe097f819d375207hd
  40:        0x10734ea06 - trans::callee::trans_fn_ref_with_substs::h8a10bfc8d2eca420nkg
  41:        0x10734d14e - trans::callee::trans_fn_ref::hdaccaca288958908X8f
  42:        0x1073650ea - trans::meth::trans_method_callee::ha9796b94ffe9fe6da3x
  43:        0x10736341b - trans::callee::trans_call_inner::h4682379842394608694
  44:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  45:        0x10731c3c6 - trans::expr::trans_into::hc315f02b271dc490Smh
  46:        0x10731d509 - trans::controlflow::trans_block::hc4ca9bc8aa6d667ct6d
  47:        0x10736e940 - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  48:        0x10731c3c6 - trans::expr::trans_into::hc315f02b271dc490Smh
  49:        0x10741f490 - trans::_match::trans_match_inner::h861edf79f4e576da5Ew
  50:        0x10736e8d3 - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  51:        0x10731c3c6 - trans::expr::trans_into::hc315f02b271dc490Smh
  52:        0x10731d509 - trans::controlflow::trans_block::hc4ca9bc8aa6d667ct6d
  53:        0x1073fc739 - trans::base::trans_closure::hc39e993224ba4a39Rjt
  54:        0x107304895 - trans::base::trans_fn::h1d576ccdd7ec4f71Kut
  55:        0x107306022 - trans::monomorphize::monomorphic_fn::h72c960e470611a152td
  56:        0x10734ebbb - trans::callee::trans_fn_ref_with_substs::h8a10bfc8d2eca420nkg
  57:        0x10734d14e - trans::callee::trans_fn_ref::hdaccaca288958908X8f
  58:        0x1073650ea - trans::meth::trans_method_callee::ha9796b94ffe9fe6da3x
  59:        0x10736341b - trans::callee::trans_call_inner::h4682379842394608694
  60:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  61:        0x10731c3c6 - trans::expr::trans_into::hc315f02b271dc490Smh
  62:        0x107437b76 - trans::_match::mk_binding_alloca::h15152849454709322174
  63:        0x10731b830 - trans::base::init_local::h70e5ce26f8b17897Vys
  64:        0x10731d1e2 - trans::controlflow::trans_block::hc4ca9bc8aa6d667ct6d
  65:        0x1073fc739 - trans::base::trans_closure::hc39e993224ba4a39Rjt
  66:        0x107304895 - trans::base::trans_fn::h1d576ccdd7ec4f71Kut
  67:        0x107306022 - trans::monomorphize::monomorphic_fn::h72c960e470611a152td
  68:        0x10734ebbb - trans::callee::trans_fn_ref_with_substs::h8a10bfc8d2eca420nkg
  69:        0x10734d14e - trans::callee::trans_fn_ref::hdaccaca288958908X8f
  70:        0x1073650ea - trans::meth::trans_method_callee::ha9796b94ffe9fe6da3x
  71:        0x10736341b - trans::callee::trans_call_inner::h4682379842394608694
  72:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  73:        0x10736ce0c - trans::expr::trans_unadjusted::hf6041f49187a68f123h
  74:        0x10731df5b - trans::expr::trans::h922f0fb9b242d298ath
  75:        0x10735ce11 - trans::callee::trans_args::ha7923c949f541125F0g
  76:        0x107364547 - trans::callee::trans_call_inner::h4682379842394608694
  77:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  78:        0x10736ce0c - trans::expr::trans_unadjusted::hf6041f49187a68f123h
  79:        0x10731df5b - trans::expr::trans::h922f0fb9b242d298ath
  80:        0x10735ce11 - trans::callee::trans_args::ha7923c949f541125F0g
  81:        0x107364547 - trans::callee::trans_call_inner::h4682379842394608694
  82:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  83:        0x10736ce0c - trans::expr::trans_unadjusted::hf6041f49187a68f123h
  84:        0x10731df5b - trans::expr::trans::h922f0fb9b242d298ath
  85:        0x10735ce11 - trans::callee::trans_args::ha7923c949f541125F0g
  86:        0x107364547 - trans::callee::trans_call_inner::h4682379842394608694
  87:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  88:        0x10736ce0c - trans::expr::trans_unadjusted::hf6041f49187a68f123h
  89:        0x10731df5b - trans::expr::trans::h922f0fb9b242d298ath
  90:        0x10735ce11 - trans::callee::trans_args::ha7923c949f541125F0g
  91:        0x107364547 - trans::callee::trans_call_inner::h4682379842394608694
  92:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  93:        0x10736ce0c - trans::expr::trans_unadjusted::hf6041f49187a68f123h
  94:        0x10731df5b - trans::expr::trans::h922f0fb9b242d298ath
  95:        0x10735ce11 - trans::callee::trans_args::ha7923c949f541125F0g
  96:        0x107364547 - trans::callee::trans_call_inner::h4682379842394608694
  97:        0x10736e05a - trans::expr::trans_rvalue_dps_unadjusted::h8983b19e474e6ca6xzi
  98:        0x10736ce0c - trans::expr::trans_unadjusted::hf6041f49187a68f123h
  99:        0x10731df5b - trans::expr::trans::h922f0fb9b242d298ath
  100:        0x10735ce11 - trans::callee::trans_args::ha7923c949f541125F0g
 ... <frames omitted>

Everything was fine with this code until I updated to the latest nightly.

Versions of cargo and rustc

cargo 0.0.1-pre-nightly (07cd618 2015-03-12) (built 2015-03-13)
rustc 1.0.0-nightly (30e1f9a1c 2015-03-14) (built 2015-03-15)
binary: rustc
commit-hash: 30e1f9a1c2bf7134135800bc9afd082773defadc
commit-date: 2015-03-14
build-date: 2015-03-15
host: x86_64-apple-darwin
release: 1.0.0-nightly

Hope this will help to reproduce the bug.

@tomaka
Copy link
Contributor

tomaka commented Mar 16, 2015

There seem to be several crates which have this ICE:

For me the ICE appeared somewhere between the 12th nightly and the 14th nightly. The faulty commit must be in this range. For glium the ICE appeared in the c9b03c24e 2015-03-12 nightly. The 2015-03-11 nightly was working.

@michaelwoerister
Copy link
Member

I've allocated today for looking into this...

@michaelwoerister
Copy link
Member

I'm making some progress on this. It seems that rustc creates invalid spans (with span.hi < span.lo) during macro expansion. This is what trips up span translation when importing another crate.

thread 'rustc' panicked at 'assertion failed: lo <= hi', /home/mw/rust/src/libsyntax/codemap.rs:181

stack backtrace:
   1:     0x2b19ace8a8a1 - sys::backtrace::write::h3e9b4dca0513864dKrD
   2:     0x2b19acea7323 - panicking::on_panic::hcb89533c10dead95GJJ
   3:     0x2b19ace0602b - rt::unwind::begin_unwind_inner::ha5515b368a7d162eeqJ
   4:     0x2b19af553ccc - rt::unwind::begin_unwind::h7177973865999339449
   5:     0x2b19af623721 - parse::parser::Parser<'a>::mk_expr::h7e6012b214477e73kyI
   6:     0x2b19af62dd58 - parse::parser::Parser<'a>::parse_more_binops::hfd08f1c10b16b5abgoJ
   7:     0x2b19af62dff9 - parse::parser::Parser<'a>::parse_assign_expr::ha90692af103ba88bGsJ
   8:     0x2b19af626b18 - parse::parser::Parser<'a>::parse_bottom_expr::haeda66665b87a4b9qDI
   9:     0x2b19af62d59b - parse::parser::Parser<'a>::parse_prefix_expr::ha7f81e84568c81e9ZiJ
  10:     0x2b19af62dfec - parse::parser::Parser<'a>::parse_assign_expr::ha90692af103ba88bGsJ
  11:     0x2b19af63faf2 - parse::parser::Parser<'a>::parse_item_const::h73b6ec07b5cd7463PmL
  12:     0x2b19af631c07 - parse::parser::Parser<'a>::parse_item_::hb119daa3df77ffaeJRL
  13:     0x2b19af7b9e4e - ext::tt::macro_rules::ParserAnyMacro<'a>.MacResult::make_items::h21f35fae734f799fsyf
  14:     0x2b19af73fe93 - ext::expand::expand_item_mac::hc8036110974a2e865Ra
  15:     0x2b19af734af5 - ext::expand::expand_annotatable::hd63e48fa5a49f5f9Nlb
  16:     0x2b19af731ad0 - ext::expand::expand_item::h3e710c5693bd09f40La
  17:     0x2b19af73aec4 - ext::expand::MacroExpander<'a, 'b>.Folder::fold_item::h5a856dd7f64966f3KDb
  18:     0x2b19af73ab70 - iter::FlatMap<I, U, F>.Iterator::next::h8620248382209828813
  19:     0x2b19af73a8ab - vec::Vec<T>.FromIterator<T>::from_iter::h17981381026392602979
  20:     0x2b19af73a548 - fold::noop_fold_mod::h13311583651119820058
  21:     0x2b19af736f47 - ext::expand::expand_item_underscore::hdbcfb7421bd9ad50GPa
  22:     0x2b19af777757 - fold::noop_fold_item_simple::h12913474026910056601
  23:     0x2b19af77744e - ptr::P<T>::map::h6853041154571815780
  24:     0x2b19af735491 - ext::expand::expand_annotatable::hd63e48fa5a49f5f9Nlb
  25:     0x2b19af731ad0 - ext::expand::expand_item::h3e710c5693bd09f40La
  26:     0x2b19af73aec4 - ext::expand::MacroExpander<'a, 'b>.Folder::fold_item::h5a856dd7f64966f3KDb
  27:     0x2b19af73ab70 - iter::FlatMap<I, U, F>.Iterator::next::h8620248382209828813
  28:     0x2b19af73a8e2 - vec::Vec<T>.FromIterator<T>::from_iter::h17981381026392602979
  29:     0x2b19af73a548 - fold::noop_fold_mod::h13311583651119820058
  30:     0x2b19af736f47 - ext::expand::expand_item_underscore::hdbcfb7421bd9ad50GPa
  31:     0x2b19af777757 - fold::noop_fold_item_simple::h12913474026910056601
  32:     0x2b19af77744e - ptr::P<T>::map::h6853041154571815780
  33:     0x2b19af735491 - ext::expand::expand_annotatable::hd63e48fa5a49f5f9Nlb
  34:     0x2b19af731ad0 - ext::expand::expand_item::h3e710c5693bd09f40La
  35:     0x2b19af73aec4 - ext::expand::MacroExpander<'a, 'b>.Folder::fold_item::h5a856dd7f64966f3KDb
  36:     0x2b19af77f2f3 - ext::expand::expand_crate::h6999d25ae521adf3bKb
  37:     0x2b19acabc113 - driver::phase_2_configure_and_expand::closure.18814
  38:     0x2b19aca7817c - driver::phase_2_configure_and_expand::h69f8943526788512Xsa
  39:     0x2b19aca69f28 - driver::compile_input::hbd3be055171b4244Rba
  40:     0x2b19acb0a049 - run_compiler::ha6b2ab1236d9b5f6S6b
  41:     0x2b19acb0825d - thunk::F.Invoke<A, R>::invoke::h12269788191574515370
  42:     0x2b19acb07835 - rt::unwind::try::try_fn::h17916825617625713907
  43:     0x2b19acf16c78 - rust_try_inner
  44:     0x2b19acf16c65 - rust_try
  45:     0x2b19acb07c43 - thunk::F.Invoke<A, R>::invoke::h724682906673806154
  46:     0x2b19ace9af89 - sys::thread::create::thread_start::h9e0cd7532d186bdd3iI
  47:     0x2b19b2c94181 - start_thread
  48:     0x2b19ad55f47c - __clone
  49:                0x0 - <unknown>
   1:     0x2b19ace8a8a1 - sys::backtrace::write::h3e9b4dca0513864dKrD
   2:     0x2b19acea7323 - panicking::on_panic::hcb89533c10dead95GJJ
   3:     0x2b19ace0602b - rt::unwind::begin_unwind_inner::ha5515b368a7d162eeqJ
   4:     0x2b19af553ccc - rt::unwind::begin_unwind::h7177973865999339449
   5:     0x2b19af623721 - parse::parser::Parser<'a>::mk_expr::h7e6012b214477e73kyI
   6:     0x2b19af62dd58 - parse::parser::Parser<'a>::parse_more_binops::hfd08f1c10b16b5abgoJ
   7:     0x2b19af62dff9 - parse::parser::Parser<'a>::parse_assign_expr::ha90692af103ba88bGsJ
   8:     0x2b19af626b18 - parse::parser::Parser<'a>::parse_bottom_expr::haeda66665b87a4b9qDI
   9:     0x2b19af62d59b - parse::parser::Parser<'a>::parse_prefix_expr::ha7f81e84568c81e9ZiJ
  10:     0x2b19af62dfec - parse::parser::Parser<'a>::parse_assign_expr::ha90692af103ba88bGsJ
  11:     0x2b19af63faf2 - parse::parser::Parser<'a>::parse_item_const::h73b6ec07b5cd7463PmL
  12:     0x2b19af631c07 - parse::parser::Parser<'a>::parse_item_::hb119daa3df77ffaeJRL
  13:     0x2b19af7b9e4e - ext::tt::macro_rules::ParserAnyMacro<'a>.MacResult::make_items::h21f35fae734f799fsyf
  14:     0x2b19af73fe93 - ext::expand::expand_item_mac::hc8036110974a2e865Ra
  15:     0x2b19af734af5 - ext::expand::expand_annotatable::hd63e48fa5a49f5f9Nlb
  16:     0x2b19af731ad0 - ext::expand::expand_item::h3e710c5693bd09f40La
  17:     0x2b19af73aec4 - ext::expand::MacroExpander<'a, 'b>.Folder::fold_item::h5a856dd7f64966f3KDb
  18:     0x2b19af73ab70 - iter::FlatMap<I, U, F>.Iterator::next::h8620248382209828813
  19:     0x2b19af73a8ab - vec::Vec<T>.FromIterator<T>::from_iter::h17981381026392602979
  20:     0x2b19af73a548 - fold::noop_fold_mod::h13311583651119820058
  21:     0x2b19af736f47 - ext::expand::expand_item_underscore::hdbcfb7421bd9ad50GPa
  22:     0x2b19af777757 - fold::noop_fold_item_simple::h12913474026910056601
  23:     0x2b19af77744e - ptr::P<T>::map::h6853041154571815780
  24:     0x2b19af735491 - ext::expand::expand_annotatable::hd63e48fa5a49f5f9Nlb
  25:     0x2b19af731ad0 - ext::expand::expand_item::h3e710c5693bd09f40La
  26:     0x2b19af73aec4 - ext::expand::MacroExpander<'a, 'b>.Folder::fold_item::h5a856dd7f64966f3KDb
  27:     0x2b19af73ab70 - iter::FlatMap<I, U, F>.Iterator::next::h8620248382209828813
  28:     0x2b19af73a8e2 - vec::Vec<T>.FromIterator<T>::from_iter::h17981381026392602979
  29:     0x2b19af73a548 - fold::noop_fold_mod::h13311583651119820058
  30:     0x2b19af736f47 - ext::expand::expand_item_underscore::hdbcfb7421bd9ad50GPa
  31:     0x2b19af777757 - fold::noop_fold_item_simple::h12913474026910056601
  32:     0x2b19af77744e - ptr::P<T>::map::h6853041154571815780
  33:     0x2b19af735491 - ext::expand::expand_annotatable::hd63e48fa5a49f5f9Nlb
  34:     0x2b19af731ad0 - ext::expand::expand_item::h3e710c5693bd09f40La
  35:     0x2b19af73aec4 - ext::expand::MacroExpander<'a, 'b>.Folder::fold_item::h5a856dd7f64966f3KDb
  36:     0x2b19af77f2f3 - ext::expand::expand_crate::h6999d25ae521adf3bKb
  37:     0x2b19acabc113 - driver::phase_2_configure_and_expand::closure.18814
  38:     0x2b19aca7817c - driver::phase_2_configure_and_expand::h69f8943526788512Xsa
  39:     0x2b19aca69f28 - driver::compile_input::hbd3be055171b4244Rba
  40:     0x2b19acb0a049 - run_compiler::ha6b2ab1236d9b5f6S6b
  41:     0x2b19acb0825d - thunk::F.Invoke<A, R>::invoke::h12269788191574515370
  42:     0x2b19acb07835 - rt::unwind::try::try_fn::h17916825617625713907
  43:     0x2b19acf16c78 - rust_try_inner
  44:     0x2b19acf16c65 - rust_try
  45:     0x2b19acb07c43 - thunk::F.Invoke<A, R>::invoke::h724682906673806154
  46:     0x2b19ace9af89 - sys::thread::create::thread_start::h9e0cd7532d186bdd3iI
  47:     0x2b19b2c94181 - start_thread
  48:     0x2b19ad55f47c - __clone
  49:                0x0 - <unknown>

@michaelwoerister
Copy link
Member

OK, so here's the problem, the parser contains code like the following:

// from Parser::parse_more_binops
let lhs_span = lhs.span;
let rhs_span = rhs.span;
let binary = self.mk_binary(codemap::respan(cur_op_span, cur_op), lhs, rhs);
let bin = self.mk_expr(lhs_span.lo, rhs_span.hi, binary);

Now, in the case of macros lhs and rhs can come from completely different contexts, like here:

add1!(3);
macro_rules! add1 { ($val:expr) => ( { 1 + $val } ) }

In the expansion of the macro, lhs_span would come from the macro-definition-site (lo: 50, hi: 51) while rhs_span would come from the expansion-site (lo: 6, hi:7). Taking lo from lhs and hi from rhs, as the above code does, we end up with a span of lo: 50, hi: 7 💥

@pnkfelix
Copy link
Member

@michaelwoerister yeah I remember when I discovered that the supposed lo <= hi invariant does not hold in general. I should have probably mentioned that up above when I first saw this bug.

We probably should try to put in tests that deliberate exercise cases like this (perhaps by even directly constructing such spans, rather than relying on the particulars of how certain patterns of source code are parsed).

@Manishearth
Copy link
Member Author

We could just put a debug-assert (or some sort of assert that doesn't reach the nightlies) in mk_span that lo < hi, and we ought to find lots of bugs i nthe compiler that way.

@pnkfelix
Copy link
Member

@Manishearth I don't think that's a good idea for the short term. I tried to put in such an assertion some time ago, and its a real rat hole.

(That is why I instead suggested that we put in some tests that exercise such strange spans instead.)

@Manishearth
Copy link
Member Author

Ah, so should we not be relying on this assumption about spans? That seems like a bigger rat hole to be honest :/

@pnkfelix
Copy link
Member

(but then again, I am not going to object if someone else wants to put into the effort necessary to try to enforce lo <= hi)

@michaelwoerister
Copy link
Member

I would have liked to tackle this as part of a bigger reform of span representation along the lines I described here: http://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/23
But since my contract is coming to an end this month I won't have time to do this.

I guess this kind of thing can happen anywhere where some AST node span is constructed from the spans of the node's children, respectively whenever a child-node span also constitutes a border of the parent-node. That's the case for many things:

// binary operators
$e1 + $e2

// unary operators
! $e

// closures
|x| $e

// parameters
fn foo($e: $t) {}

// type parameters
fn bar<$ident: $type>

// type ascription
$e : $type

// path expressions (?)
$x::foo()

// C-style enums
enum Foo {
    $ident = $e,
}

// derived types
& &mut $t

// call expressions (?)
$e()

// ... and who knows what else ...

Handling all these cases in the parser is definitely quite a bit of work. It's also not entirely clear how to handle this. I would suggest that spans that are partly in a macro are defined completely in the macro. That is, for the example above, the + expression would have the span:

macro_rules! add1 { ($val:expr) => ( { 1 + $val } ) }
                                       ^^^^^^^^

...regardless of where $val comes from. But I don't think the original span of $val is available any more at this point.

@michaelwoerister
Copy link
Member

I opened an issue (#23480) describing the underlying problem. In order to get rid of this ICE I will create a temporary workaround, probably validating spans before they get exported. This may lead to some strange debuginfo-source locations when macros are involved but not worse than is already the case.

bors added a commit that referenced this issue Mar 19, 2015
… r=alexcrichton

This should solve issues #23115, #23469, and #23407.

As the title says, this is just a workaround. The underlying problem is that macro expansion can produce invalid spans. I've opened issue #23480 so we don't forget about that.
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 20, 2015
…erflow-bug, r=alexcrichton

 This should solve issues rust-lang#23115, rust-lang#23469, and rust-lang#23407.

As the title says, this is just a workaround. The underlying problem is that macro expansion can produce invalid spans. I've opened issue rust-lang#23480 so we don't forget about that.
@michaelwoerister
Copy link
Member

@Manishearth This should be fixed already. Please close if you can verify.

@Manishearth
Copy link
Member Author

Seems to be. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

7 participants