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

Compiler crash with reference mismatch in 1.68 only #112726

Closed
AlaskanEmily opened this issue Jun 17, 2023 · 3 comments
Closed

Compiler crash with reference mismatch in 1.68 only #112726

AlaskanEmily opened this issue Jun 17, 2023 · 3 comments
Labels
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.

Comments

@AlaskanEmily
Copy link

AlaskanEmily commented Jun 17, 2023

Code

// Any copyright is dedicated to the Public Domain.
// https://creativecommons.org/publicdomain/zero/1.0/
use std::rc::Rc;
extern crate core;
use core::slice::Iter;
use core::ops::{Deref, Range};

pub struct RCSlice<T>{
    slice: Rc<[T]>,
    range: Range<u16>,
}

impl<T> RCSlice<T>{
    #[inline]
    pub fn new<U: Into<Rc<[T]>>>(that: U, range: Range<usize>) -> RCSlice<T>{   
        let range = (range.start as u16)..(range.end as u16);
        let slice = that.into();
        RCSlice{
            slice,
            range,
        }
    }    
    #[inline]
    pub fn as_slice(&self) -> &[T]{                                             
        let range = (self.range.start as usize)..(self.range.end as usize);     
        &(*self.slice)[range]
    }
    pub fn iter(&self) -> Iter<'_, T>{                                     
        self.as_slice().iter()                                                  
    } 
}

impl<T> Deref for RCSlice<T>{
    type Target = [T];
    #[inline]
    fn deref(&self) -> &[T]{
        self.as_slice()
    }
}

#[inline]
const fn lex_break(b: &u8) -> bool{
    *b == b' ' || *b == b'\t'
}

#[inline]
fn not_empty(that: (usize, &[u8])) -> bool{
    !that.1.is_empty()
}

fn parse<I>(
    iter: &mut I,
) -> Result<(), ()>
where
    I: Iterator<Item = RCSlice<u8>>
{
    for i in iter{
        let mut chunks = i.split(lex_break).enumerate().filter(not_empty);
        let mut i = 0;
        for (i, b) in chunks{

        }
    }
    Ok(())
}

Meta

rustc --version --verbose:

rustc 1.68.0 (2c8cc3432 2023-03-06) (built from a source tarball)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-openbsd
release: 1.68.0
LLVM version: 15.0.6

Also tested with:

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6

Error output

error: internal compiler error: compiler/rustc_infer/src/infer/region_constraints/mod.rs:568:17: cannot relate bound region: ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:31 ~ crash_1_68[721b]::not_empty::'_), '_) }) <= '_#23r
Backtrace

   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   3: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   4: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   5: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   6: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   7: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   8: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   9: <rustc_infer::infer::region_constraints::RegionConstraintCollector>::make_subregion
  10: <rustc_infer::infer::region_constraints::RegionConstraintCollector>::make_eqregion
  11: <rustc_infer::infer::equate::Equate as rustc_middle::ty::relate::TypeRelation>::regions
  12: rustc_middle::ty::relate::super_relate_tys::<rustc_infer::infer::equate::Equate>
  13: <rustc_infer::infer::InferCtxt>::super_combine_tys::<rustc_infer::infer::equate::Equate>
  14: <rustc_infer::infer::equate::Equate as rustc_middle::ty::relate::TypeRelation>::tys
  15: <core::result::Result<rustc_middle::ty::Ty, rustc_middle::ty::error::TypeError> as rustc_type_ir::InternIteratorElement<rustc_middle::ty::Ty, rustc_middle::ty::Ty>>::intern_with::<core::iter::adapters::map::Map<core::iter::adapters::zip::Zip<core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::Ty>>, core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::Ty>>>, rustc_middle::ty::relate::super_relate_tys<rustc_infer::infer::equate::Equate>::{closure#2}>, <rustc_middle::ty::context::TyCtxt>::mk_tup<core::iter::adapters::map::Map<core::iter::adapters::zip::Zip<core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::Ty>>, core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::Ty>>>, rustc_middle::ty::relate::super_relate_tys<rustc_infer::infer::equate::Equate>::{closure#2}>>::{closure#0}>
  16: rustc_middle::ty::relate::super_relate_tys::<rustc_infer::infer::equate::Equate>
  17: <rustc_infer::infer::InferCtxt>::super_combine_tys::<rustc_infer::infer::equate::Equate>
  18: <rustc_infer::infer::equate::Equate as rustc_middle::ty::relate::TypeRelation>::tys
  19: <rustc_infer::infer::InferCtxt>::commit_if_ok::<rustc_infer::infer::InferOk<()>, rustc_middle::ty::error::TypeError, <rustc_infer::infer::at::Trace>::eq<rustc_middle::ty::Ty>::{closure#0}>
  20: <rustc_infer::infer::InferCtxt>::can_eq::<rustc_middle::ty::Ty>
  21: rustc_trait_selection::traits::error_reporting::suggestions::hint_missing_borrow
  22: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt>::report_closure_arg_mismatch
  23: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt>::report_selection_error
  24: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  25: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors
  26: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_argument_types
  27: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_method_argument_types
  28: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  29: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_decl
  31: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
  32: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  33: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  34: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  35: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_match::{closure#0}
  36: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  37: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  38: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
  39: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  40: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  41: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  42: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_match::{closure#0}
  43: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  44: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  45: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  46: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  47: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
  48: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  49: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  50: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  51: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
  52: rustc_hir_typeck::check::check_fn
  53: rustc_hir_typeck::typeck
  54: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck, rustc_query_impl::plumbing::QueryCtxt>
  55: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  56: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_typeck::typeck_item_bodies::{closure#0}>::{closure#0}>
  57: rustc_hir_typeck::typeck_item_bodies
  58: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  59: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  60: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#7}>
  61: rustc_hir_analysis::check_crate
  62: rustc_interface::passes::analysis
  63: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  64: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  65: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#2}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  66: <rustc_interface::queries::QueryResult<rustc_interface::passes::QueryContext>>::enter::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#2}>
  67: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  68: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>

@AlaskanEmily AlaskanEmily 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 Jun 17, 2023
@AlaskanEmily
Copy link
Author

AlaskanEmily commented Jun 17, 2023

This crash goes away if the code is fixed, by changing the signature of not_empty to be fn not_empty(that: &(usize, &[u8])) -> bool

This only seems to happen on 1.68, testing with 1.69 and 1.67 using godbolt shows it succeeds. For refernce, 1.68 is the version that ships with stable OpenBSD.

@ChrisDenton
Copy link
Member

A fix is very unlikely to be backported to 1.68 by rust. You'd have to contact the OpenBSD package maintainers about that.

@est31
Copy link
Member

est31 commented Jun 17, 2023

This is a dupe of (closed) #109361 . The PR that OpenBSD maintainers would need to backport is #107306 .

@jyn514 jyn514 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2023
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. 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.
Projects
None yet
Development

No branches or pull requests

4 participants