Visitar URL original
internal compiler error: src/librustc_traits/normalize_erasing_regions.rs:42 · Issue #67684 · rust-lang/rust · GitHub
Skip to content

internal compiler error: src/librustc_traits/normalize_erasing_regions.rs:42 #67684

Closed

Description

@dpp

EDITED: MCVE is here: #67684 (comment)

I received this compiler bug:

sand:mesa_x dpp$ cargo test
   Compiling mesa_x v0.1.0 (/Users/dpp/proj/mesa_x)
error: internal compiler error: src/librustc_traits/normalize_erasing_regions.rs:42: could not fully normalize `fn() -> <impl combine::Parser as combine::Parser>::PartialState {<<impl combine::Parser as combine::Parser>::PartialState as std::default::Default>::default}`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:931:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

note: the compiler unexpectedly panicked. this is a bug.

Compiling with this cargo.toml file:

[package]
name = "mesa_x"
version = "0.1.0"
authors = ["David Pollak <feeder.of.the.bears@gmail.com>"]
edition = "2018"

[dependencies]
# nom = "5.0.1"
combine = "3.8.1"

And this main.rs:

#[macro_use]
extern crate combine;
use combine::parser::char::{alpha_num, char, digit, letter, spaces};
use combine::stream::{Stream};
use combine::{
    between, choice, attempt, easy,
    many, many1, none_of, optional, parser, sep_by, Parser,
};


#[derive(Debug, PartialEq)]
pub struct Address {}
#[derive(Debug, PartialEq)]
pub enum Range {}
#[derive(Debug, PartialEq)]
pub enum Function {}

#[derive(Debug, PartialEq)]
pub enum Expression {
    Int(i128),
    Float(f64),
    Str(String),
    Identifier(String),
    Address(Address),
    Range(Range),
    Function(String, Vec<Expression>),
    Infix(Function, Box<Expression>, Box<Expression>),
    Expression(Box<Expression>),
}


// `impl Parser` can be used to create reusable parsers with zero overhead
fn expr_<I>() -> impl Parser<Input = I, Output = Expression>
where
    I: Stream<Item = char, Error = easy::ParseError<I>>,
    // Necessary due to rust-lang/rust#24159
   // I::Error: ParseError<I::Item, I::Range, I::Position>,
{
 
    let int2 =  between(optional(spaces()), optional(spaces()), (optional(char('-')), many1(digit())))
    .and_then(|(sign, s): (Option<char>, String)| {
         match (sign, s.parse::<i128>()) {
            (Some('-'), Ok(r)) => Ok(Expression::Int(r * -1i128)),
            (_, Ok(r)) => Ok(Expression::Int(r)),
            (_, Err(_x)) => Err(easy::Error::Expected(easy::Info::Borrowed("combine"))),
        }

        });

    let string = between(
        (optional(spaces()), char('"')),
        (char('"'), optional(spaces())),
        many(none_of("\"".chars())),
    )
    .map(|s| Expression::Str(s));

    let identifier = (spaces(), letter(), many(alpha_num()))
        .map(|(_, c, st): ((), char, String)| c.to_string() + &st);

        let identifier2 = (spaces(), letter(), many(alpha_num()), spaces())
        .map(|(_, c, st, _): ((), char, String, ())| Expression::Identifier(c.to_string() + &st));

    let comma_list = sep_by(expr(), (optional(spaces()), char(','), optional(spaces()))).map(|v: Vec<Expression>| v);

    let function = (
        identifier,
        between(char('('),
        char(')'), comma_list)
    )
        .map(|(id, exprs)| Expression::Function(id, exprs));


    choice((attempt(function), attempt(identifier2), attempt(string), attempt(int2))) //.skip_spaces()
}

parser! {
    fn expr[I]()(I) -> Expression
    where [I: Stream<Item = char, Error = easy::ParseError<I>>]
    {
        expr_()
    }
}

