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

Roman numeral plugin example fails to run #27271

Closed
dtwood opened this issue Jul 24, 2015 · 10 comments
Closed

Roman numeral plugin example fails to run #27271

dtwood opened this issue Jul 24, 2015 · 10 comments
Labels
A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html A-syntaxext Area: Syntax extensions O-macos Operating system: macOS

Comments

@dtwood
Copy link

dtwood commented Jul 24, 2015

The roman numeral demo plugin compiles successfully, but fails with an ICE when run (the same as #26488).

rustc --version
rustc 1.3.0-nightly (69ca01256 2015-07-23)
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
Could not compile `hello_world`.

Caused by:
  Process didn't exit successfully: `rustc src/main.rs --crate-name hello_world --crate-type bin -g --out-dir /Users/david/Devel/rust/target/debug --emit=dep-info,link -L dependency=/Users/david/Devel/rust/target/debug -L dependency=/Users/david/Devel/rust/target/debug/deps --extern factorial=/Users/david/Devel/rust/target/debug/deps/libfactorial-9882d961a0581a0c.dylib --extern chrono=/Users/david/Devel/rust/target/debug/deps/libchrono-56e1e2f8a2c2ce0f.rlib` (exit code: 101)
st/target/debug/deps/libchrono-56e1e2f8a2c2ce0f.rlib`
       Fresh chrono v0.2.15
thread 'rustc' panicked at 'index out of bounds: the len is 60 but the index is 66', ../src/libcollections/vec.rs:1246

stack backtrace:
   1:        0x105349485 - sys::backtrace::write::hbce7e265eb321480bus
   2:        0x1053524ee - panicking::on_panic::hd723a4eed80dc3f1NUw
   3:        0x10530bf82 - rt::unwind::begin_unwind_inner::hba49c6e78082e98fYCw
   4:        0x10530ce2c - rt::unwind::begin_unwind_fmt::h9873384d3a1a818e4Bw
   5:        0x10535206c - rust_begin_unwind
   6:        0x1053a81a5 - panicking::panic_fmt::h4ce2c934001461b3PgC
   7:        0x1053a28e5 - panicking::panic_bounds_check::h5bd94edbff5d1337VfC
   8:        0x10a346a45 - parse::token::get_name::hc25bfcba291047ab0jT
   9:        0x10a34c8f8 - ast::Name.fmt..Display::fmt::h9df3ebcee2b7357bsSb
  10:        0x10cc4c3f2 - fmt::write::hf3476932417648edbfO
  11:        0x10cb7ddbb - rt::unwind::begin_unwind_fmt::h9873384d3a1a818e4Bw
  12:        0x101c3cc80 - expand_rn::h25af918a6623e675saa
  13:        0x109d8265e - ext::base::F.TTMacroExpander::expand::h8387169028212889737
  14:        0x102d54863 - ext::expand::expand_expr::closure.65736
  15:        0x102d4fce0 - ext::expand::expand_expr::h99e8da60288015c7Qeb
  16:        0x102d5878a - fold::noop_fold_expr::h12274104263851486159
  17:        0x102d4fece - ext::expand::expand_expr::closure.65736
  18:        0x102d4fce0 - ext::expand::expand_expr::h99e8da60288015c7Qeb
  19:        0x102d59ee2 - fold::noop_fold_expr::h12274104263851486159
  20:        0x102d4fece - ext::expand::expand_expr::closure.65736
  21:        0x102d4fce0 - ext::expand::expand_expr::h99e8da60288015c7Qeb
  22:        0x102d58dab - fold::noop_fold_expr::h12274104263851486159
  23:        0x102d4fece - ext::expand::expand_expr::closure.65736
  24:        0x102d4fce0 - ext::expand::expand_expr::h99e8da60288015c7Qeb
  25:        0x102d59323 - fold::noop_fold_expr::h12274104263851486159
  26:        0x102d4fece - ext::expand::expand_expr::closure.65736
  27:        0x102d4fce0 - ext::expand::expand_expr::h99e8da60288015c7Qeb
  28:        0x102d9d000 - ext::expand::expand_block_elts::closure.66444
  29:        0x102d62369 - ext::expand::expand_block_elts::hdd4860a523c2af11x0b
  30:        0x102d9cb42 - ext::expand::expand_block::h6f55c6087a5fa9a0SZb
  31:        0x102d598b1 - fold::noop_fold_expr::h12274104263851486159
  32:        0x102d4fece - ext::expand::expand_expr::closure.65736
  33:        0x102d4fce0 - ext::expand::expand_expr::h99e8da60288015c7Qeb
  34:        0x102d96ed1 - fold::noop_fold_stmt::h10788056147892267108
  35:        0x102d77b90 - ext::expand::expand_stmt::h08fa462260688915BPb
  36:        0x102d7aaec - iter::FlatMap<I, U, F>.Iterator::next::h2819660546420465906
  37:        0x102d7a4a7 - util::small_vector::SmallVector<T>.FromIterator<T>::from_iter::h13187313789686060428
  38:        0x102d79167 - ext::expand::expand_stmt::h08fa462260688915BPb
  39:        0x102d9df33 - ext::expand::expand_block_elts::closure.66450
  40:        0x102d9dc65 - iter::FlatMap<I, U, F>.Iterator::next::h7643140614824393032
  41:        0x102d9d324 - vec::Vec<T>.FromIterator<T>::from_iter::h732420624926570779
  42:        0x102d9cf17 - ext::expand::expand_block_elts::closure.66444
  43:        0x102d62369 - ext::expand::expand_block_elts::hdd4860a523c2af11x0b
  44:        0x102d9cb42 - ext::expand::expand_block::h6f55c6087a5fa9a0SZb
  45:        0x102d61e93 - ext::expand::expand_and_rename_fn_decl_and_block::h48826170e337e771Wtc
  46:        0x102d68dd6 - ext::expand::expand_item_underscore::h35b61265f1e6e32a1Db
  47:        0x102dbe7a7 - fold::noop_fold_item_simple::h15338532747737711936
  48:        0x102dbe306 - fold::noop_fold_item::h4339851499862307845
  49:        0x102d66bb7 - ext::expand::expand_annotatable::ha45359526cbf62faTac
  50:        0x102d624f9 - ext::expand::expand_item::h7d12f4c897ccb936qDb
  51:        0x102d6e8e5 - iter::FlatMap<I, U, F>.Iterator::next::h9898030771278316288
  52:        0x102d6e3bc - vec::Vec<T>.FromIterator<T>::from_iter::h13205230158317958734
  53:        0x102d6e0b7 - fold::noop_fold_mod::h15770947105538165412
  54:        0x102d69650 - ext::expand::expand_item_underscore::h35b61265f1e6e32a1Db
  55:        0x102dbe7a7 - fold::noop_fold_item_simple::h15338532747737711936
  56:        0x102dbe306 - fold::noop_fold_item::h4339851499862307845
  57:        0x102d677ed - ext::expand::expand_annotatable::ha45359526cbf62faTac
  58:        0x102d624f9 - ext::expand::expand_item::h7d12f4c897ccb936qDb
  59:        0x102dc63fc - ext::expand::expand_crate::he66664571162d53arCc
  60:        0x10180c960 - driver::phase_2_configure_and_expand::closure.22185
  61:        0x1017c15c0 - driver::phase_2_configure_and_expand::h9663d9fc8460a0b7ita
  62:        0x1017b1b08 - driver::compile_input::h88e989740af3db2aTba
  63:        0x1018948ab - run_compiler::he6382510493c3ff3A7b
  64:        0x101892120 - boxed::F.FnBox<A>::call_box::h16554067582215296081
  65:        0x101891997 - rt::unwind::try::try_fn::h9037081342499356393
  66:        0x105351f9f - __rust_try_inner
  67:        0x105351fda - __rust_try
  68:        0x10533ba65 - rt::unwind::try::inner_try::h1e2d97fb62ce1595Ryw
  69:        0x101891bd9 - boxed::F.FnBox<A>::call_box::h15046611992369909973
  70:        0x105350efd - sys::thread::Thread::new::thread_start::h2b5c9a2728ae8fd5RWv
  71:     0x7fff8df83267 - _pthread_body
  72:     0x7fff8df831e4 - _pthread_start
@dtwood
Copy link
Author

dtwood commented Jul 24, 2015

Minimal example:

> main
  > Cargo.toml
  > src
    > plugin
      > Cargo.toml
      > src
        > lib.rs
    > lib.rs

main/src/lib.rs:

#![feature(plugin)]
#![plugin(factorial)]

fn main() {
    println!(rn!(I));
}

main/src/plugin/src/lib.rs

#![crate_type="dylib"]
#![feature(plugin_registrar, rustc_private)]

extern crate syntax;
extern crate rustc;

use syntax::codemap::Span;
use syntax::parse::token;
use syntax::ast::{TokenTree, TtToken};
use syntax::ext::base::{ExtCtxt, MacResult};
use rustc::plugin::Registry;

fn expand_rn(_: &mut ExtCtxt, _: Span, args: &[TokenTree])
        -> Box<MacResult + 'static> {
    let _ = match args[0] {
        TtToken(_, token::Ident(s, _)) => panic!("{}", s),
        _ => {
            unimplemented!();
        }
    };
    unimplemented!();
}

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
    reg.register_macro("rn", expand_rn);
}

@Munksgaard
Copy link
Contributor

I'm not getting an error with rustc 1.3.0-dev (7276d8b 2015-07-25)

@dtwood
Copy link
Author

dtwood commented Jul 27, 2015

Still broken here I'm afraid:
rustc --version rustc 1.3.0-nightly (922aef035 2015-07-27)
uname -a Darwin dtw-laptop.local 14.4.0 Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64

@Munksgaard
Copy link
Contributor

Here's what I did:

plugin.rs:

#![crate_type="dylib"]
#![feature(plugin_registrar, rustc_private)]
#![feature(slice_patterns)]

extern crate syntax;
extern crate rustc;

use syntax::codemap::Span;
use syntax::parse::token;
use syntax::ast::{TokenTree, TtToken};
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder;  // trait for expr_usize
use rustc::plugin::Registry;

fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
        -> Box<MacResult + 'static> {

    static NUMERALS: &'static [(&'static str, u32)] = &[
        ("M", 1000), ("CM", 900), ("D", 500), ("CD", 400),
        ("C",  100), ("XC",  90), ("L",  50), ("XL",  40),
        ("X",   10), ("IX",   9), ("V",   5), ("IV",   4),
        ("I",    1)];

    let text = match args {
        [TtToken(_, token::Ident(s, _))] => token::get_ident(s).to_string(),
        _ => {
            cx.span_err(sp, "argument should be a single identifier");
            return DummyResult::any(sp);
        }
    };

    let mut text = &*text;
    let mut total = 0;
    while !text.is_empty() {
        match NUMERALS.iter().find(|&&(rn, _)| text.starts_with(rn)) {
            Some(&(rn, val)) => {
                total += val;
                text = &text[rn.len()..];
            }
            None => {
                cx.span_err(sp, "invalid Roman numeral");
                return DummyResult::any(sp);
            }
        }
    }

    MacEager::expr(cx.expr_u32(sp, total))
}

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
    reg.register_macro("rn", expand_rn);
}

main.rs:

#![feature(plugin)]
#![plugin(plugin)]

fn main() {
    println!(rn!(I));
}
 $ rustc plugin.rs
 $ rustc -L . main.rs
 $ ./main
1

Does that work for you?

I cannot compile main.rs with your minimal example above: It explicitly panics at I.

rustc 1.3.0-dev (8988043da 2015-07-27)

@dtwood
Copy link
Author

dtwood commented Jul 28, 2015

That doesn't work for me either - I've copied the source you plug above, then rustc plugin.rs succeeds, and gives me libplugin.dylib. rustc -L . main.rs then fails with the following:

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
thread 'rustc' panicked at 'index out of bounds: the len is 60 but the index is 65', ../src/libcollections/vec.rs:1246

stack backtrace:
   1:        0x11070c5a5 - sys::backtrace::write::h8d57f899e3fda16elus
   2:        0x11071560e - panicking::on_panic::h5ba36379bfe7cb23XUw
   3:        0x1106cf062 - rt::unwind::begin_unwind_inner::hfdefe03d89c9e15c8Cw
   4:        0x1106cff0c - rt::unwind::begin_unwind_fmt::h4abe28056f41fed5eCw
   5:        0x11071518c - rust_begin_unwind
   6:        0x11076b2f5 - panicking::panic_fmt::h13125e855ad0c512EhC
   7:        0x110765a35 - panicking::panic_bounds_check::h930022a157a2365dKgC
   8:        0x1157d65f7 - util::interner::StrInterner::get::hd168b7b16d7f039aFpa
   9:        0x110be2aa4 - parse::token::get_name::hd9e2929ac0706451apT
  10:        0x110be29d8 - parse::token::get_ident::h8eabd2f158c72c5frpT
  11:        0x110bdeeb3 - expand_rn::h7069071bf5512a5esaa
  12:        0x11521066e - ext::base::F.TTMacroExpander::expand::h13800486614208293857
  13:        0x10e115fcd - ext::expand::expand_expr::closure.66042
  14:        0x10e1103da - ext::expand::expand_expr::h10d1ec6bb3acc3e4rlb
  15:        0x10e0bf88b - ext::base::get_exprs_from_tts::h3230de70dec5bb6fTC5
  16:        0x10e0b848c - ext::concat::expand_syntax_ext::h6d30518a25606a73bi7
  17:        0x10e0bcc0e - ext::base::F.TTMacroExpander::expand::h17916794981785300046
  18:        0x10e115fcd - ext::expand::expand_expr::closure.66042
  19:        0x10e1103da - ext::expand::expand_expr::h10d1ec6bb3acc3e4rlb
  20:        0x10e1b41d8 - ext::format::expand_preparsed_format_args::h39749fc855abdc45vGd
  21:        0x10e0b5f57 - ext::format::expand_format_args::h2034aa489443eeeaIFd
  22:        0x10e0b640e - ext::base::F.TTMacroExpander::expand::h1414252957907639972
  23:        0x10e115fcd - ext::expand::expand_expr::closure.66042
  24:        0x10e1103da - ext::expand::expand_expr::h10d1ec6bb3acc3e4rlb
  25:        0x10e11abcf - fold::noop_fold_expr::h8234447633789036141
  26:        0x10e1105f3 - ext::expand::expand_expr::closure.66042
  27:        0x10e1103da - ext::expand::expand_expr::h10d1ec6bb3acc3e4rlb
  28:        0x10e158fc1 - fold::noop_fold_stmt::h6333715652680442577
  29:        0x10e139d30 - ext::expand::expand_stmt::h8c4bd9703af6a2f7b4b
  30:        0x10e13cc8c - iter::FlatMap<I, U, F>.Iterator::next::h10170223740143956055
  31:        0x10e13c647 - util::small_vector::SmallVector<T>.FromIterator<T>::from_iter::h3322216669002410848
  32:        0x10e13b307 - ext::expand::expand_stmt::h8c4bd9703af6a2f7b4b
  33:        0x10e13cc8c - iter::FlatMap<I, U, F>.Iterator::next::h10170223740143956055
  34:        0x10e13c647 - util::small_vector::SmallVector<T>.FromIterator<T>::from_iter::h3322216669002410848
  35:        0x10e13b307 - ext::expand::expand_stmt::h8c4bd9703af6a2f7b4b
  36:        0x10e15ffe3 - ext::expand::expand_block_elts::closure.66799
  37:        0x10e15fd15 - iter::FlatMap<I, U, F>.Iterator::next::h12880663052903539887
  38:        0x10e15f3d4 - vec::Vec<T>.FromIterator<T>::from_iter::h11897925576472944830
  39:        0x10e15efc7 - ext::expand::expand_block_elts::closure.66792
  40:        0x10e124529 - ext::expand::expand_block_elts::h57e4fa0ef3fb82095ec
  41:        0x10e15ebf2 - ext::expand::expand_block::hebf31e0d54524c16qec
  42:        0x10e124053 - ext::expand::expand_and_rename_fn_decl_and_block::h9735bb96b0f3ef77uIc
  43:        0x10e12af97 - ext::expand::expand_item_underscore::hf55f46424c3923c8BSb
  44:        0x10e1806e7 - fold::noop_fold_item_simple::h13360826160893592273
  45:        0x10e180246 - fold::noop_fold_item::h6178621647060960707
  46:        0x10e128d77 - ext::expand::expand_annotatable::h196830a9bb0064b9rpc
  47:        0x10e1246b9 - ext::expand::expand_item::h20b8951f3ce4e5750Rb
  48:        0x10e130a95 - iter::FlatMap<I, U, F>.Iterator::next::h16067873143848592029
  49:        0x10e13056c - vec::Vec<T>.FromIterator<T>::from_iter::h5969725813415914631
  50:        0x10e130267 - fold::noop_fold_mod::h15221366836033915591
  51:        0x10e12b8d6 - ext::expand::expand_item_underscore::hf55f46424c3923c8BSb
  52:        0x10e1806e7 - fold::noop_fold_item_simple::h13360826160893592273
  53:        0x10e180246 - fold::noop_fold_item::h6178621647060960707
  54:        0x10e1299ad - ext::expand::expand_annotatable::h196830a9bb0064b9rpc
  55:        0x10e1246b9 - ext::expand::expand_item::h20b8951f3ce4e5750Rb
  56:        0x10e18837c - ext::expand::expand_crate::h3f3f15780cfbd68bhRc
  57:        0x10cbb3a70 - driver::phase_2_configure_and_expand::closure.22339
  58:        0x10cb68430 - driver::phase_2_configure_and_expand::h39dfa417ce3247ddita
  59:        0x10cb58978 - driver::compile_input::h87a640b6a6c7679fTba
  60:        0x10cc3bb4b - run_compiler::h1988d61cd748f5f6A7b
  61:        0x10cc393c0 - boxed::F.FnBox<A>::call_box::h8812244964073324717
  62:        0x10cc38c37 - rt::unwind::try::try_fn::h15965772982377226605
  63:        0x1107150bf - __rust_try_inner
  64:        0x1107150fa - __rust_try
  65:        0x1106feb45 - rt::unwind::try::inner_try::h211b654f88b1ec3f1yw
  66:        0x10cc38e79 - boxed::F.FnBox<A>::call_box::h6462970046057749915
  67:        0x11071401d - sys::thread::Thread::new::thread_start::h9dddbcf4515946ba1Wv
  68:     0x7fff904dc267 - _pthread_body
  69:     0x7fff904dc1e4 - _pthread_start

@dtwood
Copy link
Author

dtwood commented Jul 28, 2015

Just got the nightly (so both 8b83557) working on my linux install, and it's running fine. So it appears to be an OS X only issue.

@Munksgaard
Copy link
Contributor

I guess that would explain something. I forgot to mention that I'm on linux:

$ uname -a
Linux turing 4.0.0-rc3 #15 SMP Mon Mar 9 16:42:51 CET 2015 x86_64 Intel(R) Core(TM) i7-4600U CPU @ 2.10GHz GenuineIntel GNU/Linux

@steveklabnik steveklabnik added O-macos Operating system: macOS A-syntaxext Area: Syntax extensions A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html labels Jul 29, 2015
@russellmcc
Copy link
Contributor

I actually am reproducing this issue still on homebrew (the Mac OS X package manager) nightlies, but not when I build myself from source. Very strange.

rustc 1.3.0-nightly (83b9deaf2 2015-08-01)

@regexident
Copy link
Contributor

Working fine on OS X with rustc 1.13.0-nightly. Should this be closed?

@dtwood
Copy link
Author

dtwood commented Sep 6, 2016

Yup, this now seems to be working with the latest version of rust from homebrew, so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-plugins Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html A-syntaxext Area: Syntax extensions O-macos Operating system: macOS
Projects
None yet
Development

No branches or pull requests

5 participants