Skip to content

Commit 9f83e96

Browse files
committed
Fix build after rebase.
Mostly just rename stuff. Visibility checks use DefIds rather than NodeIds now.
1 parent 4136ba0 commit 9f83e96

File tree

6 files changed

+129
-118
lines changed

6 files changed

+129
-118
lines changed

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use ty::{BareFnTy, InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
3333
use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
3434
use ty::TypeVariants::*;
3535
use ty::layout::{Layout, TargetDataLayout};
36-
use ty::inhabitedness::NodeForrest;
36+
use ty::inhabitedness::DefIdForrest;
3737
use ty::maps;
3838
use util::common::MemoizationMap;
3939
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
@@ -460,7 +460,7 @@ pub struct GlobalCtxt<'tcx> {
460460
// FIXME dep tracking -- should be harmless enough
461461
pub normalized_cache: RefCell<FxHashMap<Ty<'tcx>, Ty<'tcx>>>,
462462

463-
pub inhabitedness_cache: RefCell<FxHashMap<Ty<'tcx>, NodeForrest>>,
463+
pub inhabitedness_cache: RefCell<FxHashMap<Ty<'tcx>, DefIdForrest>>,
464464

465465
pub lang_items: middle::lang_items::LanguageItems,
466466

src/librustc/ty/inhabitedness.rs

Lines changed: 88 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -10,137 +10,139 @@
1010

1111
use std::mem;
1212
use rustc_data_structures::small_vec::SmallVec;
13-
use syntax::ast::{CRATE_NODE_ID, NodeId};
13+
use syntax::ast::CRATE_NODE_ID;
1414
use util::nodemap::FxHashSet;
1515
use ty::context::TyCtxt;
1616
use ty::{AdtDef, VariantDef, FieldDef, TyS};
1717
use ty::{DefId, Substs};
18-
use ty::{AdtKind, Visibility, NodeIdTree};
18+
use ty::{AdtKind, Visibility, DefIdTree};
1919
use ty::TypeVariants::*;
2020

21-
/// Represents a set of nodes closed under the ancestor relation. That is, if a
22-
/// node is in this set then so are all its descendants.
21+
/// Represents a set of DefIds closed under the ancestor relation. That is, if
22+
/// a DefId is in this set then so are all its descendants.
2323
#[derive(Clone)]
24-
pub struct NodeForrest {
25-
/// The minimal set of nodes required to represent the whole set.
26-
/// If A and B are nodes in the NodeForrest, and A is a desecendant
27-
/// of B, then only B will be in root_nodes.
24+
pub struct DefIdForrest {
25+
/// The minimal set of DefIds required to represent the whole set.
26+
/// If A and B are DefIds in the DefIdForrest, and A is a desecendant
27+
/// of B, then only B will be in root_ids.
2828
/// We use a SmallVec here because (for its use in this module) its rare
29-
/// that this will contain more than one or two nodes.
30-
root_nodes: SmallVec<[NodeId; 1]>,
29+
/// that this will contain even two ids.
30+
root_ids: SmallVec<[DefId; 1]>,
3131
}
3232

33-
impl<'a, 'gcx, 'tcx> NodeForrest {
34-
/// Create an empty set.
35-
pub fn empty() -> NodeForrest {
36-
NodeForrest {
37-
root_nodes: SmallVec::new(),
33+
impl<'a, 'gcx, 'tcx> DefIdForrest {
34+
/// Create an empty forrest.
35+
pub fn empty() -> DefIdForrest {
36+
DefIdForrest {
37+
root_ids: SmallVec::new(),
3838
}
3939
}
4040

41-
/// Create a set containing every node.
41+
/// Create a forrest consisting of a single tree representing the entire
42+
/// crate.
4243
#[inline]
43-
pub fn full() -> NodeForrest {
44-
NodeForrest::from_node(CRATE_NODE_ID)
44+
pub fn full(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForrest {
45+
let crate_id = tcx.map.local_def_id(CRATE_NODE_ID);
46+
DefIdForrest::from_id(crate_id)
4547
}
4648

47-
/// Create a set containing a node and all its descendants.
48-
pub fn from_node(node: NodeId) -> NodeForrest {
49-
let mut root_nodes = SmallVec::new();
50-
root_nodes.push(node);
51-
NodeForrest {
52-
root_nodes: root_nodes,
49+
/// Create a forrest containing a DefId and all its descendants.
50+
pub fn from_id(id: DefId) -> DefIdForrest {
51+
let mut root_ids = SmallVec::new();
52+
root_ids.push(id);
53+
DefIdForrest {
54+
root_ids: root_ids,
5355
}
5456
}
5557

56-
/// Test whether the set is empty.
58+
/// Test whether the forrest is empty.
5759
pub fn is_empty(&self) -> bool {
58-
self.root_nodes.is_empty()
60+
self.root_ids.is_empty()
5961
}
6062

61-
/// Test whether the set conains a node.
63+
/// Test whether the forrest conains a given DefId.
6264
pub fn contains(&self,
6365
tcx: TyCtxt<'a, 'gcx, 'tcx>,
64-
node: NodeId) -> bool
66+
id: DefId) -> bool
6567
{
66-
for root_node in self.root_nodes.iter() {
67-
if tcx.map.is_descendant_of(node, *root_node) {
68+
for root_id in self.root_ids.iter() {
69+
if tcx.is_descendant_of(id, *root_id) {
6870
return true;
6971
}
7072
}
7173
false
7274
}
7375

74-
/// Calculate the intersection of a collection of sets.
76+
/// Calculate the intersection of a collection of forrests.
7577
pub fn intersection<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
76-
iter: I) -> NodeForrest
77-
where I: IntoIterator<Item=NodeForrest>
78+
iter: I) -> DefIdForrest
79+
where I: IntoIterator<Item=DefIdForrest>
7880
{
79-
let mut ret = NodeForrest::full();
81+
let mut ret = DefIdForrest::full(tcx);
8082
let mut next_ret = SmallVec::new();
81-
let mut old_ret: SmallVec<[NodeId; 1]> = SmallVec::new();
82-
for next_set in iter {
83-
for node in ret.root_nodes.drain(..) {
84-
if next_set.contains(tcx, node) {
85-
next_ret.push(node);
83+
let mut old_ret: SmallVec<[DefId; 1]> = SmallVec::new();
84+
for next_forrest in iter {
85+
for id in ret.root_ids.drain(..) {
86+
if next_forrest.contains(tcx, id) {
87+
next_ret.push(id);
8688
} else {
87-
old_ret.push(node);
89+
old_ret.push(id);
8890
}
8991
}
90-
ret.root_nodes.extend(old_ret.drain(..));
92+
ret.root_ids.extend(old_ret.drain(..));
9193

92-
for node in next_set.root_nodes {
93-
if ret.contains(tcx, node) {
94-
next_ret.push(node);
94+
for id in next_forrest.root_ids {
95+
if ret.contains(tcx, id) {
96+
next_ret.push(id);
9597
}
9698
}
9799

98-
mem::swap(&mut next_ret, &mut ret.root_nodes);
100+
mem::swap(&mut next_ret, &mut ret.root_ids);
99101
next_ret.drain(..);
100102
}
101103
ret
102104
}
103105

104-
/// Calculate the union of a collection of sets.
106+
/// Calculate the union of a collection of forrests.
105107
pub fn union<I>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
106-
iter: I) -> NodeForrest
107-
where I: IntoIterator<Item=NodeForrest>
108+
iter: I) -> DefIdForrest
109+
where I: IntoIterator<Item=DefIdForrest>
108110
{
109-
let mut ret = NodeForrest::empty();
111+
let mut ret = DefIdForrest::empty();
110112
let mut next_ret = SmallVec::new();
111-
for next_set in iter {
112-
for node in ret.root_nodes.drain(..) {
113-
if !next_set.contains(tcx, node) {
114-
next_ret.push(node);
113+
for next_forrest in iter {
114+
for id in ret.root_ids.drain(..) {
115+
if !next_forrest.contains(tcx, id) {
116+
next_ret.push(id);
115117
}
116118
}
117119

118-
for node in next_set.root_nodes {
119-
if !next_ret.contains(&node) {
120-
next_ret.push(node);
120+
for id in next_forrest.root_ids {
121+
if !next_ret.contains(&id) {
122+
next_ret.push(id);
121123
}
122124
}
123125

124-
mem::swap(&mut next_ret, &mut ret.root_nodes);
126+
mem::swap(&mut next_ret, &mut ret.root_ids);
125127
next_ret.drain(..);
126128
}
127129
ret
128130
}
129131
}
130132

131133
impl<'a, 'gcx, 'tcx> AdtDef {
132-
/// Calculate the set of nodes from which this adt is visibly uninhabited.
134+
/// Calculate the forrest of DefIds from which this adt is visibly uninhabited.
133135
pub fn uninhabited_from(
134136
&self,
135137
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
136138
tcx: TyCtxt<'a, 'gcx, 'tcx>,
137-
substs: &'tcx Substs<'tcx>) -> NodeForrest
139+
substs: &'tcx Substs<'tcx>) -> DefIdForrest
138140
{
139141
if !visited.insert((self.did, substs)) {
140-
return NodeForrest::empty();
142+
return DefIdForrest::empty();
141143
}
142144

143-
let ret = NodeForrest::intersection(tcx, self.variants.iter().map(|v| {
145+
let ret = DefIdForrest::intersection(tcx, self.variants.iter().map(|v| {
144146
v.uninhabited_from(visited, tcx, substs, self.adt_kind())
145147
}));
146148
visited.remove(&(self.did, substs));
@@ -149,27 +151,27 @@ impl<'a, 'gcx, 'tcx> AdtDef {
149151
}
150152

151153
impl<'a, 'gcx, 'tcx> VariantDef {
152-
/// Calculate the set of nodes from which this variant is visibly uninhabited.
154+
/// Calculate the forrest of DefIds from which this variant is visibly uninhabited.
153155
pub fn uninhabited_from(
154156
&self,
155157
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
156158
tcx: TyCtxt<'a, 'gcx, 'tcx>,
157159
substs: &'tcx Substs<'tcx>,
158-
adt_kind: AdtKind) -> NodeForrest
160+
adt_kind: AdtKind) -> DefIdForrest
159161
{
160162
match adt_kind {
161163
AdtKind::Union => {
162-
NodeForrest::intersection(tcx, self.fields.iter().map(|f| {
164+
DefIdForrest::intersection(tcx, self.fields.iter().map(|f| {
163165
f.uninhabited_from(visited, tcx, substs, false)
164166
}))
165167
},
166168
AdtKind::Struct => {
167-
NodeForrest::union(tcx, self.fields.iter().map(|f| {
169+
DefIdForrest::union(tcx, self.fields.iter().map(|f| {
168170
f.uninhabited_from(visited, tcx, substs, false)
169171
}))
170172
},
171173
AdtKind::Enum => {
172-
NodeForrest::union(tcx, self.fields.iter().map(|f| {
174+
DefIdForrest::union(tcx, self.fields.iter().map(|f| {
173175
f.uninhabited_from(visited, tcx, substs, true)
174176
}))
175177
},
@@ -178,24 +180,24 @@ impl<'a, 'gcx, 'tcx> VariantDef {
178180
}
179181

180182
impl<'a, 'gcx, 'tcx> FieldDef {
181-
/// Calculate the set of nodes from which this field is visibly uninhabited.
183+
/// Calculate the forrest of DefIds from which this field is visibly uninhabited.
182184
pub fn uninhabited_from(
183185
&self,
184186
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
185187
tcx: TyCtxt<'a, 'gcx, 'tcx>,
186188
substs: &'tcx Substs<'tcx>,
187-
is_enum: bool) -> NodeForrest
189+
is_enum: bool) -> DefIdForrest
188190
{
189191
let mut data_uninhabitedness = move || self.ty(tcx, substs).uninhabited_from(visited, tcx);
190192
if is_enum {
191193
data_uninhabitedness()
192194
} else {
193195
match self.vis {
194-
Visibility::PrivateExternal => NodeForrest::empty(),
196+
Visibility::Invisible => DefIdForrest::empty(),
195197
Visibility::Restricted(from) => {
196-
let node_set = NodeForrest::from_node(from);
197-
let iter = Some(node_set).into_iter().chain(Some(data_uninhabitedness()));
198-
NodeForrest::intersection(tcx, iter)
198+
let forrest = DefIdForrest::from_id(from);
199+
let iter = Some(forrest).into_iter().chain(Some(data_uninhabitedness()));
200+
DefIdForrest::intersection(tcx, iter)
199201
},
200202
Visibility::Public => data_uninhabitedness(),
201203
}
@@ -204,58 +206,58 @@ impl<'a, 'gcx, 'tcx> FieldDef {
204206
}
205207

206208
impl<'a, 'gcx, 'tcx> TyS<'tcx> {
207-
/// Calculate the set of nodes from which this type is visibly uninhabited.
209+
/// Calculate the forrest of DefIds from which this type is visibly uninhabited.
208210
pub fn uninhabited_from(
209211
&self,
210212
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
211-
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> NodeForrest
213+
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForrest
212214
{
213215
match tcx.lift_to_global(&self) {
214216
Some(global_ty) => {
215217
{
216218
let cache = tcx.inhabitedness_cache.borrow();
217-
if let Some(closed_node_set) = cache.get(&global_ty) {
218-
return closed_node_set.clone();
219+
if let Some(forrest) = cache.get(&global_ty) {
220+
return forrest.clone();
219221
}
220222
}
221-
let node_set = global_ty.uninhabited_from_inner(visited, tcx);
223+
let forrest = global_ty.uninhabited_from_inner(visited, tcx);
222224
let mut cache = tcx.inhabitedness_cache.borrow_mut();
223-
cache.insert(global_ty, node_set.clone());
224-
node_set
225+
cache.insert(global_ty, forrest.clone());
226+
forrest
225227
},
226228
None => {
227-
let node_set = self.uninhabited_from_inner(visited, tcx);
228-
node_set
229+
let forrest = self.uninhabited_from_inner(visited, tcx);
230+
forrest
229231
},
230232
}
231233
}
232234

233235
fn uninhabited_from_inner(
234236
&self,
235237
visited: &mut FxHashSet<(DefId, &'tcx Substs<'tcx>)>,
236-
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> NodeForrest
238+
tcx: TyCtxt<'a, 'gcx, 'tcx>) -> DefIdForrest
237239
{
238240
match self.sty {
239241
TyAdt(def, substs) => {
240242
def.uninhabited_from(visited, tcx, substs)
241243
},
242244

243-
TyNever => NodeForrest::full(),
245+
TyNever => DefIdForrest::full(tcx),
244246
TyTuple(ref tys) => {
245-
NodeForrest::union(tcx, tys.iter().map(|ty| {
247+
DefIdForrest::union(tcx, tys.iter().map(|ty| {
246248
ty.uninhabited_from(visited, tcx)
247249
}))
248250
},
249251
TyArray(ty, len) => {
250252
if len == 0 {
251-
NodeForrest::empty()
253+
DefIdForrest::empty()
252254
} else {
253255
ty.uninhabited_from(visited, tcx)
254256
}
255257
}
256258
TyRef(_, ref tm) => tm.ty.uninhabited_from(visited, tcx),
257259

258-
_ => NodeForrest::empty(),
260+
_ => DefIdForrest::empty(),
259261
}
260262
}
261263
}

0 commit comments

Comments
 (0)