X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_middle%2Fsrc%2Fty%2Fquery.rs;h=f2e1d129e9ba791ac765b65b1135fad46a6ee6f4;hb=75ef06892089e0cf53b4a86419c7ff3b3c1f3c4c;hp=4a38d1c422f923b64c1807642e21fb9aff01186c;hpb=547f2ba06bc4aa93a375c54e1af3fd1216eeaf62;p=rust.git diff --git a/compiler/rustc_middle/src/ty/query.rs b/compiler/rustc_middle/src/ty/query.rs index 4a38d1c422f..f2e1d129e9b 100644 --- a/compiler/rustc_middle/src/ty/query.rs +++ b/compiler/rustc_middle/src/ty/query.rs @@ -56,7 +56,6 @@ use rustc_attr as attr; use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; -use std::collections::BTreeMap; use std::ops::Deref; use std::path::PathBuf; use std::sync::Arc; @@ -107,6 +106,12 @@ pub fn try_mark_green(self, dep_node: &dep_graph::DepNode) -> bool { #[inline(always)] fn noop(_: &T) {} +/// Helper to ensure that queries only return `Copy` types. +#[inline(always)] +fn copy(x: &T) -> T { + *x +} + macro_rules! query_helper_param_ty { (DefId) => { impl IntoQueryParam }; ($K:ty) => { $K }; @@ -205,7 +210,7 @@ pub mod query_stored { #[derive(Default)] pub struct QueryCaches<$tcx> { - $($(#[$attr])* pub $name: QueryCacheStore>,)* + $($(#[$attr])* pub $name: query_storage::$name<$tcx>,)* } impl<$tcx> TyCtxtEnsure<$tcx> { @@ -217,12 +222,12 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) { let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, noop); - let lookup = match cached { + match cached { Ok(()) => return, - Err(lookup) => lookup, - }; + Err(()) => (), + } - self.tcx.queries.$name(self.tcx, DUMMY_SP, key, lookup, QueryMode::Ensure); + self.tcx.queries.$name(self.tcx, DUMMY_SP, key, QueryMode::Ensure); })* } @@ -244,14 +249,14 @@ pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> query_stored::$name<$ let key = key.into_query_param(); opt_remap_env_constness!([$($modifiers)*][key]); - let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, Clone::clone); + let cached = try_get_cached(self.tcx, &self.tcx.query_caches.$name, &key, copy); - let lookup = match cached { + match cached { Ok(value) => return value, - Err(lookup) => lookup, - }; + Err(()) => (), + } - self.tcx.queries.$name(self.tcx, self.span, key, lookup, QueryMode::Get).unwrap() + self.tcx.queries.$name(self.tcx, self.span, key, QueryMode::Get).unwrap() })* } @@ -309,7 +314,6 @@ fn $name( tcx: TyCtxt<$tcx>, span: Span, key: query_keys::$name<$tcx>, - lookup: QueryLookup, mode: QueryMode, ) -> Option>;)* } @@ -348,6 +352,13 @@ fn into_query_param(self) -> P { } } + impl<'a, P: Copy> IntoQueryParam

for &'a P { + #[inline(always)] + fn into_query_param(self) -> P { + *self + } + } + impl IntoQueryParam for LocalDefId { #[inline(always)] fn into_query_param(self) -> DefId {