Spelling. s/forrest/forest
This commit is contained in:
parent
699b25ff3a
commit
e9ffc409bc
4 changed files with 65 additions and 65 deletions
|
@ -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};
|
||||
|
@ -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,
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -73,17 +73,17 @@ 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);
|
||||
|
@ -91,7 +91,7 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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)
|
||||
}))
|
||||
},
|
||||
|
@ -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(),
|
||||
}
|
||||
|
@ -206,28 +206,28 @@ 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
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -235,29 +235,29 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue