Skip to content

Commit fe90d37

Browse files
committed
Update inferred_outlives_of
1 parent 0df7b25 commit fe90d37

File tree

9 files changed

+30
-29
lines changed

9 files changed

+30
-29
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,7 @@ dependencies = [
19411941
"rustc_data_structures 0.0.0",
19421942
"rustc_errors 0.0.0",
19431943
"rustc_fs_util 0.0.0",
1944+
"rustc_local_drop_derive 0.1.0",
19441945
"rustc_target 0.0.0",
19451946
"scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
19461947
"serialize 0.0.0",

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rustc-rayon = "0.1.1"
2222
rustc-rayon-core = "0.1.1"
2323
rustc_apfloat = { path = "../librustc_apfloat" }
2424
rustc_target = { path = "../librustc_target" }
25+
rustc_local_drop_derive = { path = "../librustc_local_drop_derive" }
2526
rustc_data_structures = { path = "../librustc_data_structures" }
2627
rustc_errors = { path = "../librustc_errors" }
2728
serialize = { path = "../libserialize" }

src/librustc/hir/def_id.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ use std::u32;
1717

1818
newtype_index! {
1919
pub struct CrateId {
20+
derive [LocalDrop]
2021
ENCODABLE = custom
2122
}
2223
}
2324

24-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
25+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, LocalDrop)]
2526
pub enum CrateNum {
2627
/// Virtual crate for builtin macros
2728
// FIXME(jseyfried): this is also used for custom derives until proc-macro crates get
@@ -124,7 +125,7 @@ impl serialize::UseSpecializedDecodable for CrateNum {}
124125
/// Since the DefIndex is mostly treated as an opaque ID, you probably
125126
/// don't have to care about these address spaces.
126127
127-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
128+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, LocalDrop)]
128129
pub struct DefIndex(u32);
129130

130131
/// The crate root is always assigned index 0 by the AST Map code,
@@ -217,7 +218,7 @@ impl DefIndexAddressSpace {
217218

218219
/// A `DefId` identifies a particular *definition*, by combining a crate
219220
/// index and a def index.
220-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
221+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, LocalDrop)]
221222
pub struct DefId {
222223
pub krate: CrateNum,
223224
pub index: DefIndex,

src/librustc/ich/impls_ty.rs

-2
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,6 @@ impl_stable_hash_for!(struct ty::CrateVariancesMap {
855855

856856
impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
857857
predicates,
858-
// This is just an irrelevant helper value.
859-
empty_predicate -> _,
860858
});
861859

862860
impl_stable_hash_for!(struct ty::AssociatedItem {

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ extern crate graphviz;
8686
extern crate libc;
8787
extern crate polonius_engine;
8888
extern crate rustc_target;
89+
#[macro_use] extern crate rustc_local_drop_derive;
8990
#[macro_use] extern crate rustc_data_structures;
9091
extern crate serialize;
9192
extern crate parking_lot;

src/librustc/ty/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
10521052
}
10531053
}
10541054

1055-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
1055+
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, LocalDrop)]
10561056
pub enum Predicate<'tcx> {
10571057
/// Corresponds to `where Foo: Bar<A,B,C>`. `Foo` here would be
10581058
/// the `Self` type of the trait reference and `A`, `B`, and `C`
@@ -1097,10 +1097,7 @@ pub struct CratePredicatesMap<'tcx> {
10971097
/// For each struct with outlive bounds, maps to a vector of the
10981098
/// predicate of its outlive bounds. If an item has no outlives
10991099
/// bounds, it will have no entry.
1100-
pub predicates: FxHashMap<DefId, Lrc<Vec<ty::Predicate<'tcx>>>>,
1101-
1102-
/// An empty vector, useful for cloning.
1103-
pub empty_predicate: Lrc<Vec<ty::Predicate<'tcx>>>,
1100+
pub predicates: FxHashMap<DefId, &'tcx [ty::Predicate<'tcx>]>,
11041101
}
11051102

11061103
impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> {
@@ -1203,7 +1200,7 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
12031200
}
12041201
}
12051202

1206-
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
1203+
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, LocalDrop)]
12071204
pub struct TraitPredicate<'tcx> {
12081205
pub trait_ref: TraitRef<'tcx>
12091206
}
@@ -1231,7 +1228,8 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
12311228
}
12321229
}
12331230

1234-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
1231+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, LocalDrop,
1232+
Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
12351233
pub struct OutlivesPredicate<A,B>(pub A, pub B); // `A: B`
12361234
pub type PolyOutlivesPredicate<A,B> = ty::Binder<OutlivesPredicate<A,B>>;
12371235
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>,
@@ -1241,7 +1239,7 @@ pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>,
12411239
pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder<RegionOutlivesPredicate<'tcx>>;
12421240
pub type PolyTypeOutlivesPredicate<'tcx> = ty::Binder<TypeOutlivesPredicate<'tcx>>;
12431241

