Skip to content

Commit

Permalink
Remove canonicalize_hr_query_hack
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 11, 2020
1 parent 9a8ca69 commit a4b0d24
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 61 deletions.
52 changes: 0 additions & 52 deletions compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,38 +107,6 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
&mut query_state,
)
}

/// A hacky variant of `canonicalize_query` that does not
/// canonicalize `'static`. Unfortunately, the existing leak
/// check treats `'static` differently in some cases (see also
/// #33684), so if we are performing an operation that may need to
/// prove "leak-check" related things, we leave `'static`
/// alone.
///
/// `'static` is also special cased when winnowing candidates when
/// selecting implementation candidates, so we also have to leave `'static`
/// alone for queries that do selection.
//
// FIXME(#48536): once the above issues are resolved, we can remove this
// and just use `canonicalize_query`.
pub fn canonicalize_hr_query_hack<V>(
&self,
value: &V,
query_state: &mut OriginalQueryValues<'tcx>,
) -> Canonicalized<'tcx, V>
where
V: TypeFoldable<'tcx>,
{
self.tcx.sess.perf_stats.queries_canonicalized.fetch_add(1, Ordering::Relaxed);

Canonicalizer::canonicalize(
value,
Some(self),
self.tcx,
&CanonicalizeFreeRegionsOtherThanStatic,
query_state,
)
}
}

/// Controls how we canonicalize "free regions" that are not inference
Expand Down Expand Up @@ -254,26 +222,6 @@ impl CanonicalizeRegionMode for CanonicalizeAllFreeRegions {
}
}

struct CanonicalizeFreeRegionsOtherThanStatic;

impl CanonicalizeRegionMode for CanonicalizeFreeRegionsOtherThanStatic {
fn canonicalize_free_region(
&self,
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
if let ty::ReStatic = r {
r
} else {
canonicalizer.canonical_var_for_region_in_root_universe(r)
}
}

fn any(&self) -> bool {
true
}
}

struct Canonicalizer<'cx, 'tcx> {
infcx: Option<&'cx InferCtxt<'cx, 'tcx>>,
tcx: TyCtxt<'tcx>,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_trait_selection/src/traits/query/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
let mut orig_values = OriginalQueryValues::default();
// HACK(matthewjasper) `'static` is special-cased in selection,
// so we cannot canonicalize it.
let c_data = self
.infcx
.canonicalize_hr_query_hack(&self.param_env.and(*data), &mut orig_values);
let c_data =
self.infcx.canonicalize_query(&self.param_env.and(*data), &mut orig_values);
debug!("QueryNormalizer: c_data = {:#?}", c_data);
debug!("QueryNormalizer: orig_values = {:#?}", orig_values);
match tcx.normalize_projection_ty(c_data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,8 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Sized + TypeFoldable<'tcx> + 'tcx {
return Ok(result);
}

// FIXME(#33684) -- We need to use
// `canonicalize_hr_query_hack` here because of things
// like the subtype query, which go awry around
// `'static` otherwise.
let mut canonical_var_values = OriginalQueryValues::default();
let canonical_self =
infcx.canonicalize_hr_query_hack(&query_key, &mut canonical_var_values);
let canonical_self = infcx.canonicalize_query(&query_key, &mut canonical_var_values);
let canonical_result = Self::perform_query(infcx.tcx, canonical_self)?;

let param_env = query_key.param_env;
Expand Down

0 comments on commit a4b0d24

Please sign in to comment.