Skip to content

Commit

Permalink
Update inferred_outlives_of
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Apr 24, 2019
1 parent e305df1 commit 5d67618
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Expand Up @@ -174,7 +174,7 @@ rustc_queries! {

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

/// Maps from the `DefId` of a trait to the list of
/// super-predicates. This is a subset of the full list of
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/ty/mod.rs
Expand Up @@ -1118,11 +1118,7 @@ pub struct CratePredicatesMap<'tcx> {
/// For each struct with outlive bounds, maps to a vector of the
/// predicate of its outlive bounds. If an item has no outlives
/// bounds, it will have no entry.
pub predicates: FxHashMap<DefId, Lrc<Vec<ty::Predicate<'tcx>>>>,

/// An empty vector, useful for cloning.
#[stable_hasher(ignore)]
pub empty_predicate: Lrc<Vec<ty::Predicate<'tcx>>>,
pub predicates: FxHashMap<DefId, &'tcx [ty::Predicate<'tcx>]>,
}

impl<'tcx> AsRef<Predicate<'tcx>> for Predicate<'tcx> {
Expand Down
19 changes: 8 additions & 11 deletions src/librustc_typeck/outlives/mod.rs
Expand Up @@ -23,7 +23,7 @@ pub fn provide(providers: &mut Providers<'_>) {
fn inferred_outlives_of<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
item_def_id: DefId,
) -> Lrc<Vec<ty::Predicate<'tcx>>> {
) -> &'tcx [ty::Predicate<'tcx>] {
let id = tcx
.hir()
.as_local_hir_id(item_def_id)
Expand All @@ -37,8 +37,8 @@ fn inferred_outlives_of<'a, 'tcx>(
let predicates = crate_map
.predicates
.get(&item_def_id)
.unwrap_or(&crate_map.empty_predicate)
.clone();
.map(|p| *p)
.unwrap_or(&[]);

if tcx.has_attr(item_def_id, "rustc_outlives") {
let mut pred: Vec<String> = predicates
Expand All @@ -63,10 +63,10 @@ fn inferred_outlives_of<'a, 'tcx>(
predicates
}

_ => Lrc::new(Vec::new()),
_ => &[],
},

_ => Lrc::new(Vec::new()),
_ => &[],
}
}

Expand Down Expand Up @@ -96,7 +96,7 @@ fn inferred_outlives_crate<'tcx>(
let predicates = global_inferred_outlives
.iter()
.map(|(&def_id, set)| {
let vec: Vec<ty::Predicate<'tcx>> = set
let predicates = tcx.arena.alloc_from_iter(set
.iter()
.filter_map(
|ty::OutlivesPredicate(kind1, region2)| match kind1.unpack() {
Expand All @@ -115,14 +115,11 @@ fn inferred_outlives_crate<'tcx>(
None
}
},
).collect();
(def_id, Lrc::new(vec))
));
(def_id, &*predicates)
}).collect();

let empty_predicate = Lrc::new(Vec::new());

Lrc::new(ty::CratePredicatesMap {
predicates,
empty_predicate,
})
}

0 comments on commit 5d67618

Please sign in to comment.