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: bincode v2 alpha cannot be used with nightly rustc #92470

Open
kdy1 opened this issue Jan 1, 2022 · 11 comments
Open

ICE: bincode v2 alpha cannot be used with nightly rustc #92470

kdy1 opened this issue Jan 1, 2022 · 11 comments
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kdy1
Copy link
Contributor

kdy1 commented Jan 1, 2022

See: kdy1/wasm-perf#1

Code

use swc_common::input::SourceFileInput;
use swc_ecmascript::{
    ast::{EsVersion, Program},
    parser::{lexer::Lexer, Parser},
};

fn input() -> Program {
    testing::run_test(false, |cm, _handler| {
        let fm = cm.load_file(Path::new("benches/input.js")).unwrap();

        let lexer = Lexer::new(
            Default::default(),
            EsVersion::latest(),
            SourceFileInput::from(&*fm),
            None,
        );
        let mut parser = Parser::new_from(lexer);

        let program = parser.parse_program().unwrap();

        Ok(program)
    })
    .unwrap()
}

let program = input();

let config = bincode::Configuration::standard();
let ast_bincode = bincode::encode_to_vec(program, config.clone()).unwrap();

Ok(())

minimal reproduction.

I'll see if I can reduce further.

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (ad4423997 2021-11-14)
binary: rustc
commit-hash: ad442399756573dccacb314b6bf8079964bcc72a
commit-date: 2021-11-14
host: x86_64-apple-darwin
release: 1.58.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /cargo/registry/src/gi
thub.com-1ecc6299db9ec823/ena-0.14.0/src/snapshot_vec.rs:199:10
note: run with `RUST_BACKTRACE=1` environment variable to display a 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-IC
E%2C+T-compiler&template=ice.md

