Skip to content

Remove ty::BrFresh and RegionConstraintCollector::new_bound #61387

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

Merged
merged 1 commit into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ for ty::RegionKind {
ty::ReClosureBound(vid) => {
vid.hash_stable(hcx, hasher);
}
ty::ReLateBound(..) |
ty::ReVar(..) |
ty::RePlaceholder(..) => {
bug!("StableHasher: unexpected region {:?}", *self)
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
format!("the anonymous lifetime #{} defined on", idx + 1),
self.hir().span_by_hir_id(node),
),
ty::BrFresh(_) => (
"an anonymous lifetime defined on".to_owned(),
self.hir().span_by_hir_id(node),
),
_ => (
format!("the lifetime {} as defined on", region),
cm.def_span(self.hir().span_by_hir_id(node)),
Expand Down
42 changes: 2 additions & 40 deletions src/librustc/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::unify as ut;
use crate::ty::ReStatic;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::{BrFresh, ReLateBound, ReVar};
use crate::ty::{ReLateBound, ReVar};
use crate::ty::{Region, RegionVid};

use std::collections::BTreeMap;
use std::{cmp, fmt, mem, u32};
use std::{cmp, fmt, mem};
use std::ops::Range;

mod leak_check;
Expand All @@ -37,10 +37,6 @@ pub struct RegionConstraintCollector<'tcx> {
/// exist). This prevents us from making many such regions.
glbs: CombineMap<'tcx>,

/// Global counter used during the GLB algorithm to create unique
/// names for fresh bound regions
bound_count: u32,

/// The undo log records actions that might later be undone.
///
/// Note: `num_open_snapshots` is used to track if we are actively
Expand Down Expand Up @@ -392,7 +388,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
data,
lubs,
glbs,
bound_count: _,
undo_log: _,
num_open_snapshots: _,
unification_table,
Expand Down Expand Up @@ -579,39 +574,6 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
}
}

pub fn new_bound(
&mut self,
tcx: TyCtxt<'_, '_, 'tcx>,
debruijn: ty::DebruijnIndex,
) -> Region<'tcx> {
// Creates a fresh bound variable for use in GLB computations.
// See discussion of GLB computation in the large comment at
// the top of this file for more details.
//
// This computation is potentially wrong in the face of
// rollover. It's conceivable, if unlikely, that one might
// wind up with accidental capture for nested functions in
// that case, if the outer function had bound regions created
// a very long time before and the inner function somehow
// wound up rolling over such that supposedly fresh
// identifiers were in fact shadowed. For now, we just assert
// that there is no rollover -- eventually we should try to be
// robust against this possibility, either by checking the set
// of bound identifiers that appear in a given expression and
// ensure that we generate one that is distinct, or by
// changing the representation of bound regions in a fn
// declaration

let sc = self.bound_count;
self.bound_count = sc + 1;

if sc >= self.bound_count {
bug!("rollover in RegionInference new_bound()");
}

tcx.mk_region(ReLateBound(debruijn, BrFresh(sc)))
}

fn add_constraint(&mut self, constraint: Constraint<'tcx>, origin: SubregionOrigin<'tcx>) {
// cannot add constraints once regions are resolved
debug!(
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,6 @@ impl<F: fmt::Write> FmtPrinter<'_, 'gcx, 'tcx, F> {
br
}
ty::BrAnon(_) |
ty::BrFresh(_) |
ty::BrEnv => {
let name = loop {
let name = name_by_region_index(region_index);
Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl fmt::Debug for ty::BoundRegion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ty::BrAnon(n) => write!(f, "BrAnon({:?})", n),
ty::BrFresh(n) => write!(f, "BrFresh({:?})", n),
ty::BrNamed(did, name) => {
write!(f, "BrNamed({:?}:{:?}, {})",
did.krate, did.index, name)
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ pub enum BoundRegion {
/// the event of shadowing.
BrNamed(DefId, InternedString),

/// Fresh bound identifiers created during GLB computations.
BrFresh(u32),

/// Anonymous region for the implicit env pointer parameter
/// to a closure
BrEnv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
}

ty::BoundRegion::BrAnon(_) | ty::BoundRegion::BrFresh(_) => None,
ty::BoundRegion::BrAnon(_) => None,
},

ty::ReLateBound(..)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
for br in late_bound_in_ret.difference(&late_bound_in_args) {
let lifetime_name = match *br {
ty::BrNamed(_, name) => format!("lifetime `{}`,", name),
ty::BrAnon(_) | ty::BrFresh(_) | ty::BrEnv => "an anonymous lifetime".to_string(),
ty::BrAnon(_) | ty::BrEnv => "an anonymous lifetime".to_string(),
};
let mut err = struct_span_err!(tcx.sess,
decl.output.span(),
Expand Down