#[test]
fn test_parsing() {
    let test_exprs = vec![
        r#"147"#,
        r#""Hello World""#,
        r#"true"#,
        r#"if(32, "yes", "no")"#,
        r#"if(true, "yes", "no")"#,
        r#"  "Hello World""#,
        r#"-32"#,
        r#"32.99"#,
        r#"-32.822"#,
        //r#"SuM(a1:$B7)"#,
        //r#"3 + 39"#,
        //r#"IF(a1, SUM(a1:$b$7), 3 + 39)"#,
    ];

    for item in test_exprs {
        match expr().easy_parse(item) {
            Ok((_x, "")) => {
                //println!("Got {:#?}", x);
                assert!(true)},
            Ok((_, x)) => assert!(
                false,
                format!("Failed to parse whole thing... remaining '{}'", x)
            ),
            Err(x) => assert!(false, format!("Trying '{}', got Error {:#?}", item, x)),
        }
    }
}

fn main() {
    println!("Hello, world!");
}

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    C-bugCategory: This is a bug.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Dec 28, 2019
  2. Centril commented on Dec 28, 2019

    @Centril
    Contributor

    If possible, a self-contained reproducer in the playground would be quite helpful towards fixing the bug.

  3. dpp commented on Dec 28, 2019

    @dpp
    Author

    @Centril -- I tried, but the combine crate is not a default crate on the playground. How can I add a crate to a playground page? Sorry for the n00b question

  4. Centril commented on Dec 29, 2019

    @Centril
    Contributor

    @dpp You can't. What I would do is inline the pieces you need from combine into your local crate until you can reproduce the issue without combine. Once you've done that, it's a good idea to start minimizing (but once we have a playground link it gets easier to help).

  5. dpp commented on Dec 29, 2019

    @dpp
    Author

    🙄

    Okay... y'all have a bug that causes the compiler to panic. This is suboptimal in a language that is supposed to make guarantees about this kinda thing. But okay... there's a panic in the compiler.

    Me... a Rust n00b, but a person who's been doing open source for 29 years and have my share
    of non-trivial projects... I get that asking folks to help out and filing bugs in a uniform way.

    But you've just asked me to copy/paste 13,000 LoC into the playground and nibble away at the
    problem so I have a minimally reproducible example... because it's too difficult for the compiler
    team that should pride itself on having zero panics to create a new project and copy/paste
    the Cargo.toml and main.rs code from the bug .

    Not real welcoming.

  6. csmoe commented on Dec 30, 2019

    @csmoe
    Contributor

    @dpp I think there’s some misunderstanding here:

    If possible, a self-contained reproducer in the playground would be quite helpful towards fixing the bug.

    as @Centril wrote, he was just trying to guide you to create a mcve. If time is tough for you, just leave this ICE here, mvce of an ICE is not a must from the original reporter, people from the community will pick this up to minimize as the E-needs-mvce label was already added.
    And thanks for your reporting :)

  7. Centril commented on Jan 2, 2020

    @Centril
    Contributor

    ICE occurs in:

    Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),

  8. pnkfelix commented on Jan 2, 2020

    @pnkfelix
    Contributor

    triage P-high, at least to learn more about the nature of this bug itself (e.g. getting the MCVE, and/or a stack trace...)

  9. 5 remaining items

  10. fanninpm commented on May 12, 2020

    @fanninpm
    Contributor

    Curiously, I can't get the latest MVCE to ICE on the latest nightly for Mac, even though it ICEs just fine on the playground.

  11. asomers commented on Sep 8, 2020

    @asomers
    Contributor

    I am reliably hitting this ICE with nightly-2020-09-07-x86_64-unknown-freebsd, but not with nightly-2020-08-28-x86_64-unknown-freebsd. Unfortunately, I'm hitting it in a large application that only builds on FreeBSD, so my odds of reducing it to a slim test case are slim. But it looks like the same error as in the playground link above.

  12. added a commit that references this issue on Sep 8, 2020
  13. fanninpm commented on Dec 17, 2020

    @fanninpm
    Contributor

    But you've just asked me to copy/paste 13,000 LoC into the playground and nibble away at the
    problem so I have a minimally reproducible example... because it's too difficult for the compiler
    team that should pride itself on having zero panics to create a new project and copy/paste
    the Cargo.toml and main.rs code from the bug .

    @dpp You may be interested in how @chengniansun uses Perses.

  14. chengniansun commented on Dec 17, 2020

    @chengniansun

    Further reduced with perses.

    trait ParseError {
        type StreamError;
    }
    impl<T> ParseError for T {
        type StreamError = ();
    }
    trait Stream {
        type Error;
    }
    trait Parser
    where
        <Self as Parser>::PartialState: Default,
    {
        type PartialState;
        fn parse_mode(&Self, Self::PartialState) {}
    }
    struct AndThen<A, B>(core::marker::PhantomData<(A, B)>);
    impl<A, B> Parser for AndThen<A, B>
    where
        A: Stream,
        B: Into<<A::Error as ParseError>::StreamError>,
    {
        type PartialState = ();
    }
    fn expr<A>() -> impl Parser
    where
        A: Stream,
    {
        AndThen::<A, ()>(core::marker::PhantomData)
    }
    fn parse_mode_impl<A>()
    where
        A::Error: ParseError,
        A: Stream,
    {
        Parser::parse_mode(&expr::<A>(), Default::default())
    }

    Stack trace

    warning: function is never used: `expr`
      --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:25:4
       |
    25 | fn expr<A>() -> impl Parser
       |    ^^^^
       |
       = note: `#[warn(dead_code)]` on by default
    
    warning: function is never used: `parse_mode_impl`
      --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:31:4
       |
    31 | fn parse_mode_impl<A>()
       |    ^^^^^^^^^^^^^^^
    
    error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:43:32: could not fully normalize `<impl Parser as Parser>::PartialState`
    
    thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
    stack backtrace:
       0: std::panicking::begin_panic
       1: rustc_errors::HandlerInner::bug
       2: rustc_errors::Handler::bug
       3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
       4: rustc_middle::ty::context::tls::with_opt::{{closure}}
       5: rustc_middle::ty::context::tls::with_opt
       6: rustc_middle::util::bug::opt_span_bug_fmt
       7: rustc_middle::util::bug::bug_fmt
       8: rustc_infer::infer::InferCtxtBuilder::enter
       9: rustc_traits::normalize_erasing_regions::normalize_generic_arg_after_erasing_regions
      10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
      11: rustc_data_structures::stack::ensure_sufficient_stack
      12: rustc_query_system::query::plumbing::get_query_impl
      13: rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::normalize_erasing_regions
      14: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
      15: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
      16: rustc_mir::transform::run_passes
      17: rustc_mir::transform::run_optimization_passes
      18: rustc_mir::transform::optimized_mir
      19: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::optimized_mir>::compute
      20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
      21: rustc_data_structures::stack::ensure_sufficient_stack
      22: rustc_query_system::query::plumbing::get_query_impl
      23: rustc_metadata::rmeta::encoder::EncodeContext::encode_optimized_mir
      24: <rustc_metadata::rmeta::encoder::EncodeContext as rustc_hir::intravisit::Visitor>::visit_item
      25: rustc_hir::hir::Crate::visit_all_item_likes
      26: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
      27: rustc_metadata::rmeta::encoder::encode_metadata_impl
      28: rustc_data_structures::sync::join
      29: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc_middle::middle::cstore::CrateStore for rustc_metadata::creader::CStore>::encode_metadata
      30: rustc_middle::ty::context::TyCtxt::encode_metadata
      31: rustc_interface::passes::QueryContext::enter
      32: rustc_interface::queries::Queries::ongoing_codegen
      33: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
      34: rustc_span::with_source_map
      35: rustc_interface::interface::create_compiler_and_run
      36: scoped_tls::ScopedKey<T>::set
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    
    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.50.0-nightly (b32e6e6ac 2020-12-16) running on x86_64-unknown-linux-gnu
    
    note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib
    
    query stack during panic:
    #0 [normalize_generic_arg_after_erasing_regions] normalizing `<impl Parser as Parser>::PartialState`
    #1 [optimized_mir] optimizing MIR for `parse_mode_impl`
    end of query stack
    error: aborting due to previous error; 2 warnings emitted
    
    
  15. added a commit that references this issue on Dec 17, 2020
  16. removed
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Dec 19, 2020
  17. added a commit that references this issue on Dec 19, 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

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions