From 61d483c9d6d0e12bd5ea953ba539c00c4d9c2116 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 01:59:00 +0100 Subject: [PATCH 01/15] Move encode_metadata out of CrateStore. --- compiler/rustc_interface/src/callbacks.rs | 3 +++ compiler/rustc_metadata/src/lib.rs | 2 ++ compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs | 8 ++------ compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 1 + compiler/rustc_middle/src/middle/cstore.rs | 1 - compiler/rustc_middle/src/ty/context.rs | 9 ++++++++- compiler/rustc_middle/src/ty/mod.rs | 2 ++ 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index 7fa1a3eb0f591..ce2015f5dc3bb 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -11,6 +11,7 @@ use rustc_errors::{Diagnostic, TRACK_DIAGNOSTICS}; use rustc_middle::ty::tls; +use rustc_middle::ty::TyCtxt; use std::fmt; /// This is a callback from librustc_ast as it cannot access the implicit state @@ -57,5 +58,7 @@ fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) -> pub fn setup_callbacks() { rustc_span::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); + rustc_middle::ty::ENCODE_METADATA + .swap(&(rustc_metadata::encode_metadata as fn(TyCtxt<'_>) -> _)); TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_))); } diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 77766be7397c7..f8d5aaf71ab10 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -34,3 +34,5 @@ mod rmeta; pub mod creader; pub mod dynamic_lib; pub mod locator; + +pub use rmeta::encode_metadata; diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 85dc60d7eed6d..ed95acceaf0d4 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -2,7 +2,7 @@ use crate::creader::{CStore, LoadedMacro}; use crate::foreign_modules; use crate::link_args; use crate::native_libs; -use crate::rmeta::{self, encoder}; +use crate::rmeta; use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; @@ -14,7 +14,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE} use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_middle::hir::exports::Export; use rustc_middle::middle::cstore::ForeignModule; -use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata}; +use rustc_middle::middle::cstore::{CrateSource, CrateStore}; use rustc_middle::middle::exported_symbols::ExportedSymbol; use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::ty::query::Providers; @@ -512,10 +512,6 @@ impl CrateStore for CStore { result } - fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata { - encoder::encode_metadata(tcx) - } - fn metadata_encoding_version(&self) -> &[u8] { rmeta::METADATA_HEADER } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index a7cf1079b8fe4..b523d043fff8c 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2002,7 +2002,7 @@ impl<'tcx, 'v> ParItemLikeVisitor<'v> for PrefetchVisitor<'tcx> { // will allow us to slice the metadata to the precise length that we just // generated regardless of trailing bytes that end up in it. -pub(super) fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { +pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata { // Since encoding metadata is not in a query, and nothing is cached, // there's no need to do dep-graph tracking for any of it. tcx.dep_graph.assert_ignored(); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 2bd2019d3cdb5..36b9619ef22a3 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -30,6 +30,7 @@ use std::num::NonZeroUsize; use decoder::DecodeContext; pub use decoder::{provide, provide_extern}; crate use decoder::{CrateMetadata, CrateNumMap, MetadataBlob}; +pub use encoder::encode_metadata; use encoder::EncodeContext; use rustc_span::hygiene::SyntaxContextData; diff --git a/compiler/rustc_middle/src/middle/cstore.rs b/compiler/rustc_middle/src/middle/cstore.rs index ae9e4d364d3cb..e7529560a3e64 100644 --- a/compiler/rustc_middle/src/middle/cstore.rs +++ b/compiler/rustc_middle/src/middle/cstore.rs @@ -203,7 +203,6 @@ pub trait CrateStore { fn crates_untracked(&self) -> Vec; // utility functions - fn encode_metadata(&self, tcx: TyCtxt<'_>) -> EncodedMetadata; fn metadata_encoding_version(&self) -> &[u8]; fn allocator_kind(&self) -> Option; } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b29e6d4a96705..bef03e5bc3eb2 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -35,6 +35,7 @@ use rustc_data_structures::stable_hasher::{ use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal}; use rustc_data_structures::unhash::UnhashMap; +use rustc_data_structures::AtomicRef; use rustc_errors::ErrorReported; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -979,6 +980,12 @@ pub struct GlobalCtxt<'tcx> { output_filenames: Arc, } +fn dummy_encode_metadata(_: TyCtxt<'_>) -> EncodedMetadata { + panic!("Unregistered callback to `encode_metadata`.") +} +pub static ENCODE_METADATA: AtomicRef) -> EncodedMetadata> = + AtomicRef::new(&(dummy_encode_metadata as fn(TyCtxt<'_>) -> _)); + impl<'tcx> TyCtxt<'tcx> { pub fn typeck_opt_const_arg( self, @@ -1279,7 +1286,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn encode_metadata(self) -> EncodedMetadata { let _prof_timer = self.prof.verbose_generic_activity("generate_crate_metadata"); - self.cstore.encode_metadata(self) + (*ENCODE_METADATA)(self) } // Note that this is *untracked* and should only be used within the query diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 5e8a4a56db32c..9eb6db46a3efc 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -119,6 +119,8 @@ mod list; mod structural_impls; mod sty; +pub use context::ENCODE_METADATA; + // Data types pub struct ResolverOutputs { From e58d3f5aed2b26a11ecac8b82cf738550f1c97a4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 02:49:58 +0100 Subject: [PATCH 02/15] Move HashStable impls. --- compiler/rustc_attr/src/builtin.rs | 19 ++++++++ compiler/rustc_middle/src/ich/hcx.rs | 5 ++ compiler/rustc_middle/src/ich/impls_hir.rs | 56 +--------------------- compiler/rustc_span/src/def_id.rs | 37 +++++++++++++- compiler/rustc_span/src/lib.rs | 3 +- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 2fd625c2a6c26..f0f86554c0ef1 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -2,6 +2,7 @@ use rustc_ast::{self as ast, Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem}; use rustc_ast_pretty::pprust; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::{struct_span_err, Applicability}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; @@ -1049,3 +1050,21 @@ fn allow_unstable<'a>( name })) } + +impl HashStable for InlineAttr { + fn hash_stable(&self, hcx: &mut Ctxt, hasher: &mut StableHasher) { + std::mem::discriminant(self).hash_stable(hcx, hasher); + } +} + +impl HashStable for InstructionSetAttr { + fn hash_stable(&self, hcx: &mut Ctxt, hasher: &mut StableHasher) { + std::mem::discriminant(self).hash_stable(hcx, hasher); + } +} + +impl HashStable for OptimizeAttr { + fn hash_stable(&self, hcx: &mut Ctxt, hasher: &mut StableHasher) { + std::mem::discriminant(self).hash_stable(hcx, hasher); + } +} diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index 084fe4cfa168a..fb140546973d8 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -230,6 +230,11 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { self.hash_spans } + #[inline] + fn def_path_hash(&self, def_id: DefId) -> DefPathHash { + self.def_path_hash(def_id) + } + #[inline] fn hash_crate_num(&mut self, cnum: CrateNum, hasher: &mut StableHasher) { let hcx = self; diff --git a/compiler/rustc_middle/src/ich/impls_hir.rs b/compiler/rustc_middle/src/ich/impls_hir.rs index d6c6cef17513d..974d0e8b796cf 100644 --- a/compiler/rustc_middle/src/ich/impls_hir.rs +++ b/compiler/rustc_middle/src/ich/impls_hir.rs @@ -2,11 +2,10 @@ //! types in no particular order. use crate::ich::{NodeIdHashingMode, StableHashingContext}; -use rustc_attr as attr; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use rustc_hir as hir; -use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::LocalDefId; use rustc_hir::definitions::DefPathHash; use smallvec::SmallVec; use std::mem; @@ -122,41 +121,6 @@ impl<'ctx> rustc_hir::HashStableContext for StableHashingContext<'ctx> { } } -impl<'a> ToStableHashKey> for DefId { - type KeyType = DefPathHash; - - #[inline] - fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash { - hcx.def_path_hash(*self) - } -} - -impl<'a> HashStable> for LocalDefId { - #[inline] - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher); - } -} - -impl<'a> ToStableHashKey> for LocalDefId { - type KeyType = DefPathHash; - - #[inline] - fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash { - hcx.def_path_hash(self.to_def_id()) - } -} - -impl<'a> ToStableHashKey> for CrateNum { - type KeyType = DefPathHash; - - #[inline] - fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> DefPathHash { - let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX }; - def_id.to_stable_hash_key(hcx) - } -} - impl<'a> ToStableHashKey> for hir::ItemLocalId { type KeyType = hir::ItemLocalId; @@ -214,21 +178,3 @@ impl<'a> ToStableHashKey> for hir::TraitCandidate { ) } } - -impl<'hir> HashStable> for attr::InlineAttr { - fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - } -} - -impl<'hir> HashStable> for attr::InstructionSetAttr { - fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - } -} - -impl<'hir> HashStable> for attr::OptimizeAttr { - fn hash_stable(&self, hcx: &mut StableHashingContext<'hir>, hasher: &mut StableHasher) { - mem::discriminant(self).hash_stable(hcx, hasher); - } -} diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index b24ede9c53aed..85f0012f03503 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -1,6 +1,6 @@ use crate::HashStableContext; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; use rustc_data_structures::AtomicRef; use rustc_index::vec::Idx; use rustc_macros::HashStable_Generic; @@ -274,8 +274,43 @@ impl HashStable for DefId { } } +impl ToStableHashKey for DefId { + type KeyType = DefPathHash; + + #[inline] + fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + hcx.def_path_hash(*self) + } +} + +impl HashStable for LocalDefId { + #[inline] + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { + hcx.def_path_hash(self.to_def_id()).hash_stable(hcx, hasher); + } +} + +impl ToStableHashKey for LocalDefId { + type KeyType = DefPathHash; + + #[inline] + fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + hcx.def_path_hash(self.to_def_id()) + } +} + impl HashStable for CrateNum { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { hcx.hash_crate_num(*self, hasher) } } + +impl ToStableHashKey for CrateNum { + type KeyType = DefPathHash; + + #[inline] + fn to_stable_hash_key(&self, hcx: &CTX) -> DefPathHash { + let def_id = DefId { krate: *self, index: CRATE_DEF_INDEX }; + def_id.to_stable_hash_key(hcx) + } +} diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 0926561f4c513..aba29f3d74ae8 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -33,7 +33,7 @@ pub use hygiene::SyntaxContext; use hygiene::Transparency; pub use hygiene::{DesugaringKind, ExpnData, ExpnId, ExpnKind, ForLoopLoc, MacroKind}; pub mod def_id; -use def_id::{CrateNum, DefId, LOCAL_CRATE}; +use def_id::{CrateNum, DefId, DefPathHash, LOCAL_CRATE}; mod span_encoding; pub use span_encoding::{Span, DUMMY_SP}; @@ -1840,6 +1840,7 @@ fn lookup_line(lines: &[BytePos], pos: BytePos) -> isize { /// This is a hack to allow using the `HashStable_Generic` derive macro /// instead of implementing everything in librustc_middle. pub trait HashStableContext { + fn def_path_hash(&self, def_id: DefId) -> DefPathHash; fn hash_def_id(&mut self, _: DefId, hasher: &mut StableHasher); fn hash_crate_num(&mut self, _: CrateNum, hasher: &mut StableHasher); fn hash_spans(&self) -> bool; From ebaba3b7b2028aef77d246afa74b9d6fadd96157 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 13:58:35 +0100 Subject: [PATCH 03/15] Move Linkage and Visibility to codegen_fn_attrs. --- .../rustc_codegen_cranelift/src/constant.rs | 6 ++--- .../rustc_codegen_cranelift/src/driver/mod.rs | 3 ++- .../rustc_codegen_cranelift/src/linkage.rs | 3 ++- compiler/rustc_codegen_llvm/src/base.rs | 3 +-- compiler/rustc_codegen_llvm/src/mono_item.rs | 2 +- .../src/back/symbol_export.rs | 4 +-- compiler/rustc_codegen_ssa/src/mono_item.rs | 2 +- .../rustc_codegen_ssa/src/traits/declare.rs | 2 +- .../src/middle/codegen_fn_attrs.rs | 26 ++++++++++++++++++- compiler/rustc_middle/src/mir/mono.rs | 26 +------------------ .../src/monomorphize/partitioning/default.rs | 4 +-- .../src/monomorphize/partitioning/mod.rs | 4 +-- compiler/rustc_typeck/src/collect.rs | 5 ++-- 13 files changed, 45 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 41cfae4ca6e26..0c8d46ef42b18 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -4,7 +4,7 @@ use rustc_span::DUMMY_SP; use rustc_data_structures::fx::FxHashSet; use rustc_errors::ErrorReported; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage as RLinkage}; use rustc_middle::mir::interpret::{ read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer, Scalar, }; @@ -292,8 +292,8 @@ fn data_id_for_static( let rlinkage = tcx.codegen_fn_attrs(def_id).linkage; let linkage = if definition { crate::linkage::get_static_linkage(tcx, def_id) - } else if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak) - || rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny) + } else if rlinkage == Some(RLinkage::ExternalWeak) + || rlinkage == Some(RLinkage::WeakAny) { Linkage::Preemptible } else { diff --git a/compiler/rustc_codegen_cranelift/src/driver/mod.rs b/compiler/rustc_codegen_cranelift/src/driver/mod.rs index a11dc57ee6453..d605dc594d8b0 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/mod.rs @@ -3,8 +3,9 @@ use std::any::Any; +use rustc_middle::middle::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; use rustc_middle::middle::cstore::EncodedMetadata; -use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; +use rustc_middle::mir::mono::MonoItem; use crate::prelude::*; diff --git a/compiler/rustc_codegen_cranelift/src/linkage.rs b/compiler/rustc_codegen_cranelift/src/linkage.rs index dc1e2107ce712..97ede38583c29 100644 --- a/compiler/rustc_codegen_cranelift/src/linkage.rs +++ b/compiler/rustc_codegen_cranelift/src/linkage.rs @@ -1,4 +1,5 @@ -use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; +use rustc_middle::middle::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; +use rustc_middle::mir::mono::MonoItem; use crate::prelude::*; diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 1090d4a25c7cf..44be093c9b130 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -29,10 +29,9 @@ use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::dep_graph; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; +use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrs, Linkage, Visibility}; use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::exported_symbols; -use rustc_middle::mir::mono::{Linkage, Visibility}; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, SanitizerSet}; use rustc_span::symbol::Symbol; diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 992e83d08fcae..918508e6682c0 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -6,8 +6,8 @@ use crate::llvm; use crate::type_of::LayoutLlvmExt; use rustc_codegen_ssa::traits::*; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; +use rustc_middle::middle::codegen_fn_attrs::{Linkage, Visibility}; pub use rustc_middle::mir::mono::MonoItem; -use rustc_middle::mir::mono::{Linkage, Visibility}; use rustc_middle::ty::layout::FnAbiExt; use rustc_middle::ty::{self, Instance, TypeFoldable}; use rustc_target::abi::LayoutOf; diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 9a6f8cde1b25d..91023f9aa2088 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -7,7 +7,7 @@ use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::Node; use rustc_index::vec::IndexVec; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage, Visibility}; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, }; @@ -221,7 +221,7 @@ fn exported_symbols_provider_local( } if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() { - use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility}; + use rustc_middle::mir::mono::MonoItem; use rustc_middle::ty::InstanceDef; // Normally, we require that shared monomorphizations are not hidden, diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs index 607b5459673f3..06acd605ad496 100644 --- a/compiler/rustc_codegen_ssa/src/mono_item.rs +++ b/compiler/rustc_codegen_ssa/src/mono_item.rs @@ -1,7 +1,7 @@ use crate::base; use crate::traits::*; use rustc_hir as hir; -use rustc_middle::mir::mono::{Linkage, Visibility}; +use rustc_middle::middle::codegen_fn_attrs::{Linkage, Visibility}; use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::mir::mono::MonoItem; diff --git a/compiler/rustc_codegen_ssa/src/traits/declare.rs b/compiler/rustc_codegen_ssa/src/traits/declare.rs index 655afcd17f0da..ab836b34b0748 100644 --- a/compiler/rustc_codegen_ssa/src/traits/declare.rs +++ b/compiler/rustc_codegen_ssa/src/traits/declare.rs @@ -1,6 +1,6 @@ use super::BackendTypes; use rustc_hir::def_id::DefId; -use rustc_middle::mir::mono::{Linkage, Visibility}; +use rustc_middle::middle::codegen_fn_attrs::{Linkage, Visibility}; use rustc_middle::ty::Instance; pub trait PreDefineMethods<'tcx>: BackendTypes { diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index a4363bb580a2f..c2bfc209bb053 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -1,8 +1,32 @@ -use crate::mir::mono::Linkage; use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr}; use rustc_session::config::SanitizerSet; use rustc_span::symbol::Symbol; +/// Specifies the linkage type for a `MonoItem`. +/// +/// See for more details about these variants. +#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)] +pub enum Linkage { + External, + AvailableExternally, + LinkOnceAny, + LinkOnceODR, + WeakAny, + WeakODR, + Appending, + Internal, + Private, + ExternalWeak, + Common, +} + +#[derive(Copy, Clone, PartialEq, Debug, HashStable)] +pub enum Visibility { + Default, + Hidden, + Protected, +} + #[derive(Clone, TyEncodable, TyDecodable, HashStable)] pub struct CodegenFnAttrs { pub flags: CodegenFnAttrFlags, diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 1e70f7605045e..7b92b57507c99 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -1,5 +1,6 @@ use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId}; use crate::ich::{NodeIdHashingMode, StableHashingContext}; +use crate::middle::codegen_fn_attrs::{Linkage, Visibility}; use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt}; use rustc_attr::InlineAttr; use rustc_data_structures::base_n; @@ -226,31 +227,6 @@ pub struct CodegenUnit<'tcx> { size_estimate: Option, } -/// Specifies the linkage type for a `MonoItem`. -/// -/// See for more details about these variants. -#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)] -pub enum Linkage { - External, - AvailableExternally, - LinkOnceAny, - LinkOnceODR, - WeakAny, - WeakODR, - Appending, - Internal, - Private, - ExternalWeak, - Common, -} - -#[derive(Copy, Clone, PartialEq, Debug, HashStable)] -pub enum Visibility { - Default, - Hidden, - Protected, -} - impl<'tcx> CodegenUnit<'tcx> { pub fn new(name: Symbol) -> CodegenUnit<'tcx> { CodegenUnit { name, items: Default::default(), size_estimate: None } diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs index 037b80e4bf2bb..d75b5ae7f8706 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs @@ -4,9 +4,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::DefPathDataName; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage, Visibility}; use rustc_middle::middle::exported_symbols::SymbolExportLevel; -use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility}; +use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; use rustc_middle::ty::print::characteristic_def_id_of_type; use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt}; diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs b/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs index db6d3b2d912d6..70770d0813b81 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs @@ -98,8 +98,8 @@ mod merging; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync; use rustc_hir::def_id::{CrateNum, DefIdSet, LOCAL_CRATE}; -use rustc_middle::mir::mono::MonoItem; -use rustc_middle::mir::mono::{CodegenUnit, Linkage}; +use rustc_middle::middle::codegen_fn_attrs::Linkage; +use rustc_middle::mir::mono::{CodegenUnit, MonoItem}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index b431de9036944..780512694805d 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -34,8 +34,7 @@ use rustc_hir::weak_lang_items; use rustc_hir::{GenericParamKind, HirId, Node}; use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::hir::map::Map; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; -use rustc_middle::mir::mono::Linkage; +use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs, Linkage}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::util::Discr; @@ -2430,7 +2429,7 @@ fn from_target_feature( } fn linkage_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Linkage { - use rustc_middle::mir::mono::Linkage::*; + use Linkage::*; // Use the names from src/llvm/docs/LangRef.rst here. Most types are only // applicable to variable declarations and may not really make sense for From b144cc0dcafe9e3703e040e8d963115f3076c3a2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:02:03 +0100 Subject: [PATCH 04/15] Move rustc_middle::middle::cstore to rustc_crate. --- Cargo.lock | 38 ++++++++++++ .../rustc_codegen_cranelift/src/driver/aot.rs | 2 +- .../rustc_codegen_cranelift/src/driver/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/lib.rs | 3 +- .../rustc_codegen_cranelift/src/metadata.rs | 2 +- compiler/rustc_codegen_llvm/Cargo.toml | 1 + compiler/rustc_codegen_llvm/src/base.rs | 2 +- compiler/rustc_codegen_llvm/src/lib.rs | 2 +- compiler/rustc_codegen_llvm/src/metadata.rs | 2 +- compiler/rustc_codegen_ssa/Cargo.toml | 1 + compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_codegen_ssa/src/back/rpath.rs | 2 +- compiler/rustc_codegen_ssa/src/back/write.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 9 ++- compiler/rustc_codegen_ssa/src/lib.rs | 4 +- .../rustc_codegen_ssa/src/traits/backend.rs | 2 +- compiler/rustc_crate/Cargo.toml | 32 ++++++++++ .../src/middle => rustc_crate/src}/cstore.rs | 59 +++---------------- compiler/rustc_crate/src/lib.rs | 13 ++++ compiler/rustc_driver/Cargo.toml | 1 + compiler/rustc_driver/src/lib.rs | 2 +- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/passes.rs | 6 +- compiler/rustc_metadata/Cargo.toml | 1 + compiler/rustc_metadata/src/creader.rs | 4 +- .../rustc_metadata/src/dependency_format.rs | 7 ++- .../rustc_metadata/src/foreign_modules.rs | 2 +- compiler/rustc_metadata/src/locator.rs | 2 +- compiler/rustc_metadata/src/native_libs.rs | 2 +- compiler/rustc_metadata/src/rmeta/decoder.rs | 3 +- .../src/rmeta/decoder/cstore_impl.rs | 3 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 2 +- compiler/rustc_middle/Cargo.toml | 1 + compiler/rustc_middle/src/arena.rs | 4 +- .../rustc_middle/src/hir/map/collector.rs | 2 +- compiler/rustc_middle/src/ich/hcx.rs | 4 +- compiler/rustc_middle/src/middle/mod.rs | 47 ++++++++++++++- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- compiler/rustc_middle/src/ty/query/mod.rs | 5 +- compiler/rustc_passes/Cargo.toml | 1 + compiler/rustc_passes/src/lang_items.rs | 5 +- compiler/rustc_plugin_impl/Cargo.toml | 1 + compiler/rustc_plugin_impl/src/load.rs | 2 +- compiler/rustc_resolve/Cargo.toml | 1 + .../rustc_resolve/src/build_reduced_graph.rs | 2 +- compiler/rustc_resolve/src/lib.rs | 2 +- compiler/rustc_save_analysis/Cargo.toml | 1 + compiler/rustc_save_analysis/src/lib.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/lib.rs | 1 + 53 files changed, 201 insertions(+), 106 deletions(-) create mode 100644 compiler/rustc_crate/Cargo.toml rename compiler/{rustc_middle/src/middle => rustc_crate/src}/cstore.rs (76%) create mode 100644 compiler/rustc_crate/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index bb33404e69072..f637ee8088f49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3525,6 +3525,7 @@ dependencies = [ "rustc_ast", "rustc_attr", "rustc_codegen_ssa", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_feature", @@ -3557,6 +3558,7 @@ dependencies = [ "rustc_apfloat", "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_fs_util", @@ -3574,6 +3576,34 @@ dependencies = [ "tracing", ] +[[package]] +name = "rustc_crate" +version = "0.0.0" +dependencies = [ + "bitflags", + "chalk-ir", + "measureme", + "polonius-engine", + "rustc-rayon-core", + "rustc_apfloat", + "rustc_arena", + "rustc_ast", + "rustc_attr", + "rustc_data_structures", + "rustc_errors", + "rustc_feature", + "rustc_hir", + "rustc_index", + "rustc_macros", + "rustc_query_system", + "rustc_serialize", + "rustc_session", + "rustc_span", + "rustc_target", + "smallvec 1.4.2", + "tracing", +] + [[package]] name = "rustc_data_structures" version = "0.0.0" @@ -3611,6 +3641,7 @@ dependencies = [ "rustc_ast", "rustc_ast_pretty", "rustc_codegen_ssa", + "rustc_crate", "rustc_data_structures", "rustc_error_codes", "rustc_errors", @@ -3780,6 +3811,7 @@ dependencies = [ "rustc_builtin_macros", "rustc_codegen_llvm", "rustc_codegen_ssa", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_expand", @@ -3878,6 +3910,7 @@ dependencies = [ "memmap", "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_expand", @@ -3911,6 +3944,7 @@ dependencies = [ "rustc_arena", "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_feature", @@ -4011,6 +4045,7 @@ version = "0.0.0" dependencies = [ "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_hir", @@ -4029,6 +4064,7 @@ name = "rustc_plugin_impl" version = "0.0.0" dependencies = [ "rustc_ast", + "rustc_crate", "rustc_errors", "rustc_hir", "rustc_lint", @@ -4080,6 +4116,7 @@ dependencies = [ "rustc_ast_lowering", "rustc_ast_pretty", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_expand", @@ -4102,6 +4139,7 @@ dependencies = [ "rls-span", "rustc_ast", "rustc_ast_pretty", + "rustc_crate", "rustc_data_structures", "rustc_hir", "rustc_hir_pretty", diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index c0245aa1e0213..33b58fa9f4a9f 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -5,9 +5,9 @@ use std::path::PathBuf; use rustc_codegen_ssa::back::linker::LinkerInfo; use rustc_codegen_ssa::{CodegenResults, CompiledModule, CrateInfo, ModuleKind}; +use rustc_crate::cstore::EncodedMetadata; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::mir::mono::CodegenUnit; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{DebugInfo, OutputType}; diff --git a/compiler/rustc_codegen_cranelift/src/driver/mod.rs b/compiler/rustc_codegen_cranelift/src/driver/mod.rs index d605dc594d8b0..df3ba42399c3e 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/mod.rs @@ -3,8 +3,8 @@ use std::any::Any; +use rustc_crate::cstore::EncodedMetadata; use rustc_middle::middle::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::mir::mono::MonoItem; use crate::prelude::*; diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index ba9ee0d450ee6..80e1727ada837 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -18,6 +18,7 @@ extern crate snap; extern crate rustc_middle; extern crate rustc_ast; extern crate rustc_codegen_ssa; +extern crate rustc_crate; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_fs_util; @@ -37,9 +38,9 @@ use std::any::Any; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; +use rustc_crate::cstore::{EncodedMetadata, MetadataLoader}; use rustc_errors::ErrorReported; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader}; use rustc_middle::ty::query::Providers; use rustc_session::config::OutputFilenames; use rustc_session::Session; diff --git a/compiler/rustc_codegen_cranelift/src/metadata.rs b/compiler/rustc_codegen_cranelift/src/metadata.rs index 2e3b9fb8364e4..675fad30bc062 100644 --- a/compiler/rustc_codegen_cranelift/src/metadata.rs +++ b/compiler/rustc_codegen_cranelift/src/metadata.rs @@ -5,10 +5,10 @@ use std::fs::File; use std::path::Path; use rustc_codegen_ssa::METADATA_FILENAME; +use rustc_crate::cstore::{EncodedMetadata, MetadataLoader}; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::rustc_erase_owner; use rustc_data_structures::sync::MetadataRef; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader}; use rustc_middle::ty::TyCtxt; use rustc_session::config; use rustc_target::spec::Target; diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index f9373640dce5e..2f335eeec929f 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -18,6 +18,7 @@ rustc_middle = { path = "../rustc_middle" } rustc-demangle = "0.1.18" rustc_attr = { path = "../rustc_attr" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 44be093c9b130..58ee066908408 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -27,10 +27,10 @@ use rustc_codegen_ssa::base::maybe_create_entry_wrapper; use rustc_codegen_ssa::mono_item::MonoItemExt; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; +use rustc_crate::cstore::EncodedMetadata; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::dep_graph; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrs, Linkage, Visibility}; -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::exported_symbols; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, SanitizerSet}; diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 5974b59d39e42..3b24a122759a0 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -23,10 +23,10 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLTOInput, ModuleConfig}; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::ModuleCodegen; use rustc_codegen_ssa::{CodegenResults, CompiledModule}; +use rustc_crate::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{ErrorReported, FatalError, Handler}; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest}; use rustc_session::Session; diff --git a/compiler/rustc_codegen_llvm/src/metadata.rs b/compiler/rustc_codegen_llvm/src/metadata.rs index 3912d6a3a48b6..19a340ebf143f 100644 --- a/compiler/rustc_codegen_llvm/src/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/metadata.rs @@ -1,7 +1,7 @@ use crate::llvm; use crate::llvm::archive_ro::ArchiveRO; use crate::llvm::{mk_section_iter, False, ObjectFile}; -use rustc_middle::middle::cstore::MetadataLoader; +use rustc_crate::cstore::MetadataLoader; use rustc_target::spec::Target; use rustc_codegen_ssa::METADATA_FILENAME; diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index e5df0f60941a8..aa12e34c52fd1 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -20,6 +20,7 @@ pathdiff = "0.2.0" rustc_serialize = { path = "../rustc_serialize" } rustc_ast = { path = "../rustc_ast" } +rustc_crate = { path = "../rustc_crate" } rustc_span = { path = "../rustc_span" } rustc_middle = { path = "../rustc_middle" } rustc_apfloat = { path = "../rustc_apfloat" } diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 5a627a0efa364..581dcd57d00e5 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1,8 +1,8 @@ +use rustc_crate::cstore::{EncodedMetadata, LibSource, NativeLib}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_hir::def_id::CrateNum; -use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLib}; use rustc_middle::middle::dependency_format::Linkage; use rustc_session::config::{self, CFGuard, CrateType, DebugInfo}; use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SanitizerSet}; diff --git a/compiler/rustc_codegen_ssa/src/back/rpath.rs b/compiler/rustc_codegen_ssa/src/back/rpath.rs index 005d2efdd3b26..60b2921ade7c8 100644 --- a/compiler/rustc_codegen_ssa/src/back/rpath.rs +++ b/compiler/rustc_codegen_ssa/src/back/rpath.rs @@ -4,8 +4,8 @@ use std::env; use std::fs; use std::path::{Path, PathBuf}; +use rustc_crate::cstore::LibSource; use rustc_hir::def_id::CrateNum; -use rustc_middle::middle::cstore::LibSource; pub struct RPathConfig<'a> { pub used_crates: &'a [(CrateNum, LibSource)], diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 7f2bb7b5bcdaf..2304bc2f5e06c 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -9,6 +9,7 @@ use crate::{ use crate::traits::*; use jobserver::{Acquired, Client}; +use rustc_crate::cstore::EncodedMetadata; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::profiling::TimingGuard; @@ -22,7 +23,6 @@ use rustc_incremental::{ copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess, }; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_middle::ty::TyCtxt; use rustc_session::cgu_reuse_tracker::CguReuseTracker; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 5fe26dbf91402..82d0eac77a57a 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -26,6 +26,7 @@ use crate::traits::*; use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}; use rustc_attr as attr; +use rustc_crate::cstore::{EncodedMetadata, LinkagePreference}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::print_time_passes_entry; use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator}; @@ -34,9 +35,7 @@ use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_index::vec::Idx; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; -use rustc_middle::middle::cstore::EncodedMetadata; -use rustc_middle::middle::cstore::{self, LinkagePreference}; -use rustc_middle::middle::lang_items; +use rustc_middle::middle::{lang_items, used_crates}; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA}; @@ -769,8 +768,8 @@ impl CrateInfo { used_libraries: tcx.native_libraries(LOCAL_CRATE), link_args: tcx.link_args(LOCAL_CRATE), crate_name: Default::default(), - used_crates_dynamic: cstore::used_crates(tcx, LinkagePreference::RequireDynamic), - used_crates_static: cstore::used_crates(tcx, LinkagePreference::RequireStatic), + used_crates_dynamic: used_crates(tcx, LinkagePreference::RequireDynamic), + used_crates_static: used_crates(tcx, LinkagePreference::RequireStatic), used_crate_source: Default::default(), lang_item_to_crate: Default::default(), missing_lang_items: Default::default(), diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 70b92b234e94c..7c2d7fe1e83b9 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -20,12 +20,12 @@ extern crate tracing; #[macro_use] extern crate rustc_middle; +use rustc_crate::cstore::{CrateSource, EncodedMetadata, LibSource, NativeLib}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::CrateNum; use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; -use rustc_middle::middle::cstore::{CrateSource, LibSource, NativeLib}; use rustc_middle::middle::dependency_format::Dependencies; use rustc_middle::ty::query::Providers; use rustc_session::config::{OutputFilenames, OutputType, RUST_CGU_EXT}; @@ -133,7 +133,7 @@ pub struct CodegenResults { pub modules: Vec, pub allocator_module: Option, pub metadata_module: Option, - pub metadata: rustc_middle::middle::cstore::EncodedMetadata, + pub metadata: EncodedMetadata, pub windows_subsystem: Option, pub linker_info: back::linker::LinkerInfo, pub crate_info: CrateInfo, diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index b9c555c2eb069..9756e3dab82a4 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -3,10 +3,10 @@ use super::CodegenObject; use crate::{CodegenResults, ModuleCodegen}; use rustc_ast::expand::allocator::AllocatorKind; +use rustc_crate::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::ErrorReported; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoaderDyn}; use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{Ty, TyCtxt}; diff --git a/compiler/rustc_crate/Cargo.toml b/compiler/rustc_crate/Cargo.toml new file mode 100644 index 0000000000000..9c14b99eb5656 --- /dev/null +++ b/compiler/rustc_crate/Cargo.toml @@ -0,0 +1,32 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_crate" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +rustc_arena = { path = "../rustc_arena" } +bitflags = "1.2.1" +tracing = "0.1" +rustc-rayon-core = "0.3.0" +polonius-engine = "0.12.0" +rustc_apfloat = { path = "../rustc_apfloat" } +rustc_attr = { path = "../rustc_attr" } +rustc_feature = { path = "../rustc_feature" } +rustc_hir = { path = "../rustc_hir" } +rustc_target = { path = "../rustc_target" } +rustc_macros = { path = "../rustc_macros" } +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_query_system = { path = "../rustc_query_system" } +rustc_errors = { path = "../rustc_errors" } +rustc_index = { path = "../rustc_index" } +rustc_serialize = { path = "../rustc_serialize" } +rustc_ast = { path = "../rustc_ast" } +rustc_span = { path = "../rustc_span" } +chalk-ir = "0.36.0" +smallvec = { version = "1.0", features = ["union", "may_dangle"] } +measureme = "9.0.0" +rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_middle/src/middle/cstore.rs b/compiler/rustc_crate/src/cstore.rs similarity index 76% rename from compiler/rustc_middle/src/middle/cstore.rs rename to compiler/rustc_crate/src/cstore.rs index e7529560a3e64..0212723df720d 100644 --- a/compiler/rustc_middle/src/middle/cstore.rs +++ b/compiler/rustc_crate/src/cstore.rs @@ -2,8 +2,6 @@ //! are *mostly* used as a part of that interface, but these should //! probably get a better home if someone can find one. -use crate::ty::TyCtxt; - use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_data_structures::svh::Svh; @@ -11,7 +9,6 @@ use rustc_data_structures::sync::{self, MetadataRef}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; -use rustc_macros::HashStable; use rustc_session::search_paths::PathKind; use rustc_session::utils::NativeLibKind; use rustc_session::CrateDisambiguator; @@ -26,7 +23,7 @@ use std::path::{Path, PathBuf}; /// Where a crate came from on the local filesystem. One of these three options /// must be non-None. -#[derive(PartialEq, Clone, Debug, HashStable, Encodable, Decodable)] +#[derive(PartialEq, Clone, Debug, HashStable_Generic, Encodable, Decodable)] pub struct CrateSource { pub dylib: Option<(PathBuf, PathKind)>, pub rlib: Option<(PathBuf, PathKind)>, @@ -40,7 +37,7 @@ impl CrateSource { } #[derive(Encodable, Decodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)] -#[derive(HashStable)] +#[derive(HashStable_Generic)] pub enum CrateDepKind { /// A dependency that is only used for its macros. MacrosOnly, @@ -81,13 +78,13 @@ impl LibSource { } } -#[derive(Copy, Debug, PartialEq, Clone, Encodable, Decodable, HashStable)] +#[derive(Copy, Debug, PartialEq, Clone, Encodable, Decodable, HashStable_Generic)] pub enum LinkagePreference { RequireDynamic, RequireStatic, } -#[derive(Clone, Debug, Encodable, Decodable, HashStable)] +#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)] pub struct NativeLib { pub kind: NativeLibKind, pub name: Option, @@ -96,13 +93,13 @@ pub struct NativeLib { pub wasm_import_module: Option, } -#[derive(Clone, TyEncodable, TyDecodable, HashStable)] +#[derive(Clone, Encodable, Decodable, HashStable_Generic)] pub struct ForeignModule { pub foreign_items: Vec, pub def_id: DefId, } -#[derive(Copy, Clone, Debug, HashStable)] +#[derive(Copy, Clone, Debug, HashStable_Generic)] pub struct ExternCrate { pub src: ExternCrateSource, @@ -133,7 +130,7 @@ impl ExternCrate { } } -#[derive(Copy, Clone, Debug, HashStable)] +#[derive(Copy, Clone, Debug, HashStable_Generic)] pub enum ExternCrateSource { /// Crate is loaded by `extern crate`. Extern( @@ -208,45 +205,3 @@ pub trait CrateStore { } pub type CrateStoreDyn = dyn CrateStore + sync::Sync; - -// This method is used when generating the command line to pass through to -// system linker. The linker expects undefined symbols on the left of the -// command line to be defined in libraries on the right, not the other way -// around. For more info, see some comments in the add_used_library function -// below. -// -// In order to get this left-to-right dependency ordering, we perform a -// topological sort of all crates putting the leaves at the right-most -// positions. -pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> { - let mut libs = tcx - .crates() - .iter() - .cloned() - .filter_map(|cnum| { - if tcx.dep_kind(cnum).macros_only() { - return None; - } - let source = tcx.used_crate_source(cnum); - let path = match prefer { - LinkagePreference::RequireDynamic => source.dylib.clone().map(|p| p.0), - LinkagePreference::RequireStatic => source.rlib.clone().map(|p| p.0), - }; - let path = match path { - Some(p) => LibSource::Some(p), - None => { - if source.rmeta.is_some() { - LibSource::MetadataOnly - } else { - LibSource::None - } - } - }; - Some((cnum, path)) - }) - .collect::>(); - let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned(); - ordering.reverse(); - libs.sort_by_cached_key(|&(a, _)| ordering.iter().position(|x| *x == a)); - libs -} diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs new file mode 100644 index 0000000000000..a9a4a959365d9 --- /dev/null +++ b/compiler/rustc_crate/src/lib.rs @@ -0,0 +1,13 @@ +#![feature(int_error_matching)] +#![feature(once_cell)] +#![feature(or_patterns)] + +#[macro_use] +extern crate rustc_macros; + +pub mod cstore; + +/// Requirements for a `StableHashingContext` to be used in this crate. +/// This is a hack to allow using the `HashStable_Generic` derive macro +/// instead of implementing everything in librustc_middle. +pub trait HashStableContext: rustc_ast::HashStableContext + rustc_hir::HashStableContext {} diff --git a/compiler/rustc_driver/Cargo.toml b/compiler/rustc_driver/Cargo.toml index 0adc006b6244e..1ebf706666061 100644 --- a/compiler/rustc_driver/Cargo.toml +++ b/compiler/rustc_driver/Cargo.toml @@ -14,6 +14,7 @@ tracing-subscriber = { version = "0.2.13", default-features = false, features = tracing-tree = "0.1.6" rustc_middle = { path = "../rustc_middle" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } +rustc_crate = { path = "../rustc_crate" } rustc_target = { path = "../rustc_target" } rustc_lint = { path = "../rustc_lint" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index c544761255534..d353392c0a6da 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -16,6 +16,7 @@ pub extern crate rustc_plugin_impl as plugin; use rustc_ast as ast; use rustc_codegen_ssa::{traits::CodegenBackend, CodegenResults}; +use rustc_crate::cstore::MetadataLoader; use rustc_data_structures::profiling::print_time_passes_entry; use rustc_data_structures::sync::SeqCst; use rustc_errors::registry::{InvalidErrorCode, Registry}; @@ -26,7 +27,6 @@ use rustc_interface::util::{self, collect_crate_types, get_builtin_codegen_backe use rustc_interface::{interface, Queries}; use rustc_lint::LintStore; use rustc_metadata::locator; -use rustc_middle::middle::cstore::MetadataLoader; use rustc_middle::ty::TyCtxt; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index e214493a567b8..782e180352c6c 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -15,6 +15,7 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } rustc_builtin_macros = { path = "../rustc_builtin_macros" } +rustc_crate = { path = "../rustc_crate" } rustc_expand = { path = "../rustc_expand" } rustc_parse = { path = "../rustc_parse" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 82cf4ab7f5c08..5bd5c626022c0 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -6,6 +6,7 @@ use rustc_ast::mut_visit::MutVisitor; use rustc_ast::{self as ast, visit}; use rustc_codegen_ssa::back::link::emit_metadata; use rustc_codegen_ssa::traits::CodegenBackend; +use rustc_crate::cstore::{CrateStore, EncodedMetadata, MetadataLoader, MetadataLoaderDyn}; use rustc_data_structures::steal::Steal; use rustc_data_structures::sync::{par_iter, Lrc, OnceCell, ParallelIterator, WorkerLocal}; use rustc_data_structures::temp_dir::MaybeTempDir; @@ -19,7 +20,6 @@ use rustc_lint::LintStore; use rustc_middle::arena::Arena; use rustc_middle::dep_graph::DepGraph; use rustc_middle::middle; -use rustc_middle::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt}; use rustc_mir as mir; @@ -920,7 +920,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { fn encode_and_write_metadata( tcx: TyCtxt<'_>, outputs: &OutputFilenames, -) -> (middle::cstore::EncodedMetadata, bool) { +) -> (EncodedMetadata, bool) { #[derive(PartialEq, Eq, PartialOrd, Ord)] enum MetadataKind { None, @@ -943,7 +943,7 @@ fn encode_and_write_metadata( .unwrap_or(MetadataKind::None); let metadata = match metadata_kind { - MetadataKind::None => middle::cstore::EncodedMetadata::new(), + MetadataKind::None => EncodedMetadata::new(), MetadataKind::Uncompressed | MetadataKind::Compressed => tcx.encode_metadata(), }; diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index f1975e78801ef..3bf61a2484dce 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -15,6 +15,7 @@ memmap = "0.7" smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_middle = { path = "../rustc_middle" } rustc_attr = { path = "../rustc_attr" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 33cbf0fb2345e..982d400a0bcbe 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -6,6 +6,8 @@ use crate::rmeta::{CrateDep, CrateMetadata, CrateNumMap, CrateRoot, MetadataBlob use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::{self as ast, *}; +use rustc_crate::cstore::{CrateDepKind, CrateSource, ExternCrate}; +use rustc_crate::cstore::{ExternCrateSource, MetadataLoaderDyn}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::Lrc; @@ -13,8 +15,6 @@ use rustc_expand::base::SyntaxExtension; use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE}; use rustc_hir::definitions::Definitions; use rustc_index::vec::IndexVec; -use rustc_middle::middle::cstore::{CrateDepKind, CrateSource, ExternCrate}; -use rustc_middle::middle::cstore::{ExternCrateSource, MetadataLoaderDyn}; use rustc_middle::ty::TyCtxt; use rustc_session::config::{self, CrateType, ExternLocation}; use rustc_session::lint; diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index c3afc9f048cf5..1ff3725e78945 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -53,11 +53,12 @@ use crate::creader::CStore; +use rustc_crate::cstore::CrateDepKind; +use rustc_crate::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::CrateNum; -use rustc_middle::middle::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic}; -use rustc_middle::middle::cstore::{self, CrateDepKind}; use rustc_middle::middle::dependency_format::{Dependencies, DependencyList, Linkage}; +use rustc_middle::middle::used_crates; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; use rustc_target::spec::PanicStrategy; @@ -274,7 +275,7 @@ fn add_library( } fn attempt_static(tcx: TyCtxt<'_>) -> Option { - let crates = cstore::used_crates(tcx, RequireStatic); + let crates = used_crates(tcx, RequireStatic); if !crates.iter().by_ref().all(|&(_, ref p)| p.is_some()) { return None; } diff --git a/compiler/rustc_metadata/src/foreign_modules.rs b/compiler/rustc_metadata/src/foreign_modules.rs index 8675197656a48..8a04c8cf413a8 100644 --- a/compiler/rustc_metadata/src/foreign_modules.rs +++ b/compiler/rustc_metadata/src/foreign_modules.rs @@ -1,6 +1,6 @@ +use rustc_crate::cstore::ForeignModule; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; -use rustc_middle::middle::cstore::ForeignModule; use rustc_middle::ty::TyCtxt; crate fn collect(tcx: TyCtxt<'_>) -> Vec { diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index c4c025de8b3c4..13ee103807c0a 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -215,12 +215,12 @@ use crate::creader::Library; use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER}; +use rustc_crate::cstore::{CrateSource, MetadataLoader}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::owning_ref::OwningRef; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; use rustc_errors::struct_span_err; -use rustc_middle::middle::cstore::{CrateSource, MetadataLoader}; use rustc_session::config::{self, CrateType}; use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc_session::search_paths::PathKind; diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index 2f7c2c2c40519..16a38634856d7 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -1,9 +1,9 @@ use rustc_attr as attr; +use rustc_crate::cstore::NativeLib; use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; -use rustc_middle::middle::cstore::NativeLib; use rustc_middle::ty::TyCtxt; use rustc_session::parse::feature_err; use rustc_session::utils::NativeLibKind; diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index a1df1a63fc58d..8cd9f462b31ae 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -6,6 +6,7 @@ use crate::rmeta::*; use rustc_ast as ast; use rustc_attr as attr; +use rustc_crate::cstore::{CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::{Fingerprint, FingerprintDecoder}; use rustc_data_structures::fx::FxHashMap; @@ -22,8 +23,6 @@ use rustc_hir::lang_items; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::dep_graph::{self, DepNode, DepNodeExt, DepNodeIndex}; use rustc_middle::hir::exports::Export; -use rustc_middle::middle::cstore::{CrateSource, ExternCrate}; -use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc_middle::mir::{self, Body, Promoted}; diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index ed95acceaf0d4..6a1b8373a9ef9 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -6,6 +6,7 @@ use crate::rmeta; use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; +use rustc_crate::cstore::{CrateSource, CrateStore, ForeignModule}; use rustc_data_structures::stable_map::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_hir as hir; @@ -13,8 +14,6 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_middle::hir::exports::Export; -use rustc_middle::middle::cstore::ForeignModule; -use rustc_middle::middle::cstore::{CrateSource, CrateStore}; use rustc_middle::middle::exported_symbols::ExportedSymbol; use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index b523d043fff8c..4856681209d65 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -2,6 +2,7 @@ use crate::rmeta::table::{FixedSizeEncoding, TableBuilder}; use crate::rmeta::*; use rustc_ast as ast; +use rustc_crate::cstore::{EncodedMetadata, ForeignModule, LinkagePreference, NativeLib}; use rustc_data_structures::fingerprint::{Fingerprint, FingerprintEncoder}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::stable_hasher::StableHasher; @@ -16,7 +17,6 @@ use rustc_hir::{AnonConst, GenericParamKind}; use rustc_index::bit_set::GrowableBitSet; use rustc_index::vec::Idx; use rustc_middle::hir::map::Map; -use rustc_middle::middle::cstore::{EncodedMetadata, ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 36b9619ef22a3..c4a3ae68d4386 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -3,6 +3,7 @@ use table::{Table, TableBuilder}; use rustc_ast::{self as ast, MacroDef}; use rustc_attr as attr; +use rustc_crate::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib}; use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; use rustc_hir as hir; @@ -12,7 +13,6 @@ use rustc_hir::definitions::DefKey; use rustc_hir::lang_items; use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_middle::hir::exports::Export; -use rustc_middle::middle::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc_middle::mir; use rustc_middle::ty::{self, ReprOptions, Ty}; diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 3250f1830de18..0ee243a782ad2 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -19,6 +19,7 @@ rustc_feature = { path = "../rustc_feature" } rustc_hir = { path = "../rustc_hir" } rustc_target = { path = "../rustc_target" } rustc_macros = { path = "../rustc_macros" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_query_system = { path = "../rustc_query_system" } rustc_errors = { path = "../rustc_errors" } diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 672073b1d3472..21f2ba21dee28 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -76,8 +76,8 @@ macro_rules! arena_types { >, [few] all_traits: Vec, [few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels, - [few] foreign_module: rustc_middle::middle::cstore::ForeignModule, - [few] foreign_modules: Vec, + [few] foreign_module: rustc_crate::cstore::ForeignModule, + [few] foreign_modules: Vec, [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap, [] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation, [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>, diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 516c9b6752b97..5601d89a07b1a 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -2,7 +2,7 @@ use crate::arena::Arena; use crate::hir::map::{Entry, HirOwnerData, Map}; use crate::hir::{Owner, OwnerNodes, ParentedNode}; use crate::ich::StableHashingContext; -use crate::middle::cstore::CrateStore; +use rustc_crate::cstore::CrateStore; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_middle/src/ich/hcx.rs index fb140546973d8..b067cc253fd4f 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_middle/src/ich/hcx.rs @@ -1,6 +1,6 @@ use crate::ich; -use crate::middle::cstore::CrateStore; use crate::ty::{fast_reject, TyCtxt}; +use rustc_crate::cstore::CrateStore; use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -255,6 +255,8 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { } } +impl<'a> rustc_crate::HashStableContext for StableHashingContext<'a> {} + pub fn hash_stable_trait_impls<'a>( hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher, diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 9bc9ca6707afe..a687da77cba21 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -1,5 +1,8 @@ +use crate::ty::TyCtxt; +use rustc_crate::cstore::{LibSource, LinkagePreference}; +use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; + pub mod codegen_fn_attrs; -pub mod cstore; pub mod dependency_format; pub mod exported_symbols; pub mod lang_items; @@ -32,3 +35,45 @@ pub mod privacy; pub mod region; pub mod resolve_lifetime; pub mod stability; + +// This method is used when generating the command line to pass through to +// system linker. The linker expects undefined symbols on the left of the +// command line to be defined in libraries on the right, not the other way +// around. For more info, see some comments in the add_used_library function +// below. +// +// In order to get this left-to-right dependency ordering, we perform a +// topological sort of all crates putting the leaves at the right-most +// positions. +pub fn used_crates(tcx: TyCtxt<'_>, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> { + let mut libs = tcx + .crates() + .iter() + .cloned() + .filter_map(|cnum| { + if tcx.dep_kind(cnum).macros_only() { + return None; + } + let source = tcx.used_crate_source(cnum); + let path = match prefer { + LinkagePreference::RequireDynamic => source.dylib.clone().map(|p| p.0), + LinkagePreference::RequireStatic => source.rlib.clone().map(|p| p.0), + }; + let path = match path { + Some(p) => LibSource::Some(p), + None => { + if source.rmeta.is_some() { + LibSource::MetadataOnly + } else { + LibSource::None + } + } + }; + Some((cnum, path)) + }) + .collect::>(); + let mut ordering = tcx.postorder_cnums(LOCAL_CRATE).to_owned(); + ordering.reverse(); + libs.sort_by_cached_key(|&(a, _)| ordering.iter().position(|x| *x == a)); + libs +} diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index bef03e5bc3eb2..8ccf19631d291 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -7,7 +7,6 @@ use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource}; use crate::middle; -use crate::middle::cstore::{CrateStoreDyn, EncodedMetadata}; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; use crate::mir::interpret::{self, Allocation, ConstValue, Scalar}; @@ -26,6 +25,7 @@ use crate::ty::{ use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_attr as attr; +use rustc_crate::cstore::{CrateStoreDyn, EncodedMetadata}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9eb6db46a3efc..b982d9507b382 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -7,7 +7,6 @@ pub use self::Variance::*; use crate::hir::exports::ExportMap; use crate::ich::StableHashingContext; -use crate::middle::cstore::CrateStoreDyn; use crate::middle::resolve_lifetime::ObjectLifetimeDefault; use crate::mir::interpret::ErrorHandled; use crate::mir::Body; @@ -18,6 +17,7 @@ use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef}; use crate::ty::util::{Discr, IntTypeExt}; use rustc_ast as ast; use rustc_attr as attr; +use rustc_crate::cstore::CrateStoreDyn; use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 1e4fd0921ee0f..a7377b38607e5 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1,9 +1,9 @@ -use crate::middle::cstore::{ExternCrate, ExternCrateSource}; use crate::mir::interpret::{AllocId, ConstValue, GlobalAlloc, Pointer, Scalar}; use crate::ty::subst::{GenericArg, GenericArgKind, Subst}; use crate::ty::{self, ConstInt, DefIdTree, ParamConst, ScalarInt, Ty, TyCtxt, TypeFoldable}; use rustc_apfloat::ieee::{Double, Single}; use rustc_ast as ast; +use rustc_crate::cstore::{ExternCrate, ExternCrateSource}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def::{self, CtorKind, DefKind, Namespace}; diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 187f86a52f4dc..e0e65e55e4341 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -4,8 +4,6 @@ use crate::hir::map; use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; -use crate::middle::cstore::{CrateDepKind, CrateSource}; -use crate::middle::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLib}; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; @@ -31,6 +29,9 @@ use crate::traits::{self, ImplSource}; use crate::ty::subst::{GenericArg, SubstsRef}; use crate::ty::util::AlwaysRequiresDrop; use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt}; +use rustc_crate::cstore::{ + CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, +}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::stable_hasher::StableVec; diff --git a/compiler/rustc_passes/Cargo.toml b/compiler/rustc_passes/Cargo.toml index df6667a29d50b..70ccd430390d0 100644 --- a/compiler/rustc_passes/Cargo.toml +++ b/compiler/rustc_passes/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } rustc_attr = { path = "../rustc_attr" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 0ae0c381a110b..0d11d14f896c5 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -10,16 +10,15 @@ use crate::check_attr::target_from_impl_item; use crate::weak_lang_items; -use rustc_middle::middle::cstore::ExternCrate; -use rustc_middle::ty::TyCtxt; - use rustc_ast::Attribute; +use rustc_crate::cstore::ExternCrate; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::lang_items::{extract, ITEM_REFS}; use rustc_hir::{HirId, LangItem, LanguageItems, Target}; +use rustc_middle::ty::TyCtxt; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_plugin_impl/Cargo.toml b/compiler/rustc_plugin_impl/Cargo.toml index 500d13a8c1647..dc9df4fdf9bd2 100644 --- a/compiler/rustc_plugin_impl/Cargo.toml +++ b/compiler/rustc_plugin_impl/Cargo.toml @@ -10,6 +10,7 @@ doctest = false [dependencies] rustc_middle = { path = "../rustc_middle" } +rustc_crate = { path = "../rustc_crate" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } rustc_lint = { path = "../rustc_lint" } diff --git a/compiler/rustc_plugin_impl/src/load.rs b/compiler/rustc_plugin_impl/src/load.rs index 687f7db221f4e..35b1e6e41f34a 100644 --- a/compiler/rustc_plugin_impl/src/load.rs +++ b/compiler/rustc_plugin_impl/src/load.rs @@ -2,9 +2,9 @@ use crate::Registry; use rustc_ast::Crate; +use rustc_crate::cstore::MetadataLoader; use rustc_errors::struct_span_err; use rustc_metadata::locator; -use rustc_middle::middle::cstore::MetadataLoader; use rustc_session::Session; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index 821f9ea4738fe..026f049e378b3 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -17,6 +17,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_ast_lowering = { path = "../rustc_ast_lowering" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_attr = { path = "../rustc_attr" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_expand = { path = "../rustc_expand" } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 493b9f15271ef..d8831138655e7 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -20,6 +20,7 @@ use rustc_ast::{self as ast, Block, ForeignItem, ForeignItemKind, Item, ItemKind use rustc_ast::{AssocItem, AssocItemKind, MetaItemKind, StmtKind}; use rustc_ast_lowering::ResolverAstLowering; use rustc_attr as attr; +use rustc_crate::cstore::CrateStore; use rustc_data_structures::sync::Lrc; use rustc_errors::{struct_span_err, Applicability}; use rustc_expand::base::SyntaxExtension; @@ -29,7 +30,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX}; use rustc_metadata::creader::LoadedMacro; use rustc_middle::bug; use rustc_middle::hir::exports::Export; -use rustc_middle::middle::cstore::CrateStore; use rustc_middle::ty; use rustc_span::hygiene::{ExpnId, MacroKind}; use rustc_span::source_map::{respan, Spanned}; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index d18335ef2e63a..086db571e9144 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -29,6 +29,7 @@ use rustc_ast::{Crate, CRATE_NODE_ID}; use rustc_ast::{ItemKind, Path}; use rustc_ast_lowering::ResolverAstLowering; use rustc_ast_pretty::pprust; +use rustc_crate::cstore::{CrateStore, MetadataLoaderDyn}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::ptr_key::PtrKey; use rustc_data_structures::sync::Lrc; @@ -43,7 +44,6 @@ use rustc_hir::TraitCandidate; use rustc_index::vec::IndexVec; use rustc_metadata::creader::{CStore, CrateLoader}; use rustc_middle::hir::exports::ExportMap; -use rustc_middle::middle::cstore::{CrateStore, MetadataLoaderDyn}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, DefIdTree, ResolverOutputs}; use rustc_middle::{bug, span_bug}; diff --git a/compiler/rustc_save_analysis/Cargo.toml b/compiler/rustc_save_analysis/Cargo.toml index da1bed37a96cb..eef3df1045851 100644 --- a/compiler/rustc_save_analysis/Cargo.toml +++ b/compiler/rustc_save_analysis/Cargo.toml @@ -9,6 +9,7 @@ tracing = "0.1" rustc_middle = { path = "../rustc_middle" } rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_hir = { path = "../rustc_hir" } rustc_hir_pretty = { path = "../rustc_hir_pretty" } diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index eed9f2eb74d4f..4bee5437aa001 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -12,6 +12,7 @@ mod sig; use rustc_ast as ast; use rustc_ast::util::comments::beautify_doc_string; use rustc_ast_pretty::pprust::attribute_to_string; +use rustc_crate::cstore::ExternCrate; use rustc_hir as hir; use rustc_hir::def::{DefKind as HirDefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -19,7 +20,6 @@ use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::Node; use rustc_hir_pretty::{enum_def_to_string, fn_to_string, ty_to_string}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::cstore::ExternCrate; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{self, print::with_no_trimmed_paths, DefIdTree, TyCtxt}; use rustc_middle::{bug, span_bug}; diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 14a2def138310..8edfe086542d1 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,4 +1,5 @@ use rustc_attr as attr; +use rustc_crate::cstore::CrateStore; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{self, Lrc}; use rustc_driver::abort_on_err; @@ -14,7 +15,6 @@ use rustc_hir::{ }; use rustc_interface::interface; use rustc_middle::hir::map::Map; -use rustc_middle::middle::cstore::CrateStore; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_resolve as resolve; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index a88efba77b41c..a7c18972fb28b 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -31,6 +31,7 @@ extern crate tracing; extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr; +extern crate rustc_crate; extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_errors; From 224e3b4ab51d26c312c4d6066e8e56091c6f1eb1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:32:58 +0100 Subject: [PATCH 05/15] Move rustc_middle::middle::codegen_fn_attrs to rustc_crate. --- Cargo.lock | 3 +++ compiler/rustc_codegen_cranelift/src/abi/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/constant.rs | 2 +- compiler/rustc_codegen_cranelift/src/driver/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/linkage.rs | 2 +- compiler/rustc_codegen_llvm/Cargo.toml | 2 +- compiler/rustc_codegen_llvm/src/attributes.rs | 2 +- compiler/rustc_codegen_llvm/src/base.rs | 2 +- compiler/rustc_codegen_llvm/src/consts.rs | 2 +- compiler/rustc_codegen_llvm/src/mono_item.rs | 2 +- compiler/rustc_codegen_ssa/src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/debuginfo.rs | 2 +- compiler/rustc_codegen_ssa/src/mono_item.rs | 2 +- compiler/rustc_codegen_ssa/src/traits/declare.rs | 2 +- .../src/middle => rustc_crate/src}/codegen_fn_attrs.rs | 8 ++++---- compiler/rustc_crate/src/lib.rs | 3 +++ compiler/rustc_middle/src/middle/mod.rs | 1 - compiler/rustc_middle/src/mir/mono.rs | 2 +- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_middle/src/ty/query/mod.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_mir/Cargo.toml | 1 + compiler/rustc_mir/src/monomorphize/collector.rs | 2 +- .../rustc_mir/src/monomorphize/partitioning/default.rs | 2 +- compiler/rustc_mir/src/monomorphize/partitioning/mod.rs | 2 +- compiler/rustc_mir/src/transform/inline.rs | 2 +- compiler/rustc_passes/src/dead.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 2 +- compiler/rustc_symbol_mangling/Cargo.toml | 1 + compiler/rustc_symbol_mangling/src/lib.rs | 2 +- compiler/rustc_typeck/Cargo.toml | 1 + compiler/rustc_typeck/src/collect.rs | 2 +- 34 files changed, 40 insertions(+), 32 deletions(-) rename compiler/{rustc_middle/src/middle => rustc_crate/src}/codegen_fn_attrs.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index f637ee8088f49..c2c74063f0756 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3972,6 +3972,7 @@ dependencies = [ "rustc_apfloat", "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_graphviz", @@ -4205,6 +4206,7 @@ dependencies = [ "punycode", "rustc-demangle", "rustc_ast", + "rustc_crate", "rustc_data_structures", "rustc_hir", "rustc_middle", @@ -4300,6 +4302,7 @@ dependencies = [ "rustc_arena", "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_hir", diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 81091728692f3..ea45f8d745dd2 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -5,7 +5,7 @@ mod comments; mod pass_mode; mod returning; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_target::spec::abi::Abi; use cranelift_codegen::ir::{AbiParam, ArgumentPurpose}; diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 0c8d46ef42b18..72e5c30cc82b0 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -4,7 +4,7 @@ use rustc_span::DUMMY_SP; use rustc_data_structures::fx::FxHashSet; use rustc_errors::ErrorReported; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage as RLinkage}; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage as RLinkage}; use rustc_middle::mir::interpret::{ read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer, Scalar, }; diff --git a/compiler/rustc_codegen_cranelift/src/driver/mod.rs b/compiler/rustc_codegen_cranelift/src/driver/mod.rs index df3ba42399c3e..9cbf938b746cf 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/mod.rs @@ -4,7 +4,7 @@ use std::any::Any; use rustc_crate::cstore::EncodedMetadata; -use rustc_middle::middle::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; +use rustc_crate::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; use rustc_middle::mir::mono::MonoItem; use crate::prelude::*; diff --git a/compiler/rustc_codegen_cranelift/src/linkage.rs b/compiler/rustc_codegen_cranelift/src/linkage.rs index 97ede38583c29..f75370dd827c4 100644 --- a/compiler/rustc_codegen_cranelift/src/linkage.rs +++ b/compiler/rustc_codegen_cranelift/src/linkage.rs @@ -1,4 +1,4 @@ -use rustc_middle::middle::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; +use rustc_crate::codegen_fn_attrs::{Linkage as RLinkage, Visibility}; use rustc_middle::mir::mono::MonoItem; use crate::prelude::*; diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index 2f335eeec929f..45144508bf3dc 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -15,10 +15,10 @@ measureme = "9.0.0" snap = "1" tracing = "0.1" rustc_middle = { path = "../rustc_middle" } +rustc_crate = { path = "../rustc_crate" } rustc-demangle = "0.1.18" rustc_attr = { path = "../rustc_attr" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } -rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index e06e2d45665b1..c6059adb313e5 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -3,11 +3,11 @@ use std::ffi::CString; use rustc_codegen_ssa::traits::*; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_data_structures::const_cstr; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::small_c_str::SmallCStr; use rustc_hir::def_id::DefId; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt}; diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 58ee066908408..eb618757fee48 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -27,10 +27,10 @@ use rustc_codegen_ssa::base::maybe_create_entry_wrapper; use rustc_codegen_ssa::mono_item::MonoItemExt; use rustc_codegen_ssa::traits::*; use rustc_codegen_ssa::{ModuleCodegen, ModuleKind}; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrs, Linkage, Visibility}; use rustc_crate::cstore::EncodedMetadata; use rustc_data_structures::small_c_str::SmallCStr; use rustc_middle::dep_graph; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrs, Linkage, Visibility}; use rustc_middle::middle::exported_symbols; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, SanitizerSet}; diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 14dd245625d25..a1d580a693e3a 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -7,11 +7,11 @@ use crate::type_of::LayoutLlvmExt; use crate::value::Value; use libc::c_uint; use rustc_codegen_ssa::traits::*; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_data_structures::const_cstr; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_hir::Node; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::interpret::{ read_target_uint, Allocation, ErrorHandled, GlobalAlloc, Pointer, }; diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 918508e6682c0..b96ccbe99fe99 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -5,8 +5,8 @@ use crate::context::CodegenCx; use crate::llvm; use crate::type_of::LayoutLlvmExt; use rustc_codegen_ssa::traits::*; +use rustc_crate::codegen_fn_attrs::{Linkage, Visibility}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; -use rustc_middle::middle::codegen_fn_attrs::{Linkage, Visibility}; pub use rustc_middle::mir::mono::MonoItem; use rustc_middle::ty::layout::FnAbiExt; use rustc_middle::ty::{self, Instance, TypeFoldable}; diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 91023f9aa2088..af9b245e03d4c 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -1,13 +1,13 @@ use std::collections::hash_map::Entry::*; use rustc_ast::expand::allocator::ALLOCATOR_METHODS; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage, Visibility}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::Node; use rustc_index::vec::IndexVec; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage, Visibility}; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, }; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 82d0eac77a57a..41c53fca1b92e 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -26,6 +26,7 @@ use crate::traits::*; use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}; use rustc_attr as attr; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrs; use rustc_crate::cstore::{EncodedMetadata, LinkagePreference}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::profiling::print_time_passes_entry; @@ -34,7 +35,6 @@ use rustc_hir as hir; use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_index::vec::Idx; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::{lang_items, used_crates}; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem}; use rustc_middle::ty::layout::{HasTyCtxt, TyAndLayout}; diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 4e0396a15a646..4a5c0eaafae58 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -1,6 +1,6 @@ use crate::traits::*; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_index::vec::IndexVec; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir; use rustc_middle::ty; use rustc_session::config::DebugInfo; diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs index 06acd605ad496..7776395c3fb44 100644 --- a/compiler/rustc_codegen_ssa/src/mono_item.rs +++ b/compiler/rustc_codegen_ssa/src/mono_item.rs @@ -1,7 +1,7 @@ use crate::base; use crate::traits::*; +use rustc_crate::codegen_fn_attrs::{Linkage, Visibility}; use rustc_hir as hir; -use rustc_middle::middle::codegen_fn_attrs::{Linkage, Visibility}; use rustc_middle::ty::layout::HasTyCtxt; use rustc_middle::mir::mono::MonoItem; diff --git a/compiler/rustc_codegen_ssa/src/traits/declare.rs b/compiler/rustc_codegen_ssa/src/traits/declare.rs index ab836b34b0748..d6a03c612de9d 100644 --- a/compiler/rustc_codegen_ssa/src/traits/declare.rs +++ b/compiler/rustc_codegen_ssa/src/traits/declare.rs @@ -1,6 +1,6 @@ use super::BackendTypes; +use rustc_crate::codegen_fn_attrs::{Linkage, Visibility}; use rustc_hir::def_id::DefId; -use rustc_middle::middle::codegen_fn_attrs::{Linkage, Visibility}; use rustc_middle::ty::Instance; pub trait PreDefineMethods<'tcx>: BackendTypes { diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_crate/src/codegen_fn_attrs.rs similarity index 96% rename from compiler/rustc_middle/src/middle/codegen_fn_attrs.rs rename to compiler/rustc_crate/src/codegen_fn_attrs.rs index c2bfc209bb053..57caff762f7ef 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_crate/src/codegen_fn_attrs.rs @@ -5,7 +5,7 @@ use rustc_span::symbol::Symbol; /// Specifies the linkage type for a `MonoItem`. /// /// See for more details about these variants. -#[derive(Copy, Clone, PartialEq, Debug, TyEncodable, TyDecodable, HashStable)] +#[derive(Copy, Clone, PartialEq, Debug, Encodable, Decodable, HashStable_Generic)] pub enum Linkage { External, AvailableExternally, @@ -20,14 +20,14 @@ pub enum Linkage { Common, } -#[derive(Copy, Clone, PartialEq, Debug, HashStable)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic)] pub enum Visibility { Default, Hidden, Protected, } -#[derive(Clone, TyEncodable, TyDecodable, HashStable)] +#[derive(Clone, Encodable, Decodable, HashStable_Generic)] pub struct CodegenFnAttrs { pub flags: CodegenFnAttrFlags, /// Parsed representation of the `#[inline]` attribute @@ -65,7 +65,7 @@ pub struct CodegenFnAttrs { } bitflags! { - #[derive(TyEncodable, TyDecodable, HashStable)] + #[derive(Encodable, Decodable, HashStable_Generic)] pub struct CodegenFnAttrFlags: u32 { /// `#[cold]`: a hint to LLVM that this function, when called, is never on /// the hot path. diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index a9a4a959365d9..544d5990c9182 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -2,9 +2,12 @@ #![feature(once_cell)] #![feature(or_patterns)] +#[macro_use] +extern crate bitflags; #[macro_use] extern crate rustc_macros; +pub mod codegen_fn_attrs; pub mod cstore; /// Requirements for a `StableHashingContext` to be used in this crate. diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index a687da77cba21..61eb3bc860b7f 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -2,7 +2,6 @@ use crate::ty::TyCtxt; use rustc_crate::cstore::{LibSource, LinkagePreference}; use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; -pub mod codegen_fn_attrs; pub mod dependency_format; pub mod exported_symbols; pub mod lang_items; diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index 7b92b57507c99..d346b5f1d1ca7 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -1,8 +1,8 @@ use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId}; use crate::ich::{NodeIdHashingMode, StableHashingContext}; -use crate::middle::codegen_fn_attrs::{Linkage, Visibility}; use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt}; use rustc_attr::InlineAttr; +use rustc_crate::codegen_fn_attrs::{Linkage, Visibility}; use rustc_data_structures::base_n; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 306cebd9cb722..3e00658f1398a 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -1,7 +1,7 @@ -use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::subst::{InternalSubsts, Subst}; use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable}; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_errors::ErrorReported; use rustc_hir::def::Namespace; use rustc_hir::def_id::{CrateNum, DefId}; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 1e93c3650b890..fbaf7687d442d 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1,8 +1,8 @@ use crate::ich::StableHashingContext; -use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::mir::{GeneratorLayout, GeneratorSavedLocal}; use crate::ty::subst::Subst; use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable}; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_ast::{self as ast, IntTy, UintTy}; use rustc_attr as attr; diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index e0e65e55e4341..380bc90b52e69 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -3,7 +3,6 @@ use crate::hir::exports::Export; use crate::hir::map; use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; -use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; @@ -29,6 +28,7 @@ use crate::traits::{self, ImplSource}; use crate::ty::subst::{GenericArg, SubstsRef}; use crate::ty::util::AlwaysRequiresDrop; use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt}; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrs; use rustc_crate::cstore::{ CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, }; diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 5f117e19eca27..29c6953d5ea93 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1,7 +1,6 @@ //! Miscellaneous type-system utilities that are too small to deserve their own modules. use crate::ich::NodeIdHashingMode; -use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::ty::fold::TypeFolder; use crate::ty::layout::IntegerExt; use crate::ty::query::TyCtxtAt; @@ -11,6 +10,7 @@ use crate::ty::{self, DefIdTree, List, Ty, TyCtxt, TypeFoldable}; use rustc_apfloat::Float as _; use rustc_ast as ast; use rustc_attr::{self as attr, SignedInt, UnsignedInt}; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::ErrorReported; diff --git a/compiler/rustc_mir/Cargo.toml b/compiler/rustc_mir/Cargo.toml index 9bfd1da039120..8a1f651bf18cc 100644 --- a/compiler/rustc_mir/Cargo.toml +++ b/compiler/rustc_mir/Cargo.toml @@ -15,6 +15,7 @@ tracing = "0.1" polonius-engine = "0.12.0" regex = "1" rustc_middle = { path = "../rustc_middle" } +rustc_crate = { path = "../rustc_crate" } rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 938181abff244..23d4862169930 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -176,6 +176,7 @@ use crate::monomorphize; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_errors::{ErrorReported, FatalError}; @@ -184,7 +185,6 @@ use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::lang_items::LangItem; use rustc_index::bit_set::GrowableBitSet; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{AllocId, ConstValue}; use rustc_middle::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs index d75b5ae7f8706..eedbfb9388252 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs @@ -1,10 +1,10 @@ use std::collections::hash_map::Entry; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage, Visibility}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::definitions::DefPathDataName; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, Linkage, Visibility}; use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder}; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs b/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs index 70770d0813b81..fef3175156867 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs @@ -95,10 +95,10 @@ mod default; mod merging; +use rustc_crate::codegen_fn_attrs::Linkage; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync; use rustc_hir::def_id::{CrateNum, DefIdSet, LOCAL_CRATE}; -use rustc_middle::middle::codegen_fn_attrs::Linkage; use rustc_middle::mir::mono::{CodegenUnit, MonoItem}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index aae98f5b6d8d6..6cbf9665190e5 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -1,10 +1,10 @@ //! Inlining pass for MIR functions use rustc_attr as attr; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_hir as hir; use rustc_index::bit_set::BitSet; use rustc_index::vec::Idx; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::visit::*; use rustc_middle::mir::*; use rustc_middle::ty::subst::Subst; diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index f567dd83bc13d..218841f28259e 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -2,6 +2,7 @@ // closely. The idea is that all reachable symbols are live, codes called // from live codes are live, and everything else is dead. +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; @@ -10,7 +11,6 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{Node, PatKind, TyKind}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::privacy; use rustc_middle::ty::{self, DefIdTree, TyCtxt}; use rustc_session::lint; diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 8d5c980609cd9..33c5822870484 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -5,6 +5,7 @@ // makes all other generics or inline functions that it references // reachable as well. +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -13,7 +14,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::Node; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::middle::privacy; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, DefIdTree, TyCtxt}; diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index 3df5f16131922..0a1412b6262de 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -13,6 +13,7 @@ punycode = "0.4.0" rustc-demangle = "0.1.18" rustc_ast = { path = "../rustc_ast" } +rustc_crate = { path = "../rustc_crate" } rustc_span = { path = "../rustc_span" } rustc_middle = { path = "../rustc_middle" } rustc_hir = { path = "../rustc_hir" } diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 10245d21b63a5..d7bc4e76c81a2 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -97,9 +97,9 @@ #[macro_use] extern crate rustc_middle; +use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc_hir::Node; -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::SubstsRef; diff --git a/compiler/rustc_typeck/Cargo.toml b/compiler/rustc_typeck/Cargo.toml index e3ba0bea7e8e2..f5ba02a0c97c8 100644 --- a/compiler/rustc_typeck/Cargo.toml +++ b/compiler/rustc_typeck/Cargo.toml @@ -12,6 +12,7 @@ doctest = false rustc_arena = { path = "../rustc_arena" } tracing = "0.1" rustc_macros = { path = "../rustc_macros" } +rustc_crate = { path = "../rustc_crate" } rustc_middle = { path = "../rustc_middle" } rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 780512694805d..0d603fa202202 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -23,6 +23,7 @@ use crate::middle::resolve_lifetime as rl; use rustc_ast as ast; use rustc_ast::{MetaItemKind, NestedMetaItem}; use rustc_attr::{list_contains_name, InlineAttr, InstructionSetAttr, OptimizeAttr}; +use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs, Linkage}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_errors::{struct_span_err, Applicability}; @@ -34,7 +35,6 @@ use rustc_hir::weak_lang_items; use rustc_hir::{GenericParamKind, HirId, Node}; use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::hir::map::Map; -use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs, Linkage}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::util::Discr; From 6c48bb0edb18ad516e06598162ef33cb9aa3dd0a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:35:52 +0100 Subject: [PATCH 06/15] Move rustc_middle::middle::dependency_format to rustc_crate. --- compiler/rustc_codegen_cranelift/src/allocator.rs | 2 +- compiler/rustc_codegen_cranelift/src/driver/jit.rs | 2 +- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- compiler/rustc_codegen_ssa/src/back/linker.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/lib.rs | 2 +- .../src/middle => rustc_crate/src}/dependency_format.rs | 2 +- compiler/rustc_crate/src/lib.rs | 1 + compiler/rustc_metadata/src/dependency_format.rs | 2 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_middle/src/middle/mod.rs | 1 - compiler/rustc_middle/src/query/mod.rs | 2 +- 12 files changed, 11 insertions(+), 11 deletions(-) rename compiler/{rustc_middle/src/middle => rustc_crate/src}/dependency_format.rs (91%) diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs index 6c5916550ff63..5b5f984780da9 100644 --- a/compiler/rustc_codegen_cranelift/src/allocator.rs +++ b/compiler/rustc_codegen_cranelift/src/allocator.rs @@ -13,7 +13,7 @@ pub(crate) fn codegen( unwind_context: &mut UnwindContext<'_>, ) -> bool { let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { - use rustc_middle::middle::dependency_format::Linkage; + use rustc_crate::dependency_format::Linkage; list.iter().any(|&linkage| linkage == Linkage::Dynamic) }); if any_dynamic_crate { diff --git a/compiler/rustc_codegen_cranelift/src/driver/jit.rs b/compiler/rustc_codegen_cranelift/src/driver/jit.rs index 3f47df7d844b3..c7badc8528ea6 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/jit.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/jit.rs @@ -109,7 +109,7 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>) -> ! { } fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { - use rustc_middle::middle::dependency_format::Linkage; + use rustc_crate::dependency_format::Linkage; let mut dylib_paths = Vec::new(); diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 581dcd57d00e5..9a4eb7d4ceb11 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1,9 +1,9 @@ use rustc_crate::cstore::{EncodedMetadata, LibSource, NativeLib}; +use rustc_crate::dependency_format::Linkage; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_hir::def_id::CrateNum; -use rustc_middle::middle::dependency_format::Linkage; use rustc_session::config::{self, CFGuard, CrateType, DebugInfo}; use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SanitizerSet}; use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename}; diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 3df956c465e5e..089dc6bfffabc 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -10,9 +10,9 @@ use std::io::{self, BufWriter}; use std::mem; use std::path::{Path, PathBuf}; +use rustc_crate::dependency_format::Linkage; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; -use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::ty::TyCtxt; use rustc_serialize::{json, Encoder}; use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip}; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 41c53fca1b92e..6269e80399a4d 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -521,7 +521,7 @@ pub fn codegen_crate( // one instead. If nothing exists then it's our job to generate the // allocator! let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| { - use rustc_middle::middle::dependency_format::Linkage; + use rustc_crate::dependency_format::Linkage; list.iter().any(|&linkage| linkage == Linkage::Dynamic) }); let allocator_module = if any_dynamic_crate { diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 7c2d7fe1e83b9..09a3615610471 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -21,12 +21,12 @@ extern crate tracing; extern crate rustc_middle; use rustc_crate::cstore::{CrateSource, EncodedMetadata, LibSource, NativeLib}; +use rustc_crate::dependency_format::Dependencies; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::CrateNum; use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; -use rustc_middle::middle::dependency_format::Dependencies; use rustc_middle::ty::query::Providers; use rustc_session::config::{OutputFilenames, OutputType, RUST_CGU_EXT}; use rustc_span::symbol::Symbol; diff --git a/compiler/rustc_middle/src/middle/dependency_format.rs b/compiler/rustc_crate/src/dependency_format.rs similarity index 91% rename from compiler/rustc_middle/src/middle/dependency_format.rs rename to compiler/rustc_crate/src/dependency_format.rs index e079843bfbc3c..25107b608c403 100644 --- a/compiler/rustc_middle/src/middle/dependency_format.rs +++ b/compiler/rustc_crate/src/dependency_format.rs @@ -19,7 +19,7 @@ pub type DependencyList = Vec; /// This is local to the tcx, and is generally relevant to one session. pub type Dependencies = Vec<(CrateType, DependencyList)>; -#[derive(Copy, Clone, PartialEq, Debug, HashStable, Encodable, Decodable)] +#[derive(Copy, Clone, PartialEq, Debug, HashStable_Generic, Encodable, Decodable)] pub enum Linkage { NotLinked, IncludedFromDylib, diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index 544d5990c9182..5973408da1c46 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -9,6 +9,7 @@ extern crate rustc_macros; pub mod codegen_fn_attrs; pub mod cstore; +pub mod dependency_format; /// Requirements for a `StableHashingContext` to be used in this crate. /// This is a hack to allow using the `HashStable_Generic` derive macro diff --git a/compiler/rustc_metadata/src/dependency_format.rs b/compiler/rustc_metadata/src/dependency_format.rs index 1ff3725e78945..b81ef2cba1ad0 100644 --- a/compiler/rustc_metadata/src/dependency_format.rs +++ b/compiler/rustc_metadata/src/dependency_format.rs @@ -55,9 +55,9 @@ use crate::creader::CStore; use rustc_crate::cstore::CrateDepKind; use rustc_crate::cstore::LinkagePreference::{self, RequireDynamic, RequireStatic}; +use rustc_crate::dependency_format::{Dependencies, DependencyList, Linkage}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::CrateNum; -use rustc_middle::middle::dependency_format::{Dependencies, DependencyList, Linkage}; use rustc_middle::middle::used_crates; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 4856681209d65..4c572928fd95f 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -3,6 +3,7 @@ use crate::rmeta::*; use rustc_ast as ast; use rustc_crate::cstore::{EncodedMetadata, ForeignModule, LinkagePreference, NativeLib}; +use rustc_crate::dependency_format::Linkage; use rustc_data_structures::fingerprint::{Fingerprint, FingerprintEncoder}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_data_structures::stable_hasher::StableHasher; @@ -17,7 +18,6 @@ use rustc_hir::{AnonConst, GenericParamKind}; use rustc_index::bit_set::GrowableBitSet; use rustc_index::vec::Idx; use rustc_middle::hir::map::Map; -use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, }; diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 61eb3bc860b7f..1e14ccf5918d7 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -2,7 +2,6 @@ use crate::ty::TyCtxt; use rustc_crate::cstore::{LibSource, LinkagePreference}; use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; -pub mod dependency_format; pub mod exported_symbols; pub mod lang_items; pub mod lib_features { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 72360e219ecbd..0fd57259dec0d 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1012,7 +1012,7 @@ rustc_queries! { } query dependency_formats(_: CrateNum) - -> Lrc + -> Lrc { desc { "get the linkage format of all dependencies" } } From 73b00597c7f5f8df8627d818047c24324dc9399f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:39:27 +0100 Subject: [PATCH 07/15] Move rustc_middle::middle::lib_features to rustc_crate. --- compiler/rustc_crate/src/lib.rs | 23 ++++++++++++++++++++++ compiler/rustc_middle/src/middle/mod.rs | 24 ----------------------- compiler/rustc_middle/src/ty/context.rs | 3 +-- compiler/rustc_middle/src/ty/query/mod.rs | 2 +- compiler/rustc_passes/src/lib_features.rs | 2 +- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index 5973408da1c46..488c6b1117b4b 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -7,10 +7,33 @@ extern crate bitflags; #[macro_use] extern crate rustc_macros; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_span::symbol::Symbol; + pub mod codegen_fn_attrs; pub mod cstore; pub mod dependency_format; +#[derive(HashStable_Generic)] +pub struct LibFeatures { + // A map from feature to stabilisation version. + pub stable: FxHashMap, + pub unstable: FxHashSet, +} + +impl LibFeatures { + pub fn to_vec(&self) -> Vec<(Symbol, Option)> { + let mut all_features: Vec<_> = self + .stable + .iter() + .map(|(f, s)| (*f, Some(*s))) + .chain(self.unstable.iter().map(|f| (*f, None))) + .collect(); + all_features.sort_unstable_by_key(|f| f.0.as_str()); + all_features + } +} + /// Requirements for a `StableHashingContext` to be used in this crate. /// This is a hack to allow using the `HashStable_Generic` derive macro /// instead of implementing everything in librustc_middle. diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 1e14ccf5918d7..8e06fba20f433 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -4,30 +4,6 @@ use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; pub mod exported_symbols; pub mod lang_items; -pub mod lib_features { - use rustc_data_structures::fx::{FxHashMap, FxHashSet}; - use rustc_span::symbol::Symbol; - - #[derive(HashStable)] - pub struct LibFeatures { - // A map from feature to stabilisation version. - pub stable: FxHashMap, - pub unstable: FxHashSet, - } - - impl LibFeatures { - pub fn to_vec(&self) -> Vec<(Symbol, Option)> { - let mut all_features: Vec<_> = self - .stable - .iter() - .map(|(f, s)| (*f, Some(*s))) - .chain(self.unstable.iter().map(|f| (*f, None))) - .collect(); - all_features.sort_unstable_by_key(|f| f.0.as_str()); - all_features - } - } -} pub mod limits; pub mod privacy; pub mod region; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 8ccf19631d291..bc88b5febee89 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -6,7 +6,6 @@ use crate::hir::exports::ExportMap; use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource}; -use crate::middle; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; use crate::mir::interpret::{self, Allocation, ConstValue, Scalar}; @@ -1188,7 +1187,7 @@ impl<'tcx> TyCtxt<'tcx> { self.sess.consider_optimizing(&cname, msg) } - pub fn lib_features(self) -> &'tcx middle::lib_features::LibFeatures { + pub fn lib_features(self) -> &'tcx rustc_crate::LibFeatures { self.get_lib_features(LOCAL_CRATE) } diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 380bc90b52e69..7d344c68ea406 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -4,7 +4,6 @@ use crate::hir::map; use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; -use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; use crate::middle::region; use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes}; @@ -32,6 +31,7 @@ use rustc_crate::codegen_fn_attrs::CodegenFnAttrs; use rustc_crate::cstore::{ CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, }; +use rustc_crate::LibFeatures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::stable_hasher::StableVec; diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 7c62a234dbaec..17592ee24241c 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -5,11 +5,11 @@ // (unlike lang features), which means we need to collect them instead. use rustc_ast::{Attribute, MetaItem, MetaItemKind}; +use rustc_crate::LibFeatures; use rustc_errors::struct_span_err; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::lib_features::LibFeatures; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::Symbol; From 7e53e462bac48eeef10e2a1051ad53c2fe17705d Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:42:55 +0100 Subject: [PATCH 08/15] Move rustc_middle::middle::limits to rustc_crate. --- compiler/rustc_crate/src/lib.rs | 1 + .../{rustc_middle/src/middle => rustc_crate/src}/limits.rs | 7 +++---- compiler/rustc_interface/src/passes.rs | 3 +-- compiler/rustc_middle/src/middle/mod.rs | 1 - 4 files changed, 5 insertions(+), 7 deletions(-) rename compiler/{rustc_middle/src/middle => rustc_crate/src}/limits.rs (89%) diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index 488c6b1117b4b..5a141ee507f94 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -13,6 +13,7 @@ use rustc_span::symbol::Symbol; pub mod codegen_fn_attrs; pub mod cstore; pub mod dependency_format; +pub mod limits; #[derive(HashStable_Generic)] pub struct LibFeatures { diff --git a/compiler/rustc_middle/src/middle/limits.rs b/compiler/rustc_crate/src/limits.rs similarity index 89% rename from compiler/rustc_middle/src/middle/limits.rs rename to compiler/rustc_crate/src/limits.rs index 41342764ba773..969fc5f2b37d4 100644 --- a/compiler/rustc_middle/src/middle/limits.rs +++ b/compiler/rustc_crate/src/limits.rs @@ -5,7 +5,6 @@ //! this via an attribute on the crate like `#![recursion_limit="22"]`. This pass //! just peeks and looks for that attribute. -use crate::bug; use rustc_ast as ast; use rustc_data_structures::sync::OnceCell; use rustc_session::{Limit, Session}; @@ -52,10 +51,10 @@ fn update_limit( IntErrorKind::Empty => "`limit` must be a non-negative integer", IntErrorKind::InvalidDigit => "not a valid integer", IntErrorKind::NegOverflow => { - bug!("`limit` should never negatively overflow") + panic!("`limit` should never negatively overflow") } - IntErrorKind::Zero => bug!("zero is a valid `limit`"), - kind => bug!("unimplemented IntErrorKind variant: {:?}", kind), + IntErrorKind::Zero => panic!("zero is a valid `limit`"), + kind => panic!("unimplemented IntErrorKind variant: {:?}", kind), }; err.span_label(value_span, error_str); diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 5bd5c626022c0..c70a476040515 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -19,7 +19,6 @@ use rustc_hir::Crate; use rustc_lint::LintStore; use rustc_middle::arena::Arena; use rustc_middle::dep_graph::DepGraph; -use rustc_middle::middle; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt}; use rustc_mir as mir; @@ -186,7 +185,7 @@ pub fn register_plugins<'a>( } sess.time("recursion_limit", || { - middle::limits::update_limits(sess, &krate); + rustc_crate::limits::update_limits(sess, &krate); }); let mut lint_store = rustc_lint::new_lint_store( diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 8e06fba20f433..06b93e64c303c 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -4,7 +4,6 @@ use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; pub mod exported_symbols; pub mod lang_items; -pub mod limits; pub mod privacy; pub mod region; pub mod resolve_lifetime; From a86535c6d1263f714edb61366e6945855f65e54c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:44:29 +0100 Subject: [PATCH 09/15] Move rustc_middle::middle::privacy to rustc_crate. --- Cargo.lock | 2 ++ compiler/rustc_crate/src/lib.rs | 1 + .../{rustc_middle/src/middle => rustc_crate/src}/privacy.rs | 3 +-- compiler/rustc_lint/Cargo.toml | 1 + compiler/rustc_lint/src/context.rs | 2 +- compiler/rustc_middle/src/arena.rs | 2 +- compiler/rustc_middle/src/ich/impls_ty.rs | 4 ++-- compiler/rustc_middle/src/middle/mod.rs | 1 - compiler/rustc_middle/src/ty/query/mod.rs | 2 +- compiler/rustc_passes/src/dead.rs | 2 +- compiler/rustc_passes/src/reachable.rs | 2 +- compiler/rustc_passes/src/stability.rs | 2 +- compiler/rustc_privacy/Cargo.toml | 1 + compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_save_analysis/src/lib.rs | 2 +- src/librustdoc/config.rs | 2 +- src/librustdoc/core.rs | 2 +- src/librustdoc/formats/cache.rs | 2 +- src/librustdoc/passes/stripper.rs | 2 +- src/librustdoc/visit_ast.rs | 2 +- src/librustdoc/visit_lib.rs | 2 +- 21 files changed, 22 insertions(+), 19 deletions(-) rename compiler/{rustc_middle/src/middle => rustc_crate/src}/privacy.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index c2c74063f0756..3963c7cc502d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3857,6 +3857,7 @@ dependencies = [ "rustc_ast", "rustc_ast_pretty", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_feature", @@ -4080,6 +4081,7 @@ name = "rustc_privacy" version = "0.0.0" dependencies = [ "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_hir", diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index 5a141ee507f94..f34e36aaad203 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -14,6 +14,7 @@ pub mod codegen_fn_attrs; pub mod cstore; pub mod dependency_format; pub mod limits; +pub mod privacy; #[derive(HashStable_Generic)] pub struct LibFeatures { diff --git a/compiler/rustc_middle/src/middle/privacy.rs b/compiler/rustc_crate/src/privacy.rs similarity index 98% rename from compiler/rustc_middle/src/middle/privacy.rs rename to compiler/rustc_crate/src/privacy.rs index 254b57a005e8e..059d4e411cd6b 100644 --- a/compiler/rustc_middle/src/middle/privacy.rs +++ b/compiler/rustc_crate/src/privacy.rs @@ -4,12 +4,11 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::HirId; -use rustc_macros::HashStable; use std::fmt; use std::hash::Hash; // Accessibility levels, sorted in ascending order -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, HashStable)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, HashStable_Generic)] pub enum AccessLevel { /// Superset of `AccessLevel::Reachable` used to mark impl Trait items. ReachableFromImplTrait, diff --git a/compiler/rustc_lint/Cargo.toml b/compiler/rustc_lint/Cargo.toml index 760a8e385d680..1cd058bb47a01 100644 --- a/compiler/rustc_lint/Cargo.toml +++ b/compiler/rustc_lint/Cargo.toml @@ -10,6 +10,7 @@ unicode-security = "0.0.5" rustc_middle = { path = "../rustc_middle" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_attr = { path = "../rustc_attr" } +rustc_crate = { path = "../rustc_crate" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } rustc_target = { path = "../rustc_target" } diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 4cfeb0d968b95..603f664b31ae7 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -20,6 +20,7 @@ use crate::levels::LintLevelsBuilder; use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc_ast as ast; use rustc_ast::util::lev_distance::find_best_match_for_name; +use rustc_crate::privacy::AccessLevels; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; use rustc_errors::{add_elided_lifetime_in_path_suggestion, struct_span_err, Applicability}; @@ -28,7 +29,6 @@ use rustc_hir::def::Res; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_middle::lint::LintDiagnosticBuilder; -use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::middle::stability; use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 21f2ba21dee28..7eb44a4d0c3fd 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -75,7 +75,7 @@ macro_rules! arena_types { rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::ty::Ty<'tcx>> >, [few] all_traits: Vec, - [few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels, + [few] privacy_access_levels: rustc_crate::privacy::AccessLevels, [few] foreign_module: rustc_crate::cstore::ForeignModule, [few] foreign_modules: Vec, [] upvars_mentioned: rustc_data_structures::fx::FxIndexMap, diff --git a/compiler/rustc_middle/src/ich/impls_ty.rs b/compiler/rustc_middle/src/ich/impls_ty.rs index 69bb4e23c4c0d..93efe54042ba5 100644 --- a/compiler/rustc_middle/src/ich/impls_ty.rs +++ b/compiler/rustc_middle/src/ich/impls_ty.rs @@ -184,10 +184,10 @@ impl<'a> HashStable> for ty::FloatVid { } } -impl<'a> HashStable> for crate::middle::privacy::AccessLevels { +impl<'a> HashStable> for rustc_crate::privacy::AccessLevels { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - let crate::middle::privacy::AccessLevels { ref map } = *self; + let rustc_crate::privacy::AccessLevels { ref map } = *self; map.hash_stable(hcx, hasher); }); diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 06b93e64c303c..1f78aee344e0e 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -4,7 +4,6 @@ use rustc_span::def_id::{CrateNum, LOCAL_CRATE}; pub mod exported_symbols; pub mod lang_items; -pub mod privacy; pub mod region; pub mod resolve_lifetime; pub mod stability; diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 7d344c68ea406..40f5298240336 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -4,7 +4,6 @@ use crate::hir::map; use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; -use crate::middle::privacy::AccessLevels; use crate::middle::region; use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes}; use crate::middle::stability::{self, DeprecationEntry}; @@ -31,6 +30,7 @@ use rustc_crate::codegen_fn_attrs::CodegenFnAttrs; use rustc_crate::cstore::{ CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, }; +use rustc_crate::privacy::AccessLevels; use rustc_crate::LibFeatures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 218841f28259e..d23a857f5fed7 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -3,6 +3,7 @@ // from live codes are live, and everything else is dead. use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_crate::privacy; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; @@ -11,7 +12,6 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::{Node, PatKind, TyKind}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::privacy; use rustc_middle::ty::{self, DefIdTree, TyCtxt}; use rustc_session::lint; diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 33c5822870484..3ad902d210756 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -6,6 +6,7 @@ // reachable as well. use rustc_crate::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; +use rustc_crate::privacy; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; @@ -14,7 +15,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::Node; -use rustc_middle::middle::privacy; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, DefIdTree, TyCtxt}; use rustc_session::config::CrateType; diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 04b5c65e464fb..5db96c134fb4c 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -3,6 +3,7 @@ use rustc_ast::Attribute; use rustc_attr::{self as attr, ConstStability, Stability}; +use rustc_crate::privacy::AccessLevels; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::struct_span_err; use rustc_hir as hir; @@ -11,7 +12,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Generics, HirId, Item, StructField, TraitRef, Ty, TyKind, Variant}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::middle::stability::{DeprecationEntry, Index}; use rustc_middle::ty::{self, query::Providers, TyCtxt}; use rustc_session::lint; diff --git a/compiler/rustc_privacy/Cargo.toml b/compiler/rustc_privacy/Cargo.toml index ce83dc1de78c7..01634db3d18a9 100644 --- a/compiler/rustc_privacy/Cargo.toml +++ b/compiler/rustc_privacy/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] rustc_middle = { path = "../rustc_middle" } rustc_attr = { path = "../rustc_attr" } +rustc_crate = { path = "../rustc_crate" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } rustc_typeck = { path = "../rustc_typeck" } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 75d75433f1bf1..c4c6adc0fb9c8 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -7,6 +7,7 @@ #![recursion_limit = "256"] use rustc_attr as attr; +use rustc_crate::privacy::{AccessLevel, AccessLevels}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir as hir; @@ -16,7 +17,6 @@ use rustc_hir::intravisit::{self, DeepVisitor, NestedVisitorMap, Visitor}; use rustc_hir::{AssocItemKind, HirIdSet, Node, PatKind}; use rustc_middle::bug; use rustc_middle::hir::map::Map; -use rustc_middle::middle::privacy::{AccessLevel, AccessLevels}; use rustc_middle::span_bug; use rustc_middle::ty::fold::TypeVisitor; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 4bee5437aa001..a3f244830112a 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -13,6 +13,7 @@ use rustc_ast as ast; use rustc_ast::util::comments::beautify_doc_string; use rustc_ast_pretty::pprust::attribute_to_string; use rustc_crate::cstore::ExternCrate; +use rustc_crate::privacy::AccessLevels; use rustc_hir as hir; use rustc_hir::def::{DefKind as HirDefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; @@ -20,7 +21,6 @@ use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::Node; use rustc_hir_pretty::{enum_def_to_string, fn_to_string, ty_to_string}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{self, print::with_no_trimmed_paths, DefIdTree, TyCtxt}; use rustc_middle::{bug, span_bug}; use rustc_session::config::{CrateType, Input, OutputType}; diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index f0fc0dc6514c0..063b0e998c1b9 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -4,9 +4,9 @@ use std::ffi::OsStr; use std::fmt; use std::path::PathBuf; +use rustc_crate::privacy::AccessLevels; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def_id::DefId; -use rustc_middle::middle::privacy::AccessLevels; use rustc_session::config::{self, parse_crate_types_from_list, parse_externs, CrateType}; use rustc_session::config::{ build_codegen_options, build_debugging_options, get_cmd_lint_options, host_triple, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 8edfe086542d1..7e8c68da0f544 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,5 +1,6 @@ use rustc_attr as attr; use rustc_crate::cstore::CrateStore; +use rustc_crate::privacy::AccessLevels; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{self, Lrc}; use rustc_driver::abort_on_err; @@ -15,7 +16,6 @@ use rustc_hir::{ }; use rustc_interface::interface; use rustc_middle::hir::map::Map; -use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_resolve as resolve; use rustc_session::config::{self, CrateType, ErrorOutputType}; diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 277571b11f51b..fd570a05a0d6a 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -4,9 +4,9 @@ use std::mem; use std::path::{Path, PathBuf}; use std::sync::Arc; +use rustc_crate::privacy::AccessLevels; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; -use rustc_middle::middle::privacy::AccessLevels; use rustc_span::source_map::FileName; use crate::clean::{self, GetDefId}; diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4250c2b48fc50..c74c7321f00a0 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -1,5 +1,5 @@ +use rustc_crate::privacy::AccessLevels; use rustc_hir::def_id::{DefId, DefIdSet}; -use rustc_middle::middle::privacy::AccessLevels; use std::mem; use crate::clean::{self, GetDefId, Item}; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index cbfd2199d9fd6..7b1c92ea3f61c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -2,12 +2,12 @@ //! usable for `clean`. use rustc_ast as ast; +use rustc_crate::privacy::AccessLevel; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Node; -use rustc_middle::middle::privacy::AccessLevel; use rustc_middle::ty::TyCtxt; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index ea2f5f8abc701..f6de5da5321ea 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -1,7 +1,7 @@ +use rustc_crate::privacy::{AccessLevel, AccessLevels}; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; -use rustc_middle::middle::privacy::{AccessLevel, AccessLevels}; use rustc_middle::ty::{TyCtxt, Visibility}; use rustc_span::symbol::sym; From 5f1330da459b9ddad3b5ba203ee85a80eb292639 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 03:52:08 +0100 Subject: [PATCH 10/15] Move rustc_middle::middle::stability to rustc_crate. --- compiler/rustc_crate/src/lib.rs | 1 + compiler/rustc_crate/src/stability.rs | 217 ++++++++++++++++++ compiler/rustc_lint/src/context.rs | 2 +- .../src/rmeta/decoder/cstore_impl.rs | 2 +- compiler/rustc_middle/src/middle/stability.rs | 214 +---------------- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/query/mod.rs | 2 +- compiler/rustc_passes/src/stability.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 2 +- src/librustdoc/html/render/mod.rs | 2 +- 10 files changed, 232 insertions(+), 214 deletions(-) create mode 100644 compiler/rustc_crate/src/stability.rs diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index f34e36aaad203..7ebd70aefe656 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -15,6 +15,7 @@ pub mod cstore; pub mod dependency_format; pub mod limits; pub mod privacy; +pub mod stability; #[derive(HashStable_Generic)] pub struct LibFeatures { diff --git a/compiler/rustc_crate/src/stability.rs b/compiler/rustc_crate/src/stability.rs new file mode 100644 index 0000000000000..310da7948af61 --- /dev/null +++ b/compiler/rustc_crate/src/stability.rs @@ -0,0 +1,217 @@ +//! A pass that annotates every item and method with its stability level, +//! propagating default levels lexically from parent to children ast nodes. + +pub use self::StabilityLevel::*; + +use rustc_ast::CRATE_NODE_ID; +use rustc_attr::{self as attr, ConstStability, Deprecation, Stability}; +use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_feature::GateIssue; +use rustc_hir::def_id::CrateNum; +use rustc_hir::{self, HirId}; +use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE}; +use rustc_session::lint::{BuiltinLintDiagnostics, Lint, LintBuffer}; +use rustc_session::parse::feature_err_issue; +use rustc_session::{DiagnosticMessageId, Session}; +use rustc_span::symbol::Symbol; +use rustc_span::{MultiSpan, Span}; + +use std::num::NonZeroU32; + +#[derive(PartialEq, Clone, Copy, Debug)] +pub enum StabilityLevel { + Unstable, + Stable, +} + +impl StabilityLevel { + pub fn from_attr_level(level: &attr::StabilityLevel) -> Self { + if level.is_stable() { Stable } else { Unstable } + } +} + +/// An entry in the `depr_map`. +#[derive(Clone, HashStable_Generic)] +pub struct DeprecationEntry { + /// The metadata of the attribute associated with this entry. + pub attr: Deprecation, + /// The `DefId` where the attr was originally attached. `None` for non-local + /// `DefId`'s. + origin: Option, +} + +impl DeprecationEntry { + pub fn local(attr: Deprecation, id: HirId) -> DeprecationEntry { + DeprecationEntry { attr, origin: Some(id) } + } + + pub fn external(attr: Deprecation) -> DeprecationEntry { + DeprecationEntry { attr, origin: None } + } + + pub fn same_origin(&self, other: &DeprecationEntry) -> bool { + match (self.origin, other.origin) { + (Some(o1), Some(o2)) => o1 == o2, + _ => false, + } + } +} + +/// A stability index, giving the stability level for items and methods. +#[derive(HashStable_Generic)] +pub struct Index<'tcx> { + /// This is mostly a cache, except the stabilities of local items + /// are filled by the annotator. + pub stab_map: FxHashMap, + pub const_stab_map: FxHashMap, + pub depr_map: FxHashMap, + + /// Maps for each crate whether it is part of the staged API. + pub staged_api: FxHashMap, + + /// Features enabled for this crate. + pub active_features: FxHashSet, +} + +impl<'tcx> Index<'tcx> { + pub fn local_stability(&self, id: HirId) -> Option<&'tcx Stability> { + self.stab_map.get(&id).cloned() + } + + pub fn local_const_stability(&self, id: HirId) -> Option<&'tcx ConstStability> { + self.const_stab_map.get(&id).cloned() + } + + pub fn local_deprecation_entry(&self, id: HirId) -> Option { + self.depr_map.get(&id).cloned() + } +} + +pub fn report_unstable( + sess: &Session, + feature: Symbol, + reason: Option, + issue: Option, + is_soft: bool, + span: Span, + soft_handler: impl FnOnce(&'static Lint, Span, &str), +) { + let msg = match reason { + Some(r) => format!("use of unstable library feature '{}': {}", feature, r), + None => format!("use of unstable library feature '{}'", &feature), + }; + + let msp: MultiSpan = span.into(); + let sm = &sess.parse_sess.source_map(); + let span_key = msp.primary_span().and_then(|sp: Span| { + if !sp.is_dummy() { + let file = sm.lookup_char_pos(sp.lo()).file; + if file.is_imported() { None } else { Some(span) } + } else { + None + } + }); + + let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone()); + let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id); + if fresh { + if is_soft { + soft_handler(SOFT_UNSTABLE, span, &msg) + } else { + feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg) + .emit(); + } + } +} + +/// Checks whether an item marked with `deprecated(since="X")` is currently +/// deprecated (i.e., whether X is not greater than the current rustc version). +pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>) -> bool { + let since = if let Some(since) = since { + if is_since_rustc_version { + since + } else { + // We assume that the deprecation is in effect if it's not a + // rustc version. + return true; + } + } else { + // If since attribute is not set, then we're definitely in effect. + return true; + }; + fn parse_version(ver: &str) -> Vec { + // We ignore non-integer components of the version (e.g., "nightly"). + ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect() + } + + if let Some(rustc) = option_env!("CFG_RELEASE") { + let since: Vec = parse_version(&since); + let rustc: Vec = parse_version(rustc); + // We simply treat invalid `since` attributes as relating to a previous + // Rust version, thus always displaying the warning. + if since.len() != 3 { + return true; + } + since <= rustc + } else { + // By default, a deprecation warning applies to + // the current version of the compiler. + true + } +} + +pub fn deprecation_suggestion( + diag: &mut DiagnosticBuilder<'_>, + kind: &str, + suggestion: Option, + span: Span, +) { + if let Some(suggestion) = suggestion { + diag.span_suggestion( + span, + &format!("replace the use of the deprecated {}", kind), + suggestion.to_string(), + Applicability::MachineApplicable, + ); + } +} + +pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) { + let (message, lint) = if deprecation_in_effect( + depr.is_since_rustc_version, + depr.since.map(Symbol::as_str).as_deref(), + ) { + (format!("use of deprecated {} `{}`", kind, path), DEPRECATED) + } else { + ( + format!( + "use of {} `{}` that will be deprecated in future version {}", + kind, + path, + depr.since.unwrap() + ), + DEPRECATED_IN_FUTURE, + ) + }; + let message = match depr.note { + Some(reason) => format!("{}: {}", message, reason), + None => message, + }; + (message, lint) +} + +pub fn early_report_deprecation<'a>( + lint_buffer: &'a mut LintBuffer, + message: &str, + suggestion: Option, + lint: &'static Lint, + span: Span, +) { + if span.in_derive_expansion() { + return; + } + + let diag = BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span); + lint_buffer.buffer_lint_with_diagnostic(lint, CRATE_NODE_ID, span, message, diag); +} diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 603f664b31ae7..2214a3598b9bb 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -21,6 +21,7 @@ use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc_ast as ast; use rustc_ast::util::lev_distance::find_best_match_for_name; use rustc_crate::privacy::AccessLevels; +use rustc_crate::stability; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync; use rustc_errors::{add_elided_lifetime_in_path_suggestion, struct_span_err, Applicability}; @@ -29,7 +30,6 @@ use rustc_hir::def::Res; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; use rustc_middle::lint::LintDiagnosticBuilder; -use rustc_middle::middle::stability; use rustc_middle::ty::layout::{LayoutError, TyAndLayout}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt}; diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 6a1b8373a9ef9..79623c0e8895b 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -7,6 +7,7 @@ use crate::rmeta; use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_crate::cstore::{CrateSource, CrateStore, ForeignModule}; +use rustc_crate::stability::DeprecationEntry; use rustc_data_structures::stable_map::FxHashMap; use rustc_data_structures::svh::Svh; use rustc_hir as hir; @@ -15,7 +16,6 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE} use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_middle::hir::exports::Export; use rustc_middle::middle::exported_symbols::ExportedSymbol; -use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::utils::NativeLibKind; diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index 978f08927c6ef..535419ee0d0c2 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -4,221 +4,21 @@ pub use self::StabilityLevel::*; use crate::ty::{self, TyCtxt}; -use rustc_ast::CRATE_NODE_ID; -use rustc_attr::{self as attr, ConstStability, Deprecation, Stability}; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{Applicability, DiagnosticBuilder}; -use rustc_feature::GateIssue; +use rustc_attr::{self as attr, Deprecation, Stability}; use rustc_hir as hir; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX}; use rustc_hir::{self, HirId}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE}; -use rustc_session::lint::{BuiltinLintDiagnostics, Lint, LintBuffer}; -use rustc_session::parse::feature_err_issue; -use rustc_session::{DiagnosticMessageId, Session}; +use rustc_session::lint::Lint; use rustc_span::symbol::{sym, Symbol}; -use rustc_span::{MultiSpan, Span}; +use rustc_span::Span; use std::num::NonZeroU32; -#[derive(PartialEq, Clone, Copy, Debug)] -pub enum StabilityLevel { - Unstable, - Stable, -} - -impl StabilityLevel { - pub fn from_attr_level(level: &attr::StabilityLevel) -> Self { - if level.is_stable() { Stable } else { Unstable } - } -} - -/// An entry in the `depr_map`. -#[derive(Clone, HashStable)] -pub struct DeprecationEntry { - /// The metadata of the attribute associated with this entry. - pub attr: Deprecation, - /// The `DefId` where the attr was originally attached. `None` for non-local - /// `DefId`'s. - origin: Option, -} - -impl DeprecationEntry { - pub fn local(attr: Deprecation, id: HirId) -> DeprecationEntry { - DeprecationEntry { attr, origin: Some(id) } - } - - pub fn external(attr: Deprecation) -> DeprecationEntry { - DeprecationEntry { attr, origin: None } - } - - pub fn same_origin(&self, other: &DeprecationEntry) -> bool { - match (self.origin, other.origin) { - (Some(o1), Some(o2)) => o1 == o2, - _ => false, - } - } -} - -/// A stability index, giving the stability level for items and methods. -#[derive(HashStable)] -pub struct Index<'tcx> { - /// This is mostly a cache, except the stabilities of local items - /// are filled by the annotator. - pub stab_map: FxHashMap, - pub const_stab_map: FxHashMap, - pub depr_map: FxHashMap, - - /// Maps for each crate whether it is part of the staged API. - pub staged_api: FxHashMap, - - /// Features enabled for this crate. - pub active_features: FxHashSet, -} - -impl<'tcx> Index<'tcx> { - pub fn local_stability(&self, id: HirId) -> Option<&'tcx Stability> { - self.stab_map.get(&id).cloned() - } - - pub fn local_const_stability(&self, id: HirId) -> Option<&'tcx ConstStability> { - self.const_stab_map.get(&id).cloned() - } - - pub fn local_deprecation_entry(&self, id: HirId) -> Option { - self.depr_map.get(&id).cloned() - } -} - -pub fn report_unstable( - sess: &Session, - feature: Symbol, - reason: Option, - issue: Option, - is_soft: bool, - span: Span, - soft_handler: impl FnOnce(&'static Lint, Span, &str), -) { - let msg = match reason { - Some(r) => format!("use of unstable library feature '{}': {}", feature, r), - None => format!("use of unstable library feature '{}'", &feature), - }; - - let msp: MultiSpan = span.into(); - let sm = &sess.parse_sess.source_map(); - let span_key = msp.primary_span().and_then(|sp: Span| { - if !sp.is_dummy() { - let file = sm.lookup_char_pos(sp.lo()).file; - if file.is_imported() { None } else { Some(span) } - } else { - None - } - }); - - let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone()); - let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id); - if fresh { - if is_soft { - soft_handler(SOFT_UNSTABLE, span, &msg) - } else { - feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg) - .emit(); - } - } -} - -/// Checks whether an item marked with `deprecated(since="X")` is currently -/// deprecated (i.e., whether X is not greater than the current rustc version). -pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>) -> bool { - let since = if let Some(since) = since { - if is_since_rustc_version { - since - } else { - // We assume that the deprecation is in effect if it's not a - // rustc version. - return true; - } - } else { - // If since attribute is not set, then we're definitely in effect. - return true; - }; - fn parse_version(ver: &str) -> Vec { - // We ignore non-integer components of the version (e.g., "nightly"). - ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect() - } - - if let Some(rustc) = option_env!("CFG_RELEASE") { - let since: Vec = parse_version(&since); - let rustc: Vec = parse_version(rustc); - // We simply treat invalid `since` attributes as relating to a previous - // Rust version, thus always displaying the warning. - if since.len() != 3 { - return true; - } - since <= rustc - } else { - // By default, a deprecation warning applies to - // the current version of the compiler. - true - } -} - -pub fn deprecation_suggestion( - diag: &mut DiagnosticBuilder<'_>, - kind: &str, - suggestion: Option, - span: Span, -) { - if let Some(suggestion) = suggestion { - diag.span_suggestion( - span, - &format!("replace the use of the deprecated {}", kind), - suggestion.to_string(), - Applicability::MachineApplicable, - ); - } -} - -pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) { - let (message, lint) = if deprecation_in_effect( - depr.is_since_rustc_version, - depr.since.map(Symbol::as_str).as_deref(), - ) { - (format!("use of deprecated {} `{}`", kind, path), DEPRECATED) - } else { - ( - format!( - "use of {} `{}` that will be deprecated in future version {}", - kind, - path, - depr.since.unwrap() - ), - DEPRECATED_IN_FUTURE, - ) - }; - let message = match depr.note { - Some(reason) => format!("{}: {}", message, reason), - None => message, - }; - (message, lint) -} - -pub fn early_report_deprecation( - lint_buffer: &'a mut LintBuffer, - message: &str, - suggestion: Option, - lint: &'static Lint, - span: Span, -) { - if span.in_derive_expansion() { - return; - } - - let diag = BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span); - lint_buffer.buffer_lint_with_diagnostic(lint, CRATE_NODE_ID, span, message, diag); -} +use rustc_crate::stability::{ + deprecation_message, deprecation_suggestion, report_unstable, StabilityLevel, +}; fn late_report_deprecation( tcx: TyCtxt<'_>, diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index bc88b5febee89..05944b4b91024 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -7,7 +7,6 @@ use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource}; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; -use crate::middle::stability; use crate::mir::interpret::{self, Allocation, ConstValue, Scalar}; use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted}; use crate::traits; @@ -25,6 +24,7 @@ use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_attr as attr; use rustc_crate::cstore::{CrateStoreDyn, EncodedMetadata}; +use rustc_crate::stability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index 40f5298240336..210469aa8651a 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -6,7 +6,6 @@ use crate::lint::LintLevelMap; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use crate::middle::region; use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes}; -use crate::middle::stability::{self, DeprecationEntry}; use crate::mir; use crate::mir::interpret::GlobalId; use crate::mir::interpret::{ConstValue, EvalToAllocationRawResult, EvalToConstValueResult}; @@ -31,6 +30,7 @@ use rustc_crate::cstore::{ CrateDepKind, CrateSource, ExternCrate, ForeignModule, LinkagePreference, NativeLib, }; use rustc_crate::privacy::AccessLevels; +use rustc_crate::stability::{self, DeprecationEntry}; use rustc_crate::LibFeatures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 5db96c134fb4c..ab1c656820759 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -4,6 +4,7 @@ use rustc_ast::Attribute; use rustc_attr::{self as attr, ConstStability, Stability}; use rustc_crate::privacy::AccessLevels; +use rustc_crate::stability::{DeprecationEntry, Index}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::struct_span_err; use rustc_hir as hir; @@ -12,7 +13,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::{Generics, HirId, Item, StructField, TraitRef, Ty, TyKind, Variant}; use rustc_middle::hir::map::Map; -use rustc_middle::middle::stability::{DeprecationEntry, Index}; use rustc_middle::ty::{self, query::Providers, TyCtxt}; use rustc_session::lint; use rustc_session::lint::builtin::{INEFFECTIVE_UNSTABLE_TRAIT_IMPL, USELESS_DEPRECATED}; diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index e052b6b334529..10d23c8b302fb 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -10,6 +10,7 @@ use rustc_ast::{self as ast, NodeId}; use rustc_ast_lowering::ResolverAstLowering; use rustc_ast_pretty::pprust; use rustc_attr::StabilityLevel; +use rustc_crate::stability; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::ptr_key::PtrKey; use rustc_errors::struct_span_err; @@ -19,7 +20,6 @@ use rustc_expand::expand::{AstFragment, AstFragmentKind, Invocation, InvocationK use rustc_feature::is_builtin_attr_name; use rustc_hir::def::{self, DefKind, NonMacroAttrKind}; use rustc_hir::def_id; -use rustc_middle::middle::stability; use rustc_middle::ty; use rustc_session::lint::builtin::UNUSED_MACROS; use rustc_session::Session; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index eebb07f0476c0..5ac099c7175bd 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -50,12 +50,12 @@ use std::sync::Arc; use itertools::Itertools; use rustc_ast_pretty::pprust; use rustc_attr::StabilityLevel; +use rustc_crate::stability; use rustc_data_structures::flock; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Mutability; -use rustc_middle::middle::stability; use rustc_span::edition::Edition; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::FileName; From 44fc785515fed9f752d4c1031950067c363c7e60 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 16:35:31 +0100 Subject: [PATCH 11/15] Move ICH to rustc_crate. --- .../src/ich/hcx.rs | 56 +++------------- .../src/ich/impls_hir.rs | 0 .../src/ich/impls_syntax.rs | 0 compiler/rustc_crate/src/ich/mod.rs | 19 ++++++ compiler/rustc_crate/src/lib.rs | 3 + compiler/rustc_middle/src/ich/impls_ty.rs | 12 +--- compiler/rustc_middle/src/ich/mod.rs | 65 ++++++++++++++----- 7 files changed, 81 insertions(+), 74 deletions(-) rename compiler/{rustc_middle => rustc_crate}/src/ich/hcx.rs (82%) rename compiler/{rustc_middle => rustc_crate}/src/ich/impls_hir.rs (100%) rename compiler/{rustc_middle => rustc_crate}/src/ich/impls_syntax.rs (100%) create mode 100644 compiler/rustc_crate/src/ich/mod.rs diff --git a/compiler/rustc_middle/src/ich/hcx.rs b/compiler/rustc_crate/src/ich/hcx.rs similarity index 82% rename from compiler/rustc_middle/src/ich/hcx.rs rename to compiler/rustc_crate/src/ich/hcx.rs index b067cc253fd4f..12d824219c254 100644 --- a/compiler/rustc_middle/src/ich/hcx.rs +++ b/compiler/rustc_crate/src/ich/hcx.rs @@ -1,23 +1,19 @@ +use crate::cstore::CrateStore; use crate::ich; -use crate::ty::{fast_reject, TyCtxt}; -use rustc_crate::cstore::CrateStore; use rustc_ast as ast; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_hir as hir; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::definitions::{DefPathHash, Definitions}; use rustc_session::Session; +use rustc_span::def_id::{CrateNum, CRATE_DEF_INDEX}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::Symbol; use rustc_span::{BytePos, CachingSourceMapView, SourceFile}; -use rustc_span::def_id::{CrateNum, CRATE_DEF_INDEX}; -use smallvec::SmallVec; -use std::cmp::Ord; - fn compute_ignored_attr_names() -> FxHashSet { debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty()); ich::IGNORED_ATTRIBUTES.iter().copied().collect() @@ -207,12 +203,6 @@ impl<'a, 'b, T: StableHashingContextProvider<'a>> StableHashingContextProvider<' } } -impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> { - fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> { - (*self).create_stable_hashing_context() - } -} - impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> { fn get_stable_hashing_context(&self) -> StableHashingContext<'a> { self.clone() @@ -255,40 +245,14 @@ impl<'a> rustc_span::HashStableContext for StableHashingContext<'a> { } } -impl<'a> rustc_crate::HashStableContext for StableHashingContext<'a> {} +impl<'a> crate::HashStableContext for StableHashingContext<'a> {} -pub fn hash_stable_trait_impls<'a>( - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - blanket_impls: &[DefId], - non_blanket_impls: &FxHashMap>, -) { - { - let mut blanket_impls: SmallVec<[_; 8]> = - blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect(); +impl<'a> HashStable> for crate::privacy::AccessLevels { + fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { + hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { + let crate::privacy::AccessLevels { ref map } = *self; - if blanket_impls.len() > 1 { - blanket_impls.sort_unstable(); - } - - blanket_impls.hash_stable(hcx, hasher); - } - - { - let mut keys: SmallVec<[_; 8]> = - non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect(); - keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2)); - keys.len().hash_stable(hcx, hasher); - for (key, ref stable_key) in keys { - stable_key.hash_stable(hcx, hasher); - let mut impls: SmallVec<[_; 8]> = - non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect(); - - if impls.len() > 1 { - impls.sort_unstable(); - } - - impls.hash_stable(hcx, hasher); - } + map.hash_stable(hcx, hasher); + }); } } diff --git a/compiler/rustc_middle/src/ich/impls_hir.rs b/compiler/rustc_crate/src/ich/impls_hir.rs similarity index 100% rename from compiler/rustc_middle/src/ich/impls_hir.rs rename to compiler/rustc_crate/src/ich/impls_hir.rs diff --git a/compiler/rustc_middle/src/ich/impls_syntax.rs b/compiler/rustc_crate/src/ich/impls_syntax.rs similarity index 100% rename from compiler/rustc_middle/src/ich/impls_syntax.rs rename to compiler/rustc_crate/src/ich/impls_syntax.rs diff --git a/compiler/rustc_crate/src/ich/mod.rs b/compiler/rustc_crate/src/ich/mod.rs new file mode 100644 index 0000000000000..f847cc6677a1e --- /dev/null +++ b/compiler/rustc_crate/src/ich/mod.rs @@ -0,0 +1,19 @@ +//! ICH - Incremental Compilation Hash + +pub use self::hcx::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider}; +use rustc_span::symbol::{sym, Symbol}; + +mod hcx; +mod impls_hir; +mod impls_syntax; + +pub const IGNORED_ATTRIBUTES: &[Symbol] = &[ + sym::cfg, + sym::rustc_if_this_changed, + sym::rustc_then_this_would_need, + sym::rustc_dirty, + sym::rustc_clean, + sym::rustc_partition_reused, + sym::rustc_partition_codegened, + sym::rustc_expected_cgu_reuse, +]; diff --git a/compiler/rustc_crate/src/lib.rs b/compiler/rustc_crate/src/lib.rs index 7ebd70aefe656..feccb4146b199 100644 --- a/compiler/rustc_crate/src/lib.rs +++ b/compiler/rustc_crate/src/lib.rs @@ -1,5 +1,7 @@ #![feature(int_error_matching)] +#![feature(min_specialization)] #![feature(once_cell)] +#![feature(option_expect_none)] #![feature(or_patterns)] #[macro_use] @@ -13,6 +15,7 @@ use rustc_span::symbol::Symbol; pub mod codegen_fn_attrs; pub mod cstore; pub mod dependency_format; +pub mod ich; pub mod limits; pub mod privacy; pub mod stability; diff --git a/compiler/rustc_middle/src/ich/impls_ty.rs b/compiler/rustc_middle/src/ich/impls_ty.rs index 93efe54042ba5..fd5a9cb1b3bca 100644 --- a/compiler/rustc_middle/src/ich/impls_ty.rs +++ b/compiler/rustc_middle/src/ich/impls_ty.rs @@ -1,7 +1,7 @@ //! This module contains `HashStable` implementations for various data types //! from `rustc_middle::ty` in no particular order. -use crate::ich::{NodeIdHashingMode, StableHashingContext}; +use crate::ich::StableHashingContext; use crate::middle::region; use crate::mir; use crate::ty; @@ -183,13 +183,3 @@ impl<'a> HashStable> for ty::FloatVid { bug!("ty::TyKind::hash_stable() - can't hash a FloatVid {:?}.", *self) } } - -impl<'a> HashStable> for rustc_crate::privacy::AccessLevels { - fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { - hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - let rustc_crate::privacy::AccessLevels { ref map } = *self; - - map.hash_stable(hcx, hasher); - }); - } -} diff --git a/compiler/rustc_middle/src/ich/mod.rs b/compiler/rustc_middle/src/ich/mod.rs index c8fb2bf39cc80..dc9e53393d933 100644 --- a/compiler/rustc_middle/src/ich/mod.rs +++ b/compiler/rustc_middle/src/ich/mod.rs @@ -1,23 +1,54 @@ //! ICH - Incremental Compilation Hash -pub use self::hcx::{ - hash_stable_trait_impls, NodeIdHashingMode, StableHashingContext, StableHashingContextProvider, -}; -use rustc_span::symbol::{sym, Symbol}; +use crate::ty::{fast_reject, TyCtxt}; +use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; +use rustc_hir::def_id::DefId; +use smallvec::SmallVec; +use std::cmp::Ord; -mod hcx; +pub use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider}; -mod impls_hir; -mod impls_syntax; mod impls_ty; -pub const IGNORED_ATTRIBUTES: &[Symbol] = &[ - sym::cfg, - sym::rustc_if_this_changed, - sym::rustc_then_this_would_need, - sym::rustc_dirty, - sym::rustc_clean, - sym::rustc_partition_reused, - sym::rustc_partition_codegened, - sym::rustc_expected_cgu_reuse, -]; +impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> { + fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> { + (*self).create_stable_hashing_context() + } +} + +pub fn hash_stable_trait_impls<'a>( + hcx: &mut StableHashingContext<'a>, + hasher: &mut StableHasher, + blanket_impls: &[DefId], + non_blanket_impls: &FxHashMap>, +) { + { + let mut blanket_impls: SmallVec<[_; 8]> = + blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect(); + + if blanket_impls.len() > 1 { + blanket_impls.sort_unstable(); + } + + blanket_impls.hash_stable(hcx, hasher); + } + + { + let mut keys: SmallVec<[_; 8]> = + non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect(); + keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2)); + keys.len().hash_stable(hcx, hasher); + for (key, ref stable_key) in keys { + stable_key.hash_stable(hcx, hasher); + let mut impls: SmallVec<[_; 8]> = + non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect(); + + if impls.len() > 1 { + impls.sort_unstable(); + } + + impls.hash_stable(hcx, hasher); + } + } +} From 886c0737480d7b24a4c8979ba197c7d05cbf925f Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 16:48:54 +0100 Subject: [PATCH 12/15] Remove re-export. --- Cargo.lock | 1 + compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs | 2 +- compiler/rustc_macros/src/hash_stable.rs | 4 ++-- compiler/rustc_middle/src/dep_graph/mod.rs | 2 +- compiler/rustc_middle/src/hir/map/collector.rs | 2 +- compiler/rustc_middle/src/hir/mod.rs | 2 +- compiler/rustc_middle/src/ich/impls_ty.rs | 2 +- compiler/rustc_middle/src/ich/mod.rs | 3 +-- compiler/rustc_middle/src/lint.rs | 2 +- compiler/rustc_middle/src/middle/region.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/mir/mono.rs | 2 +- compiler/rustc_middle/src/traits/query.rs | 2 +- compiler/rustc_middle/src/traits/specialization_graph.rs | 3 ++- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/fast_reject.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/query/plumbing.rs | 7 ++----- compiler/rustc_middle/src/ty/trait_def.rs | 3 ++- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_mir/src/interpret/eval_context.rs | 2 +- compiler/rustc_mir/src/transform/coverage/mod.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_trait_selection/Cargo.toml | 1 + src/tools/clippy/clippy_lints/src/lib.rs | 1 + src/tools/clippy/clippy_lints/src/utils/hir_utils.rs | 2 +- 27 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3963c7cc502d8..a31b01c6b1adc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4247,6 +4247,7 @@ version = "0.0.0" dependencies = [ "rustc_ast", "rustc_attr", + "rustc_crate", "rustc_data_structures", "rustc_errors", "rustc_hir", diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 27b81ebcff676..3446500110b19 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -20,6 +20,7 @@ use crate::value::Value; use rustc_ast as ast; use rustc_codegen_ssa::traits::*; +use rustc_crate::ich::NodeIdHashingMode; use rustc_data_structures::const_cstr; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; @@ -28,7 +29,6 @@ use rustc_fs_util::path_to_c_string; use rustc_hir::def::CtorKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_index::vec::{Idx, IndexVec}; -use rustc_middle::ich::NodeIdHashingMode; use rustc_middle::mir::{self, Field, GeneratorLayout}; use rustc_middle::ty::layout::{self, IntegerExt, PrimitiveExt, TyAndLayout}; use rustc_middle::ty::subst::GenericArgKind; diff --git a/compiler/rustc_macros/src/hash_stable.rs b/compiler/rustc_macros/src/hash_stable.rs index c955c13778276..df6510d2a40d6 100644 --- a/compiler/rustc_macros/src/hash_stable.rs +++ b/compiler/rustc_macros/src/hash_stable.rs @@ -115,13 +115,13 @@ pub fn hash_stable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::To s.bound_impl( quote!( ::rustc_data_structures::stable_hasher::HashStable< - ::rustc_middle::ich::StableHashingContext<'__ctx>, + ::rustc_crate::ich::StableHashingContext<'__ctx>, > ), quote! { fn hash_stable( &self, - __hcx: &mut ::rustc_middle::ich::StableHashingContext<'__ctx>, + __hcx: &mut ::rustc_crate::ich::StableHashingContext<'__ctx>, __hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher) { #discriminant match *self { #body } diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index 6697524279874..a4eec3e02e972 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -1,6 +1,6 @@ -use crate::ich::StableHashingContext; use crate::ty::query::try_load_from_on_disk_cache; use crate::ty::{self, TyCtxt}; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sync::Lock; use rustc_data_structures::thin_vec::ThinVec; diff --git a/compiler/rustc_middle/src/hir/map/collector.rs b/compiler/rustc_middle/src/hir/map/collector.rs index 5601d89a07b1a..8fec7d3ab1d22 100644 --- a/compiler/rustc_middle/src/hir/map/collector.rs +++ b/compiler/rustc_middle/src/hir/map/collector.rs @@ -1,8 +1,8 @@ use crate::arena::Arena; use crate::hir::map::{Entry, HirOwnerData, Map}; use crate::hir::{Owner, OwnerNodes, ParentedNode}; -use crate::ich::StableHashingContext; use rustc_crate::cstore::CrateStore; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index ae3b30217cc4a..141cec737ac2a 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -6,9 +6,9 @@ pub mod exports; pub mod map; pub mod place; -use crate::ich::StableHashingContext; use crate::ty::query::Providers; use crate::ty::TyCtxt; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; diff --git a/compiler/rustc_middle/src/ich/impls_ty.rs b/compiler/rustc_middle/src/ich/impls_ty.rs index fd5a9cb1b3bca..a485047bca5c4 100644 --- a/compiler/rustc_middle/src/ich/impls_ty.rs +++ b/compiler/rustc_middle/src/ich/impls_ty.rs @@ -1,10 +1,10 @@ //! This module contains `HashStable` implementations for various data types //! from `rustc_middle::ty` in no particular order. -use crate::ich::StableHashingContext; use crate::middle::region; use crate::mir; use crate::ty; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; diff --git a/compiler/rustc_middle/src/ich/mod.rs b/compiler/rustc_middle/src/ich/mod.rs index dc9e53393d933..c9827675753a5 100644 --- a/compiler/rustc_middle/src/ich/mod.rs +++ b/compiler/rustc_middle/src/ich/mod.rs @@ -1,14 +1,13 @@ //! ICH - Incremental Compilation Hash use crate::ty::{fast_reject, TyCtxt}; +use rustc_crate::ich::{StableHashingContext, StableHashingContextProvider}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::DefId; use smallvec::SmallVec; use std::cmp::Ord; -pub use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider}; - mod impls_ty; impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> { diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index a61d37cc90eba..2dafa4b20d710 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -1,6 +1,6 @@ use std::cmp; -use crate::ich::StableHashingContext; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::{DiagnosticBuilder, DiagnosticId}; diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index d060549ca8137..c50ff34aadcb5 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -6,8 +6,8 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html -use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::ty::TyCtxt; +use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext}; use rustc_hir as hir; use rustc_hir::Node; diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 5fe7b0f647dcd..47c42adc68892 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -745,7 +745,7 @@ pub enum ImplicitSelfKind { CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, } mod binding_form_impl { - use crate::ich::StableHashingContext; + use rustc_crate::ich::StableHashingContext; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; impl<'a, 'tcx> HashStable> for super::BindingForm<'tcx> { diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index d346b5f1d1ca7..b1d0d13ecc85d 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -1,8 +1,8 @@ use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId}; -use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt}; use rustc_attr::InlineAttr; use rustc_crate::codegen_fn_attrs::{Linkage, Visibility}; +use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext}; use rustc_data_structures::base_n; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs index f9cadb3bb2dbc..a300480145c2e 100644 --- a/compiler/rustc_middle/src/traits/query.rs +++ b/compiler/rustc_middle/src/traits/query.rs @@ -5,12 +5,12 @@ //! The providers for the queries defined here can be found in //! `librustc_traits`. -use crate::ich::StableHashingContext; use crate::infer::canonical::{Canonical, QueryResponse}; use crate::ty::error::TypeError; use crate::ty::subst::GenericArg; use crate::ty::{self, Ty, TyCtxt}; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::Lrc; use rustc_errors::struct_span_err; diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index ec6010e6eecf4..60e9a70ea415d 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -1,7 +1,8 @@ -use crate::ich::{self, StableHashingContext}; +use crate::ich; use crate::ty::fast_reject::SimplifiedType; use crate::ty::fold::TypeFoldable; use crate::ty::{self, TyCtxt}; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::ErrorReported; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 05944b4b91024..562ff2d9bb930 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -3,7 +3,6 @@ use crate::arena::Arena; use crate::dep_graph::{self, DepConstructor, DepGraph}; use crate::hir::exports::ExportMap; -use crate::ich::{NodeIdHashingMode, StableHashingContext}; use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos}; use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintSource}; use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; @@ -24,6 +23,7 @@ use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_attr as attr; use rustc_crate::cstore::{CrateStoreDyn, EncodedMetadata}; +use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext}; use rustc_crate::stability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 860f91db2bf7a..4cea621b9ec1c 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -1,6 +1,6 @@ -use crate::ich::StableHashingContext; use crate::ty::{self, Ty, TyCtxt}; use rustc_ast as ast; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::DefId; use std::fmt::Debug; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index fbaf7687d442d..be56d0aa8cdf7 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1,8 +1,8 @@ -use crate::ich::StableHashingContext; use crate::mir::{GeneratorLayout, GeneratorSavedLocal}; use crate::ty::subst::Subst; use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable}; use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_crate::ich::StableHashingContext; use rustc_ast::{self as ast, IntTy, UintTy}; use rustc_attr as attr; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index b982d9507b382..4df917ebfacd5 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -6,7 +6,6 @@ pub use self::IntVarValue::*; pub use self::Variance::*; use crate::hir::exports::ExportMap; -use crate::ich::StableHashingContext; use crate::middle::resolve_lifetime::ObjectLifetimeDefault; use crate::mir::interpret::ErrorHandled; use crate::mir::Body; @@ -18,6 +17,7 @@ use crate::ty::util::{Discr, IntTypeExt}; use rustc_ast as ast; use rustc_attr as attr; use rustc_crate::cstore::CrateStoreDyn; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::captures::Captures; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; diff --git a/compiler/rustc_middle/src/ty/query/plumbing.rs b/compiler/rustc_middle/src/ty/query/plumbing.rs index d038695283c10..80043e2ebdd0b 100644 --- a/compiler/rustc_middle/src/ty/query/plumbing.rs +++ b/compiler/rustc_middle/src/ty/query/plumbing.rs @@ -253,11 +253,8 @@ macro_rules! define_queries { [$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => { use std::mem; - use crate::{ - rustc_data_structures::stable_hasher::HashStable, - rustc_data_structures::stable_hasher::StableHasher, - ich::StableHashingContext - }; + use rustc_crate::ich::StableHashingContext; + use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; define_queries_struct! { tcx: $tcx, diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 86476dffc0312..4a56597560c17 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -1,8 +1,9 @@ -use crate::ich::{self, StableHashingContext}; +use crate::ich; use crate::traits::specialization_graph; use crate::ty::fast_reject; use crate::ty::fold::TypeFoldable; use crate::ty::{Ty, TyCtxt}; +use rustc_crate::ich::StableHashingContext; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId}; use rustc_hir::definitions::DefPathHash; diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 29c6953d5ea93..c66dd5b148d96 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -1,6 +1,5 @@ //! Miscellaneous type-system utilities that are too small to deserve their own modules. -use crate::ich::NodeIdHashingMode; use crate::ty::fold::TypeFolder; use crate::ty::layout::IntegerExt; use crate::ty::query::TyCtxtAt; @@ -11,6 +10,7 @@ use rustc_apfloat::Float as _; use rustc_ast as ast; use rustc_attr::{self as attr, SignedInt, UnsignedInt}; use rustc_crate::codegen_fn_attrs::CodegenFnAttrFlags; +use rustc_crate::ich::NodeIdHashingMode; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_errors::ErrorReported; diff --git a/compiler/rustc_mir/src/interpret/eval_context.rs b/compiler/rustc_mir/src/interpret/eval_context.rs index 0f86a181a55f7..15c19c4a4a788 100644 --- a/compiler/rustc_mir/src/interpret/eval_context.rs +++ b/compiler/rustc_mir/src/interpret/eval_context.rs @@ -2,12 +2,12 @@ use std::cell::Cell; use std::fmt; use std::mem; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::{self as hir, def::DefKind, def_id::DefId, definitions::DefPathData}; use rustc_index::vec::IndexVec; use rustc_macros::HashStable; -use rustc_middle::ich::StableHashingContext; use rustc_middle::mir; use rustc_middle::mir::interpret::{GlobalId, InterpResult, Pointer, Scalar}; use rustc_middle::ty::layout::{self, TyAndLayout}; diff --git a/compiler/rustc_mir/src/transform/coverage/mod.rs b/compiler/rustc_mir/src/transform/coverage/mod.rs index 192bb6680e420..5db98280c9cb7 100644 --- a/compiler/rustc_mir/src/transform/coverage/mod.rs +++ b/compiler/rustc_mir/src/transform/coverage/mod.rs @@ -15,6 +15,7 @@ use spans::{CoverageSpan, CoverageSpans}; use crate::transform::MirPass; use crate::util::pretty; +use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::graph::WithNumNodes; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -22,7 +23,6 @@ use rustc_data_structures::sync::Lrc; use rustc_index::vec::IndexVec; use rustc_middle::hir; use rustc_middle::hir::map::blocks::FnLikeNode; -use rustc_middle::ich::StableHashingContext; use rustc_middle::mir::coverage::*; use rustc_middle::mir::{ self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator, diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index ac91fcf62937a..fa1d178dab61d 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -1,7 +1,7 @@ +use rustc_crate::ich::NodeIdHashingMode; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::CrateNum; use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData}; -use rustc_middle::ich::NodeIdHashingMode; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::print::{PrettyPrinter, Print, Printer}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; diff --git a/compiler/rustc_trait_selection/Cargo.toml b/compiler/rustc_trait_selection/Cargo.toml index a72c172918bb0..2ddde258f2af1 100644 --- a/compiler/rustc_trait_selection/Cargo.toml +++ b/compiler/rustc_trait_selection/Cargo.toml @@ -13,6 +13,7 @@ tracing = "0.1" rustc_attr = { path = "../rustc_attr" } rustc_middle = { path = "../rustc_middle" } rustc_ast = { path = "../rustc_ast" } +rustc_crate = { path = "../rustc_crate" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } diff --git a/src/tools/clippy/clippy_lints/src/lib.rs b/src/tools/clippy/clippy_lints/src/lib.rs index 126852df502eb..b1c9d5ea9e3d3 100644 --- a/src/tools/clippy/clippy_lints/src/lib.rs +++ b/src/tools/clippy/clippy_lints/src/lib.rs @@ -26,6 +26,7 @@ extern crate rustc_ast; extern crate rustc_ast_pretty; extern crate rustc_attr; +extern crate rustc_crate; extern crate rustc_data_structures; extern crate rustc_errors; extern crate rustc_hir; diff --git a/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs b/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs index e4ad105c3513e..78cc6d2480be0 100644 --- a/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs +++ b/src/tools/clippy/clippy_lints/src/utils/hir_utils.rs @@ -1,6 +1,7 @@ use crate::consts::{constant_context, constant_simple}; use crate::utils::differing_macro_contexts; use rustc_ast::ast::InlineAsmTemplatePiece; +use rustc_crate::ich::StableHashingContextProvider; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::{ BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FieldPat, FnRetTy, @@ -8,7 +9,6 @@ use rustc_hir::{ PathSegment, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding, }; use rustc_lint::LateContext; -use rustc_middle::ich::StableHashingContextProvider; use rustc_middle::ty::TypeckResults; use rustc_span::Symbol; use std::hash::Hash; From de2ac9026f4e1882845cc643315f2b63b909239b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 17:04:40 +0100 Subject: [PATCH 13/15] Fully remove rustc_middle::ich. --- compiler/rustc_middle/src/ich/mod.rs | 53 ------------------- compiler/rustc_middle/src/lib.rs | 1 - .../src/traits/specialization_graph.rs | 3 +- compiler/rustc_middle/src/ty/context.rs | 8 ++- .../rustc_middle/src/{ich => ty}/impls_ty.rs | 39 ++++++++++++++ compiler/rustc_middle/src/ty/mod.rs | 2 + compiler/rustc_middle/src/ty/trait_def.rs | 5 +- 7 files changed, 51 insertions(+), 60 deletions(-) delete mode 100644 compiler/rustc_middle/src/ich/mod.rs rename compiler/rustc_middle/src/{ich => ty}/impls_ty.rs (84%) diff --git a/compiler/rustc_middle/src/ich/mod.rs b/compiler/rustc_middle/src/ich/mod.rs deleted file mode 100644 index c9827675753a5..0000000000000 --- a/compiler/rustc_middle/src/ich/mod.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! ICH - Incremental Compilation Hash - -use crate::ty::{fast_reject, TyCtxt}; -use rustc_crate::ich::{StableHashingContext, StableHashingContextProvider}; -use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use rustc_hir::def_id::DefId; -use smallvec::SmallVec; -use std::cmp::Ord; - -mod impls_ty; - -impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> { - fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> { - (*self).create_stable_hashing_context() - } -} - -pub fn hash_stable_trait_impls<'a>( - hcx: &mut StableHashingContext<'a>, - hasher: &mut StableHasher, - blanket_impls: &[DefId], - non_blanket_impls: &FxHashMap>, -) { - { - let mut blanket_impls: SmallVec<[_; 8]> = - blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect(); - - if blanket_impls.len() > 1 { - blanket_impls.sort_unstable(); - } - - blanket_impls.hash_stable(hcx, hasher); - } - - { - let mut keys: SmallVec<[_; 8]> = - non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect(); - keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2)); - keys.len().hash_stable(hcx, hasher); - for (key, ref stable_key) in keys { - stable_key.hash_stable(hcx, hasher); - let mut impls: SmallVec<[_; 8]> = - non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect(); - - if impls.len() > 1 { - impls.sort_unstable(); - } - - impls.hash_stable(hcx, hasher); - } - } -} diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index 4a1d5459d1eec..4be2ed88e4cd4 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -77,7 +77,6 @@ pub mod query; pub mod arena; pub mod dep_graph; pub mod hir; -pub mod ich; pub mod infer; pub mod lint; pub mod middle; diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index 60e9a70ea415d..f5619838d7b20 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -1,4 +1,3 @@ -use crate::ich; use crate::ty::fast_reject::SimplifiedType; use crate::ty::fold::TypeFoldable; use crate::ty::{self, TyCtxt}; @@ -241,6 +240,6 @@ impl<'a> HashStable> for Children { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let Children { ref nonblanket_impls, ref blanket_impls } = *self; - ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, nonblanket_impls); + ty::hash_stable_trait_impls(hcx, hasher, blanket_impls, nonblanket_impls); } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 562ff2d9bb930..c7f80ebf49ead 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -23,7 +23,7 @@ use rustc_ast as ast; use rustc_ast::expand::allocator::AllocatorKind; use rustc_attr as attr; use rustc_crate::cstore::{CrateStoreDyn, EncodedMetadata}; -use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext}; +use rustc_crate::ich::{NodeIdHashingMode, StableHashingContext, StableHashingContextProvider}; use rustc_crate::stability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::profiling::SelfProfilerRef; @@ -883,6 +883,12 @@ impl<'tcx> Deref for TyCtxt<'tcx> { } } +impl StableHashingContextProvider<'tcx> for TyCtxt<'tcx> { + fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> { + (*self).create_stable_hashing_context() + } +} + pub struct GlobalCtxt<'tcx> { pub arena: &'tcx WorkerLocal>, diff --git a/compiler/rustc_middle/src/ich/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs similarity index 84% rename from compiler/rustc_middle/src/ich/impls_ty.rs rename to compiler/rustc_middle/src/ty/impls_ty.rs index a485047bca5c4..84a6114f90fb2 100644 --- a/compiler/rustc_middle/src/ich/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -4,13 +4,52 @@ use crate::middle::region; use crate::mir; use crate::ty; +use crate::ty::fast_reject; use rustc_crate::ich::StableHashingContext; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; +use rustc_span::def_id::DefId; +use smallvec::SmallVec; use std::cell::RefCell; use std::mem; +pub fn hash_stable_trait_impls<'a>( + hcx: &mut StableHashingContext<'a>, + hasher: &mut StableHasher, + blanket_impls: &[DefId], + non_blanket_impls: &FxHashMap>, +) { + { + let mut blanket_impls: SmallVec<[_; 8]> = + blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect(); + + if blanket_impls.len() > 1 { + blanket_impls.sort_unstable(); + } + + blanket_impls.hash_stable(hcx, hasher); + } + + { + let mut keys: SmallVec<[_; 8]> = + non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect(); + keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2)); + keys.len().hash_stable(hcx, hasher); + for (key, ref stable_key) in keys { + stable_key.hash_stable(hcx, hasher); + let mut impls: SmallVec<[_; 8]> = + non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect(); + + if impls.len() > 1 { + impls.sort_unstable(); + } + + impls.hash_stable(hcx, hasher); + } + } +} + impl<'a, 'tcx, T> HashStable> for &'tcx ty::List where T: HashStable>, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 4df917ebfacd5..3b3a2e633c21b 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -114,12 +114,14 @@ pub mod walk; mod consts; mod context; mod diagnostics; +mod impls_ty; mod instance; mod list; mod structural_impls; mod sty; pub use context::ENCODE_METADATA; +pub use impls_ty::hash_stable_trait_impls; // Data types diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 4a56597560c17..e4ab7a29cadf4 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -1,8 +1,7 @@ -use crate::ich; use crate::traits::specialization_graph; use crate::ty::fast_reject; use crate::ty::fold::TypeFoldable; -use crate::ty::{Ty, TyCtxt}; +use crate::ty::{self, Ty, TyCtxt}; use rustc_crate::ich::StableHashingContext; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId}; @@ -252,6 +251,6 @@ impl<'a> HashStable> for TraitImpls { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { let TraitImpls { ref blanket_impls, ref non_blanket_impls } = *self; - ich::hash_stable_trait_impls(hcx, hasher, blanket_impls, non_blanket_impls); + ty::hash_stable_trait_impls(hcx, hasher, blanket_impls, non_blanket_impls); } } From f832a89ade544e30967df46a974ef51deb2f85d3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 17:50:04 +0100 Subject: [PATCH 14/15] Reduce dependencies. --- Cargo.lock | 9 --------- compiler/rustc_crate/Cargo.toml | 21 ++++++--------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a31b01c6b1adc..a9128aa0ff0da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3581,27 +3581,18 @@ name = "rustc_crate" version = "0.0.0" dependencies = [ "bitflags", - "chalk-ir", - "measureme", - "polonius-engine", - "rustc-rayon-core", - "rustc_apfloat", - "rustc_arena", "rustc_ast", "rustc_attr", "rustc_data_structures", "rustc_errors", "rustc_feature", "rustc_hir", - "rustc_index", "rustc_macros", - "rustc_query_system", "rustc_serialize", "rustc_session", "rustc_span", "rustc_target", "smallvec 1.4.2", - "tracing", ] [[package]] diff --git a/compiler/rustc_crate/Cargo.toml b/compiler/rustc_crate/Cargo.toml index 9c14b99eb5656..f36a73072c4f0 100644 --- a/compiler/rustc_crate/Cargo.toml +++ b/compiler/rustc_crate/Cargo.toml @@ -8,25 +8,16 @@ edition = "2018" doctest = false [dependencies] -rustc_arena = { path = "../rustc_arena" } bitflags = "1.2.1" -tracing = "0.1" -rustc-rayon-core = "0.3.0" -polonius-engine = "0.12.0" -rustc_apfloat = { path = "../rustc_apfloat" } +smallvec = { version = "1.0", features = ["union", "may_dangle"] } +rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } rustc_hir = { path = "../rustc_hir" } -rustc_target = { path = "../rustc_target" } rustc_macros = { path = "../rustc_macros" } -rustc_data_structures = { path = "../rustc_data_structures" } -rustc_query_system = { path = "../rustc_query_system" } -rustc_errors = { path = "../rustc_errors" } -rustc_index = { path = "../rustc_index" } rustc_serialize = { path = "../rustc_serialize" } -rustc_ast = { path = "../rustc_ast" } -rustc_span = { path = "../rustc_span" } -chalk-ir = "0.36.0" -smallvec = { version = "1.0", features = ["union", "may_dangle"] } -measureme = "9.0.0" rustc_session = { path = "../rustc_session" } +rustc_span = { path = "../rustc_span" } +rustc_target = { path = "../rustc_target" } From 9c79f60a88827cba00cc7cc5d14ca2d731fa4dcc Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 14 Nov 2020 18:42:36 +0100 Subject: [PATCH 15/15] Fix test. --- .../hotplug_codegen_backend/the_backend.rs | 7 ++++--- src/test/ui-fulldeps/hash-stable-is-unstable.rs | 4 ++-- src/test/ui-fulldeps/hash-stable-is-unstable.stderr | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs index 0e1bef6f68d53..759b4f0ed8aa4 100644 --- a/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs +++ b/src/test/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs @@ -1,11 +1,12 @@ #![feature(rustc_private)] extern crate rustc_codegen_ssa; -extern crate rustc_errors; -extern crate rustc_middle; +extern crate rustc_crate; extern crate rustc_data_structures; extern crate rustc_driver; +extern crate rustc_errors; extern crate rustc_hir; +extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; extern crate rustc_symbol_mangling; @@ -14,12 +15,12 @@ extern crate rustc_target; use rustc_codegen_ssa::back::linker::LinkerInfo; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::{CodegenResults, CrateInfo}; +use rustc_crate::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::MetadataRef; use rustc_errors::ErrorReported; use rustc_middle::dep_graph::DepGraph; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader, MetadataLoaderDyn}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::config::OutputFilenames; diff --git a/src/test/ui-fulldeps/hash-stable-is-unstable.rs b/src/test/ui-fulldeps/hash-stable-is-unstable.rs index d93e21cf7916c..216779beca54c 100644 --- a/src/test/ui-fulldeps/hash-stable-is-unstable.rs +++ b/src/test/ui-fulldeps/hash-stable-is-unstable.rs @@ -1,8 +1,8 @@ // ignore-stage1 -extern crate rustc_data_structures; +extern crate rustc_crate; //~^ use of unstable library feature 'rustc_private' -extern crate rustc_middle; +extern crate rustc_data_structures; //~^ use of unstable library feature 'rustc_private' extern crate rustc_macros; //~^ use of unstable library feature 'rustc_private' diff --git a/src/test/ui-fulldeps/hash-stable-is-unstable.stderr b/src/test/ui-fulldeps/hash-stable-is-unstable.stderr index 3c30e0402d96d..a741811d71564 100644 --- a/src/test/ui-fulldeps/hash-stable-is-unstable.stderr +++ b/src/test/ui-fulldeps/hash-stable-is-unstable.stderr @@ -1,8 +1,8 @@ error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? --> $DIR/hash-stable-is-unstable.rs:3:1 | -LL | extern crate rustc_data_structures; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | extern crate rustc_crate; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #27812 for more information = help: add `#![feature(rustc_private)]` to the crate attributes to enable @@ -10,8 +10,8 @@ LL | extern crate rustc_data_structures; error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead? --> $DIR/hash-stable-is-unstable.rs:5:1 | -LL | extern crate rustc_middle; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | extern crate rustc_data_structures; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #27812 for more information = help: add `#![feature(rustc_private)]` to the crate attributes to enable