1244-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
1242+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, LocalDrop)]
12451243
pub struct SubtypePredicate<'tcx> {
12461244
pub a_is_expected: bool,
12471245
pub a: Ty<'tcx>,
@@ -1261,7 +1259,7 @@ pub type PolySubtypePredicate<'tcx> = ty::Binder<SubtypePredicate<'tcx>>;
12611259
/// equality between arbitrary types. Processing an instance of
12621260
/// Form #2 eventually yields one of these `ProjectionPredicate`
12631261
/// instances to normalize the LHS.
1264-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
1262+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, LocalDrop)]
12651263
pub struct ProjectionPredicate<'tcx> {
12661264
pub projection_ty: ProjectionTy<'tcx>,
12671265
pub ty: Ty<'tcx>,
@@ -2477,7 +2475,8 @@ impl<'a, 'gcx, 'tcx> FieldDef {
24772475
///
24782476
/// You can get the environment type of a closure using
24792477
/// `tcx.closure_env_ty()`.
2480-
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
2478+
#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, LocalDrop,
2479+
Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
24812480
pub enum ClosureKind {
24822481
// Warning: Ordering is significant here! The ordering is chosen
24832482
// because the trait Fn is a subtrait of FnMut and so in turn, and

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ define_queries! { <'tcx>
142142

143143
/// Returns the inferred outlives predicates (e.g., for `struct
144144
/// Foo<'a, T> { x: &'a T }`, this would return `T: 'a`).
145-
[] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> Lrc<Vec<ty::Predicate<'tcx>>>,
145+
[] fn inferred_outlives_of: InferredOutlivesOf(DefId) -> &'tcx [ty::Predicate<'tcx>],
146146

147147
/// Maps from the def-id of a trait to the list of
148148
/// super-predicates. This is a subset of the full list of

src/librustc/ty/sty.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ static_assert!(MEM_SIZE_OF_TY_KIND: ::std::mem::size_of::<TyKind<'_>>() == 24);
313313
///
314314
/// It'd be nice to split this struct into ClosureSubsts and
315315
/// GeneratorSubsts, I believe. -nmatsakis
316-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
316+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd,
317+
Ord, Hash, Debug, RustcEncodable, RustcDecodable, LocalDrop)]
317318
pub struct ClosureSubsts<'tcx> {
318319
/// Lifetime and type parameters from the enclosing function,
319320
/// concatenated with the types of the upvars.
@@ -647,7 +648,7 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
647648
/// Note that a `TraitRef` introduces a level of region binding, to
648649
/// account for higher-ranked trait bounds like `T: for<'a> Foo<&'a U>`
649650
/// or higher-ranked object types.
650-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
651+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, LocalDrop)]
651652
pub struct TraitRef<'tcx> {
652653
pub def_id: DefId,
653654
pub substs: &'tcx Substs<'tcx>,
@@ -785,7 +786,8 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
785786
/// erase, or otherwise "discharge" these bound vars, we change the
786787
/// type from `Binder<T>` to just `T` (see
787788
/// e.g. `liberate_late_bound_regions`).
788-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
789+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
790+
Debug, RustcEncodable, RustcDecodable, LocalDrop)]
789791
pub struct Binder<T>(T);
790792

791793
impl<T> Binder<T> {
@@ -890,7 +892,8 @@ impl<T> Binder<T> {
890892

891893
/// Represents the projection of an associated type. In explicit UFCS
892894
/// form this would be written `<T as Trait<..>>::N`.
893-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
895+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, LocalDrop,
896+
Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
894897
pub struct ProjectionTy<'tcx> {
895898
/// The parameters of the associated item.
896899
pub substs: &'tcx Substs<'tcx>,

src/librustc_typeck/outlives/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn provide(providers: &mut Providers) {
3333
fn inferred_outlives_of<'a, 'tcx>(
3434
tcx: TyCtxt<'a, 'tcx, 'tcx>,
3535
item_def_id: DefId,
36-
) -> Lrc<Vec<ty::Predicate<'tcx>>> {
36+
) -> &'tcx [ty::Predicate<'tcx>] {
3737
let id = tcx
3838
.hir
3939
.as_local_node_id(item_def_id)
@@ -47,8 +47,8 @@ fn inferred_outlives_of<'a, 'tcx>(
4747
let predicates = crate_map
4848
.predicates
4949
.get(&item_def_id)
50-
.unwrap_or(&crate_map.empty_predicate)
51-
.clone();
50+
.map(|p| *p)
51+
.unwrap_or(&[]);
5252

5353
if tcx.has_attr(item_def_id, "rustc_outlives") {
5454
let mut pred: Vec<String> = predicates
@@ -73,10 +73,10 @@ fn inferred_outlives_of<'a, 'tcx>(
7373
predicates
7474
}
7575

76-
_ => Lrc::new(Vec::new()),
76+
_ => &[],
7777
},
7878

79-
_ => Lrc::new(Vec::new()),
79+
_ => &[],
8080
}
8181
}
8282

@@ -118,13 +118,10 @@ fn inferred_outlives_crate<'tcx>(
118118
),
119119
},
120120
).collect();
121-
(def_id, Lrc::new(vec))
121+
(def_id, tcx.promote_vec(vec))
122122
}).collect();
123123

124-
let empty_predicate = Lrc::new(Vec::new());
125-
126124
Lrc::new(ty::CratePredicatesMap {
127125
predicates,
128-
empty_predicate,
129126
})
130127
}

0 commit comments

Comments
 (0)