Skip to content

Commit ae8975c

Browse files
committed
Update GenericPredicates queries
1 parent ba5d9c0 commit ae8975c

File tree

11 files changed

+64
-55
lines changed

11 files changed

+64
-55
lines changed

src/librustc/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ macro_rules! arena_types {
6868
>
6969
>,
7070
[few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes,
71+
[decode] generic_predicates: rustc::ty::GenericPredicates<'tcx>,
7172
], $tcx);
7273
)
7374
}

src/librustc/query/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ rustc_queries! {
6161
/// predicate gets in the way of some checks, which are intended
6262
/// to operate over only the actual where-clauses written by the
6363
/// user.)
64-
query predicates_of(_: DefId) -> Lrc<ty::GenericPredicates<'tcx>> {}
64+
query predicates_of(_: DefId) -> &'tcx ty::GenericPredicates<'tcx> {}
6565

6666
query native_libraries(_: CrateNum) -> Lrc<Vec<NativeLibrary>> {
6767
desc { "looking up the native libraries of a linked crate" }
@@ -166,11 +166,11 @@ rustc_queries! {
166166
/// equal to the `explicit_predicates_of` predicates plus the
167167
/// `inferred_outlives_of` predicates.
168168
query predicates_defined_on(_: DefId)
169-
-> Lrc<ty::GenericPredicates<'tcx>> {}
169+
-> &'tcx ty::GenericPredicates<'tcx> {}
170170

171171
/// Returns the predicates written explicitly by the user.
172172
query explicit_predicates_of(_: DefId)
173-
-> Lrc<ty::GenericPredicates<'tcx>> {}
173+
-> &'tcx ty::GenericPredicates<'tcx> {}
174174

175175
/// Returns the inferred outlives predicates (e.g., for `struct
176176
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
@@ -182,14 +182,14 @@ rustc_queries! {
182182
/// evaluate them even during type conversion, often before the
183183
/// full predicates are available (note that supertraits have
184184
/// additional acyclicity requirements).
185-
query super_predicates_of(key: DefId) -> Lrc<ty::GenericPredicates<'tcx>> {
185+
query super_predicates_of(key: DefId) -> &'tcx ty::GenericPredicates<'tcx> {
186186
desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) }
187187
}
188188

189189
/// To avoid cycles within the predicates of a single item we compute
190190
/// per-type-parameter predicates for resolving `T::AssocTy`.
191191
query type_param_predicates(key: (DefId, DefId))
192-
-> Lrc<ty::GenericPredicates<'tcx>> {
192+
-> &'tcx ty::GenericPredicates<'tcx> {
193193
no_force
194194
desc { |tcx| "computing the bounds for type parameter `{}`", {
195195
let id = tcx.hir().as_local_hir_id(key.1).unwrap();

src/librustc/ty/context.rs

+14
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
201201
}
202202
}
203203

204+
pub struct Common<'tcx> {
205+
pub empty_predicates: ty::GenericPredicates<'tcx>,
206+
}
207+
204208
pub struct CommonTypes<'tcx> {
205209
pub unit: Ty<'tcx>,
206210
pub bool: Ty<'tcx>,
@@ -1045,6 +1049,9 @@ pub struct GlobalCtxt<'tcx> {
10451049

10461050
pub dep_graph: DepGraph,
10471051

1052+
/// Common objects.
1053+
pub common: Common<'tcx>,
1054+
10481055
/// Common types, pre-interned for your convenience.
10491056
pub types: CommonTypes<'tcx>,
10501057

@@ -1252,6 +1259,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12521259
s.fatal(&err);
12531260
});
12541261
let interners = CtxtInterners::new(&arenas.interner);
1262+
let common = Common {
1263+
empty_predicates: ty::GenericPredicates {
1264+
parent: None,
1265+
predicates: vec![],
1266+
},
1267+
};
12551268
let common_types = CommonTypes::new(&interners);
12561269
let common_lifetimes = CommonLifetimes::new(&interners);
12571270
let common_consts = CommonConsts::new(&interners, &common_types);
@@ -1308,6 +1321,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13081321
global_arenas: &arenas.global,
13091322
global_interners: interners,
13101323
dep_graph,
1324+
common,
13111325
types: common_types,
13121326
lifetimes: common_lifetimes,
13131327
consts: common_consts,

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
22982298
}
22992299

23002300
#[inline]
2301-
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Lrc<GenericPredicates<'gcx>> {
2301+
pub fn predicates(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> &'tcx GenericPredicates<'gcx> {
23022302
tcx.predicates_of(self.did)
23032303
}
23042304

src/librustc_metadata/cstore_impl.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ provide! { <'tcx> tcx, def_id, other, cdata,
9696
generics_of => {
9797
tcx.alloc_generics(cdata.get_generics(def_id.index, tcx.sess))
9898
}
99-
predicates_of => { Lrc::new(cdata.get_predicates(def_id.index, tcx)) }
100-
predicates_defined_on => { Lrc::new(cdata.get_predicates_defined_on(def_id.index, tcx)) }
101-
super_predicates_of => { Lrc::new(cdata.get_super_predicates(def_id.index, tcx)) }
99+
predicates_of => { tcx.arena.alloc(cdata.get_predicates(def_id.index, tcx)) }
100+
predicates_defined_on => {
101+
tcx.arena.alloc(cdata.get_predicates_defined_on(def_id.index, tcx))
102+
}
103+
super_predicates_of => { tcx.arena.alloc(cdata.get_super_predicates(def_id.index, tcx)) }
102104
trait_def => {
103105
tcx.alloc_trait_def(cdata.get_trait_def(def_id.index, tcx.sess))
104106
}

src/librustc_privacy/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ trait DefIdVisitor<'a, 'tcx: 'a> {
6767
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> bool {
6868
self.skeleton().visit_trait(trait_ref)
6969
}
70-
fn visit_predicates(&mut self, predicates: Lrc<ty::GenericPredicates<'tcx>>) -> bool {
70+
fn visit_predicates(&mut self, predicates: &ty::GenericPredicates<'tcx>) -> bool {
7171
self.skeleton().visit_predicates(predicates)
7272
}
7373
}
@@ -89,8 +89,8 @@ impl<'a, 'tcx, V> DefIdVisitorSkeleton<'_, 'a, 'tcx, V>
8989
(!self.def_id_visitor.shallow() && substs.visit_with(self))
9090
}
9191

92-
fn visit_predicates(&mut self, predicates: Lrc<ty::GenericPredicates<'tcx>>) -> bool {
93-
let ty::GenericPredicates { parent: _, predicates } = &*predicates;
92+
fn visit_predicates(&mut self, predicates: &ty::GenericPredicates<'tcx>) -> bool {
93+
let ty::GenericPredicates { parent: _, predicates } = predicates;
9494
for (predicate, _span) in predicates {
9595
match predicate {
9696
ty::Predicate::Trait(poly_predicate) => {

src/librustc_typeck/astconv.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc::ty::{GenericParamDef, GenericParamDefKind};
1717
use rustc::ty::subst::{Kind, Subst, InternalSubsts, SubstsRef};
1818
use rustc::ty::wf::object_region_bounds;
1919
use rustc::mir::interpret::ConstValue;
20-
use rustc_data_structures::sync::Lrc;
2120
use rustc_target::spec::abi;
2221
use crate::require_c_abi_if_c_variadic;
2322
use smallvec::SmallVec;
@@ -46,7 +45,7 @@ pub trait AstConv<'gcx, 'tcx> {
4645
/// Returns the set of bounds in scope for the type parameter with
4746
/// the given id.
4847
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId)
49-
-> Lrc<ty::GenericPredicates<'tcx>>;
48+
-> &'tcx ty::GenericPredicates<'tcx>;
5049

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

src/librustc_typeck/check/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ use crate::namespace::Namespace;
9797
use rustc::infer::{self, InferCtxt, InferOk, InferResult};
9898
use rustc::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
9999
use rustc_data_structures::indexed_vec::Idx;
100-
use rustc_data_structures::sync::Lrc;
101100
use rustc_target::spec::abi::Abi;
102101
use rustc::infer::opaque_types::OpaqueTypeDecl;
103102
use rustc::infer::type_variable::{TypeVariableOrigin};
@@ -1907,15 +1906,15 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
19071906
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
19081907

19091908
fn get_type_parameter_bounds(&self, _: Span, def_id: DefId)
1910-
-> Lrc<ty::GenericPredicates<'tcx>>
1909+
-> &'tcx ty::GenericPredicates<'tcx>
19111910
{
19121911
let tcx = self.tcx;
19131912
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
19141913
let item_id = tcx.hir().ty_param_owner(hir_id);
19151914
let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id);
19161915
let generics = tcx.generics_of(item_def_id);
19171916
let index = generics.param_def_id_to_index[&def_id];
1918-
Lrc::new(ty::GenericPredicates {
1917+
tcx.arena.alloc(ty::GenericPredicates {
19191918
parent: None,
19201919
predicates: self.param_env.caller_bounds.iter().filter_map(|&predicate| {
19211920
match predicate {

src/librustc_typeck/collect.rs

+27-34
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use rustc::ty::{self, AdtKind, ToPolyTraitRef, Ty, TyCtxt};
3131
use rustc::ty::{ReprOptions, ToPredicate};
3232
use rustc::util::captures::Captures;
3333
use rustc::util::nodemap::FxHashMap;
34-
use rustc_data_structures::sync::Lrc;
3534
use rustc_target::spec::abi;
3635

3736
use syntax::ast;
@@ -178,7 +177,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
178177
}
179178

180179
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId)
181-
-> Lrc<ty::GenericPredicates<'tcx>> {
180+
-> &'tcx ty::GenericPredicates<'tcx> {
182181
self.tcx
183182
.at(span)
184183
.type_param_predicates((self.item_def_id, def_id))
@@ -243,7 +242,7 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
243242
fn type_param_predicates<'a, 'tcx>(
244243
tcx: TyCtxt<'a, 'tcx, 'tcx>,
245244
(item_def_id, def_id): (DefId, DefId),
246-
) -> Lrc<ty::GenericPredicates<'tcx>> {
245+
) -> &'tcx ty::GenericPredicates<'tcx> {
247246
use rustc::hir::*;
248247

249248
// In the AST, bounds can derive from two places. Either
@@ -264,16 +263,11 @@ fn type_param_predicates<'a, 'tcx>(
264263
tcx.generics_of(item_def_id).parent
265264
};
266265

267-
let mut result = parent.map_or_else(
268-
|| Lrc::new(ty::GenericPredicates {
269-
parent: None,
270-
predicates: vec![],
271-
}),
272-
|parent| {
273-
let icx = ItemCtxt::new(tcx, parent);
274-
icx.get_type_parameter_bounds(DUMMY_SP, def_id)
275-
},
276-
);
266+
let result = parent.map_or(&tcx.common.empty_predicates, |parent| {
267+
let icx = ItemCtxt::new(tcx, parent);
268+
icx.get_type_parameter_bounds(DUMMY_SP, def_id)
269+
});
270+
let mut extend = None;
277271

278272
let item_hir_id = tcx.hir().as_local_hir_id(item_def_id).unwrap();
279273
let ast_generics = match tcx.hir().get_by_hir_id(item_hir_id) {
@@ -298,9 +292,7 @@ fn type_param_predicates<'a, 'tcx>(
298292
// Implied `Self: Trait` and supertrait bounds.
299293
if param_id == item_hir_id {
300294
let identity_trait_ref = ty::TraitRef::identity(tcx, item_def_id);
301-
Lrc::make_mut(&mut result)
302-
.predicates
303-
.push((identity_trait_ref.to_predicate(), item.span));
295+
extend = Some((identity_trait_ref.to_predicate(), item.span));
304296
}
305297
generics
306298
}
@@ -317,11 +309,12 @@ fn type_param_predicates<'a, 'tcx>(
317309
};
318310

319311
let icx = ItemCtxt::new(tcx, item_def_id);
320-
Lrc::make_mut(&mut result)
321-
.predicates
322-
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
323-
OnlySelfBounds(true)));
324-
result
312+
let mut result = (*result).clone();
313+
result.predicates.extend(extend.into_iter());
314+
result.predicates
315+
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
316+
OnlySelfBounds(true)));
317+
tcx.arena.alloc(result)
325318
}
326319

327320
impl<'a, 'tcx> ItemCtxt<'a, 'tcx> {
@@ -690,7 +683,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
690683
fn super_predicates_of<'a, 'tcx>(
691684
tcx: TyCtxt<'a, 'tcx, 'tcx>,
692685
trait_def_id: DefId,
693-
) -> Lrc<ty::GenericPredicates<'tcx>> {
686+
) -> &'tcx ty::GenericPredicates<'tcx> {
694687
debug!("super_predicates(trait_def_id={:?})", trait_def_id);
695688
let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id).unwrap();
696689

@@ -734,7 +727,7 @@ fn super_predicates_of<'a, 'tcx>(
734727
}
735728
}
736729

737-
Lrc::new(ty::GenericPredicates {
730+
tcx.arena.alloc(ty::GenericPredicates {
738731
parent: None,
739732
predicates: superbounds,
740733
})
@@ -1842,7 +1835,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
18421835
fn predicates_defined_on<'a, 'tcx>(
18431836
tcx: TyCtxt<'a, 'tcx, 'tcx>,
18441837
def_id: DefId,
1845-
) -> Lrc<ty::GenericPredicates<'tcx>> {
1838+
) -> &'tcx ty::GenericPredicates<'tcx> {
18461839
debug!("predicates_defined_on({:?})", def_id);
18471840
let mut result = tcx.explicit_predicates_of(def_id);
18481841
debug!(
@@ -1858,9 +1851,9 @@ fn predicates_defined_on<'a, 'tcx>(
18581851
def_id,
18591852
inferred_outlives,
18601853
);
1861-
Lrc::make_mut(&mut result)
1862-
.predicates
1863-
.extend(inferred_outlives.iter().map(|&p| (p, span)));
1854+
let mut predicates = (*result).clone();
1855+
predicates.predicates.extend(inferred_outlives.iter().map(|&p| (p, span)));
1856+
result = tcx.arena.alloc(predicates);
18641857
}
18651858
debug!("predicates_defined_on({:?}) = {:?}", def_id, result);
18661859
result
@@ -1872,7 +1865,7 @@ fn predicates_defined_on<'a, 'tcx>(
18721865
fn predicates_of<'a, 'tcx>(
18731866
tcx: TyCtxt<'a, 'tcx, 'tcx>,
18741867
def_id: DefId,
1875-
) -> Lrc<ty::GenericPredicates<'tcx>> {
1868+
) -> &'tcx ty::GenericPredicates<'tcx> {
18761869
let mut result = tcx.predicates_defined_on(def_id);
18771870

18781871
if tcx.is_trait(def_id) {
@@ -1889,9 +1882,9 @@ fn predicates_of<'a, 'tcx>(
18891882
// used, and adding the predicate into this list ensures
18901883
// that this is done.
18911884
let span = tcx.def_span(def_id);
1892-
Lrc::make_mut(&mut result)
1893-
.predicates
1894-
.push((ty::TraitRef::identity(tcx, def_id).to_predicate(), span));
1885+
let mut predicates = (*result).clone();
1886+
predicates.predicates.push((ty::TraitRef::identity(tcx, def_id).to_predicate(), span));
1887+
result = tcx.arena.alloc(predicates);
18951888
}
18961889
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
18971890
result
@@ -1902,7 +1895,7 @@ fn predicates_of<'a, 'tcx>(
19021895
fn explicit_predicates_of<'a, 'tcx>(
19031896
tcx: TyCtxt<'a, 'tcx, 'tcx>,
19041897
def_id: DefId,
1905-
) -> Lrc<ty::GenericPredicates<'tcx>> {
1898+
) -> &'tcx ty::GenericPredicates<'tcx> {
19061899
use rustc::hir::*;
19071900
use rustc_data_structures::fx::FxHashSet;
19081901

@@ -2017,7 +2010,7 @@ fn explicit_predicates_of<'a, 'tcx>(
20172010

20182011
if impl_trait_fn.is_some() {
20192012
// impl Trait
2020-
return Lrc::new(ty::GenericPredicates {
2013+
return tcx.arena.alloc(ty::GenericPredicates {
20212014
parent: None,
20222015
predicates: bounds.predicates(tcx, opaque_ty),
20232016
});
@@ -2228,7 +2221,7 @@ fn explicit_predicates_of<'a, 'tcx>(
22282221
);
22292222
}
22302223

2231-
let result = Lrc::new(ty::GenericPredicates {
2224+
let result = tcx.arena.alloc(ty::GenericPredicates {
22322225
parent: generics.parent,
22332226
predicates,
22342227
});

src/librustdoc/clean/auto_trait.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
104104
// Instead, we generate `impl !Send for Foo<T>`, which better
105105
// expresses the fact that `Foo<T>` never implements `Send`,
106106
// regardless of the choice of `T`.
107-
let params = (self.cx.tcx.generics_of(param_env_def_id), &Default::default())
108-
.clean(self.cx).params;
107+
let params = (
108+
self.cx.tcx.generics_of(param_env_def_id),
109+
&&self.cx.tcx.common.empty_predicates,
110+
).clean(self.cx).params;
109111

110112
Generics {
111113
params,

src/librustdoc/clean/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod auto_trait;
1010
mod blanket_impl;
1111

1212
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
13-
use rustc_data_structures::sync::Lrc;
1413
use rustc_target::spec::abi::Abi;
1514
use rustc_typeck::hir_ty_to_ty;
1615
use rustc::infer::region_constraints::{RegionConstraintData, Constraint};
@@ -1687,7 +1686,7 @@ impl Clean<Generics> for hir::Generics {
16871686
}
16881687

16891688
impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1690-
&'a Lrc<ty::GenericPredicates<'tcx>>) {
1689+
&'a &'tcx ty::GenericPredicates<'tcx>) {
16911690
fn clean(&self, cx: &DocContext<'_>) -> Generics {
16921691
use self::WherePredicate as WP;
16931692

0 commit comments

Comments
 (0)