Skip to content

Commit 474fecc

Browse files
committed
Update GenericPredicates queries
1 parent d03c5b9 commit 474fecc

File tree

8 files changed

+55
-49
lines changed

8 files changed

+55
-49
lines changed

src/librustc/ty/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,13 @@ pub struct GenericPredicates<'tcx> {
10301030
pub predicates: Vec<(Predicate<'tcx>, Span)>,
10311031
}
10321032

1033+
unsafe impl<'tcx> DeferDeallocs for GenericPredicates<'tcx> {
1034+
fn defer(&self, deferred: &mut DeferredDeallocs) {
1035+
self.parent.defer(deferred);
1036+
self.predicates.defer(deferred);
1037+
}
1038+
}
1039+
10331040
impl<'tcx> serialize::UseSpecializedEncodable for GenericPredicates<'tcx> {}
10341041
impl<'tcx> serialize::UseSpecializedDecodable for GenericPredicates<'tcx> {}
10351042

@@ -2251,7 +2258,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
22512258
}
22522259

22532260
#[inline]
2254-
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Lrc<GenericPredicates<'gcx>> {
2261+
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Bx<'tcx, GenericPredicates<'gcx>> {
22552262
tcx.predicates_of(self.did)
22562263
}
22572264

src/librustc/ty/query/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,18 @@ define_queries! { <'tcx>
127127
/// predicate gets in the way of some checks, which are intended
128128
/// to operate over only the actual where-clauses written by the
129129
/// user.)
130-
[] fn predicates_of: PredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
130+
[] fn predicates_of: PredicatesOfItem(DefId) -> Bx<'tcx, ty::GenericPredicates<'tcx>>,
131131

132132
/// Maps from the def-id of an item (trait/struct/enum/fn) to the
133133
/// predicates (where clauses) directly defined on it. This is
134134
/// equal to the `explicit_predicates_of` predicates plus the
135135
/// `inferred_outlives_of` predicates.
136136
[] fn predicates_defined_on: PredicatesDefinedOnItem(DefId)
137-
-> Lrc<ty::GenericPredicates<'tcx>>,
137+
-> Bx<'tcx, ty::GenericPredicates<'tcx>>,
138138

139139
/// Returns the predicates written explicit by the user.
140140
[] fn explicit_predicates_of: ExplicitPredicatesOfItem(DefId)
141-
-> Lrc<ty::GenericPredicates<'tcx>>,
141+
-> Bx<'tcx, ty::GenericPredicates<'tcx>>,
142142

143143
/// Returns the inferred outlives predicates (e.g., for `struct
144144
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
@@ -150,12 +150,13 @@ define_queries! { <'tcx>
150150
/// evaluate them even during type conversion, often before the
151151
/// full predicates are available (note that supertraits have
152152
/// additional acyclicity requirements).
153-
[] fn super_predicates_of: SuperPredicatesOfItem(DefId) -> Lrc<ty::GenericPredicates<'tcx>>,
153+
[] fn super_predicates_of: SuperPredicatesOfItem(DefId)
154+
-> Bx<'tcx, ty::GenericPredicates<'tcx>>,
154155

155156
/// To avoid cycles within the predicates of a single item we compute
156157
/// per-type-parameter predicates for resolving `T::AssocTy`.
157158
[] fn type_param_predicates: type_param_predicates((DefId, DefId))
158-
-> Lrc<ty::GenericPredicates<'tcx>>,
159+
-> Bx<'tcx, ty::GenericPredicates<'tcx>>,
159160

160161
[] fn trait_def: TraitDefOfItem(DefId) -> &'tcx ty::TraitDef,
161162
[] fn adt_def: AdtDefOfItem(DefId) -> &'tcx ty::AdtDef,

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
103103
generics_of => {
104104
tcx.alloc_generics(cdata.get_generics(def_id.index, tcx.sess))
105105
}
106-
predicates_of => { Lrc::new(cdata.get_predicates(def_id.index, tcx)) }
107-
predicates_defined_on => { Lrc::new(cdata.get_predicates_defined_on(def_id.index, tcx)) }
108-
super_predicates_of => { Lrc::new(cdata.get_super_predicates(def_id.index, tcx)) }
106+
predicates_of => { tcx.bx(cdata.get_predicates(def_id.index, tcx)) }
107+
predicates_defined_on => { tcx.bx(cdata.get_predicates_defined_on(def_id.index, tcx)) }
108+
super_predicates_of => { tcx.bx(cdata.get_super_predicates(def_id.index, tcx)) }
109109
trait_def => {
110110
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index, tcx.sess))
111111
}

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ use middle::resolve_lifetime as rl;
2121
use namespace::Namespace;
2222
use rustc::ty::subst::{Kind, Subst, Substs};
2323
use rustc::traits;
24-
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
24+
use rustc::ty::{self, Bx, Ty, TyCtxt, ToPredicate, TypeFoldable};
2525
use rustc::ty::{GenericParamDef, GenericParamDefKind};
2626
use rustc::ty::wf::object_region_bounds;
27-
use rustc_data_structures::sync::Lrc;
2827
use rustc_target::spec::abi;
2928
use std::collections::BTreeSet;
3029
use std::slice;
@@ -47,7 +46,7 @@ pub trait AstConv<'gcx, 'tcx> {
4746
/// Returns the set of bounds in scope for the type parameter with
4847
/// the given id.
4948
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId)
50-
-> Lrc<ty::GenericPredicates<'tcx>>;
49+
-> Bx<'tcx, ty::GenericPredicates<'tcx>>;
5150

