Skip to content

Commit

Permalink
Spelling. s/forrest/forest
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Jan 3, 2017
1 parent 699b25f commit e9ffc40
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/librustc/ty/context.rs
Expand Up @@ -33,7 +33,7 @@ use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
use ty::TypeVariants::*;
use ty::layout::{Layout, TargetDataLayout};
use ty::inhabitedness::DefIdForrest;
use ty::inhabitedness::DefIdForest;
use ty::maps;
use util::common::MemoizationMap;
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
Expand Down Expand Up @@ -460,7 +460,7 @@ pub struct GlobalCtxt<'tcx> {
// FIXME dep tracking -- should be harmless enough
pub normalized_cache: RefCell<FxHashMap<Ty<'tcx>, Ty<'tcx>>>,

pub inhabitedness_cache: RefCell<FxHashMap<Ty<'tcx>, DefIdForrest>>,
pub inhabitedness_cache: RefCell<FxHashMap<Ty<'tcx>, DefIdForest>>,

pub lang_items: middle::lang_items::LanguageItems,

Expand Down
114 changes: 57 additions & 57 deletions src/librustc/ty/inhabitedness.rs
Expand Up @@ -21,46 +21,46 @@ use ty::TypeVariants::*;
/// Represents a set of DefIds closed under the ancestor relation. That is, if
/// a DefId is in this set then so are all its descendants.
#[derive(Clone)]
pub struct DefIdForrest {
pub struct DefIdForest {
/// The minimal set of DefIds required to represent the whole set.
/// If A and B are DefIds in the DefIdForrest, and A is a desecendant
/// If A and B are DefIds in the DefIdForest, and A is a desecendant
/// of B, then only B will be in root_ids.
/// We use a SmallVec here because (for its use in this module) its rare
/// that this will contain even two ids.
root_ids: SmallVec<[DefId; 1]>,
}

impl<'a, 'gcx, 'tcx> DefIdForrest {
/// Create an empty forrest.
pub fn empty() -> DefIdForrest {
DefIdForrest {
impl<'a, 'gcx, 'tcx> DefIdForest {
/// Create an empty forest.
pub fn empty() -> DefIdForest {
DefIdForest {
root_ids: SmallVec::new(),
}
}

/// Create a forrest consisting of a single tree representing the entire
/// Create a forest consisting of a single tree representing the entire
/// crate.
#[inline]
pub fn full(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForrest {
pub fn full(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForest {
let crate_id = tcx.map.local_def_id(CRATE_NODE_ID);
DefIdForrest::from_id(crate_id)
DefIdForest::from_id(crate_id)
}

/// Create a forrest containing a DefId and all its descendants.
pub fn from_id(id: DefId) -> DefIdForrest {
/// Create a forest containing a DefId and all its descendants.
pub fn from_id(id: DefId) -> DefIdForest {
let mut root_ids = SmallVec::new();
root_ids.push(id);
DefIdForrest {
DefIdForest {
root_ids: root_ids,
}
}

/// Test whether the forrest is empty.
/// Test whether the forest is empty.
pub fn is_empty(&self) -> bool {
self.root_ids.is_empty()
}

/// Test whether the forrest conains a given DefId.
/// Test whether the forest conains a given DefId.
pub fn contains(&self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
id: DefId) -> bool
Expand All @@ -73,25 +73,25 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
false
}

/// Calculate the intersection of a collection of forrests.
/// Calculate the intersection of a collection of forests.
pub fn intersection<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
iter: I) -> DefIdForrest
where I: IntoIterator<Item=DefIdForrest>
iter: I) -> DefIdForest
where I: IntoIterator<Item=DefIdForest>
{
let mut ret = DefIdForrest::full(tcx);
let mut ret = DefIdForest::full(tcx);
let mut next_ret = SmallVec::new();
let mut old_ret: SmallVec<[DefId; 1]> = SmallVec::new();
for next_forrest in iter {
for next_forest in iter {
for id in ret.root_ids.drain(..) {
if next_forrest.contains(tcx, id) {
if next_forest.contains(tcx, id) {
next_ret.push(id);
} else {
old_ret.push(id);
}
}
ret.root_ids.extend(old_ret.drain(..));

for id in next_forrest.root_ids {
for id in next_forest.root_ids {
if ret.contains(tcx, id) {
next_ret.push(id);
}
Expand All @@ -103,21 +103,21 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
ret
}

/// Calculate the union of a collection of forrests.
/// Calculate the union of a collection of forests.
pub fn union<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
iter: I) -> DefIdForrest
where I: IntoIterator<Item=DefIdForrest>
iter: I) -> DefIdForest
where I: IntoIterator<Item=DefIdForest>
{
let mut ret = DefIdForrest::empty();
let mut ret = DefIdForest::empty();
let mut next_ret = SmallVec::new();
for next_forrest in iter {
for next_forest in iter {
for id in ret.root_ids.drain(..) {
if !next_forrest.contains(tcx, id) {
if !next_forest.contains(tcx, id) {
next_ret.push(id);
}
}

for id in next_forrest.root_ids {
for id in next_forest.root_ids {
if !next_ret.contains(&id) {
next_ret.push(id);
}
Expand All @@ -131,18 +131,18 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
}

impl<'a, 'gcx, 'tcx> AdtDef {
/// Calculate the forrest of DefIds from which this adt is visibly uninhabited.
/// Calculate the forest of DefIds from which this adt is visibly uninhabited.
pub fn uninhabited_from(
&self,
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
substs: &'tcx Substs<'tcx>) -> DefIdForrest
substs: &'tcx Substs<'tcx>) -> DefIdForest
{
if !visited.insert((self.did, substs)) {
return DefIdForrest::empty();
return DefIdForest::empty();
}

let ret = DefIdForrest::intersection(tcx, self.variants.iter().map(|v| {
let ret = DefIdForest::intersection(tcx, self.variants.iter().map(|v| {
v.uninhabited_from(visited, tcx, substs, self.adt_kind())
}));
visited.remove(&(self.did, substs));
Expand All @@ -151,27 +151,27 @@ impl<'a, 'gcx, 'tcx> AdtDef {
}

impl<'a, 'gcx, 'tcx> VariantDef {
/// Calculate the forrest of DefIds from which this variant is visibly uninhabited.
/// Calculate the forest of DefIds from which this variant is visibly uninhabited.
pub fn uninhabited_from(
&self,
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
substs: &'tcx Substs<'tcx>,
adt_kind: AdtKind) -> DefIdForrest
adt_kind: AdtKind) -> DefIdForest
{
match adt_kind {
AdtKind::Union => {
DefIdForrest::intersection(tcx, self.fields.iter().map(|f| {
DefIdForest::intersection(tcx, self.fields.iter().map(|f| {
f.uninhabited_from(visited, tcx, substs, false)
}))
},
AdtKind::Struct => {
DefIdForrest::union(tcx, self.fields.iter().map(|f| {
DefIdForest::union(tcx, self.fields.iter().map(|f| {
f.uninhabited_from(visited, tcx, substs, false)
}))
},
AdtKind::Enum => {
DefIdForrest::union(tcx, self.fields.iter().map(|f| {
DefIdForest::union(tcx, self.fields.iter().map(|f| {
f.uninhabited_from(visited, tcx, substs, true)
}))
},
Expand All @@ -180,24 +180,24 @@ impl<'a, 'gcx, 'tcx> VariantDef {
}

impl<'a, 'gcx, 'tcx> FieldDef {
/// Calculate the forrest of DefIds from which this field is visibly uninhabited.
/// Calculate the forest of DefIds from which this field is visibly uninhabited.
pub fn uninhabited_from(
&self,
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
substs: &'tcx Substs<'tcx>,
is_enum: bool) -> DefIdForrest
is_enum: bool) -> DefIdForest
{
let mut data_uninhabitedness = move || self.ty(tcx, substs).uninhabited_from(visited, tcx);
if is_enum {
data_uninhabitedness()
} else {
match self.vis {
Visibility::Invisible => DefIdForrest::empty(),
Visibility::Invisible => DefIdForest::empty(),
Visibility::Restricted(from) => {
let forrest = DefIdForrest::from_id(from);
let iter = Some(forrest).into_iter().chain(Some(data_uninhabitedness()));
DefIdForrest::intersection(tcx, iter)
let forest = DefIdForest::from_id(from);
let iter = Some(forest).into_iter().chain(Some(data_uninhabitedness()));
DefIdForest::intersection(tcx, iter)
},
Visibility::Public => data_uninhabitedness(),
}
Expand All @@ -206,58 +206,58 @@ impl<'a, 'gcx, 'tcx> FieldDef {
}

impl<'a, 'gcx, 'tcx> TyS<'tcx> {
/// Calculate the forrest of DefIds from which this type is visibly uninhabited.
/// Calculate the forest of DefIds from which this type is visibly uninhabited.
pub fn uninhabited_from(
&self,
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForrest
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForest
{
match tcx.lift_to_global(&self) {
Some(global_ty) => {
{
let cache = tcx.inhabitedness_cache.borrow();
if let Some(forrest) = cache.get(&global_ty) {
return forrest.clone();
if let Some(forest) = cache.get(&global_ty) {
return forest.clone();
}
}
let forrest = global_ty.uninhabited_from_inner(visited, tcx);
let forest = global_ty.uninhabited_from_inner(visited, tcx);
let mut cache = tcx.inhabitedness_cache.borrow_mut();
cache.insert(global_ty, forrest.clone());
forrest
cache.insert(global_ty, forest.clone());
forest
},
None => {
let forrest = self.uninhabited_from_inner(visited, tcx);
forrest
let forest = self.uninhabited_from_inner(visited, tcx);
forest
},
}
}

fn uninhabited_from_inner(
&self,
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForrest
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForest
{
match self.sty {
TyAdt(def, substs) => {
def.uninhabited_from(visited, tcx, substs)
},

TyNever => DefIdForrest::full(tcx),
TyNever => DefIdForest::full(tcx),
TyTuple(ref tys) => {
DefIdForrest::union(tcx, tys.iter().map(|ty| {
DefIdForest::union(tcx, tys.iter().map(|ty| {
ty.uninhabited_from(visited, tcx)
}))
},
TyArray(ty, len) => {
if len == 0 {
DefIdForrest::empty()
DefIdForest::empty()
} else {
ty.uninhabited_from(visited, tcx)
}
}
TyRef(_, ref tm) => tm.ty.uninhabited_from(visited, tcx),

_ => DefIdForrest::empty(),
_ => DefIdForest::empty(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/sty.rs
Expand Up @@ -982,8 +982,8 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
/// Checks whether a type is visibly uninhabited from a particular module.
pub fn is_uninhabited_from(&self, module: DefId, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
let mut visited = FxHashSet::default();
let forrest = self.uninhabited_from(&mut visited, tcx);
forrest.contains(tcx, module)
let forest = self.uninhabited_from(&mut visited, tcx);
forest.contains(tcx, module)
}

/// Checks whether a type is uninhabited.
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_const_eval/_match.rs
Expand Up @@ -394,10 +394,10 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
ty::TyAdt(def, substs) if def.is_enum() && def.variants.len() != 1 => {
def.variants.iter().filter_map(|v| {
let mut visited = FxHashSet::default();
let forrest = v.uninhabited_from(&mut visited,
cx.tcx, substs,
AdtKind::Enum);
if forrest.contains(cx.tcx, cx.module) {
let forest = v.uninhabited_from(&mut visited,
cx.tcx, substs,
AdtKind::Enum);
if forest.contains(cx.tcx, cx.module) {
None
} else {
Some(Variant(v.did))
Expand Down

0 comments on commit e9ffc40

Please sign in to comment.