note: rustc 1.58.0-nightly (ad4423997 2021-11-14) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `bincode::config::internal::InternalIntEncodingConfig` fulfil
ls its obligations
#1 [resolve_instance] resolving instance `<_ as bincode::config::internal::InternalIntEncodingConfig>::IN
T_ENCODING`
Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /Users/runner/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/ena-0.14.0/src/snapshot_vec.rs:199:10
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <rustc_infer::infer::type_variable::TypeVariableTable>::probe
   4: <rustc_infer::infer::freshen::TypeFreshener as rustc_middle::ty::fold::TypeFolder>::fold_ty
   5: <&rustc_middle::ty::list::List<rustc_middle::ty::subst::GenericArg> as rustc_middle::ty::fold::TypeFoldable>::fold_with::<rustc_infer::infer::freshen::TypeFreshener>
   6: <rustc_trait_selection::traits::select::SelectionContext>::select_from_obligation
   7: <rustc_trait_selection::traits::select::SelectionContext>::select
   8: <rustc_infer::infer::InferCtxtBuilder>::enter::<core::result::Result<rustc_middle::traits::ImplSource<()>, rustc_errors::ErrorReported>, rustc_trait_selection::traits::codegen::codegen_fulfill_obligation::{closure#0}>
   9: rustc_trait_selection::traits::codegen::codegen_fulfill_obligation
  10: rustc_data_structures::stack::ensure_sufficient_stack::<core::result::Result<rustc_middle::traits::ImplSource<()>, rustc_errors::ErrorReported>, rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (rustc_middle::ty::ParamEnv, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>), core::result::Result<rustc_middle::traits::ImplSource<()>, rustc_errors::ErrorReported>>::{closure#0}>
  11: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::codegen_fulfill_obligation, rustc_query_impl::plumbing::QueryCtxt>
  12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::codegen_fulfill_obligation
  13: rustc_ty_utils::instance::inner_resolve_instance
  14: rustc_ty_utils::instance::resolve_instance
  15: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::resolve_instance, rustc_query_impl::plumbing::QueryCtxt>
  16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::resolve_instance
  17: <rustc_middle::ty::instance::Instance>::resolve_opt_const_arg
  18: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  19: <rustc_monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_constant
  20: <rustc_monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_operand
  21: rustc_monomorphize::collector::collect_neighbours
  22: rustc_monomorphize::collector::collect_items_rec
  23: rustc_monomorphize::collector::collect_items_rec
  24: rustc_monomorphize::collector::collect_items_rec
  25: rustc_monomorphize::collector::collect_items_rec
  26: rustc_monomorphize::collector::collect_items_rec
  27: rustc_monomorphize::collector::collect_items_rec
  28: rustc_monomorphize::collector::collect_items_rec
  29: rustc_monomorphize::collector::collect_items_rec
  30: rustc_monomorphize::collector::collect_items_rec
  31: rustc_monomorphize::collector::collect_items_rec
  32: rustc_monomorphize::collector::collect_items_rec
  33: rustc_monomorphize::collector::collect_items_rec
  34: rustc_monomorphize::collector::collect_items_rec
  35: rustc_monomorphize::collector::collect_items_rec
  36: rustc_monomorphize::collector::collect_items_rec
  37: rustc_monomorphize::collector::collect_items_rec
  38: rustc_monomorphize::collector::collect_items_rec
  39: rustc_monomorphize::collector::collect_items_rec
  40: rustc_monomorphize::collector::collect_items_rec
  41: rustc_monomorphize::collector::collect_items_rec
  42: rustc_monomorphize::collector::collect_items_rec
  43: rustc_monomorphize::collector::collect_items_rec
  44: rustc_monomorphize::collector::collect_items_rec
  45: rustc_monomorphize::collector::collect_items_rec
  46: rustc_monomorphize::collector::collect_items_rec
  47: rustc_monomorphize::collector::collect_items_rec
  48: rustc_monomorphize::collector::collect_items_rec
  49: rustc_monomorphize::collector::collect_items_rec
  50: rustc_monomorphize::collector::collect_items_rec
  51: rustc_monomorphize::collector::collect_items_rec
  52: rustc_monomorphize::collector::collect_items_rec
  53: rustc_monomorphize::collector::collect_items_rec
  54: rustc_monomorphize::collector::collect_items_rec
  55: rustc_monomorphize::collector::collect_items_rec
  56: rustc_monomorphize::collector::collect_items_rec
  57: rustc_monomorphize::collector::collect_items_rec
  58: rustc_monomorphize::collector::collect_items_rec
  59: rustc_monomorphize::collector::collect_items_rec
  60: rustc_monomorphize::collector::collect_items_rec
  61: rustc_monomorphize::collector::collect_items_rec
  62: rustc_monomorphize::collector::collect_items_rec
  63: rustc_monomorphize::collector::collect_items_rec
  64: rustc_monomorphize::collector::collect_items_rec
  65: rustc_monomorphize::collector::collect_items_rec
  66: rustc_monomorphize::collector::collect_items_rec
  67: rustc_monomorphize::collector::collect_items_rec
  68: rustc_monomorphize::collector::collect_items_rec
  69: rustc_monomorphize::collector::collect_items_rec
  70: rustc_monomorphize::collector::collect_items_rec
  71: rustc_monomorphize::collector::collect_items_rec
  72: rustc_monomorphize::collector::collect_items_rec
  73: rustc_monomorphize::collector::collect_items_rec
  74: rustc_monomorphize::collector::collect_items_rec
  75: rustc_monomorphize::collector::collect_items_rec
  76: rustc_monomorphize::collector::collect_items_rec
  77: rustc_monomorphize::collector::collect_items_rec
  78: rustc_monomorphize::collector::collect_items_rec
  79: rustc_monomorphize::collector::collect_items_rec
  80: rustc_monomorphize::collector::collect_items_rec
  81: rustc_monomorphize::collector::collect_items_rec
  82: rustc_monomorphize::collector::collect_items_rec
  83: rustc_monomorphize::collector::collect_items_rec
  84: rustc_monomorphize::collector::collect_items_rec
  85: rustc_monomorphize::collector::collect_items_rec
  86: rustc_monomorphize::collector::collect_items_rec
  87: rustc_monomorphize::collector::collect_items_rec
  88: rustc_monomorphize::collector::collect_items_rec
  89: rustc_monomorphize::collector::collect_items_rec
  90: rustc_monomorphize::collector::collect_items_rec
  91: rustc_monomorphize::collector::collect_items_rec
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@kdy1 kdy1 added 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. labels Jan 1, 2022
@VictorKoenders
Copy link

Still ICE's on 1.59.0-nightly (fcef61230 2021-12-17)

@ZoeyR
Copy link

ZoeyR commented Jan 12, 2022

I created a minimal reproduction of the issue. This ICEs on stable as of 1.57

fn main() {
    let writer = WriteImpl;
    let mut encoder = EncoderImpl::<_>::new(writer);
    Item.encode(&mut encoder);
}

pub trait Encode {
    fn encode<E: Encoder>(&self, encoder: E);
}

pub trait Encoder {
    type W: Writer;

    fn writer(&mut self) -> &mut Self::W;
}

pub trait Writer {
    fn write(&mut self);
}

struct Item;

impl Encode for Item {
    fn encode<E: Encoder>(&self, mut encoder: E) {
        encoder.writer().write();
        self.encode(&mut encoder);
    }
}

struct EncoderImpl<W: Writer> {
    writer: W,
}

impl<W: Writer> EncoderImpl<W> {
    pub fn new(writer: W) -> EncoderImpl<W> {
        EncoderImpl { writer }
    }
}

impl<W: Writer> Encoder for EncoderImpl<W> {
    type W = W;

    fn writer(&mut self) -> &mut Self::W {
        &mut self.writer
    }
}

struct WriteImpl;

impl Writer for WriteImpl {
    fn write(&mut self) {}
}

impl<'a, T> Encoder for &'a mut T
where
    T: Encoder,
{
    type W = T::W;

    fn writer(&mut self) -> &mut Self::W {
        T::writer(self)
    }
}

The expectation is that the type checker should hit the recursion limit. In fact you can see this happen if you comment out the line encoder.writer().write();

@Eijebong
Copy link
Contributor

@Aaron1011 I was told by @lqd that this should hopefully be fixed by #92210 which doesn't seem to be changing anything.

> rustc +fc922e0fe35a7aaa4bf5dbbe516ffd78dde591c2 a.rs
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/ena-0.14.0/src/snapshot_vec.rs:199:10
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.59.0-nightly (fc922e0fe 2022-01-02) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [codegen_fulfill_obligation] checking if `Writer` fulfills its obligations
#1 [resolve_instance] resolving instance `<_ as Writer>::write`
end of query stack

@est31
Copy link
Member

est31 commented Jan 12, 2022

Minimized a bit further:

fn main() {
    encode(&mut EncoderImpl);
}

pub trait Encoder {
    type W;

    fn writer(&self) -> Self::W;
}

fn encode<E: Encoder>(mut encoder: E) {
    encoder.writer();
    encode(&mut encoder);
}

struct EncoderImpl;

impl Encoder for EncoderImpl {
    type W = ();

    fn writer(&self) {}
}

impl<'a, T: Encoder> Encoder for &'a mut T {
    type W = T::W;

    fn writer(&self) -> Self::W {
        panic!()
    }
}

@lqd
Copy link
Member

lqd commented Jan 12, 2022

(That was an incorrect guess on my part: I've seen this query in other incremental issues recently, and this actually does not seem to be related to that at all)

@Eijebong
Copy link
Contributor

Bisected to 50171c3 with cargo-bisect-rustc --end 73422130ee96c09e7214c876a3600ac1f32aa8c8 --start 9faa714154dbc03faa174a7d4f72d6bbbfd61f7c --regress ice and est31's example

@est31
Copy link
Member

est31 commented Jan 12, 2022

Auto merge of # 88563 - ehuss:update-cargo-books, r=ehuss

Are you sure you bisected correctly? A cargo update should not have introduced it, as the bug is reproducible without any cargo involvement at all.

But the ICE does seem to be a regression, as according to experiments on godbolt.org, it doesn't ICE on rustc 1.30.0, but does ICE on rustc 1.31.0 (both Zoey's shared snippet and my example).

  • In rustc 1.30.0 there is no ICE, but an error
  • In rustc 1.31.0 until 1.36.0 inclusive there is an ICE with the error message: 'called Option::unwrap() on a None value'
  • In rustc 1.37.0 the ICE message is: 'could not lift for printing', src/libcore/option.rs:1034:5
  • Starting with rustc 1.38.0 until 1.57.0 and current nightly the ICE message is: 'index out of bounds: the len is 0 but the index is 0'

@Eijebong
Copy link
Contributor

Yeah the bisect is very weird. I tried running some versions manually that were reported as good by the tool and they still ICEd. I think --regress ice is broken

@matthiaskrgr
Copy link
Member

Another reproducer from ./src/test/ui/closures/print/closure-print-generic-verbose-1.rs (needs --edition=2021 to crash)

fn to_fn_once<F:FnOnce()>(f: F) -> F { f }

fn f<T: std::fmt::Display>(y: T) {
    struct Foo<U: std::fmt::Display> {
        x: U
    };

    let foo =  Foo{ x: "x" };

    let c = to_fn_once(move|| {
        println!("{} {}", foo.x, y);
    });

    c();
    c();
    //~^ ERROR use of moved value
}


fn main() {
    f("S");
}

@JohnTitor
Copy link
Member

Triage: Fixed by #100757, I think it has a regression test that should cover this case, closing.

@matthiaskrgr
Copy link
Member

Reopened by #104610

@matthiaskrgr matthiaskrgr reopened this Nov 24, 2022
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

10 participants