5251
/// What lifetime should we use when a lifetime is omitted (and not elided)?
5352
fn re_infer(&self, span: Span, _def: Option<&ty::GenericParamDef>)

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ use util::common::{ErrorReported, indenter};
115115
use util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap};
116116

117117
use std::cell::{Cell, RefCell, Ref, RefMut};
118-
use rustc_data_structures::sync::Lrc;
119118
use std::collections::hash_map::Entry;
120119
use std::cmp;
121120
use std::fmt::Display;
@@ -1878,15 +1877,15 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
18781877
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
18791878

18801879
fn get_type_parameter_bounds(&self, _: Span, def_id: DefId)
1881-
-> Lrc<ty::GenericPredicates<'tcx>>
1880+
-> Bx<'tcx, ty::GenericPredicates<'tcx>>
18821881
{
18831882
let tcx = self.tcx;
18841883
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
18851884
let item_id = tcx.hir.ty_param_owner(node_id);
18861885
let item_def_id = tcx.hir.local_def_id(item_id);
18871886
let generics = tcx.generics_of(item_def_id);
18881887
let index = generics.param_def_id_to_index[&def_id];
1889-
Lrc::new(ty::GenericPredicates {
1888+
tcx.bx(ty::GenericPredicates {
18901889
parent: None,
18911890
predicates: self.param_env.caller_bounds.iter().filter_map(|&predicate| {
18921891
match predicate {

src/librustc_typeck/collect.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ use rustc::ty::query::Providers;
3535
use rustc::ty::subst::Substs;
3636
use rustc::ty::util::Discr;
3737
use rustc::ty::util::IntTypeExt;
38-
use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
38+
use rustc::ty::{self, Bx, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
3939
use rustc::ty::{ReprOptions, ToPredicate};
4040
use rustc::util::captures::Captures;
4141
use rustc::util::nodemap::FxHashMap;
42-
use rustc_data_structures::sync::Lrc;
4342
use rustc_target::spec::abi;
4443

4544
use syntax::ast;
@@ -180,7 +179,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
180179
}
181180

182181
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId)
183-
-> Lrc<ty::GenericPredicates<'tcx>> {
182+
-> Bx<'tcx, ty::GenericPredicates<'tcx>> {
184183
self.tcx
185184
.at(span)
186185
.type_param_predicates((self.item_def_id, def_id))
@@ -245,7 +244,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
245244
fn type_param_predicates<'a, 'tcx>(
246245
tcx: TyCtxt<'a, 'tcx, 'tcx>,
247246
(item_def_id, def_id): (DefId, DefId),
248-
) -> Lrc<ty::GenericPredicates<'tcx>> {
247+
) -> Bx<'tcx, ty::GenericPredicates<'tcx>> {
249248
use rustc::hir::*;
250249

251250
// In the AST, bounds can derive from two places. Either
@@ -266,8 +265,8 @@ fn type_param_predicates<'a, 'tcx>(
266265
tcx.generics_of(item_def_id).parent
267266
};
268267

269-
let mut result = parent.map_or_else(
270-
|| Lrc::new(ty::GenericPredicates {
268+
let result = parent.map_or_else(
269+
|| tcx.bx(ty::GenericPredicates {
271270
parent: None,
272271
predicates: vec![],
273272
}),
@@ -276,6 +275,7 @@ fn type_param_predicates<'a, 'tcx>(
276275
icx.get_type_parameter_bounds(DUMMY_SP, def_id)
277276
},
278277
);
278+
let mut extend = None;
279279

280280
let item_node_id = tcx.hir.as_local_node_id(item_def_id).unwrap();
281281
let ast_generics = match tcx.hir.get(item_node_id) {
@@ -300,9 +300,7 @@ fn type_param_predicates<'a, 'tcx>(
300300
// Implied `Self: Trait` and supertrait bounds.
301301
if param_id == item_node_id {
302302
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id);
303-
Lrc::make_mut(&mut result)
304-
.predicates
305-
.push((identity_trait_ref.to_predicate(), item.span));
303+
extend = Some((identity_trait_ref.to_predicate(), item.span));
306304
}
307305
generics
308306
}
@@ -319,11 +317,12 @@ fn type_param_predicates<'a, 'tcx>(
319317
};
320318

321319
let icx = ItemCtxt::new(tcx, item_def_id);
322-
Lrc::make_mut(&mut result)
323-
.predicates
324-
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
325-
OnlySelfBounds(true)));
326-
result
320+
let mut result = (*result).clone();
321+
result.predicates.extend(extend.into_iter());
322+
result.predicates
323+
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
324+
OnlySelfBounds(true)));
325+
tcx.bx(result)
327326
}
328327

329328
impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
@@ -687,7 +686,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
687686
fn super_predicates_of<'a, 'tcx>(
688687
tcx: TyCtxt<'a, 'tcx, 'tcx>,
689688
trait_def_id: DefId,
690-
) -> Lrc<ty::GenericPredicates<'tcx>> {
689+
) -> Bx<'tcx, ty::GenericPredicates<'tcx>> {
691690
debug!("super_predicates(trait_def_id={:?})", trait_def_id);
692691
let trait_node_id = tcx.hir.as_local_node_id(trait_def_id).unwrap();
693692

@@ -731,7 +730,7 @@ fn super_predicates_of<'a, 'tcx>(
731730
}
732731
}
733732

734-
Lrc::new(ty::GenericPredicates {
733+
tcx.bx(ty::GenericPredicates {
735734
parent: None,
736735
predicates: superbounds,
737736
})
@@ -1607,9 +1606,9 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
16071606
fn predicates_defined_on<'a, 'tcx>(
16081607
tcx: TyCtxt<'a, 'tcx, 'tcx>,
16091608
def_id: DefId,
1610-
) -> Lrc<ty::GenericPredicates<'tcx>> {
1609+
) -> Bx<'tcx, ty::GenericPredicates<'tcx>> {
16111610
debug!("predicates_defined_on({:?})", def_id);
1612-
let mut result = tcx.explicit_predicates_of(def_id);
1611+
let result = tcx.explicit_predicates_of(def_id);
16131612
debug!(
16141613
"predicates_defined_on: explicit_predicates_of({:?}) = {:?}",
16151614
def_id,
@@ -1623,18 +1622,19 @@ fn predicates_defined_on<'a, 'tcx>(
16231622
def_id,
16241623
inferred_outlives,
16251624
);
1626-
Lrc::make_mut(&mut result)
1627-
.predicates
1628-
.extend(inferred_outlives.iter().map(|&p| (p, span)));
1625+
let mut result = (*result).clone();
1626+
result.predicates.extend(inferred_outlives.iter().map(|&p| (p, span)));
1627+
tcx.bx(result)
1628+
} else {
1629+
result
16291630
}
1630-
result
16311631
}
16321632

16331633
fn predicates_of<'a, 'tcx>(
16341634
tcx: TyCtxt<'a, 'tcx, 'tcx>,
16351635
def_id: DefId,
1636-
) -> Lrc<ty::GenericPredicates<'tcx>> {
1637-
let mut result = tcx.predicates_defined_on(def_id);
1636+
) -> Bx<'tcx, ty::GenericPredicates<'tcx>> {
1637+
let result = tcx.predicates_defined_on(def_id);
16381638

16391639
if tcx.is_trait(def_id) {
16401640
// For traits, add `Self: Trait` predicate. This is
@@ -1650,17 +1650,18 @@ fn predicates_of<'a, 'tcx>(
16501650
// used, and adding the predicate into this list ensures
16511651
// that this is done.
16521652
let span = tcx.def_span(def_id);
1653-
Lrc::make_mut(&mut result)
1654-
.predicates
1655-
.push((ty::TraitRef::identity(tcx, def_id).to_predicate(), span));
1653+
let mut result = (*result).clone();
1654+
result.predicates.push((ty::TraitRef::identity(tcx, def_id).to_predicate(), span));
1655+
tcx.bx(result)
1656+
} else {
1657+
result
16561658
}
1657-
result
16581659
}
16591660

16601661
fn explicit_predicates_of<'a, 'tcx>(
16611662
tcx: TyCtxt<'a, 'tcx, 'tcx>,
16621663
def_id: DefId,
1663-
) -> Lrc<ty::GenericPredicates<'tcx>> {
1664+
) -> Bx<'tcx, ty::GenericPredicates<'tcx>> {
16641665
use rustc::hir::*;
16651666
use rustc_data_structures::fx::FxHashSet;
16661667

@@ -1771,7 +1772,7 @@ fn explicit_predicates_of<'a, 'tcx>(
17711772

17721773
if impl_trait_fn.is_some() {
17731774
// impl Trait
1774-
return Lrc::new(ty::GenericPredicates {
1775+
return tcx.bx(ty::GenericPredicates {
17751776
parent: None,
17761777
predicates: bounds.predicates(tcx, opaque_ty),
17771778
});
@@ -1981,7 +1982,7 @@ fn explicit_predicates_of<'a, 'tcx>(
19811982
);
19821983
}
19831984

1984-
Lrc::new(ty::GenericPredicates {
1985+
tcx.bx(ty::GenericPredicates {
19851986
parent: generics.parent,
19861987
predicates,
19871988
})

src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
151151
// Instead, we generate `impl !Send for Foo<T>`, which better
152152
// expresses the fact that `Foo<T>` never implements `Send`,
153153
// regardless of the choice of `T`.
154-
let real_generics = (&generics, &Default::default());
154+
let real_generics = (&generics, &self.cx.tcx.bx(Default::default()));
155155

156156
// Clean the generics, but ignore the '?Sized' bounds generated
157157
// by the `Clean` impl

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use std::hash::{Hash, Hasher};
5151
use std::default::Default;
5252
use std::{mem, slice, vec};
5353
use std::iter::{FromIterator, once};
54-
use rustc_data_structures::sync::Lrc;
5554
use std::rc::Rc;
5655
use std::str::FromStr;
5756
use std::cell::RefCell;
@@ -1563,7 +1562,7 @@ impl Clean<Generics> for hir::Generics {
15631562
}
15641563

15651564
impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1566-
&'a Lrc<ty::GenericPredicates<'tcx>>) {
1565+
&'a Bx<'tcx, ty::GenericPredicates<'tcx>>) {
15671566
fn clean(&self, cx: &DocContext) -> Generics {
15681567
use self::WherePredicate as WP;
15691568

0 commit comments

Comments
 (0)