From 7d90547532012f31ad6fb1cda664bc47c558c6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 3 Dec 2018 01:14:35 +0100 Subject: [PATCH 1/4] Define queries using a proc macro --- src/librustc/dep_graph/dep_node.rs | 23 +- src/librustc/dep_graph/mod.rs | 2 +- src/librustc/lib.rs | 6 + src/librustc/query/mod.rs | 37 +++ src/librustc/ty/query/config.rs | 17 +- src/librustc/ty/query/mod.rs | 16 +- src/librustc/ty/query/plumbing.rs | 32 +- .../persist/dirty_clean.rs | 8 +- src/librustc_macros/src/lib.rs | 11 + src/librustc_macros/src/query.rs | 302 ++++++++++++++++++ src/librustc_macros/src/tt.rs | 65 ++++ src/test/incremental/hashes/consts.rs | 8 +- src/test/incremental/hashes/enum_defs.rs | 38 +-- .../incremental/hashes/function_interfaces.rs | 6 +- src/test/incremental/hashes/inherent_impls.rs | 10 +- src/test/incremental/hashes/statics.rs | 8 +- src/test/incremental/hashes/struct_defs.rs | 84 ++--- .../dep-graph/dep-graph-struct-signature.rs | 14 +- src/test/ui/dep-graph/dep-graph-type-alias.rs | 14 +- 19 files changed, 563 insertions(+), 138 deletions(-) create mode 100644 src/librustc/query/mod.rs create mode 100644 src/librustc_macros/src/query.rs create mode 100644 src/librustc_macros/src/tt.rs diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index eb75e624d34b2..b88ce643ea499 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -423,7 +423,7 @@ impl DefId { } } -define_dep_nodes!( <'tcx> +rustc_dep_node_append!([define_dep_nodes!][ <'tcx> // We use this for most things when incr. comp. is turned off. [] Null, @@ -492,7 +492,6 @@ define_dep_nodes!( <'tcx> // table in the tcx (or elsewhere) maps to one of these // nodes. [] AssociatedItems(DefId), - [] TypeOfItem(DefId), [] GenericsOfItem(DefId), [] PredicatesOfItem(DefId), [] ExplicitPredicatesOfItem(DefId), @@ -570,7 +569,6 @@ define_dep_nodes!( <'tcx> [] FnArgNames(DefId), [] RenderedConst(DefId), [] DylibDepFormats(CrateNum), - [] IsPanicRuntime(CrateNum), [] IsCompilerBuiltins(CrateNum), [] HasGlobalAllocator(CrateNum), [] HasPanicHandler(CrateNum), @@ -588,7 +586,6 @@ define_dep_nodes!( <'tcx> [] CheckTraitItemWellFormed(DefId), [] CheckImplItemWellFormed(DefId), [] ReachableNonGenerics(CrateNum), - [] NativeLibraries(CrateNum), [] EntryFn(CrateNum), [] PluginRegistrarFn(CrateNum), [] ProcMacroDeclsStatic(CrateNum), @@ -679,7 +676,23 @@ define_dep_nodes!( <'tcx> [] UpstreamMonomorphizations(CrateNum), [] UpstreamMonomorphizationsFor(DefId), -); +]); + +pub trait RecoverKey<'tcx>: Sized { + fn recover(tcx: TyCtxt<'_, 'tcx, 'tcx>, dep_node: &DepNode) -> Option; +} + +impl RecoverKey<'tcx> for CrateNum { + fn recover(tcx: TyCtxt<'_, 'tcx, 'tcx>, dep_node: &DepNode) -> Option { + dep_node.extract_def_id(tcx).map(|id| id.krate) + } +} + +impl RecoverKey<'tcx> for DefId { + fn recover(tcx: TyCtxt<'_, 'tcx, 'tcx>, dep_node: &DepNode) -> Option { + dep_node.extract_def_id(tcx) + } +} trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug { const CAN_RECONSTRUCT_QUERY_KEY: bool; diff --git a/src/librustc/dep_graph/mod.rs b/src/librustc/dep_graph/mod.rs index b84d2ad145889..1535e6d349cf1 100644 --- a/src/librustc/dep_graph/mod.rs +++ b/src/librustc/dep_graph/mod.rs @@ -9,7 +9,7 @@ mod serialized; pub mod cgu_reuse_tracker; pub use self::dep_tracking_map::{DepTrackingMap, DepTrackingMapConfig}; -pub use self::dep_node::{DepNode, DepKind, DepConstructor, WorkProductId, label_strs}; +pub use self::dep_node::{DepNode, DepKind, DepConstructor, WorkProductId, RecoverKey, label_strs}; pub use self::graph::{DepGraph, WorkProduct, DepNodeIndex, DepNodeColor, TaskDeps, hash_result}; pub use self::graph::WorkProductFileKind; pub use self::prev::PreviousDepGraph; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index b6677326227f4..4b2fda3b02f9d 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -60,6 +60,8 @@ #![feature(test)] #![feature(in_band_lifetimes)] #![feature(crate_visibility_modifier)] +#![feature(proc_macro_hygiene)] +#![feature(log_syntax)] #![recursion_limit="512"] @@ -69,6 +71,7 @@ extern crate getopts; #[macro_use] extern crate scoped_tls; #[cfg(windows)] extern crate libc; +#[macro_use] extern crate rustc_macros; #[macro_use] extern crate rustc_data_structures; #[macro_use] extern crate log; @@ -96,6 +99,9 @@ mod macros; // registered before they are used. pub mod diagnostics; +#[macro_use] +pub mod query; + pub mod cfg; pub mod dep_graph; pub mod hir; diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs new file mode 100644 index 0000000000000..709d34a156ccc --- /dev/null +++ b/src/librustc/query/mod.rs @@ -0,0 +1,37 @@ +use crate::ty::query::QueryDescription; +use crate::ty::query::queries; +use crate::ty::TyCtxt; +use crate::hir::def_id::CrateNum; +use crate::dep_graph::SerializedDepNodeIndex; +use std::borrow::Cow; + +// Each of these queries corresponds to a function pointer field in the +// `Providers` struct for requesting a value of that type, and a method +// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way +// which memoizes and does dep-graph tracking, wrapping around the actual +// `Providers` that the driver creates (using several `rustc_*` crates). +// +// The result type of each query must implement `Clone`, and additionally +// `ty::query::values::Value`, which produces an appropriate placeholder +// (error) value if the query resulted in a query cycle. +// Queries marked with `fatal_cycle` do not need the latter implementation, +// as they will raise an fatal error on query cycles instead. +rustc_queries! { + Other { + /// Records the type of every item. + query type_of(key: DefId) -> Ty<'tcx> { + cache { key.is_local() } + } + + query native_libraries(_: CrateNum) -> Lrc> { + desc { "looking up the native libraries of a linked crate" } + } + } + + Codegen { + query is_panic_runtime(_: CrateNum) -> bool { + fatal_cycle + desc { "checking if the crate is_panic_runtime" } + } + } +} diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 395b288df141e..6e964fc540ee0 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -34,7 +34,7 @@ pub trait QueryConfig<'tcx> { type Value: Clone; } -pub(super) trait QueryAccessors<'tcx>: QueryConfig<'tcx> { +pub(crate) trait QueryAccessors<'tcx>: QueryConfig<'tcx> { fn query(key: Self::Key) -> Query<'tcx>; // Don't use this method to access query results, instead use the methods on TyCtxt @@ -53,7 +53,7 @@ pub(super) trait QueryAccessors<'tcx>: QueryConfig<'tcx> { fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>, error: CycleError<'tcx>) -> Self::Value; } -pub(super) trait QueryDescription<'tcx>: QueryAccessors<'tcx> { +pub(crate) trait QueryDescription<'tcx>: QueryAccessors<'tcx> { fn describe(tcx: TyCtxt<'_, '_, '_>, key: Self::Key) -> Cow<'static, str>; #[inline] @@ -587,12 +587,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::dylib_dependency_formats<'tcx> { } } -impl<'tcx> QueryDescription<'tcx> for queries::is_panic_runtime<'tcx> { - fn describe(_: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> { - "checking if the crate is_panic_runtime".into() - } -} - impl<'tcx> QueryDescription<'tcx> for queries::is_compiler_builtins<'tcx> { fn describe(_: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> { "checking if the crate is_compiler_builtins".into() @@ -671,12 +665,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::reachable_non_generics<'tcx> { } } -impl<'tcx> QueryDescription<'tcx> for queries::native_libraries<'tcx> { - fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> { - "looking up the native libraries of a linked crate".into() - } -} - impl<'tcx> QueryDescription<'tcx> for queries::foreign_modules<'tcx> { fn describe(_tcx: TyCtxt<'_, '_, '_>, _: CrateNum) -> Cow<'static, str> { "looking up the foreign modules of a linked crate".into() @@ -1027,7 +1015,6 @@ impl_disk_cacheable_query!(borrowck, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(mir_const_qualif, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(check_match, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(def_symbol_name, |_, _| true); -impl_disk_cacheable_query!(type_of, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(predicates_of, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(used_trait_imports, |_, def_id| def_id.is_local()); impl_disk_cacheable_query!(codegen_fn_attrs, |_, _| true); diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 8804ed22264ce..bccc69af2350a 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -80,13 +80,14 @@ mod values; use self::values::Value; mod config; +pub(crate) use self::config::QueryDescription; pub use self::config::QueryConfig; -use self::config::{QueryAccessors, QueryDescription}; +use self::config::QueryAccessors; mod on_disk_cache; pub use self::on_disk_cache::OnDiskCache; -// Each of these quries corresponds to a function pointer field in the +// Each of these queries corresponds to a function pointer field in the // `Providers` struct for requesting a value of that type, and a method // on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way // which memoizes and does dep-graph tracking, wrapping around the actual @@ -97,14 +98,12 @@ pub use self::on_disk_cache::OnDiskCache; // (error) value if the query resulted in a query cycle. // Queries marked with `fatal_cycle` do not need the latter implementation, // as they will raise an fatal error on query cycles instead. -define_queries! { <'tcx> + +rustc_query_append! { [define_queries!][ <'tcx> Other { /// Run analysis passes on the crate [] fn analysis: Analysis(CrateNum) -> Result<(), ErrorReported>, - /// Records the type of every item. - [] fn type_of: TypeOfItem(DefId) -> Ty<'tcx>, - /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its /// associated generics. [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics, @@ -446,7 +445,6 @@ define_queries! { <'tcx> }, Codegen { - [fatal_cycle] fn is_panic_runtime: IsPanicRuntime(CrateNum) -> bool, [fatal_cycle] fn is_compiler_builtins: IsCompilerBuiltins(CrateNum) -> bool, [fatal_cycle] fn has_global_allocator: HasGlobalAllocator(CrateNum) -> bool, [fatal_cycle] fn has_panic_handler: HasPanicHandler(CrateNum) -> bool, @@ -504,8 +502,6 @@ define_queries! { <'tcx> }, Other { - [] fn native_libraries: NativeLibraries(CrateNum) -> Lrc>, - [] fn foreign_modules: ForeignModules(CrateNum) -> Lrc>, /// Identifies the entry-point (e.g., the `main` function) for a given @@ -752,7 +748,7 @@ define_queries! { <'tcx> [] fn wasm_import_module_map: WasmImportModuleMap(CrateNum) -> Lrc>, }, -} +]} ////////////////////////////////////////////////////////////////////// // These functions are little shims used to find the dep-node for a diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index cff99f23d0e95..e78d98cd4f1e1 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -1131,10 +1131,12 @@ macro_rules! define_provider_struct { /// then `force_from_dep_node()` should not fail for it. Otherwise, you can just /// add it to the "We don't have enough information to reconstruct..." group in /// the match below. -pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, - dep_node: &DepNode) - -> bool { +pub fn force_from_dep_node<'tcx>( + tcx: TyCtxt<'_, 'tcx, 'tcx>, + dep_node: &DepNode +) -> bool { use crate::hir::def_id::LOCAL_CRATE; + use crate::dep_graph::RecoverKey; // We must avoid ever having to call force_from_dep_node() for a // DepNode::CodegenUnit: @@ -1171,17 +1173,26 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, () => { (def_id!()).krate } }; - macro_rules! force { - ($query:ident, $key:expr) => { + macro_rules! force_ex { + ($tcx:expr, $query:ident, $key:expr) => { { - tcx.force_query::>($key, DUMMY_SP, *dep_node); + $tcx.force_query::>( + $key, + DUMMY_SP, + *dep_node + ); } } }; + macro_rules! force { + ($query:ident, $key:expr) => { force_ex!(tcx, $query, $key) } + }; + // FIXME(#45015): We should try move this boilerplate code into a macro // somehow. - match dep_node.kind { + + rustc_dep_node_force!([dep_node, tcx] // These are inputs that are expected to be pre-allocated and that // should therefore always be red or green already DepKind::AllLocalTraitImpls | @@ -1274,7 +1285,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, DepKind::MirKeys => { force!(mir_keys, LOCAL_CRATE); } DepKind::CrateVariances => { force!(crate_variances, LOCAL_CRATE); } DepKind::AssociatedItems => { force!(associated_item, def_id!()); } - DepKind::TypeOfItem => { force!(type_of, def_id!()); } DepKind::GenericsOfItem => { force!(generics_of, def_id!()); } DepKind::PredicatesOfItem => { force!(predicates_of, def_id!()); } DepKind::PredicatesDefinedOnItem => { force!(predicates_defined_on, def_id!()); } @@ -1332,7 +1342,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, DepKind::FnArgNames => { force!(fn_arg_names, def_id!()); } DepKind::RenderedConst => { force!(rendered_const, def_id!()); } DepKind::DylibDepFormats => { force!(dylib_dependency_formats, krate!()); } - DepKind::IsPanicRuntime => { force!(is_panic_runtime, krate!()); } DepKind::IsCompilerBuiltins => { force!(is_compiler_builtins, krate!()); } DepKind::HasGlobalAllocator => { force!(has_global_allocator, krate!()); } DepKind::HasPanicHandler => { force!(has_panic_handler, krate!()); } @@ -1349,7 +1358,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, DepKind::CheckTraitItemWellFormed => { force!(check_trait_item_well_formed, def_id!()); } DepKind::CheckImplItemWellFormed => { force!(check_impl_item_well_formed, def_id!()); } DepKind::ReachableNonGenerics => { force!(reachable_non_generics, krate!()); } - DepKind::NativeLibraries => { force!(native_libraries, krate!()); } DepKind::EntryFn => { force!(entry_fn, krate!()); } DepKind::PluginRegistrarFn => { force!(plugin_registrar_fn, krate!()); } DepKind::ProcMacroDeclsStatic => { force!(proc_macro_decls_static, krate!()); } @@ -1432,7 +1440,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>, DepKind::BackendOptimizationLevel => { force!(backend_optimization_level, krate!()); } - } + ); true } @@ -1493,7 +1501,7 @@ impl_load_from_cache!( SymbolName => def_symbol_name, ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static, CheckMatch => check_match, - TypeOfItem => type_of, + TypeOf => type_of, GenericsOfItem => generics_of, PredicatesOfItem => predicates_of, UsedTraitImports => used_trait_imports, diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index 5551cf6b3b604..c7a9f1afd0ac6 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -36,7 +36,7 @@ const CFG: &str = "cfg"; /// For typedef, constants, and statics const BASE_CONST: &[&str] = &[ - label_strs::TypeOfItem, + label_strs::TypeOf, ]; /// DepNodes for functions + methods @@ -45,7 +45,7 @@ const BASE_FN: &[&str] = &[ label_strs::FnSignature, label_strs::GenericsOfItem, label_strs::PredicatesOfItem, - label_strs::TypeOfItem, + label_strs::TypeOf, // And a big part of compilation (that we eventually want to cache) is type inference // information: @@ -80,7 +80,7 @@ const BASE_MIR: &[&str] = &[ const BASE_STRUCT: &[&str] = &[ label_strs::GenericsOfItem, label_strs::PredicatesOfItem, - label_strs::TypeOfItem, + label_strs::TypeOf, ]; /// Trait definition `DepNode`s. @@ -179,7 +179,7 @@ const LABELS_TRAIT: &[&[&str]] = &[ // Fields are kind of separate from their containers, as they can change independently from // them. We should at least check // -// TypeOfItem for these. +// TypeOf for these. type Labels = FxHashSet; diff --git a/src/librustc_macros/src/lib.rs b/src/librustc_macros/src/lib.rs index cad31264b05a4..78520b6dce690 100644 --- a/src/librustc_macros/src/lib.rs +++ b/src/librustc_macros/src/lib.rs @@ -1,8 +1,19 @@ #![feature(proc_macro_hygiene)] #![deny(rust_2018_idioms)] +extern crate proc_macro; + use synstructure::decl_derive; +use proc_macro::TokenStream; + mod hash_stable; +mod query; +mod tt; + +#[proc_macro] +pub fn rustc_queries(input: TokenStream) -> TokenStream { + query::rustc_queries(input) +} decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive); diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs new file mode 100644 index 0000000000000..aeb830ff9b9dc --- /dev/null +++ b/src/librustc_macros/src/query.rs @@ -0,0 +1,302 @@ +use proc_macro::TokenStream; +use proc_macro2::Span; +use syn::{ + Token, Ident, Type, Attribute, ReturnType, Expr, + braced, parenthesized, parse_macro_input, +}; +use syn::parse::{Result, Parse, ParseStream}; +use syn::punctuated::Punctuated; +use quote::quote; +use crate::tt::TS; + +struct IdentOrWild(Ident); + +impl Parse for IdentOrWild { + fn parse(input: ParseStream<'_>) -> Result { + Ok(if input.peek(Token![_]) { + input.parse::()?; + IdentOrWild(Ident::new("_", Span::call_site())) + } else { + IdentOrWild(input.parse()?) + }) + } +} + +enum QueryAttribute { + Desc(Option, Punctuated), + Cache(Option, Expr), + FatalCycle, +} + +impl Parse for QueryAttribute { + fn parse(input: ParseStream<'_>) -> Result { + let attr: Ident = input.parse()?; + if attr == "desc" { + let attr_content; + braced!(attr_content in input); + let tcx = if attr_content.peek(Token![|]) { + attr_content.parse::()?; + let tcx = attr_content.parse()?; + attr_content.parse::()?; + Some(tcx) + } else { + None + }; + let desc = attr_content.parse_terminated(Expr::parse)?; + if !attr_content.is_empty() { + panic!("unexpected tokens in block"); + }; + Ok(QueryAttribute::Desc(tcx, desc)) + } else if attr == "cache" { + let attr_content; + braced!(attr_content in input); + let tcx = if attr_content.peek(Token![|]) { + attr_content.parse::()?; + let tcx = attr_content.parse()?; + attr_content.parse::()?; + Some(tcx) + } else { + None + }; + let expr = attr_content.parse()?; + if !attr_content.is_empty() { + panic!("unexpected tokens in block"); + }; + Ok(QueryAttribute::Cache(tcx, expr)) + } else if attr == "fatal_cycle" { + Ok(QueryAttribute::FatalCycle) + } else { + panic!("unknown query modifier {}", attr) + } + } +} + +struct Query { + attrs: List, + name: Ident, + key: IdentOrWild, + arg: Type, + result: ReturnType, +} + +fn check_attributes(attrs: Vec) { + for attr in attrs { + let path = attr.path; + let path = quote! { #path }; + let path = TS(&path); + + if path != TS("e! { doc }) { + panic!("attribute `{}` not supported on queries", path.0) + } + } +} + +impl Parse for Query { + fn parse(input: ParseStream<'_>) -> Result { + check_attributes(input.call(Attribute::parse_outer)?); + + let query: Ident = input.parse()?; + if query != "query" { + panic!("expected `query`"); + } + let name: Ident = input.parse()?; + let arg_content; + parenthesized!(arg_content in input); + let key = arg_content.parse()?; + arg_content.parse::()?; + let arg = arg_content.parse()?; + if !arg_content.is_empty() { + panic!("expected only one query argument"); + }; + let result = input.parse()?; + + let content; + braced!(content in input); + let attrs = content.parse()?; + + Ok(Query { + attrs, + name, + key, + arg, + result, + }) + } +} + +struct List(Vec); + +impl Parse for List { + fn parse(input: ParseStream<'_>) -> Result { + let mut list = Vec::new(); + while !input.is_empty() { + list.push(input.parse()?); + } + Ok(List(list)) + } +} + +struct Group { + name: Ident, + queries: List, +} + +impl Parse for Group { + fn parse(input: ParseStream<'_>) -> Result { + let name: Ident = input.parse()?; + let content; + braced!(content in input); + Ok(Group { + name, + queries: content.parse()?, + }) + } +} + +fn camel_case(string: &str) -> String { + let mut pos = vec![0]; + for (i, c) in string.chars().enumerate() { + if c == '_' { + pos.push(i + 1); + } + } + string.chars().enumerate().filter(|c| c.1 != '_').flat_map(|(i, c)| { + if pos.contains(&i) { + c.to_uppercase().collect::>() + } else { + vec![c] + } + }).collect() +} + +pub fn rustc_queries(input: TokenStream) -> TokenStream { + let groups = parse_macro_input!(input as List); + + let mut query_stream = quote! {}; + let mut query_description_stream = quote! {}; + let mut dep_node_def_stream = quote! {}; + let mut dep_node_force_stream = quote! {}; + + for group in groups.0 { + let mut group_stream = quote! {}; + for query in &group.queries.0 { + let name = &query.name; + let dep_node_name = Ident::new( + &camel_case(&name.to_string()), + name.span()); + let arg = &query.arg; + let key = &query.key.0; + let result_full = &query.result; + let result = match query.result { + ReturnType::Default => quote! { -> () }, + _ => quote! { #result_full }, + }; + + // Find out if we should cache the query on disk + let cache = query.attrs.0.iter().find_map(|attr| match attr { + QueryAttribute::Cache(tcx, expr) => Some((tcx, expr)), + _ => None, + }).map(|(tcx, expr)| { + let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); + quote! { + #[inline] + fn cache_on_disk(#tcx: TyCtxt<'_, 'tcx, 'tcx>, #key: Self::Key) -> bool { + #expr + } + + #[inline] + fn try_load_from_disk( + tcx: TyCtxt<'_, 'tcx, 'tcx>, + id: SerializedDepNodeIndex + ) -> Option { + tcx.queries.on_disk_cache.try_load_query_result(tcx, id) + } + } + }); + + let fatal_cycle = query.attrs.0.iter().find_map(|attr| match attr { + QueryAttribute::FatalCycle => Some(()), + _ => None, + }).map(|_| quote! { fatal_cycle }).unwrap_or(quote! {}); + + group_stream.extend(quote! { + [#fatal_cycle] fn #name: #dep_node_name(#arg) #result, + }); + + let desc = query.attrs.0.iter().find_map(|attr| match attr { + QueryAttribute::Desc(tcx, desc) => Some((tcx, desc)), + _ => None, + }).map(|(tcx, desc)| { + let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); + quote! { + fn describe( + #tcx: TyCtxt<'_, '_, '_>, + #key: #arg, + ) -> Cow<'static, str> { + format!(#desc).into() + } + } + }); + + if desc.is_some() || cache.is_some() { + let cache = cache.unwrap_or(quote! {}); + let desc = desc.unwrap_or(quote! {}); + + query_description_stream.extend(quote! { + impl<'tcx> QueryDescription<'tcx> for queries::#name<'tcx> { + #desc + #cache + } + }); + } + + dep_node_def_stream.extend(quote! { + [] #dep_node_name(#arg), + }); + dep_node_force_stream.extend(quote! { + DepKind::#dep_node_name => { + if let Some(key) = RecoverKey::recover($tcx, $dep_node) { + force_ex!($tcx, #name, key); + } else { + return false; + } + } + }); + } + let name = &group.name; + query_stream.extend(quote! { + #name { #group_stream }, + }); + } + TokenStream::from(quote! { + macro_rules! rustc_query_append { + ([$($macro:tt)*][$($other:tt)*]) => { + $($macro)* { + $($other)* + + #query_stream + + } + } + } + macro_rules! rustc_dep_node_append { + ([$($macro:tt)*][$($other:tt)*]) => { + $($macro)*( + $($other)* + + #dep_node_def_stream + ); + } + } + macro_rules! rustc_dep_node_force { + ([$dep_node:expr, $tcx:expr] $($other:tt)*) => { + match $dep_node.kind { + $($other)* + + #dep_node_force_stream + } + } + } + #query_description_stream + }) +} diff --git a/src/librustc_macros/src/tt.rs b/src/librustc_macros/src/tt.rs new file mode 100644 index 0000000000000..66180ec8ad373 --- /dev/null +++ b/src/librustc_macros/src/tt.rs @@ -0,0 +1,65 @@ +use proc_macro2::{Delimiter, TokenStream, TokenTree}; + +pub struct TT<'a>(pub &'a TokenTree); + +impl<'a> PartialEq for TT<'a> { + fn eq(&self, other: &Self) -> bool { + use proc_macro2::Spacing; + + match (self.0, other.0) { + (&TokenTree::Group(ref g1), &TokenTree::Group(ref g2)) => { + match (g1.delimiter(), g2.delimiter()) { + (Delimiter::Parenthesis, Delimiter::Parenthesis) + | (Delimiter::Brace, Delimiter::Brace) + | (Delimiter::Bracket, Delimiter::Bracket) + | (Delimiter::None, Delimiter::None) => {} + _ => return false, + } + + let s1 = g1.stream().clone().into_iter(); + let mut s2 = g2.stream().clone().into_iter(); + + for item1 in s1 { + let item2 = match s2.next() { + Some(item) => item, + None => return false, + }; + if TT(&item1) != TT(&item2) { + return false; + } + } + s2.next().is_none() + } + (&TokenTree::Punct(ref o1), &TokenTree::Punct(ref o2)) => { + o1.as_char() == o2.as_char() + && match (o1.spacing(), o2.spacing()) { + (Spacing::Alone, Spacing::Alone) | (Spacing::Joint, Spacing::Joint) => true, + _ => false, + } + } + (&TokenTree::Literal(ref l1), &TokenTree::Literal(ref l2)) => { + l1.to_string() == l2.to_string() + } + (&TokenTree::Ident(ref s1), &TokenTree::Ident(ref s2)) => s1 == s2, + _ => false, + } + } +} + +pub struct TS<'a>(pub &'a TokenStream); + +impl<'a> PartialEq for TS<'a> { + fn eq(&self, other: &Self) -> bool { + let left = self.0.clone().into_iter().collect::>(); + let right = other.0.clone().into_iter().collect::>(); + if left.len() != right.len() { + return false; + } + for (a, b) in left.into_iter().zip(right) { + if TT(&a) != TT(&b) { + return false; + } + } + true + } +} diff --git a/src/test/incremental/hashes/consts.rs b/src/test/incremental/hashes/consts.rs index 0ab0915d4d071..03c21712d2d0b 100644 --- a/src/test/incremental/hashes/consts.rs +++ b/src/test/incremental/hashes/consts.rs @@ -29,7 +29,7 @@ pub const CONST_VISIBILITY: u8 = 0; const CONST_CHANGE_TYPE_1: i32 = 0; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_1: u32 = 0; @@ -39,7 +39,7 @@ const CONST_CHANGE_TYPE_1: u32 = 0; const CONST_CHANGE_TYPE_2: Option = None; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_2: Option = None; @@ -99,11 +99,11 @@ mod const_change_type_indirectly { #[cfg(not(cfail1))] use super::ReferencedType2 as Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_1: Type = Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_2: Option = None; } diff --git a/src/test/incremental/hashes/enum_defs.rs b/src/test/incremental/hashes/enum_defs.rs index 294476258ab95..62f6e1f571b6d 100644 --- a/src/test/incremental/hashes/enum_defs.rs +++ b/src/test/incremental/hashes/enum_defs.rs @@ -42,7 +42,7 @@ enum EnumChangeNameCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameCStyleVariant { Variant1, @@ -59,7 +59,7 @@ enum EnumChangeNameTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameTupleStyleVariant { Variant1, @@ -76,7 +76,7 @@ enum EnumChangeNameStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameStructStyleVariant { Variant1, @@ -109,7 +109,7 @@ enum EnumChangeValueCStyleVariant1 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumChangeValueCStyleVariant1 { Variant1, @@ -125,7 +125,7 @@ enum EnumAddCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddCStyleVariant { Variant1, @@ -142,7 +142,7 @@ enum EnumRemoveCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveCStyleVariant { Variant1, @@ -157,7 +157,7 @@ enum EnumAddTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddTupleStyleVariant { Variant1, @@ -174,7 +174,7 @@ enum EnumRemoveTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveTupleStyleVariant { Variant1, @@ -189,7 +189,7 @@ enum EnumAddStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddStructStyleVariant { Variant1, @@ -206,7 +206,7 @@ enum EnumRemoveStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveStructStyleVariant { Variant1, @@ -257,7 +257,7 @@ enum EnumChangeFieldNameStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumChangeFieldNameStructStyleVariant { Variant1 { a: u32, c: u32 }, @@ -289,7 +289,7 @@ enum EnumChangeFieldOrderStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumChangeFieldOrderStructStyleVariant { Variant1 { b: f32, a: u32 }, @@ -304,7 +304,7 @@ enum EnumAddFieldTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddFieldTupleStyleVariant { Variant1(u32, u32, u32), @@ -319,7 +319,7 @@ enum EnumAddFieldStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddFieldStructStyleVariant { Variant1 { a: u32, b: u32, c: u32 }, @@ -353,7 +353,7 @@ enum EnumAddReprC { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] #[repr(C)] enum EnumAddReprC { @@ -435,7 +435,7 @@ enum EnumAddLifetimeParameterBound<'a, 'b> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="GenericsOfItem,TypeOfItem")] +#[rustc_dirty(cfg="cfail2", except="GenericsOfItem,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameterBound<'a, 'b: 'a> { Variant1(&'a u32), @@ -450,7 +450,7 @@ enum EnumAddLifetimeBoundToParameter<'a, T> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="TypeOfItem")] +#[rustc_dirty(cfg="cfail2", except="TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeBoundToParameter<'a, T: 'a> { Variant1(T), @@ -482,7 +482,7 @@ enum EnumAddLifetimeParameterBoundWhere<'a, 'b> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="GenericsOfItem,TypeOfItem")] +#[rustc_dirty(cfg="cfail2", except="GenericsOfItem,TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameterBoundWhere<'a, 'b> where 'b: 'a { Variant1(&'a u32), @@ -499,7 +499,7 @@ enum EnumAddLifetimeBoundToParameterWhere<'a, T> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="TypeOfItem")] +#[rustc_dirty(cfg="cfail2", except="TypeOf")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeBoundToParameterWhere<'a, T> where T: 'a { Variant1(T), diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs index 4330b0025a251..6d7bbf2b7dad9 100644 --- a/src/test/incremental/hashes/function_interfaces.rs +++ b/src/test/incremental/hashes/function_interfaces.rs @@ -117,7 +117,7 @@ pub fn type_parameter() {} #[cfg(not(cfail1))] #[rustc_clean(cfg = "cfail2", - except = "Hir, HirBody, GenericsOfItem, TypeOfItem, PredicatesOfItem")] + except = "Hir, HirBody, GenericsOfItem, TypeOf, PredicatesOfItem")] #[rustc_clean(cfg = "cfail3")] pub fn type_parameter() {} @@ -162,7 +162,7 @@ pub fn lifetime_bound<'a, T>() {} #[cfg(not(cfail1))] #[rustc_clean(cfg = "cfail2", - except = "Hir, HirBody, GenericsOfItem, TypeOfItem, PredicatesOfItem")] + except = "Hir, HirBody, GenericsOfItem, TypeOf, PredicatesOfItem")] #[rustc_clean(cfg = "cfail3")] pub fn lifetime_bound<'a, T: 'a>() {} @@ -196,7 +196,7 @@ pub fn second_lifetime_bound<'a, 'b, T: 'a>() {} #[cfg(not(cfail1))] #[rustc_clean(cfg = "cfail2", - except = "Hir, HirBody, GenericsOfItem, TypeOfItem, PredicatesOfItem")] + except = "Hir, HirBody, GenericsOfItem, TypeOf, PredicatesOfItem")] #[rustc_clean(cfg = "cfail3")] pub fn second_lifetime_bound<'a, 'b, T: 'a + 'b>() {} diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index d1574aee9a9c0..a66c6f6eee5d4 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -97,7 +97,7 @@ impl Foo { #[rustc_clean(cfg="cfail2", except="Hir,HirBody")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_dirty(cfg="cfail2", except="TypeOfItem,PredicatesOfItem")] + #[rustc_dirty(cfg="cfail2", except="TypeOf,PredicatesOfItem")] #[rustc_clean(cfg="cfail3")] pub fn method_selfness(&self) { } } @@ -334,7 +334,7 @@ impl Foo { // appear dirty, that might be the cause. -nmatsakis #[rustc_clean( cfg="cfail2", - except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem", + except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOf", )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_method(&self) { } @@ -354,7 +354,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem,TypeckTables" + except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOf,TypeckTables" )] #[rustc_clean(cfg="cfail3")] pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { } @@ -382,7 +382,7 @@ impl Foo { // body will be affected. So if you start to see `TypeckTables` // appear dirty, that might be the cause. -nmatsakis #[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,\ - TypeOfItem")] + TypeOf")] #[rustc_clean(cfg="cfail3")] pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { } } @@ -447,7 +447,7 @@ impl Bar { impl Bar { #[rustc_clean( cfg="cfail2", - except="GenericsOfItem,FnSignature,TypeckTables,TypeOfItem,MirOptimized,MirBuilt" + except="GenericsOfItem,FnSignature,TypeckTables,TypeOf,MirOptimized,MirBuilt" )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_impl(&self) { } diff --git a/src/test/incremental/hashes/statics.rs b/src/test/incremental/hashes/statics.rs index c3db4369b7dd0..aa78389faf48e 100644 --- a/src/test/incremental/hashes/statics.rs +++ b/src/test/incremental/hashes/statics.rs @@ -74,7 +74,7 @@ static STATIC_THREAD_LOCAL: u8 = 0; static STATIC_CHANGE_TYPE_1: i16 = 0; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_1: u64 = 0; @@ -84,7 +84,7 @@ static STATIC_CHANGE_TYPE_1: u64 = 0; static STATIC_CHANGE_TYPE_2: Option = None; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_2: Option = None; @@ -144,11 +144,11 @@ mod static_change_type_indirectly { #[cfg(not(cfail1))] use super::ReferencedType2 as Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option = None; } diff --git a/src/test/incremental/hashes/struct_defs.rs b/src/test/incremental/hashes/struct_defs.rs index 9fca1ce1c46fe..b948ae8228e24 100644 --- a/src/test/incremental/hashes/struct_defs.rs +++ b/src/test/incremental/hashes/struct_defs.rs @@ -26,12 +26,12 @@ pub struct LayoutPacked; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] #[repr(packed)] @@ -43,12 +43,12 @@ struct LayoutC; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] #[repr(C)] @@ -63,12 +63,12 @@ struct TupleStructFieldType(i32); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] // Note that changing the type of a field does not change the type of the struct or enum, but @@ -86,12 +86,12 @@ struct TupleStructAddField(i32); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct TupleStructAddField( @@ -108,12 +108,12 @@ struct TupleStructFieldVisibility(char); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct TupleStructFieldVisibility(pub char); @@ -127,12 +127,12 @@ struct RecordStructFieldType { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] // Note that changing the type of a field does not change the type of the struct or enum, but @@ -150,12 +150,12 @@ struct RecordStructFieldName { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct RecordStructFieldName { y: f32 } @@ -169,12 +169,12 @@ struct RecordStructAddField { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct RecordStructAddField { @@ -190,12 +190,12 @@ struct RecordStructFieldVisibility { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct RecordStructFieldVisibility { @@ -211,12 +211,12 @@ struct AddLifetimeParameter<'a>(&'a f32, &'a f64); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_dirty(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64); @@ -230,12 +230,12 @@ struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct AddLifetimeParameterBound<'a, 'b: 'a>( @@ -249,12 +249,12 @@ struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct AddLifetimeParameterBoundWhereClause<'a, 'b>( @@ -271,12 +271,12 @@ struct AddTypeParameter(T1, T1); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOfItem", cfg="cfail2")] +#[rustc_dirty(label="TypeOf", cfg="cfail2")] #[rustc_dirty(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct AddTypeParameter( @@ -295,12 +295,12 @@ struct AddTypeParameterBound(T); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct AddTypeParameterBound( @@ -314,12 +314,12 @@ struct AddTypeParameterBoundWhereClause(T); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct AddTypeParameterBoundWhereClause( @@ -334,12 +334,12 @@ struct AddTypeParameterBoundWhereClause( // Note: there is no #[cfg(...)], so this is ALWAYS compiled #[rustc_clean(label="Hir", cfg="cfail2")] #[rustc_clean(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] pub struct EmptyStruct; @@ -353,12 +353,12 @@ struct Visibility; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOfItem", cfg="cfail2")] +#[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOfItem", cfg="cfail3")] +#[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] pub struct Visibility; @@ -375,12 +375,12 @@ mod tuple_struct_change_field_type_indirectly { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOfItem", cfg="cfail2")] + #[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOfItem", cfg="cfail3")] + #[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct TupleStruct( @@ -398,12 +398,12 @@ mod record_struct_change_field_type_indirectly { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOfItem", cfg="cfail2")] + #[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOfItem", cfg="cfail3")] + #[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct RecordStruct { @@ -426,12 +426,12 @@ mod change_trait_bound_indirectly { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOfItem", cfg="cfail2")] + #[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOfItem", cfg="cfail3")] + #[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct Struct(T); @@ -446,12 +446,12 @@ mod change_trait_bound_indirectly_in_where_clause { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOfItem", cfg="cfail2")] + #[rustc_clean(label="TypeOf", cfg="cfail2")] #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOfItem", cfg="cfail3")] + #[rustc_clean(label="TypeOf", cfg="cfail3")] #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] struct Struct(T) where T : Trait; diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.rs b/src/test/ui/dep-graph/dep-graph-struct-signature.rs index 3d660aa8f4b32..d077255343f06 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.rs +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.rs @@ -24,7 +24,7 @@ struct WontChange { mod signatures { use WillChange; - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path + #[rustc_then_this_would_need(TypeOf)] //~ ERROR no path #[rustc_then_this_would_need(AssociatedItems)] //~ ERROR no path #[rustc_then_this_would_need(TraitDefOfItem)] //~ ERROR no path trait Bar { @@ -42,14 +42,14 @@ mod signatures { WillChange { x: x, y: y } } - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK impl WillChange { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn new(x: u32, y: u32) -> WillChange { loop { } } } - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK impl WillChange { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK @@ -57,21 +57,21 @@ mod signatures { } struct WillChanges { - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK x: WillChange, - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK y: WillChange } // The fields change, not the type itself. - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path + #[rustc_then_this_would_need(TypeOf)] //~ ERROR no path fn indirect(x: WillChanges) { } } mod invalid_signatures { use WontChange; - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path + #[rustc_then_this_would_need(TypeOf)] //~ ERROR no path trait A { #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path fn do_something_else_twice(x: WontChange); diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.rs b/src/test/ui/dep-graph/dep-graph-type-alias.rs index 0f703aeb0f7a3..9ddc53a3d2131 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.rs +++ b/src/test/ui/dep-graph/dep-graph-type-alias.rs @@ -14,23 +14,23 @@ type TypeAlias = u32; // The type alias directly affects the type of the field, // not the enclosing struct: -#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path struct Struct { - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK x: TypeAlias, y: u32 } -#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path enum Enum { Variant1 { - #[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK + #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK t: TypeAlias }, Variant2(i32) } -#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path trait Trait { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK fn method(&self, _: TypeAlias); @@ -38,14 +38,14 @@ trait Trait { struct SomeType; -#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR no path +#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path impl SomeType { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn method(&self, _: TypeAlias) {} } -#[rustc_then_this_would_need(TypeOfItem)] //~ ERROR OK +#[rustc_then_this_would_need(TypeOf)] //~ ERROR OK type TypeAlias2 = TypeAlias; #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK From 9e9d03fd66f2fa0eb04b5381f491d6139fab94ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 17 Mar 2019 07:00:46 +0100 Subject: [PATCH 2/4] Add load_cached query modifier and keep dep node names consistent with query names --- src/librustc/dep_graph/dep_node.rs | 2 - src/librustc/query/mod.rs | 29 ++ src/librustc/ty/query/config.rs | 15 -- src/librustc/ty/query/mod.rs | 21 -- src/librustc/ty/query/plumbing.rs | 8 +- .../persist/dirty_clean.rs | 22 +- src/librustc_macros/src/query.rs | 78 +++--- src/test/incremental/hashes/consts.rs | 8 +- src/test/incremental/hashes/enum_defs.rs | 46 ++-- .../incremental/hashes/function_interfaces.rs | 20 +- src/test/incremental/hashes/inherent_impls.rs | 16 +- src/test/incremental/hashes/statics.rs | 8 +- src/test/incremental/hashes/struct_defs.rs | 252 +++++++++--------- .../dep-graph/dep-graph-struct-signature.rs | 14 +- .../dep-graph-struct-signature.stderr | 34 +-- src/test/ui/dep-graph/dep-graph-type-alias.rs | 14 +- .../ui/dep-graph/dep-graph-type-alias.stderr | 36 +-- 17 files changed, 315 insertions(+), 308 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index b88ce643ea499..43e865ad08941 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -492,8 +492,6 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx> // table in the tcx (or elsewhere) maps to one of these // nodes. [] AssociatedItems(DefId), - [] GenericsOfItem(DefId), - [] PredicatesOfItem(DefId), [] ExplicitPredicatesOfItem(DefId), [] PredicatesDefinedOnItem(DefId), [] InferredOutlivesOf(DefId), diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 709d34a156ccc..ecc0089860002 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -1,6 +1,7 @@ use crate::ty::query::QueryDescription; use crate::ty::query::queries; use crate::ty::TyCtxt; +use crate::ty; use crate::hir::def_id::CrateNum; use crate::dep_graph::SerializedDepNodeIndex; use std::borrow::Cow; @@ -23,6 +24,34 @@ rustc_queries! { cache { key.is_local() } } + /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its + /// associated generics. + query generics_of(key: DefId) -> &'tcx ty::Generics { + cache { key.is_local() } + load_cached(tcx, id) { + let generics: Option = tcx.queries.on_disk_cache + .try_load_query_result(tcx, id); + generics.map(|x| tcx.alloc_generics(x)) + } + } + + /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the + /// predicates (where-clauses) that must be proven true in order + /// to reference it. This is almost always the "predicates query" + /// that you want. + /// + /// `predicates_of` builds on `predicates_defined_on` -- in fact, + /// it is almost always the same as that query, except for the + /// case of traits. For traits, `predicates_of` contains + /// an additional `Self: Trait<...>` predicate that users don't + /// actually write. This reflects the fact that to invoke the + /// trait (e.g., via `Default::default`) you must supply types + /// that actually implement the trait. (However, this extra + /// predicate gets in the way of some checks, which are intended + /// to operate over only the actual where-clauses written by the + /// user.) + query predicates_of(_: DefId) -> Lrc> {} + query native_libraries(_: CrateNum) -> Lrc> { desc { "looking up the native libraries of a linked crate" } } diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 6e964fc540ee0..d8159f11acec0 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -937,21 +937,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::instance_def_size_estimate<'tcx> } } -impl<'tcx> QueryDescription<'tcx> for queries::generics_of<'tcx> { - #[inline] - fn cache_on_disk(_: TyCtxt<'_, 'tcx, 'tcx>, def_id: Self::Key) -> bool { - def_id.is_local() - } - - fn try_load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: SerializedDepNodeIndex) - -> Option { - let generics: Option = tcx.queries.on_disk_cache - .try_load_query_result(tcx, id); - generics.map(|x| tcx.alloc_generics(x)) - } -} - impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> { fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> { "generating chalk-style clauses".into() diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index bccc69af2350a..2f085a973d202 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -104,27 +104,6 @@ rustc_query_append! { [define_queries!][ <'tcx> /// Run analysis passes on the crate [] fn analysis: Analysis(CrateNum) -> Result<(), ErrorReported>, - /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its - /// associated generics. - [] fn generics_of: GenericsOfItem(DefId) -> &'tcx ty::Generics, - - /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the - /// predicates (where-clauses) that must be proven true in order - /// to reference it. This is almost always the "predicates query" - /// that you want. - /// - /// `predicates_of` builds on `predicates_defined_on` -- in fact, - /// it is almost always the same as that query, except for the - /// case of traits. For traits, `predicates_of` contains - /// an additional `Self: Trait<...>` predicate that users don't - /// actually write. This reflects the fact that to invoke the - /// trait (e.g., via `Default::default`) you must supply types - /// that actually implement the trait. (However, this extra - /// predicate gets in the way of some checks, which are intended - /// to operate over only the actual where-clauses written by the - /// user.) - [] fn predicates_of: PredicatesOfItem(DefId) -> Lrc>, - /// Maps from the `DefId` of an item (trait/struct/enum/fn) to the /// predicates (where-clauses) directly defined on it. This is /// equal to the `explicit_predicates_of` predicates plus the diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index e78d98cd4f1e1..e82e09c299765 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -1285,8 +1285,6 @@ pub fn force_from_dep_node<'tcx>( DepKind::MirKeys => { force!(mir_keys, LOCAL_CRATE); } DepKind::CrateVariances => { force!(crate_variances, LOCAL_CRATE); } DepKind::AssociatedItems => { force!(associated_item, def_id!()); } - DepKind::GenericsOfItem => { force!(generics_of, def_id!()); } - DepKind::PredicatesOfItem => { force!(predicates_of, def_id!()); } DepKind::PredicatesDefinedOnItem => { force!(predicates_defined_on, def_id!()); } DepKind::ExplicitPredicatesOfItem => { force!(explicit_predicates_of, def_id!()); } DepKind::InferredOutlivesOf => { force!(inferred_outlives_of, def_id!()); } @@ -1501,9 +1499,9 @@ impl_load_from_cache!( SymbolName => def_symbol_name, ConstIsRvaluePromotableToStatic => const_is_rvalue_promotable_to_static, CheckMatch => check_match, - TypeOf => type_of, - GenericsOfItem => generics_of, - PredicatesOfItem => predicates_of, + type_of => type_of, + generics_of => generics_of, + predicates_of => predicates_of, UsedTraitImports => used_trait_imports, CodegenFnAttrs => codegen_fn_attrs, SpecializationGraph => specialization_graph_of, diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index c7a9f1afd0ac6..6b5e19ca49b76 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -36,16 +36,16 @@ const CFG: &str = "cfg"; /// For typedef, constants, and statics const BASE_CONST: &[&str] = &[ - label_strs::TypeOf, + label_strs::type_of, ]; /// DepNodes for functions + methods const BASE_FN: &[&str] = &[ // Callers will depend on the signature of these items, so we better test label_strs::FnSignature, - label_strs::GenericsOfItem, - label_strs::PredicatesOfItem, - label_strs::TypeOf, + label_strs::generics_of, + label_strs::predicates_of, + label_strs::type_of, // And a big part of compilation (that we eventually want to cache) is type inference // information: @@ -62,7 +62,7 @@ const BASE_HIR: &[&str] = &[ /// `impl` implementation of struct/trait const BASE_IMPL: &[&str] = &[ label_strs::AssociatedItemDefIds, - label_strs::GenericsOfItem, + label_strs::generics_of, label_strs::ImplTraitRef, ]; @@ -78,17 +78,17 @@ const BASE_MIR: &[&str] = &[ /// Note that changing the type of a field does not change the type of the struct or enum, but /// adding/removing fields or changing a fields name or visibility does. const BASE_STRUCT: &[&str] = &[ - label_strs::GenericsOfItem, - label_strs::PredicatesOfItem, - label_strs::TypeOf, + label_strs::generics_of, + label_strs::predicates_of, + label_strs::type_of, ]; /// Trait definition `DepNode`s. const BASE_TRAIT_DEF: &[&str] = &[ label_strs::AssociatedItemDefIds, - label_strs::GenericsOfItem, + label_strs::generics_of, label_strs::ObjectSafety, - label_strs::PredicatesOfItem, + label_strs::predicates_of, label_strs::SpecializationGraph, label_strs::TraitDefOfItem, label_strs::TraitImpls, @@ -179,7 +179,7 @@ const LABELS_TRAIT: &[&[&str]] = &[ // Fields are kind of separate from their containers, as they can change independently from // them. We should at least check // -// TypeOf for these. +// type_of for these. type Labels = FxHashSet; diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs index aeb830ff9b9dc..75ce8641b1091 100644 --- a/src/librustc_macros/src/query.rs +++ b/src/librustc_macros/src/query.rs @@ -1,7 +1,7 @@ use proc_macro::TokenStream; use proc_macro2::Span; use syn::{ - Token, Ident, Type, Attribute, ReturnType, Expr, + Token, Ident, Type, Attribute, ReturnType, Expr, Block, braced, parenthesized, parse_macro_input, }; use syn::parse::{Result, Parse, ParseStream}; @@ -25,6 +25,7 @@ impl Parse for IdentOrWild { enum QueryAttribute { Desc(Option, Punctuated), Cache(Option, Expr), + LoadCached(Ident, Ident, Block), FatalCycle, } @@ -63,6 +64,17 @@ impl Parse for QueryAttribute { panic!("unexpected tokens in block"); }; Ok(QueryAttribute::Cache(tcx, expr)) + } else if attr == "load_cached" { + let args; + parenthesized!(args in input); + let tcx = args.parse()?; + args.parse::()?; + let id = args.parse()?; + if !args.is_empty() { + panic!("unexpected tokens in arguments"); + }; + let block = input.parse()?; + Ok(QueryAttribute::LoadCached(tcx, id, block)) } else if attr == "fatal_cycle" { Ok(QueryAttribute::FatalCycle) } else { @@ -153,22 +165,6 @@ impl Parse for Group { } } -fn camel_case(string: &str) -> String { - let mut pos = vec![0]; - for (i, c) in string.chars().enumerate() { - if c == '_' { - pos.push(i + 1); - } - } - string.chars().enumerate().filter(|c| c.1 != '_').flat_map(|(i, c)| { - if pos.contains(&i) { - c.to_uppercase().collect::>() - } else { - vec![c] - } - }).collect() -} - pub fn rustc_queries(input: TokenStream) -> TokenStream { let groups = parse_macro_input!(input as List); @@ -181,9 +177,6 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { let mut group_stream = quote! {}; for query in &group.queries.0 { let name = &query.name; - let dep_node_name = Ident::new( - &camel_case(&name.to_string()), - name.span()); let arg = &query.arg; let key = &query.key.0; let result_full = &query.result; @@ -192,11 +185,38 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { _ => quote! { #result_full }, }; + let load_cached = query.attrs.0.iter().find_map(|attr| match attr { + QueryAttribute::LoadCached(tcx, id, block) => Some((tcx, id, block)), + _ => None, + }); + // Find out if we should cache the query on disk let cache = query.attrs.0.iter().find_map(|attr| match attr { QueryAttribute::Cache(tcx, expr) => Some((tcx, expr)), _ => None, }).map(|(tcx, expr)| { + let try_load_from_disk = if let Some((tcx, id, block)) = load_cached { + quote! { + #[inline] + fn try_load_from_disk( + #tcx: TyCtxt<'_, 'tcx, 'tcx>, + #id: SerializedDepNodeIndex + ) -> Option { + #block + } + } + } else { + quote! { + #[inline] + fn try_load_from_disk( + tcx: TyCtxt<'_, 'tcx, 'tcx>, + id: SerializedDepNodeIndex + ) -> Option { + tcx.queries.on_disk_cache.try_load_query_result(tcx, id) + } + } + }; + let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); quote! { #[inline] @@ -204,23 +224,21 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { #expr } - #[inline] - fn try_load_from_disk( - tcx: TyCtxt<'_, 'tcx, 'tcx>, - id: SerializedDepNodeIndex - ) -> Option { - tcx.queries.on_disk_cache.try_load_query_result(tcx, id) - } + #try_load_from_disk } }); + if cache.is_none() && load_cached.is_some() { + panic!("load_cached modifier on query `{}` without a cache modifier", name); + } + let fatal_cycle = query.attrs.0.iter().find_map(|attr| match attr { QueryAttribute::FatalCycle => Some(()), _ => None, }).map(|_| quote! { fatal_cycle }).unwrap_or(quote! {}); group_stream.extend(quote! { - [#fatal_cycle] fn #name: #dep_node_name(#arg) #result, + [#fatal_cycle] fn #name: #name(#arg) #result, }); let desc = query.attrs.0.iter().find_map(|attr| match attr { @@ -251,10 +269,10 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { } dep_node_def_stream.extend(quote! { - [] #dep_node_name(#arg), + [] #name(#arg), }); dep_node_force_stream.extend(quote! { - DepKind::#dep_node_name => { + DepKind::#name => { if let Some(key) = RecoverKey::recover($tcx, $dep_node) { force_ex!($tcx, #name, key); } else { diff --git a/src/test/incremental/hashes/consts.rs b/src/test/incremental/hashes/consts.rs index 03c21712d2d0b..516276a49ea8f 100644 --- a/src/test/incremental/hashes/consts.rs +++ b/src/test/incremental/hashes/consts.rs @@ -29,7 +29,7 @@ pub const CONST_VISIBILITY: u8 = 0; const CONST_CHANGE_TYPE_1: i32 = 0; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_1: u32 = 0; @@ -39,7 +39,7 @@ const CONST_CHANGE_TYPE_1: u32 = 0; const CONST_CHANGE_TYPE_2: Option = None; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_2: Option = None; @@ -99,11 +99,11 @@ mod const_change_type_indirectly { #[cfg(not(cfail1))] use super::ReferencedType2 as Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_1: Type = Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_2: Option = None; } diff --git a/src/test/incremental/hashes/enum_defs.rs b/src/test/incremental/hashes/enum_defs.rs index 62f6e1f571b6d..aa2dc798b81c8 100644 --- a/src/test/incremental/hashes/enum_defs.rs +++ b/src/test/incremental/hashes/enum_defs.rs @@ -42,7 +42,7 @@ enum EnumChangeNameCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameCStyleVariant { Variant1, @@ -59,7 +59,7 @@ enum EnumChangeNameTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameTupleStyleVariant { Variant1, @@ -76,7 +76,7 @@ enum EnumChangeNameStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameStructStyleVariant { Variant1, @@ -109,7 +109,7 @@ enum EnumChangeValueCStyleVariant1 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeValueCStyleVariant1 { Variant1, @@ -125,7 +125,7 @@ enum EnumAddCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddCStyleVariant { Variant1, @@ -142,7 +142,7 @@ enum EnumRemoveCStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveCStyleVariant { Variant1, @@ -157,7 +157,7 @@ enum EnumAddTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddTupleStyleVariant { Variant1, @@ -174,7 +174,7 @@ enum EnumRemoveTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveTupleStyleVariant { Variant1, @@ -189,7 +189,7 @@ enum EnumAddStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddStructStyleVariant { Variant1, @@ -206,7 +206,7 @@ enum EnumRemoveStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumRemoveStructStyleVariant { Variant1, @@ -257,7 +257,7 @@ enum EnumChangeFieldNameStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeFieldNameStructStyleVariant { Variant1 { a: u32, c: u32 }, @@ -289,7 +289,7 @@ enum EnumChangeFieldOrderStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeFieldOrderStructStyleVariant { Variant1 { b: f32, a: u32 }, @@ -304,7 +304,7 @@ enum EnumAddFieldTupleStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddFieldTupleStyleVariant { Variant1(u32, u32, u32), @@ -319,7 +319,7 @@ enum EnumAddFieldStructStyleVariant { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddFieldStructStyleVariant { Variant1 { a: u32, b: u32, c: u32 }, @@ -353,7 +353,7 @@ enum EnumAddReprC { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] #[repr(C)] enum EnumAddReprC { @@ -402,7 +402,7 @@ enum EnumChangeNameOfLifetimeParameter<'a> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="PredicatesOfItem")] +#[rustc_dirty(cfg="cfail2", except="predicates_of")] #[rustc_clean(cfg="cfail3")] enum EnumChangeNameOfLifetimeParameter<'b> { Variant1(&'b u32), @@ -418,7 +418,7 @@ enum EnumAddLifetimeParameter<'a> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="PredicatesOfItem")] +#[rustc_dirty(cfg="cfail2", except="predicates_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameter<'a, 'b> { Variant1(&'a u32), @@ -435,7 +435,7 @@ enum EnumAddLifetimeParameterBound<'a, 'b> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="GenericsOfItem,TypeOf")] +#[rustc_dirty(cfg="cfail2", except="generics_of,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameterBound<'a, 'b: 'a> { Variant1(&'a u32), @@ -450,7 +450,7 @@ enum EnumAddLifetimeBoundToParameter<'a, T> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="TypeOf")] +#[rustc_dirty(cfg="cfail2", except="type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeBoundToParameter<'a, T: 'a> { Variant1(T), @@ -482,7 +482,7 @@ enum EnumAddLifetimeParameterBoundWhere<'a, 'b> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="GenericsOfItem,TypeOf")] +#[rustc_dirty(cfg="cfail2", except="generics_of,type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeParameterBoundWhere<'a, 'b> where 'b: 'a { Variant1(&'a u32), @@ -499,7 +499,7 @@ enum EnumAddLifetimeBoundToParameterWhere<'a, T> { } #[cfg(not(cfail1))] -#[rustc_dirty(cfg="cfail2", except="TypeOf")] +#[rustc_dirty(cfg="cfail2", except="type_of")] #[rustc_clean(cfg="cfail3")] enum EnumAddLifetimeBoundToParameterWhere<'a, T> where T: 'a { Variant1(T), @@ -618,7 +618,7 @@ mod change_trait_bound_indirectly { #[cfg(not(cfail1))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,PredicatesOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,predicates_of")] #[rustc_clean(cfg="cfail3")] enum Enum { Variant1(T) @@ -634,7 +634,7 @@ mod change_trait_bound_indirectly_where { #[cfg(not(cfail1))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,PredicatesOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,predicates_of")] #[rustc_clean(cfg="cfail3")] enum Enum where T: Trait { Variant1(T) diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs index 6d7bbf2b7dad9..fccec704d6356 100644 --- a/src/test/incremental/hashes/function_interfaces.rs +++ b/src/test/incremental/hashes/function_interfaces.rs @@ -117,7 +117,7 @@ pub fn type_parameter() {} #[cfg(not(cfail1))] #[rustc_clean(cfg = "cfail2", - except = "Hir, HirBody, GenericsOfItem, TypeOf, PredicatesOfItem")] + except = "Hir, HirBody, generics_of, type_of, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn type_parameter() {} @@ -128,7 +128,7 @@ pub fn type_parameter() {} pub fn lifetime_parameter() {} #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, GenericsOfItem")] +#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, generics_of")] #[rustc_clean(cfg = "cfail3")] pub fn lifetime_parameter<'a>() {} @@ -139,7 +139,7 @@ pub fn lifetime_parameter<'a>() {} pub fn trait_bound() {} #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, PredicatesOfItem")] +#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn trait_bound() {} @@ -150,7 +150,7 @@ pub fn trait_bound() {} pub fn builtin_bound() {} #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, PredicatesOfItem")] +#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn builtin_bound() {} @@ -162,7 +162,7 @@ pub fn lifetime_bound<'a, T>() {} #[cfg(not(cfail1))] #[rustc_clean(cfg = "cfail2", - except = "Hir, HirBody, GenericsOfItem, TypeOf, PredicatesOfItem")] + except = "Hir, HirBody, generics_of, type_of, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn lifetime_bound<'a, T: 'a>() {} @@ -173,7 +173,7 @@ pub fn lifetime_bound<'a, T: 'a>() {} pub fn second_trait_bound() {} #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, PredicatesOfItem")] +#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn second_trait_bound() {} @@ -184,7 +184,7 @@ pub fn second_trait_bound() {} pub fn second_builtin_bound() {} #[cfg(not(cfail1))] -#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, PredicatesOfItem")] +#[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn second_builtin_bound() {} @@ -196,7 +196,7 @@ pub fn second_lifetime_bound<'a, 'b, T: 'a>() {} #[cfg(not(cfail1))] #[rustc_clean(cfg = "cfail2", - except = "Hir, HirBody, GenericsOfItem, TypeOf, PredicatesOfItem")] + except = "Hir, HirBody, generics_of, type_of, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn second_lifetime_bound<'a, 'b, T: 'a + 'b>() {} @@ -326,7 +326,7 @@ pub mod change_trait_bound_indirectly { #[cfg(not(cfail1))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, PredicatesOfItem")] + #[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn indirect_trait_bound(p: T) {} } @@ -340,7 +340,7 @@ pub mod change_trait_bound_indirectly_in_where_clause { #[cfg(not(cfail1))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, PredicatesOfItem")] + #[rustc_clean(cfg = "cfail2", except = "Hir, HirBody, predicates_of")] #[rustc_clean(cfg = "cfail3")] pub fn indirect_trait_bound_where(p: T) where diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index a66c6f6eee5d4..ebafd07dbef57 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -97,7 +97,7 @@ impl Foo { #[rustc_clean(cfg="cfail2", except="Hir,HirBody")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_dirty(cfg="cfail2", except="TypeOf,PredicatesOfItem")] + #[rustc_dirty(cfg="cfail2", except="type_of,predicates_of")] #[rustc_clean(cfg="cfail3")] pub fn method_selfness(&self) { } } @@ -334,7 +334,7 @@ impl Foo { // appear dirty, that might be the cause. -nmatsakis #[rustc_clean( cfg="cfail2", - except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOf", + except="Hir,HirBody,generics_of,predicates_of,type_of", )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_method(&self) { } @@ -354,7 +354,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOf,TypeckTables" + except="Hir,HirBody,generics_of,predicates_of,type_of,TypeckTables" )] #[rustc_clean(cfg="cfail3")] pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { } @@ -381,8 +381,8 @@ impl Foo { // generics before the body, then the `HirId` for things in the // body will be affected. So if you start to see `TypeckTables` // appear dirty, that might be the cause. -nmatsakis - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,\ - TypeOf")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,generics_of,predicates_of,\ + type_of")] #[rustc_clean(cfg="cfail3")] pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { } } @@ -408,7 +408,7 @@ impl Foo { // generics before the body, then the `HirId` for things in the // body will be affected. So if you start to see `TypeckTables` // appear dirty, that might be the cause. -nmatsakis - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,PredicatesOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,predicates_of")] #[rustc_clean(cfg="cfail3")] pub fn add_trait_bound_to_type_param_of_method(&self) { } } @@ -442,12 +442,12 @@ impl Bar { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,generics_of")] #[rustc_clean(cfg="cfail3")] impl Bar { #[rustc_clean( cfg="cfail2", - except="GenericsOfItem,FnSignature,TypeckTables,TypeOf,MirOptimized,MirBuilt" + except="generics_of,FnSignature,TypeckTables,type_of,MirOptimized,MirBuilt" )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_impl(&self) { } diff --git a/src/test/incremental/hashes/statics.rs b/src/test/incremental/hashes/statics.rs index aa78389faf48e..3bee2aca5b6c2 100644 --- a/src/test/incremental/hashes/statics.rs +++ b/src/test/incremental/hashes/statics.rs @@ -74,7 +74,7 @@ static STATIC_THREAD_LOCAL: u8 = 0; static STATIC_CHANGE_TYPE_1: i16 = 0; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_1: u64 = 0; @@ -84,7 +84,7 @@ static STATIC_CHANGE_TYPE_1: u64 = 0; static STATIC_CHANGE_TYPE_2: Option = None; #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] +#[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_2: Option = None; @@ -144,11 +144,11 @@ mod static_change_type_indirectly { #[cfg(not(cfail1))] use super::ReferencedType2 as Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type; - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeOf")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,type_of")] #[rustc_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option = None; } diff --git a/src/test/incremental/hashes/struct_defs.rs b/src/test/incremental/hashes/struct_defs.rs index b948ae8228e24..8d32e33054ccc 100644 --- a/src/test/incremental/hashes/struct_defs.rs +++ b/src/test/incremental/hashes/struct_defs.rs @@ -26,14 +26,14 @@ pub struct LayoutPacked; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] #[repr(packed)] pub struct LayoutPacked; @@ -43,14 +43,14 @@ struct LayoutC; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] #[repr(C)] struct LayoutC; @@ -63,14 +63,14 @@ struct TupleStructFieldType(i32); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] // Note that changing the type of a field does not change the type of the struct or enum, but // adding/removing fields or changing a fields name or visibility does. struct TupleStructFieldType( @@ -86,14 +86,14 @@ struct TupleStructAddField(i32); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct TupleStructAddField( i32, u32 @@ -108,14 +108,14 @@ struct TupleStructFieldVisibility(char); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct TupleStructFieldVisibility(pub char); @@ -127,14 +127,14 @@ struct RecordStructFieldType { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] // Note that changing the type of a field does not change the type of the struct or enum, but // adding/removing fields or changing a fields name or visibility does. struct RecordStructFieldType { @@ -150,14 +150,14 @@ struct RecordStructFieldName { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStructFieldName { y: f32 } @@ -169,14 +169,14 @@ struct RecordStructAddField { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStructAddField { x: f32, y: () } @@ -190,14 +190,14 @@ struct RecordStructFieldVisibility { x: f32 } #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStructFieldVisibility { pub x: f32 } @@ -211,14 +211,14 @@ struct AddLifetimeParameter<'a>(&'a f32, &'a f64); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_dirty(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64); @@ -230,14 +230,14 @@ struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddLifetimeParameterBound<'a, 'b: 'a>( &'a f32, &'b f64 @@ -249,14 +249,14 @@ struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddLifetimeParameterBoundWhereClause<'a, 'b>( &'a f32, &'b f64) @@ -271,14 +271,14 @@ struct AddTypeParameter(T1, T1); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_dirty(label="TypeOf", cfg="cfail2")] -#[rustc_dirty(label="GenericsOfItem", cfg="cfail2")] -#[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_dirty(label="type_of", cfg="cfail2")] +#[rustc_dirty(label="generics_of", cfg="cfail2")] +#[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddTypeParameter( // The field contains the parent's Generics, so it's dirty even though its // type hasn't changed. @@ -295,14 +295,14 @@ struct AddTypeParameterBound(T); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddTypeParameterBound( T ); @@ -314,14 +314,14 @@ struct AddTypeParameterBoundWhereClause(T); #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] struct AddTypeParameterBoundWhereClause( T ) where T: Sync; @@ -334,14 +334,14 @@ struct AddTypeParameterBoundWhereClause( // Note: there is no #[cfg(...)], so this is ALWAYS compiled #[rustc_clean(label="Hir", cfg="cfail2")] #[rustc_clean(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] pub struct EmptyStruct; @@ -353,14 +353,14 @@ struct Visibility; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] -#[rustc_clean(label="TypeOf", cfg="cfail2")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail2")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] +#[rustc_clean(label="type_of", cfg="cfail2")] +#[rustc_clean(label="generics_of", cfg="cfail2")] +#[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] -#[rustc_clean(label="TypeOf", cfg="cfail3")] -#[rustc_clean(label="GenericsOfItem", cfg="cfail3")] -#[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] +#[rustc_clean(label="type_of", cfg="cfail3")] +#[rustc_clean(label="generics_of", cfg="cfail3")] +#[rustc_clean(label="predicates_of", cfg="cfail3")] pub struct Visibility; struct ReferencedType1; @@ -375,14 +375,14 @@ mod tuple_struct_change_field_type_indirectly { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOf", cfg="cfail2")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] - #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] + #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="generics_of", cfg="cfail2")] + #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOf", cfg="cfail3")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] - #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] + #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="generics_of", cfg="cfail3")] + #[rustc_clean(label="predicates_of", cfg="cfail3")] struct TupleStruct( FieldType ); @@ -398,14 +398,14 @@ mod record_struct_change_field_type_indirectly { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOf", cfg="cfail2")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] - #[rustc_clean(label="PredicatesOfItem", cfg="cfail2")] + #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="generics_of", cfg="cfail2")] + #[rustc_clean(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOf", cfg="cfail3")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] - #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] + #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="generics_of", cfg="cfail3")] + #[rustc_clean(label="predicates_of", cfg="cfail3")] struct RecordStruct { _x: FieldType } @@ -426,14 +426,14 @@ mod change_trait_bound_indirectly { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOf", cfg="cfail2")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] - #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] + #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="generics_of", cfg="cfail2")] + #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOf", cfg="cfail3")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] - #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] + #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="generics_of", cfg="cfail3")] + #[rustc_clean(label="predicates_of", cfg="cfail3")] struct Struct(T); } @@ -446,13 +446,13 @@ mod change_trait_bound_indirectly_in_where_clause { #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_dirty(label="HirBody", cfg="cfail2")] - #[rustc_clean(label="TypeOf", cfg="cfail2")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail2")] - #[rustc_dirty(label="PredicatesOfItem", cfg="cfail2")] + #[rustc_clean(label="type_of", cfg="cfail2")] + #[rustc_clean(label="generics_of", cfg="cfail2")] + #[rustc_dirty(label="predicates_of", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_clean(label="HirBody", cfg="cfail3")] - #[rustc_clean(label="TypeOf", cfg="cfail3")] - #[rustc_clean(label="GenericsOfItem", cfg="cfail3")] - #[rustc_clean(label="PredicatesOfItem", cfg="cfail3")] + #[rustc_clean(label="type_of", cfg="cfail3")] + #[rustc_clean(label="generics_of", cfg="cfail3")] + #[rustc_clean(label="predicates_of", cfg="cfail3")] struct Struct(T) where T : Trait; } diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.rs b/src/test/ui/dep-graph/dep-graph-struct-signature.rs index d077255343f06..bd6d3a7e56fc3 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.rs +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.rs @@ -24,7 +24,7 @@ struct WontChange { mod signatures { use WillChange; - #[rustc_then_this_would_need(TypeOf)] //~ ERROR no path + #[rustc_then_this_would_need(type_of)] //~ ERROR no path #[rustc_then_this_would_need(AssociatedItems)] //~ ERROR no path #[rustc_then_this_would_need(TraitDefOfItem)] //~ ERROR no path trait Bar { @@ -42,14 +42,14 @@ mod signatures { WillChange { x: x, y: y } } - #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK + #[rustc_then_this_would_need(type_of)] //~ ERROR OK impl WillChange { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn new(x: u32, y: u32) -> WillChange { loop { } } } - #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK + #[rustc_then_this_would_need(type_of)] //~ ERROR OK impl WillChange { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK @@ -57,21 +57,21 @@ mod signatures { } struct WillChanges { - #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK + #[rustc_then_this_would_need(type_of)] //~ ERROR OK x: WillChange, - #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK + #[rustc_then_this_would_need(type_of)] //~ ERROR OK y: WillChange } // The fields change, not the type itself. - #[rustc_then_this_would_need(TypeOf)] //~ ERROR no path + #[rustc_then_this_would_need(type_of)] //~ ERROR no path fn indirect(x: WillChanges) { } } mod invalid_signatures { use WontChange; - #[rustc_then_this_would_need(TypeOf)] //~ ERROR no path + #[rustc_then_this_would_need(type_of)] //~ ERROR no path trait A { #[rustc_then_this_would_need(FnSignature)] //~ ERROR no path fn do_something_else_twice(x: WontChange); diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.stderr b/src/test/ui/dep-graph/dep-graph-struct-signature.stderr index 8736d15624736..7aa4251752e5c 100644 --- a/src/test/ui/dep-graph/dep-graph-struct-signature.stderr +++ b/src/test/ui/dep-graph/dep-graph-struct-signature.stderr @@ -1,8 +1,8 @@ -error: no path from `WillChange` to `TypeOfItem` +error: no path from `WillChange` to `type_of` --> $DIR/dep-graph-struct-signature.rs:27:5 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: no path from `WillChange` to `AssociatedItems` --> $DIR/dep-graph-struct-signature.rs:28:5 @@ -43,38 +43,38 @@ LL | #[rustc_then_this_would_need(TypeckTables)] error: OK --> $DIR/dep-graph-struct-signature.rs:45:5 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:52:5 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:60:9 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-struct-signature.rs:62:9 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `TypeOfItem` +error: no path from `WillChange` to `type_of` --> $DIR/dep-graph-struct-signature.rs:67:5 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `WillChange` to `TypeOfItem` +error: no path from `WillChange` to `type_of` --> $DIR/dep-graph-struct-signature.rs:74:5 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: no path from `WillChange` to `FnSignature` --> $DIR/dep-graph-struct-signature.rs:80:5 diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.rs b/src/test/ui/dep-graph/dep-graph-type-alias.rs index 9ddc53a3d2131..5621284fb18b2 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.rs +++ b/src/test/ui/dep-graph/dep-graph-type-alias.rs @@ -14,23 +14,23 @@ type TypeAlias = u32; // The type alias directly affects the type of the field, // not the enclosing struct: -#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path +#[rustc_then_this_would_need(type_of)] //~ ERROR no path struct Struct { - #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK + #[rustc_then_this_would_need(type_of)] //~ ERROR OK x: TypeAlias, y: u32 } -#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path +#[rustc_then_this_would_need(type_of)] //~ ERROR no path enum Enum { Variant1 { - #[rustc_then_this_would_need(TypeOf)] //~ ERROR OK + #[rustc_then_this_would_need(type_of)] //~ ERROR OK t: TypeAlias }, Variant2(i32) } -#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path +#[rustc_then_this_would_need(type_of)] //~ ERROR no path trait Trait { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK fn method(&self, _: TypeAlias); @@ -38,14 +38,14 @@ trait Trait { struct SomeType; -#[rustc_then_this_would_need(TypeOf)] //~ ERROR no path +#[rustc_then_this_would_need(type_of)] //~ ERROR no path impl SomeType { #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK #[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK fn method(&self, _: TypeAlias) {} } -#[rustc_then_this_would_need(TypeOf)] //~ ERROR OK +#[rustc_then_this_would_need(type_of)] //~ ERROR OK type TypeAlias2 = TypeAlias; #[rustc_then_this_would_need(FnSignature)] //~ ERROR OK diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.stderr b/src/test/ui/dep-graph/dep-graph-type-alias.stderr index f54e511acc1ff..520c2a5ed2182 100644 --- a/src/test/ui/dep-graph/dep-graph-type-alias.stderr +++ b/src/test/ui/dep-graph/dep-graph-type-alias.stderr @@ -1,44 +1,44 @@ -error: no path from `TypeAlias` to `TypeOfItem` +error: no path from `TypeAlias` to `type_of` --> $DIR/dep-graph-type-alias.rs:17:1 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:19:5 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `TypeAlias` to `TypeOfItem` +error: no path from `TypeAlias` to `type_of` --> $DIR/dep-graph-type-alias.rs:24:1 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:27:9 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `TypeAlias` to `TypeOfItem` +error: no path from `TypeAlias` to `type_of` --> $DIR/dep-graph-type-alias.rs:33:1 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: no path from `TypeAlias` to `TypeOfItem` +error: no path from `TypeAlias` to `type_of` --> $DIR/dep-graph-type-alias.rs:41:1 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:48:1 | -LL | #[rustc_then_this_would_need(TypeOfItem)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_then_this_would_need(type_of)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: OK --> $DIR/dep-graph-type-alias.rs:51:1 From 4f49fff019c50d70240116090a2720a8a2dd5c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 18 Mar 2019 08:19:23 +0100 Subject: [PATCH 3/4] Clean up parsing code and split out codegen for the QueryDescription impl --- src/librustc_macros/src/lib.rs | 1 - src/librustc_macros/src/query.rs | 261 +++++++++++++++++-------------- src/librustc_macros/src/tt.rs | 65 -------- 3 files changed, 142 insertions(+), 185 deletions(-) delete mode 100644 src/librustc_macros/src/tt.rs diff --git a/src/librustc_macros/src/lib.rs b/src/librustc_macros/src/lib.rs index 78520b6dce690..e99ceb1b0c79b 100644 --- a/src/librustc_macros/src/lib.rs +++ b/src/librustc_macros/src/lib.rs @@ -9,7 +9,6 @@ use proc_macro::TokenStream; mod hash_stable; mod query; -mod tt; #[proc_macro] pub fn rustc_queries(input: TokenStream) -> TokenStream { diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs index 75ce8641b1091..2f9fdacdd71ca 100644 --- a/src/librustc_macros/src/query.rs +++ b/src/librustc_macros/src/query.rs @@ -1,14 +1,21 @@ use proc_macro::TokenStream; use proc_macro2::Span; use syn::{ - Token, Ident, Type, Attribute, ReturnType, Expr, Block, + Token, Ident, Type, Attribute, ReturnType, Expr, Block, Error, braced, parenthesized, parse_macro_input, }; +use syn::spanned::Spanned; use syn::parse::{Result, Parse, ParseStream}; use syn::punctuated::Punctuated; +use syn; use quote::quote; -use crate::tt::TS; +#[allow(non_camel_case_types)] +mod kw { + syn::custom_keyword!(query); +} + +/// Ident or a wildcard `_`. struct IdentOrWild(Ident); impl Parse for IdentOrWild { @@ -22,17 +29,27 @@ impl Parse for IdentOrWild { } } -enum QueryAttribute { +/// A modifier for a query +enum QueryModifier { + /// The description of the query Desc(Option, Punctuated), + + /// Cache the query to disk if the `Expr` returns true. Cache(Option, Expr), + + /// Custom code to load the query from disk. LoadCached(Ident, Ident, Block), + + /// A cycle error for this query aborting the compilation with a fatal error. FatalCycle, } -impl Parse for QueryAttribute { +impl Parse for QueryModifier { fn parse(input: ParseStream<'_>) -> Result { - let attr: Ident = input.parse()?; - if attr == "desc" { + let modifier: Ident = input.parse()?; + if modifier == "desc" { + // Parse a description modifier like: + // `desc { |tcx| "foo {}", tcx.item_path(key) }` let attr_content; braced!(attr_content in input); let tcx = if attr_content.peek(Token![|]) { @@ -44,11 +61,10 @@ impl Parse for QueryAttribute { None }; let desc = attr_content.parse_terminated(Expr::parse)?; - if !attr_content.is_empty() { - panic!("unexpected tokens in block"); - }; - Ok(QueryAttribute::Desc(tcx, desc)) - } else if attr == "cache" { + Ok(QueryModifier::Desc(tcx, desc)) + } else if modifier == "cache" { + // Parse a cache modifier like: + // `cache { |tcx| key.is_local() }` let attr_content; braced!(attr_content in input); let tcx = if attr_content.peek(Token![|]) { @@ -60,68 +76,59 @@ impl Parse for QueryAttribute { None }; let expr = attr_content.parse()?; - if !attr_content.is_empty() { - panic!("unexpected tokens in block"); - }; - Ok(QueryAttribute::Cache(tcx, expr)) - } else if attr == "load_cached" { + Ok(QueryModifier::Cache(tcx, expr)) + } else if modifier == "load_cached" { + // Parse a load_cached modifier like: + // `load_cached(tcx, id) { tcx.queries.on_disk_cache.try_load_query_result(tcx, id) }` let args; parenthesized!(args in input); let tcx = args.parse()?; args.parse::()?; let id = args.parse()?; - if !args.is_empty() { - panic!("unexpected tokens in arguments"); - }; let block = input.parse()?; - Ok(QueryAttribute::LoadCached(tcx, id, block)) - } else if attr == "fatal_cycle" { - Ok(QueryAttribute::FatalCycle) + Ok(QueryModifier::LoadCached(tcx, id, block)) + } else if modifier == "fatal_cycle" { + Ok(QueryModifier::FatalCycle) } else { - panic!("unknown query modifier {}", attr) + Err(Error::new(modifier.span(), "unknown query modifier")) } } } +/// Ensures only doc comment attributes are used +fn check_attributes(attrs: Vec) -> Result<()> { + for attr in attrs { + if !attr.path.is_ident("doc") { + return Err(Error::new(attr.span(), "attributes not supported on queries")); + } + } + Ok(()) +} + +/// A compiler query. `query ... { ... }` struct Query { - attrs: List, + attrs: List, name: Ident, key: IdentOrWild, arg: Type, result: ReturnType, } -fn check_attributes(attrs: Vec) { - for attr in attrs { - let path = attr.path; - let path = quote! { #path }; - let path = TS(&path); - - if path != TS("e! { doc }) { - panic!("attribute `{}` not supported on queries", path.0) - } - } -} - impl Parse for Query { fn parse(input: ParseStream<'_>) -> Result { - check_attributes(input.call(Attribute::parse_outer)?); + check_attributes(input.call(Attribute::parse_outer)?)?; - let query: Ident = input.parse()?; - if query != "query" { - panic!("expected `query`"); - } + // Parse the query declaration. Like `query type_of(key: DefId) -> Ty<'tcx>` + input.parse::()?; let name: Ident = input.parse()?; let arg_content; parenthesized!(arg_content in input); let key = arg_content.parse()?; arg_content.parse::()?; let arg = arg_content.parse()?; - if !arg_content.is_empty() { - panic!("expected only one query argument"); - }; let result = input.parse()?; + // Parse the query modifiers let content; braced!(content in input); let attrs = content.parse()?; @@ -136,6 +143,7 @@ impl Parse for Query { } } +/// A type used to greedily parse another type until the input is empty. struct List(Vec); impl Parse for List { @@ -148,6 +156,7 @@ impl Parse for List { } } +/// A named group containing queries. struct Group { name: Ident, queries: List, @@ -165,6 +174,88 @@ impl Parse for Group { } } +/// Add the impl of QueryDescription for the query to `impls` if one is requested +fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStream) { + let name = &query.name; + let arg = &query.arg; + let key = &query.key.0; + + // Find custom code to load the query from disk + let load_cached = query.attrs.0.iter().find_map(|attr| match attr { + QueryModifier::LoadCached(tcx, id, block) => Some((tcx, id, block)), + _ => None, + }); + + // Find out if we should cache the query on disk + let cache = query.attrs.0.iter().find_map(|attr| match attr { + QueryModifier::Cache(tcx, expr) => Some((tcx, expr)), + _ => None, + }).map(|(tcx, expr)| { + let try_load_from_disk = if let Some((tcx, id, block)) = load_cached { + quote! { + #[inline] + fn try_load_from_disk( + #tcx: TyCtxt<'_, 'tcx, 'tcx>, + #id: SerializedDepNodeIndex + ) -> Option { + #block + } + } + } else { + quote! { + #[inline] + fn try_load_from_disk( + tcx: TyCtxt<'_, 'tcx, 'tcx>, + id: SerializedDepNodeIndex + ) -> Option { + tcx.queries.on_disk_cache.try_load_query_result(tcx, id) + } + } + }; + + let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); + quote! { + #[inline] + fn cache_on_disk(#tcx: TyCtxt<'_, 'tcx, 'tcx>, #key: Self::Key) -> bool { + #expr + } + + #try_load_from_disk + } + }); + + if cache.is_none() && load_cached.is_some() { + panic!("load_cached modifier on query `{}` without a cache modifier", name); + } + + let desc = query.attrs.0.iter().find_map(|attr| match attr { + QueryModifier::Desc(tcx, desc) => Some((tcx, desc)), + _ => None, + }).map(|(tcx, desc)| { + let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); + quote! { + fn describe( + #tcx: TyCtxt<'_, '_, '_>, + #key: #arg, + ) -> Cow<'static, str> { + format!(#desc).into() + } + } + }); + + if desc.is_some() || cache.is_some() { + let cache = cache.unwrap_or(quote! {}); + let desc = desc.unwrap_or(quote! {}); + + impls.extend(quote! { + impl<'tcx> QueryDescription<'tcx> for queries::#name<'tcx> { + #desc + #cache + } + }); + } +} + pub fn rustc_queries(input: TokenStream) -> TokenStream { let groups = parse_macro_input!(input as List); @@ -178,99 +269,31 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { for query in &group.queries.0 { let name = &query.name; let arg = &query.arg; - let key = &query.key.0; let result_full = &query.result; let result = match query.result { ReturnType::Default => quote! { -> () }, _ => quote! { #result_full }, }; - let load_cached = query.attrs.0.iter().find_map(|attr| match attr { - QueryAttribute::LoadCached(tcx, id, block) => Some((tcx, id, block)), - _ => None, - }); - - // Find out if we should cache the query on disk - let cache = query.attrs.0.iter().find_map(|attr| match attr { - QueryAttribute::Cache(tcx, expr) => Some((tcx, expr)), - _ => None, - }).map(|(tcx, expr)| { - let try_load_from_disk = if let Some((tcx, id, block)) = load_cached { - quote! { - #[inline] - fn try_load_from_disk( - #tcx: TyCtxt<'_, 'tcx, 'tcx>, - #id: SerializedDepNodeIndex - ) -> Option { - #block - } - } - } else { - quote! { - #[inline] - fn try_load_from_disk( - tcx: TyCtxt<'_, 'tcx, 'tcx>, - id: SerializedDepNodeIndex - ) -> Option { - tcx.queries.on_disk_cache.try_load_query_result(tcx, id) - } - } - }; - - let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); - quote! { - #[inline] - fn cache_on_disk(#tcx: TyCtxt<'_, 'tcx, 'tcx>, #key: Self::Key) -> bool { - #expr - } - - #try_load_from_disk - } - }); - - if cache.is_none() && load_cached.is_some() { - panic!("load_cached modifier on query `{}` without a cache modifier", name); - } - + // Look for a fatal_cycle modifier to pass on let fatal_cycle = query.attrs.0.iter().find_map(|attr| match attr { - QueryAttribute::FatalCycle => Some(()), + QueryModifier::FatalCycle => Some(()), _ => None, }).map(|_| quote! { fatal_cycle }).unwrap_or(quote! {}); + // Add the query to the group group_stream.extend(quote! { [#fatal_cycle] fn #name: #name(#arg) #result, }); - let desc = query.attrs.0.iter().find_map(|attr| match attr { - QueryAttribute::Desc(tcx, desc) => Some((tcx, desc)), - _ => None, - }).map(|(tcx, desc)| { - let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); - quote! { - fn describe( - #tcx: TyCtxt<'_, '_, '_>, - #key: #arg, - ) -> Cow<'static, str> { - format!(#desc).into() - } - } - }); - - if desc.is_some() || cache.is_some() { - let cache = cache.unwrap_or(quote! {}); - let desc = desc.unwrap_or(quote! {}); - - query_description_stream.extend(quote! { - impl<'tcx> QueryDescription<'tcx> for queries::#name<'tcx> { - #desc - #cache - } - }); - } + add_query_description_impl(query, &mut query_description_stream); + // Create a dep node for the query dep_node_def_stream.extend(quote! { [] #name(#arg), }); + + // Add a match arm to force the query given the dep node dep_node_force_stream.extend(quote! { DepKind::#name => { if let Some(key) = RecoverKey::recover($tcx, $dep_node) { diff --git a/src/librustc_macros/src/tt.rs b/src/librustc_macros/src/tt.rs deleted file mode 100644 index 66180ec8ad373..0000000000000 --- a/src/librustc_macros/src/tt.rs +++ /dev/null @@ -1,65 +0,0 @@ -use proc_macro2::{Delimiter, TokenStream, TokenTree}; - -pub struct TT<'a>(pub &'a TokenTree); - -impl<'a> PartialEq for TT<'a> { - fn eq(&self, other: &Self) -> bool { - use proc_macro2::Spacing; - - match (self.0, other.0) { - (&TokenTree::Group(ref g1), &TokenTree::Group(ref g2)) => { - match (g1.delimiter(), g2.delimiter()) { - (Delimiter::Parenthesis, Delimiter::Parenthesis) - | (Delimiter::Brace, Delimiter::Brace) - | (Delimiter::Bracket, Delimiter::Bracket) - | (Delimiter::None, Delimiter::None) => {} - _ => return false, - } - - let s1 = g1.stream().clone().into_iter(); - let mut s2 = g2.stream().clone().into_iter(); - - for item1 in s1 { - let item2 = match s2.next() { - Some(item) => item, - None => return false, - }; - if TT(&item1) != TT(&item2) { - return false; - } - } - s2.next().is_none() - } - (&TokenTree::Punct(ref o1), &TokenTree::Punct(ref o2)) => { - o1.as_char() == o2.as_char() - && match (o1.spacing(), o2.spacing()) { - (Spacing::Alone, Spacing::Alone) | (Spacing::Joint, Spacing::Joint) => true, - _ => false, - } - } - (&TokenTree::Literal(ref l1), &TokenTree::Literal(ref l2)) => { - l1.to_string() == l2.to_string() - } - (&TokenTree::Ident(ref s1), &TokenTree::Ident(ref s2)) => s1 == s2, - _ => false, - } - } -} - -pub struct TS<'a>(pub &'a TokenStream); - -impl<'a> PartialEq for TS<'a> { - fn eq(&self, other: &Self) -> bool { - let left = self.0.clone().into_iter().collect::>(); - let right = other.0.clone().into_iter().collect::>(); - if left.len() != right.len() { - return false; - } - for (a, b) in left.into_iter().zip(right) { - if TT(&a) != TT(&b) { - return false; - } - } - true - } -} From 198dfceb80e62dfe62f5f3fdbedcd9ffbe25c93b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 18 Mar 2019 14:17:26 +0100 Subject: [PATCH 4/4] Preprocess query modifiers --- src/librustc_macros/src/query.rs | 113 ++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 31 deletions(-) diff --git a/src/librustc_macros/src/query.rs b/src/librustc_macros/src/query.rs index 2f9fdacdd71ca..3849e47d40365 100644 --- a/src/librustc_macros/src/query.rs +++ b/src/librustc_macros/src/query.rs @@ -1,5 +1,4 @@ use proc_macro::TokenStream; -use proc_macro2::Span; use syn::{ Token, Ident, Type, Attribute, ReturnType, Expr, Block, Error, braced, parenthesized, parse_macro_input, @@ -21,8 +20,8 @@ struct IdentOrWild(Ident); impl Parse for IdentOrWild { fn parse(input: ParseStream<'_>) -> Result { Ok(if input.peek(Token![_]) { - input.parse::()?; - IdentOrWild(Ident::new("_", Span::call_site())) + let underscore = input.parse::()?; + IdentOrWild(Ident::new("_", underscore.span())) } else { IdentOrWild(input.parse()?) }) @@ -31,7 +30,7 @@ impl Parse for IdentOrWild { /// A modifier for a query enum QueryModifier { - /// The description of the query + /// The description of the query. Desc(Option, Punctuated), /// Cache the query to disk if the `Expr` returns true. @@ -107,7 +106,7 @@ fn check_attributes(attrs: Vec) -> Result<()> { /// A compiler query. `query ... { ... }` struct Query { - attrs: List, + modifiers: List, name: Ident, key: IdentOrWild, arg: Type, @@ -131,10 +130,10 @@ impl Parse for Query { // Parse the query modifiers let content; braced!(content in input); - let attrs = content.parse()?; + let modifiers = content.parse()?; Ok(Query { - attrs, + modifiers, name, key, arg, @@ -174,24 +173,76 @@ impl Parse for Group { } } +struct QueryModifiers { + /// The description of the query. + desc: Option<(Option, Punctuated)>, + + /// Cache the query to disk if the `Expr` returns true. + cache: Option<(Option, Expr)>, + + /// Custom code to load the query from disk. + load_cached: Option<(Ident, Ident, Block)>, + + /// A cycle error for this query aborting the compilation with a fatal error. + fatal_cycle: bool, +} + +/// Process query modifiers into a struct, erroring on duplicates +fn process_modifiers(query: &mut Query) -> QueryModifiers { + let mut load_cached = None; + let mut cache = None; + let mut desc = None; + let mut fatal_cycle = false; + for modifier in query.modifiers.0.drain(..) { + match modifier { + QueryModifier::LoadCached(tcx, id, block) => { + if load_cached.is_some() { + panic!("duplicate modifier `load_cached` for query `{}`", query.name); + } + load_cached = Some((tcx, id, block)); + } + QueryModifier::Cache(tcx, expr) => { + if cache.is_some() { + panic!("duplicate modifier `cache` for query `{}`", query.name); + } + cache = Some((tcx, expr)); + } + QueryModifier::Desc(tcx, list) => { + if desc.is_some() { + panic!("duplicate modifier `desc` for query `{}`", query.name); + } + desc = Some((tcx, list)); + } + QueryModifier::FatalCycle => { + if fatal_cycle { + panic!("duplicate modifier `fatal_cycle` for query `{}`", query.name); + } + fatal_cycle = true; + } + } + } + QueryModifiers { + load_cached, + cache, + desc, + fatal_cycle, + } +} + /// Add the impl of QueryDescription for the query to `impls` if one is requested -fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStream) { +fn add_query_description_impl( + query: &Query, + modifiers: QueryModifiers, + impls: &mut proc_macro2::TokenStream +) { let name = &query.name; let arg = &query.arg; let key = &query.key.0; - // Find custom code to load the query from disk - let load_cached = query.attrs.0.iter().find_map(|attr| match attr { - QueryModifier::LoadCached(tcx, id, block) => Some((tcx, id, block)), - _ => None, - }); - // Find out if we should cache the query on disk - let cache = query.attrs.0.iter().find_map(|attr| match attr { - QueryModifier::Cache(tcx, expr) => Some((tcx, expr)), - _ => None, - }).map(|(tcx, expr)| { - let try_load_from_disk = if let Some((tcx, id, block)) = load_cached { + let cache = modifiers.cache.as_ref().map(|(tcx, expr)| { + let try_load_from_disk = if let Some((tcx, id, block)) = modifiers.load_cached.as_ref() { + // Use custom code to load the query from disk quote! { #[inline] fn try_load_from_disk( @@ -202,6 +253,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea } } } else { + // Use the default code to load the query from disk quote! { #[inline] fn try_load_from_disk( @@ -224,14 +276,11 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea } }); - if cache.is_none() && load_cached.is_some() { + if cache.is_none() && modifiers.load_cached.is_some() { panic!("load_cached modifier on query `{}` without a cache modifier", name); } - let desc = query.attrs.0.iter().find_map(|attr| match attr { - QueryModifier::Desc(tcx, desc) => Some((tcx, desc)), - _ => None, - }).map(|(tcx, desc)| { + let desc = modifiers.desc.as_ref().map(|(tcx, desc)| { let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ }); quote! { fn describe( @@ -266,7 +315,8 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { for group in groups.0 { let mut group_stream = quote! {}; - for query in &group.queries.0 { + for mut query in group.queries.0 { + let modifiers = process_modifiers(&mut query); let name = &query.name; let arg = &query.arg; let result_full = &query.result; @@ -275,18 +325,19 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream { _ => quote! { #result_full }, }; - // Look for a fatal_cycle modifier to pass on - let fatal_cycle = query.attrs.0.iter().find_map(|attr| match attr { - QueryModifier::FatalCycle => Some(()), - _ => None, - }).map(|_| quote! { fatal_cycle }).unwrap_or(quote! {}); + // Pass on the fatal_cycle modifier + let fatal_cycle = if modifiers.fatal_cycle { + quote! { fatal_cycle } + } else { + quote! {} + }; // Add the query to the group group_stream.extend(quote! { [#fatal_cycle] fn #name: #name(#arg) #result, }); - add_query_description_impl(query, &mut query_description_stream); + add_query_description_impl(&query, modifiers, &mut query_description_stream); // Create a dep node for the query dep_node_def_stream.extend(quote! {