Skip to content

Commit 62fba55

Browse files
Make trivial dropck outlives a query
This allows caching some recursive types and getting to an error much more quickly.
1 parent 026447b commit 62fba55

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/librustc/query/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ rustc_queries! {
231231
cycle_delay_bug
232232
}
233233

234+
query trivial_dropck_outlives(ty: Ty<'tcx>) -> bool {
235+
anon
236+
no_force
237+
desc { "checking if `{:?}` has trivial dropck", ty }
238+
}
239+
234240
query adt_dtorck_constraint(
235241
_: DefId
236242
) -> Result<DtorckConstraint<'tcx>, NoSolution> {}

src/librustc/traits/query/dropck_outlives.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::iter::FromIterator;
55
use syntax::source_map::Span;
66
use crate::ty::subst::GenericArg;
77
use crate::ty::{self, Ty, TyCtxt};
8+
use crate::ty::query::Providers;
89

910
impl<'cx, 'tcx> At<'cx, 'tcx> {
1011
/// Given a type `ty` of some value being dropped, computes a set
@@ -33,7 +34,7 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
3334
// Quick check: there are a number of cases that we know do not require
3435
// any destructor.
3536
let tcx = self.infcx.tcx;
36-
if trivial_dropck_outlives(tcx, ty) {
37+
if tcx.trivial_dropck_outlives(ty) {
3738
return InferOk {
3839
value: vec![],
3940
obligations: vec![],
@@ -207,15 +208,15 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
207208
| ty::Error => true,
208209

209210
// [T; N] and [T] have same properties as T.
210-
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty),
211+
ty::Array(ty, _) | ty::Slice(ty) => tcx.trivial_dropck_outlives(ty),
211212

212213
// (T1..Tn) and closures have same properties as T1..Tn --
213214
// check if *any* of those are trivial.
214-
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
215+
ty::Tuple(ref tys) => tys.iter().all(|t| tcx.trivial_dropck_outlives(t.expect_ty())),
215216
ty::Closure(def_id, ref substs) => substs
216217
.as_closure()
217218
.upvar_tys(def_id, tcx)
218-
.all(|t| trivial_dropck_outlives(tcx, t)),
219+
.all(|t| tcx.trivial_dropck_outlives(t)),
219220

220221
ty::Adt(def, _) => {
221222
if Some(def.did) == tcx.lang_items().manually_drop() {
@@ -243,3 +244,10 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
243244
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
244245
}
245246
}
247+
248+
crate fn provide(p: &mut Providers<'_>) {
249+
*p = Providers {
250+
trivial_dropck_outlives,
251+
..*p
252+
};
253+
}

src/librustc/traits/query/type_op/outlives.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2-
use crate::traits::query::dropck_outlives::trivial_dropck_outlives;
32
use crate::traits::query::dropck_outlives::DropckOutlivesResult;
43
use crate::traits::query::Fallible;
54
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
@@ -22,7 +21,7 @@ impl super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
2221
tcx: TyCtxt<'tcx>,
2322
key: &ParamEnvAnd<'tcx, Self>,
2423
) -> Option<Self::QueryResponse> {
25-
if trivial_dropck_outlives(tcx, key.value.dropped_ty) {
24+
if tcx.trivial_dropck_outlives(key.value.dropped_ty) {
2625
Some(DropckOutlivesResult::default())
2726
} else {
2827
None

src/librustc/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3394,6 +3394,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
33943394
layout::provide(providers);
33953395
util::provide(providers);
33963396
constness::provide(providers);
3397+
crate::traits::query::dropck_outlives::provide(providers);
33973398
*providers = ty::query::Providers {
33983399
asyncness,
33993400
associated_item,

src/librustc_traits/dropck_outlives.rs

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ fn dtorck_constraint_for_ty<'tcx>(
166166
});
167167
}
168168

169+
if tcx.trivial_dropck_outlives(ty) {
170+
return Ok(DtorckConstraint::empty());
171+
}
172+
169173
let result = match ty.kind {
170174
ty::Bool
171175
| ty::Char

0 commit comments

Comments
 (0)