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] 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 eb75e624d34..b88ce643ea4 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 b84d2ad1458..1535e6d349c 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 b6677326227..4b2fda3b02f 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 00000000000..709d34a156c --- /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 395b288df14..6e964fc540e 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 8804ed22264..bccc69af235 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 cff99f23d0e..e78d98cd4f1 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 5551cf6b3b6..c7a9f1afd0a 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 cad31264b05..78520b6dce6 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 00000000000..aeb830ff9b9 --- /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 00000000000..66180ec8ad3 --- /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 0ab0915d4d0..03c21712d2d 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 294476258ab..62f6e1f571b 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 4330b0025a2..6d7bbf2b7da 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 d1574aee9a9..a66c6f6eee5 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 c3db4369b7d..aa78389faf4 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 9fca1ce1c46..b948ae8228e 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 3d660aa8f4b..d077255343f 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 0f703aeb0f7..9ddc53a3d21 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