Skip to content

ICE with boxed unboxed closures: !generic_bounds.has_escaping_regions() #20396

Closed
@pfalabella

Description

@pfalabella

code (attempted port of Y-combinator on rosettacode to modern syntax):

use Mu::Roll;

enum Mu<'a, T> { Roll(Box<Fn(Mu<T>) -> T + 'a>) }
fn unroll<'a, T>(Roll(f): Mu<'a, T>) -> Box<Fn(Mu<T>) -> T + 'a> { f }

type RecFunc<'a, A, B> = Box<Fn(Box<Fn(A) -> B + 'a>) -> Box<Fn(A) -> B + 'a> +'a>;

fn fix<'a, A, B>(f: RecFunc<'a, A, B>) -> Box<Fn(A) -> B + 'a> {
    let g: Box<Fn(Mu<Box<Fn(A) -> B>>) -> Box<Fn(A) -> B>> =
        move |&: x| move |&: a| f(unroll(x)(x))(a);
    g(Roll(g))
}

fn main() {
    let fac: RecFunc<uint, uint> =
        |f| |x| if (x==0) { 1 } else { f(x-1) * x };
    let fib : RecFunc<uint, uint> =
        |f| |x| if (x<2) { 1 } else { f(x-1) + f(x-2) };

    let ns = Vec::from_fn(20, |&: i| i);
    println!("{}", ns.map(|&n| fix(fac)(n)));
    println!("{}", ns.map(|&n| fix(fib)(n)));
}
thread 'rustc' panicked at 'assertion failed: !generic_bounds.has_escaping_regions()', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/librustc_typeck/check/mod.rs:2114

stack backtrace:
   1:     0x7fd4ecc76f10 - sys::backtrace::write::h01bfd86ab993f97afst
   2:     0x7fd4ecc9c0f0 - failure::on_fail::he030316fdcf28146rLz
   3:     0x7fd4ecc02be0 - rt::unwind::begin_unwind_inner::h622221e44b516048spz
   4:     0x7fd4ec2264e0 - rt::unwind::begin_unwind::h12531509240495221161
   5:     0x7fd4ec28c3c0 - check::FnCtxt<'a, 'tcx>::add_obligations_for_parameters::h34a427e8a2848633nPl
   6:     0x7fd4ec2b07f0 - check::wf::BoundsChecker<'cx, 'tcx>.TypeFolder<'tcx>::fold_ty::h15afb99283156e5dMzi
   7:     0x7fd4ec2b37c0 - vec::Vec<T>.FromIterator<T>::from_iter::h8357745960494389659
   8:     0x7fd4ec2b07f0 - check::wf::BoundsChecker<'cx, 'tcx>.TypeFolder<'tcx>::fold_ty::h15afb99283156e5dMzi
   9:     0x7fd4ec2b3410 - vec::Vec<T>.FromIterator<T>::from_iter::h9257776069425921094
  10:     0x7fd4ec2b32c0 - middle::subst::VecPerParamSpace<T>::map_enumerated::h4964435232940319426
  11:     0x7fd4ec2b2f20 - middle::ty_fold::super_fold_substs::h11206375604243926129
  12:     0x7fd4ec2b3970 - middle::ty_fold::super_fold_trait_ref::h15759136620816278104
  13:     0x7fd4ec2b07f0 - check::wf::BoundsChecker<'cx, 'tcx>.TypeFolder<'tcx>::fold_ty::h15afb99283156e5dMzi
  14:     0x7fd4ec2b07f0 - check::wf::BoundsChecker<'cx, 'tcx>.TypeFolder<'tcx>::fold_ty::h15afb99283156e5dMzi
  15:     0x7fd4ec305ea0 - check::GatherLocalsVisitor<'a, 'tcx>.Visitor<'v>::visit_local::h4f05cc9e40115c48aEj
  16:     0x7fd4ec307620 - visit::walk_block::h3936202465432908698
  17:     0x7fd4ec2f2240 - check::check_fn::hbb77b4681b36de3ehLj
  18:     0x7fd4ec302db0 - check::check_bare_fn::h8edfebc01afef72dzAj
  19:     0x7fd4ec2fa3f0 - check::check_item::h544bbdf7050c959dBTj
  20:     0x7fd4ec498340 - check_crate::unboxed_closure.39845
  21:     0x7fd4ec492f90 - check_crate::h87199c2bd279af76gNx
  22:     0x7fd4ed1c3880 - driver::phase_3_run_analysis_passes::h2a07a00301c8a103qva
  23:     0x7fd4ed1b2120 - driver::compile_input::h67695e67b1bff0f4wba
  24:     0x7fd4ed2fd8e0 - thunk::F.Invoke<A, R>::invoke::h9986526786811822135
  25:     0x7fd4ed2fc690 - rt::unwind::try::try_fn::h16517315690643326631
  26:     0x7fd4ecd024a0 - rust_try_inner
  27:     0x7fd4ecd02490 - rust_try
  28:     0x7fd4ed2fc9e0 - thunk::F.Invoke<A, R>::invoke::h3031254063568753567
  29:     0x7fd4ecc888d0 - sys::thread::thread_start::hb9b5795af18281d0alw
  30:     0x7fd4e75f00c0 - start_thread
  31:     0x7fd4ec8a8ec9 - __clone
  32:                0x0 - <unknown>

rustc 0.13.0-nightly (10d99a973 2014-12-31 21:01:42 +0000)
binary: rustc
commit-hash: 10d99a973498c5a1be6ba318210751efc1c2cf61
commit-date: 2014-12-31 21:01:42 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions