Move monomorphize code to its own crate.

This commit is contained in:
Camille GILLOT 2021-01-02 14:42:15 +01:00
parent bba4be681d
commit 81a600b6b7
13 changed files with 72 additions and 23 deletions

View file

@ -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"

View file

@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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<dyn std::error::Error>> {
}
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()];
}

View file

@ -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" }

View file

@ -743,6 +743,7 @@ pub fn prepare_outputs(
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);

View file

@ -4,7 +4,6 @@
*/
#![feature(array_windows)]
#![feature(assert_matches)]
#![cfg_attr(bootstrap, feature(bindings_after_at))]
#![feature(associated_type_defaults)]
@ -36,7 +35,6 @@
pub mod const_eval;
pub mod dataflow;
pub mod interpret;
pub mod monomorphize;
pub mod transform;
pub mod util;
@ -44,8 +42,6 @@
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;

View file

@ -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" }

View file

@ -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)))

View file

@ -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);
}

View file

@ -13,9 +13,9 @@
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,
};

View file

@ -6,7 +6,7 @@
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>,

View file

@ -105,8 +105,8 @@
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>,