Skip to content

Commit

Permalink
RegionFolder should only invoke callback on free regions.
Browse files Browse the repository at this point in the history
In other words, Late-bound regions that occur non-free should be
skipped.

Fix #10846.
  • Loading branch information
pnkfelix committed Jun 22, 2014
1 parent 43d1938 commit 36caa7a
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions src/librustc/middle/ty_fold.rs
Expand Up @@ -15,6 +15,7 @@ use middle::subst::VecPerParamSpace;
use middle::ty;
use middle::typeck;
use std::rc::Rc;
use syntax::ast;
use syntax::owned_slice::OwnedSlice;
use util::ppaux::Repr;

Expand Down Expand Up @@ -449,10 +450,23 @@ impl<'a> TypeFolder for BottomUpFolder<'a> {
///////////////////////////////////////////////////////////////////////////
// Region folder

/// Folds over the substructure of a type, visiting its component
/// types and all regions that occur *free* within it.
///
/// That is, `ty::t` can contain function or method types that bind
/// regions at the call site (`ReLateBound`), and occurrences of
/// regions (aka "lifetimes") that are bound within a type are not
/// visited by this folder; only regions that occur free will be
/// visited by `fld_r`.
///
/// (The distinction between "free" and "bound" is represented by
/// keeping track of each `FnSig` in the lexical context of the
/// current position of the fold.)
pub struct RegionFolder<'a> {
tcx: &'a ty::ctxt,
fld_t: |ty::t|: 'a -> ty::t,
fld_r: |ty::Region|: 'a -> ty::Region,
within_binder_ids: Vec<ast::NodeId>,
}

impl<'a> RegionFolder<'a> {
Expand All @@ -463,7 +477,8 @@ impl<'a> RegionFolder<'a> {
RegionFolder {
tcx: tcx,
fld_t: fld_t,
fld_r: fld_r
fld_r: fld_r,
within_binder_ids: vec![],
}
}

Expand All @@ -474,22 +489,53 @@ impl<'a> RegionFolder<'a> {
RegionFolder {
tcx: tcx,
fld_t: noop,
fld_r: fld_r
fld_r: fld_r,
within_binder_ids: vec![],
}
}
}

/// If `ty` has `FnSig` (i.e. closure or fn), return its binder_id;
/// else None.
fn opt_binder_id_of_function(t: ty::t) -> Option<ast::NodeId> {
match ty::get(t).sty {
ty::ty_closure(ref f) => Some(f.sig.binder_id),
ty::ty_bare_fn(ref f) => Some(f.sig.binder_id),
_ => None,
}
}

impl<'a> TypeFolder for RegionFolder<'a> {
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx }

fn fold_ty(&mut self, ty: ty::t) -> ty::t {
debug!("RegionFolder.fold_ty({})", ty.repr(self.tcx()));
let opt_binder_id = opt_binder_id_of_function(ty);
match opt_binder_id {
Some(binder_id) => self.within_binder_ids.push(binder_id),
None => {}
}

let t1 = super_fold_ty(self, ty);
(self.fld_t)(t1)
let ret = (self.fld_t)(t1);

if opt_binder_id.is_some() {
self.within_binder_ids.pop();
}

ret
}

fn fold_region(&mut self, r: ty::Region) -> ty::Region {
debug!("RegionFolder.fold_region({})", r.repr(self.tcx()));
(self.fld_r)(r)
match r {
ty::ReLateBound(binder_id, _) if self.within_binder_ids.contains(&binder_id) => {
debug!("RegionFolder.fold_region({}) skipped bound region", r.repr(self.tcx()));
r
}
_ => {
debug!("RegionFolder.fold_region({}) folding free region", r.repr(self.tcx()));
(self.fld_r)(r)
}
}
}
}

16 comments on commit 36caa7a

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at pnkfelix@36caa7a

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pnkfelix/rust/fsk-fix-issue-10846 = 36caa7a into auto

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnkfelix/rust/fsk-fix-issue-10846 = 36caa7a merged ok, testing candidate = f463bbfc

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at pnkfelix@36caa7a

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pnkfelix/rust/fsk-fix-issue-10846 = 36caa7a into auto

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnkfelix/rust/fsk-fix-issue-10846 = 36caa7a merged ok, testing candidate = 43903898

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pnkfelix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton hey if you could email me hints on how you would diagnose this (which seems like build sys issue) I would appreciate it

@alexcrichton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you been able to reproduce the failure locally? It looks like it's only failing for an unoptimized compiler, which I often forget to when when attempting to reproduce.

@pnkfelix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh super interesting, I did not notice that detail. I will try to reproduce locally.

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at pnkfelix@36caa7a

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pnkfelix/rust/fsk-fix-issue-10846 = 36caa7a into auto

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnkfelix/rust/fsk-fix-issue-10846 = 36caa7a merged ok, testing candidate = c6f86e4

@bors
Copy link
Contributor

@bors bors commented on 36caa7a Jun 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c6f86e4

Please sign in to comment.