diff --git a/Cargo.lock b/Cargo.lock index 3ec143d2492..841fc608476 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3929,6 +3929,7 @@ dependencies = [ "rustc_mir", "rustc_mir_build", "rustc_mir_transform", + "rustc_monomorphize", "rustc_parse", "rustc_passes", "rustc_plugin_impl", @@ -4142,6 +4143,22 @@ dependencies = [ "tracing", ] +[[package]] +name = "rustc_monomorphize" +version = "0.0.0" +dependencies = [ + "rustc_data_structures", + "rustc_errors", + "rustc_hir", + "rustc_index", + "rustc_middle", + "rustc_session", + "rustc_span", + "rustc_target", + "smallvec", + "tracing", +] + [[package]] name = "rustc_parse" version = "0.0.0" diff --git a/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs b/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs index c4801a0a87b..7a51293f5cd 100755 --- a/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs +++ b/compiler/rustc_codegen_cranelift/scripts/filter_profile.rs @@ -42,7 +42,7 @@ fn main() -> Result<(), Box> { continue; } - if stack.contains("rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items") + if stack.contains("rustc_monomorphize::partitioning::collect_and_partition_mono_items") || stack.contains("rustc_incremental::assert_dep_graph::assert_dep_graph") || stack.contains("rustc_symbol_mangling::test::report_symbol_names") { @@ -81,7 +81,7 @@ fn main() -> Result<(), Box> { } const COLLECT_AND_PARTITION_MONO_ITEMS: &str = - "rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items"; + "rustc_monomorphize::partitioning::collect_and_partition_mono_items"; if let Some(index) = stack.find(COLLECT_AND_PARTITION_MONO_ITEMS) { stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()]; } diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 8b277269258..306728dbeac 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -35,6 +35,7 @@ rustc_metadata = { path = "../rustc_metadata" } rustc_mir = { path = "../rustc_mir" } rustc_mir_build = { path = "../rustc_mir_build" } rustc_mir_transform = { path = "../rustc_mir_transform" } +rustc_monomorphize = { path = "../rustc_monomorphize" } rustc_passes = { path = "../rustc_passes" } rustc_typeck = { path = "../rustc_typeck" } rustc_lint = { path = "../rustc_lint" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 7d41db0d4ae..547823a067c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -743,6 +743,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { mir_borrowck::provide(providers); mir_build::provide(providers); rustc_mir_transform::provide(providers); + rustc_monomorphize::provide(providers); rustc_privacy::provide(providers); typeck::provide(providers); ty::provide(providers); diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index 4c79c7da15c..fa1f27daa80 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -4,7 +4,6 @@ Rust MIR: a lowered representation of Rust. */ -#![feature(array_windows)] #![feature(assert_matches)] #![cfg_attr(bootstrap, feature(bindings_after_at))] #![feature(associated_type_defaults)] @@ -36,7 +35,6 @@ extern crate rustc_middle; pub mod const_eval; pub mod dataflow; pub mod interpret; -pub mod monomorphize; pub mod transform; pub mod util; @@ -44,8 +42,6 @@ use rustc_middle::ty::query::Providers; pub fn provide(providers: &mut Providers) { const_eval::provide(providers); - monomorphize::partitioning::provide(providers); - monomorphize::polymorphize::provide(providers); providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider; providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider; providers.const_caller_location = const_eval::const_caller_location; diff --git a/compiler/rustc_monomorphize/Cargo.toml b/compiler/rustc_monomorphize/Cargo.toml new file mode 100644 index 00000000000..93a964bf3cc --- /dev/null +++ b/compiler/rustc_monomorphize/Cargo.toml @@ -0,0 +1,20 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_monomorphize" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +tracing = "0.1" +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } +rustc_hir = { path = "../rustc_hir" } +rustc_index = { path = "../rustc_index" } +rustc_middle = { path = "../rustc_middle" } +rustc_session = { path = "../rustc_session" } +rustc_span = { path = "../rustc_span" } +rustc_target = { path = "../rustc_target" } diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_monomorphize/src/collector.rs similarity index 99% rename from compiler/rustc_mir/src/monomorphize/collector.rs rename to compiler/rustc_monomorphize/src/collector.rs index 4cb362238c1..1e39b1bd5e8 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -178,8 +178,6 @@ //! this is not implemented however: a mono item will be produced //! regardless of whether it is actually needed or not. -use crate::monomorphize; - use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator}; use rustc_errors::{ErrorReported, FatalError}; @@ -1052,7 +1050,7 @@ fn find_vtable_types_for_unsizing<'tcx>( assert_eq!(source_adt_def, target_adt_def); let CustomCoerceUnsized::Struct(coerce_index) = - monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty); + crate::custom_coerce_unsize_info(tcx, source_ty, target_ty); let source_fields = &source_adt_def.non_enum_variant().fields; let target_fields = &target_adt_def.non_enum_variant().fields; @@ -1085,7 +1083,7 @@ fn create_fn_mono_item<'tcx>( let def_id = instance.def_id(); if tcx.sess.opts.debugging_opts.profile_closures && def_id.is_local() && tcx.is_closure(def_id) { - monomorphize::util::dump_closure_profile(tcx, instance); + crate::util::dump_closure_profile(tcx, instance); } respan(source, MonoItem::Fn(instance.polymorphize(tcx))) diff --git a/compiler/rustc_mir/src/monomorphize/mod.rs b/compiler/rustc_monomorphize/src/lib.rs similarity index 66% rename from compiler/rustc_mir/src/monomorphize/mod.rs rename to compiler/rustc_monomorphize/src/lib.rs index 57d2723cf9c..2a40eeac5bd 100644 --- a/compiler/rustc_mir/src/monomorphize/mod.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -1,13 +1,24 @@ -use rustc_middle::traits; -use rustc_middle::ty::adjustment::CustomCoerceUnsized; -use rustc_middle::ty::{self, Ty, TyCtxt}; +#![feature(array_windows)] +#![feature(bool_to_option)] +#![feature(crate_visibility_modifier)] +#![feature(control_flow_enum)] +#![feature(in_band_lifetimes)] + +#[macro_use] +extern crate tracing; +#[macro_use] +extern crate rustc_middle; use rustc_hir::lang_items::LangItem; +use rustc_middle::traits; +use rustc_middle::ty::adjustment::CustomCoerceUnsized; +use rustc_middle::ty::query::Providers; +use rustc_middle::ty::{self, Ty, TyCtxt}; -pub mod collector; -pub mod partitioning; -pub mod polymorphize; -pub mod util; +mod collector; +mod partitioning; +mod polymorphize; +mod util; fn custom_coerce_unsize_info<'tcx>( tcx: TyCtxt<'tcx>, @@ -31,3 +42,8 @@ fn custom_coerce_unsize_info<'tcx>( } } } + +pub fn provide(providers: &mut Providers) { + partitioning::provide(providers); + polymorphize::provide(providers); +} diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_monomorphize/src/partitioning/default.rs similarity index 99% rename from compiler/rustc_mir/src/monomorphize/partitioning/default.rs rename to compiler/rustc_monomorphize/src/partitioning/default.rs index a559a6ce415..429ed53d379 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_monomorphize/src/partitioning/default.rs @@ -13,9 +13,9 @@ use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt}; use rustc_span::symbol::Symbol; use super::PartitioningCx; -use crate::monomorphize::collector::InliningMap; -use crate::monomorphize::partitioning::merging; -use crate::monomorphize::partitioning::{ +use crate::collector::InliningMap; +use crate::partitioning::merging; +use crate::partitioning::{ MonoItemPlacement, Partitioner, PostInliningPartitioning, PreInliningPartitioning, }; diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs b/compiler/rustc_monomorphize/src/partitioning/merging.rs similarity index 98% rename from compiler/rustc_mir/src/monomorphize/partitioning/merging.rs rename to compiler/rustc_monomorphize/src/partitioning/merging.rs index cbe36665790..229468b47ff 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/merging.rs +++ b/compiler/rustc_monomorphize/src/partitioning/merging.rs @@ -6,7 +6,7 @@ use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder}; use rustc_span::symbol::{Symbol, SymbolStr}; use super::PartitioningCx; -use crate::monomorphize::partitioning::PreInliningPartitioning; +use crate::partitioning::PreInliningPartitioning; pub fn merge_codegen_units<'tcx>( cx: &PartitioningCx<'_, 'tcx>, diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs b/compiler/rustc_monomorphize/src/partitioning/mod.rs similarity index 99% rename from compiler/rustc_mir/src/monomorphize/partitioning/mod.rs rename to compiler/rustc_monomorphize/src/partitioning/mod.rs index 6ed0ab8be41..7a7a56a034e 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/mod.rs +++ b/compiler/rustc_monomorphize/src/partitioning/mod.rs @@ -105,8 +105,8 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::Symbol; -use crate::monomorphize::collector::InliningMap; -use crate::monomorphize::collector::{self, MonoItemCollectionMode}; +use crate::collector::InliningMap; +use crate::collector::{self, MonoItemCollectionMode}; pub struct PartitioningCx<'a, 'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_mir/src/monomorphize/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs similarity index 100% rename from compiler/rustc_mir/src/monomorphize/polymorphize.rs rename to compiler/rustc_monomorphize/src/polymorphize.rs diff --git a/compiler/rustc_mir/src/monomorphize/util.rs b/compiler/rustc_monomorphize/src/util.rs similarity index 100% rename from compiler/rustc_mir/src/monomorphize/util.rs rename to compiler/rustc_monomorphize/src/util.rs