Move monomorphize code to its own crate.
This commit is contained in:
parent
bba4be681d
commit
81a600b6b7
13 changed files with 72 additions and 23 deletions
17
Cargo.lock
17
Cargo.lock
|
@ -3929,6 +3929,7 @@ dependencies = [
|
||||||
"rustc_mir",
|
"rustc_mir",
|
||||||
"rustc_mir_build",
|
"rustc_mir_build",
|
||||||
"rustc_mir_transform",
|
"rustc_mir_transform",
|
||||||
|
"rustc_monomorphize",
|
||||||
"rustc_parse",
|
"rustc_parse",
|
||||||
"rustc_passes",
|
"rustc_passes",
|
||||||
"rustc_plugin_impl",
|
"rustc_plugin_impl",
|
||||||
|
@ -4142,6 +4143,22 @@ dependencies = [
|
||||||
"tracing",
|
"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]]
|
[[package]]
|
||||||
name = "rustc_parse"
|
name = "rustc_parse"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
|
|
@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
continue;
|
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_incremental::assert_dep_graph::assert_dep_graph")
|
||||||
|| stack.contains("rustc_symbol_mangling::test::report_symbol_names")
|
|| 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 =
|
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) {
|
if let Some(index) = stack.find(COLLECT_AND_PARTITION_MONO_ITEMS) {
|
||||||
stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()];
|
stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()];
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ rustc_metadata = { path = "../rustc_metadata" }
|
||||||
rustc_mir = { path = "../rustc_mir" }
|
rustc_mir = { path = "../rustc_mir" }
|
||||||
rustc_mir_build = { path = "../rustc_mir_build" }
|
rustc_mir_build = { path = "../rustc_mir_build" }
|
||||||
rustc_mir_transform = { path = "../rustc_mir_transform" }
|
rustc_mir_transform = { path = "../rustc_mir_transform" }
|
||||||
|
rustc_monomorphize = { path = "../rustc_monomorphize" }
|
||||||
rustc_passes = { path = "../rustc_passes" }
|
rustc_passes = { path = "../rustc_passes" }
|
||||||
rustc_typeck = { path = "../rustc_typeck" }
|
rustc_typeck = { path = "../rustc_typeck" }
|
||||||
rustc_lint = { path = "../rustc_lint" }
|
rustc_lint = { path = "../rustc_lint" }
|
||||||
|
|
|
@ -743,6 +743,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
|
||||||
mir_borrowck::provide(providers);
|
mir_borrowck::provide(providers);
|
||||||
mir_build::provide(providers);
|
mir_build::provide(providers);
|
||||||
rustc_mir_transform::provide(providers);
|
rustc_mir_transform::provide(providers);
|
||||||
|
rustc_monomorphize::provide(providers);
|
||||||
rustc_privacy::provide(providers);
|
rustc_privacy::provide(providers);
|
||||||
typeck::provide(providers);
|
typeck::provide(providers);
|
||||||
ty::provide(providers);
|
ty::provide(providers);
|
||||||
|
|
|
@ -4,7 +4,6 @@ Rust MIR: a lowered representation of Rust.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#![feature(array_windows)]
|
|
||||||
#![feature(assert_matches)]
|
#![feature(assert_matches)]
|
||||||
#![cfg_attr(bootstrap, feature(bindings_after_at))]
|
#![cfg_attr(bootstrap, feature(bindings_after_at))]
|
||||||
#![feature(associated_type_defaults)]
|
#![feature(associated_type_defaults)]
|
||||||
|
@ -36,7 +35,6 @@ extern crate rustc_middle;
|
||||||
pub mod const_eval;
|
pub mod const_eval;
|
||||||
pub mod dataflow;
|
pub mod dataflow;
|
||||||
pub mod interpret;
|
pub mod interpret;
|
||||||
pub mod monomorphize;
|
|
||||||
pub mod transform;
|
pub mod transform;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
|
@ -44,8 +42,6 @@ use rustc_middle::ty::query::Providers;
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
const_eval::provide(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_const_value_raw = const_eval::eval_to_const_value_raw_provider;
|
||||||
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
|
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
|
||||||
providers.const_caller_location = const_eval::const_caller_location;
|
providers.const_caller_location = const_eval::const_caller_location;
|
||||||
|
|
20
compiler/rustc_monomorphize/Cargo.toml
Normal file
20
compiler/rustc_monomorphize/Cargo.toml
Normal 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" }
|
|
@ -178,8 +178,6 @@
|
||||||
//! this is not implemented however: a mono item will be produced
|
//! this is not implemented however: a mono item will be produced
|
||||||
//! regardless of whether it is actually needed or not.
|
//! regardless of whether it is actually needed or not.
|
||||||
|
|
||||||
use crate::monomorphize;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
|
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
|
||||||
use rustc_errors::{ErrorReported, FatalError};
|
use rustc_errors::{ErrorReported, FatalError};
|
||||||
|
@ -1052,7 +1050,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
|
||||||
assert_eq!(source_adt_def, target_adt_def);
|
assert_eq!(source_adt_def, target_adt_def);
|
||||||
|
|
||||||
let CustomCoerceUnsized::Struct(coerce_index) =
|
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 source_fields = &source_adt_def.non_enum_variant().fields;
|
||||||
let target_fields = &target_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();
|
let def_id = instance.def_id();
|
||||||
if tcx.sess.opts.debugging_opts.profile_closures && def_id.is_local() && tcx.is_closure(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)))
|
respan(source, MonoItem::Fn(instance.polymorphize(tcx)))
|
|
@ -1,13 +1,24 @@
|
||||||
use rustc_middle::traits;
|
#![feature(array_windows)]
|
||||||
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
|
#![feature(bool_to_option)]
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
#![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_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;
|
mod collector;
|
||||||
pub mod partitioning;
|
mod partitioning;
|
||||||
pub mod polymorphize;
|
mod polymorphize;
|
||||||
pub mod util;
|
mod util;
|
||||||
|
|
||||||
fn custom_coerce_unsize_info<'tcx>(
|
fn custom_coerce_unsize_info<'tcx>(
|
||||||
tcx: TyCtxt<'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);
|
||||||
|
}
|
|
@ -13,9 +13,9 @@ use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt};
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
use super::PartitioningCx;
|
use super::PartitioningCx;
|
||||||
use crate::monomorphize::collector::InliningMap;
|
use crate::collector::InliningMap;
|
||||||
use crate::monomorphize::partitioning::merging;
|
use crate::partitioning::merging;
|
||||||
use crate::monomorphize::partitioning::{
|
use crate::partitioning::{
|
||||||
MonoItemPlacement, Partitioner, PostInliningPartitioning, PreInliningPartitioning,
|
MonoItemPlacement, Partitioner, PostInliningPartitioning, PreInliningPartitioning,
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder};
|
||||||
use rustc_span::symbol::{Symbol, SymbolStr};
|
use rustc_span::symbol::{Symbol, SymbolStr};
|
||||||
|
|
||||||
use super::PartitioningCx;
|
use super::PartitioningCx;
|
||||||
use crate::monomorphize::partitioning::PreInliningPartitioning;
|
use crate::partitioning::PreInliningPartitioning;
|
||||||
|
|
||||||
pub fn merge_codegen_units<'tcx>(
|
pub fn merge_codegen_units<'tcx>(
|
||||||
cx: &PartitioningCx<'_, 'tcx>,
|
cx: &PartitioningCx<'_, 'tcx>,
|
|
@ -105,8 +105,8 @@ use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
use crate::monomorphize::collector::InliningMap;
|
use crate::collector::InliningMap;
|
||||||
use crate::monomorphize::collector::{self, MonoItemCollectionMode};
|
use crate::collector::{self, MonoItemCollectionMode};
|
||||||
|
|
||||||
pub struct PartitioningCx<'a, 'tcx> {
|
pub struct PartitioningCx<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
Loading…
Add table
Add a link
Reference in a new issue