Skip to content

Commit 81a600b

Browse files
committed
Move monomorphize code to its own crate.
1 parent bba4be6 commit 81a600b

File tree

13 files changed

+71
-22
lines changed

13 files changed

+71
-22
lines changed

Cargo.lock

+17
Original file line numberDiff line numberDiff line change
@@ -3929,6 +3929,7 @@ dependencies = [
39293929
"rustc_mir",
39303930
"rustc_mir_build",
39313931
"rustc_mir_transform",
3932+
"rustc_monomorphize",
39323933
"rustc_parse",
39333934
"rustc_passes",
39343935
"rustc_plugin_impl",
@@ -4142,6 +4143,22 @@ dependencies = [
41424143
"tracing",
41434144
]
41444145

4146+
[[package]]
4147+
name = "rustc_monomorphize"
4148+
version = "0.0.0"
4149+
dependencies = [
4150+
"rustc_data_structures",
4151+
"rustc_errors",
4152+
"rustc_hir",
4153+
"rustc_index",
4154+
"rustc_middle",
4155+
"rustc_session",
4156+
"rustc_span",
4157+
"rustc_target",
4158+
"smallvec",
4159+
"tracing",
4160+
]
4161+
41454162
[[package]]
41464163
name = "rustc_parse"
41474164
version = "0.0.0"

compiler/rustc_codegen_cranelift/scripts/filter_profile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4242
continue;
4343
}
4444

45-
if stack.contains("rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items")
45+
if stack.contains("rustc_monomorphize::partitioning::collect_and_partition_mono_items")
4646
|| stack.contains("rustc_incremental::assert_dep_graph::assert_dep_graph")
4747
|| stack.contains("rustc_symbol_mangling::test::report_symbol_names")
4848
{
@@ -81,7 +81,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8181
}
8282

8383
const COLLECT_AND_PARTITION_MONO_ITEMS: &str =
84-
"rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items";
84+
"rustc_monomorphize::partitioning::collect_and_partition_mono_items";
8585
if let Some(index) = stack.find(COLLECT_AND_PARTITION_MONO_ITEMS) {
8686
stack = &stack[..index + COLLECT_AND_PARTITION_MONO_ITEMS.len()];
8787
}

compiler/rustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ rustc_metadata = { path = "../rustc_metadata" }
3535
rustc_mir = { path = "../rustc_mir" }
3636
rustc_mir_build = { path = "../rustc_mir_build" }
3737
rustc_mir_transform = { path = "../rustc_mir_transform" }
38+
rustc_monomorphize = { path = "../rustc_monomorphize" }
3839
rustc_passes = { path = "../rustc_passes" }
3940
rustc_typeck = { path = "../rustc_typeck" }
4041
rustc_lint = { path = "../rustc_lint" }

compiler/rustc_interface/src/passes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
743743
mir_borrowck::provide(providers);
744744
mir_build::provide(providers);
745745
rustc_mir_transform::provide(providers);
746+
rustc_monomorphize::provide(providers);
746747
rustc_privacy::provide(providers);
747748
typeck::provide(providers);
748749
ty::provide(providers);

compiler/rustc_mir/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Rust MIR: a lowered representation of Rust.
44
55
*/
66

7-
#![feature(array_windows)]
87
#![feature(assert_matches)]
98
#![cfg_attr(bootstrap, feature(bindings_after_at))]
109
#![feature(associated_type_defaults)]
@@ -36,16 +35,13 @@ extern crate rustc_middle;
3635
pub mod const_eval;
3736
pub mod dataflow;
3837
pub mod interpret;
39-
pub mod monomorphize;
4038
pub mod transform;
4139
pub mod util;
4240

4341
use rustc_middle::ty::query::Providers;
4442

4543
pub fn provide(providers: &mut Providers) {
4644
const_eval::provide(providers);
47-
monomorphize::partitioning::provide(providers);
48-
monomorphize::polymorphize::provide(providers);
4945
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
5046
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
5147
providers.const_caller_location = const_eval::const_caller_location;
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_monomorphize"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }
12+
tracing = "0.1"
13+
rustc_data_structures = { path = "../rustc_data_structures" }
14+
rustc_errors = { path = "../rustc_errors" }
15+
rustc_hir = { path = "../rustc_hir" }
16+
rustc_index = { path = "../rustc_index" }
17+
rustc_middle = { path = "../rustc_middle" }
18+
rustc_session = { path = "../rustc_session" }
19+
rustc_span = { path = "../rustc_span" }
20+
rustc_target = { path = "../rustc_target" }

compiler/rustc_mir/src/monomorphize/collector.rs renamed to compiler/rustc_monomorphize/src/collector.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@
178178
//! this is not implemented however: a mono item will be produced
179179
//! regardless of whether it is actually needed or not.
180180
181-
use crate::monomorphize;
182-
183181
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
184182
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
185183
use rustc_errors::{ErrorReported, FatalError};
@@ -1052,7 +1050,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
10521050
assert_eq!(source_adt_def, target_adt_def);
10531051

10541052
let CustomCoerceUnsized::Struct(coerce_index) =
1055-
monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
1053+
crate::custom_coerce_unsize_info(tcx, source_ty, target_ty);
10561054

10571055
let source_fields = &source_adt_def.non_enum_variant().fields;
10581056
let target_fields = &target_adt_def.non_enum_variant().fields;
@@ -1085,7 +1083,7 @@ fn create_fn_mono_item<'tcx>(
10851083
let def_id = instance.def_id();
10861084
if tcx.sess.opts.debugging_opts.profile_closures && def_id.is_local() && tcx.is_closure(def_id)
10871085
{
1088-
monomorphize::util::dump_closure_profile(tcx, instance);
1086+
crate::util::dump_closure_profile(tcx, instance);
10891087
}
10901088

10911089
respan(source, MonoItem::Fn(instance.polymorphize(tcx)))

compiler/rustc_mir/src/monomorphize/mod.rs renamed to compiler/rustc_monomorphize/src/lib.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
#![feature(array_windows)]
2+
#![feature(bool_to_option)]
3+
#![feature(crate_visibility_modifier)]
4+
#![feature(control_flow_enum)]
5+
#![feature(in_band_lifetimes)]
6+
7+
#[macro_use]
8+
extern crate tracing;
9+
#[macro_use]
10+
extern crate rustc_middle;
11+
12+
use rustc_hir::lang_items::LangItem;
113
use rustc_middle::traits;
214
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
15+
use rustc_middle::ty::query::Providers;
316
use rustc_middle::ty::{self, Ty, TyCtxt};
417

5-
use rustc_hir::lang_items::LangItem;
6-
7-
pub mod collector;
8-
pub mod partitioning;
9-
pub mod polymorphize;
10-
pub mod util;
18+
mod collector;
19+
mod partitioning;
20+
mod polymorphize;
21+
mod util;
1122

1223
fn custom_coerce_unsize_info<'tcx>(
1324
tcx: TyCtxt<'tcx>,
@@ -31,3 +42,8 @@ fn custom_coerce_unsize_info<'tcx>(
3142
}
3243
}
3344
}
45+
46+
pub fn provide(providers: &mut Providers) {
47+
partitioning::provide(providers);
48+
polymorphize::provide(providers);
49+
}

compiler/rustc_mir/src/monomorphize/partitioning/default.rs renamed to compiler/rustc_monomorphize/src/partitioning/default.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt};
1313
use rustc_span::symbol::Symbol;
1414

1515
use super::PartitioningCx;
16-
use crate::monomorphize::collector::InliningMap;
17-
use crate::monomorphize::partitioning::merging;
18-
use crate::monomorphize::partitioning::{
16+
use crate::collector::InliningMap;
17+
use crate::partitioning::merging;
18+
use crate::partitioning::{
1919
MonoItemPlacement, Partitioner, PostInliningPartitioning, PreInliningPartitioning,
2020
};
2121

compiler/rustc_mir/src/monomorphize/partitioning/merging.rs renamed to compiler/rustc_monomorphize/src/partitioning/merging.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder};
66
use rustc_span::symbol::{Symbol, SymbolStr};
77

88
use super::PartitioningCx;
9-
use crate::monomorphize::partitioning::PreInliningPartitioning;
9+
use crate::partitioning::PreInliningPartitioning;
1010

1111
pub fn merge_codegen_units<'tcx>(
1212
cx: &PartitioningCx<'_, 'tcx>,

compiler/rustc_mir/src/monomorphize/partitioning/mod.rs renamed to compiler/rustc_monomorphize/src/partitioning/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ use rustc_middle::ty::query::Providers;
105105
use rustc_middle::ty::TyCtxt;
106106
use rustc_span::symbol::Symbol;
107107

108-
use crate::monomorphize::collector::InliningMap;
109-
use crate::monomorphize::collector::{self, MonoItemCollectionMode};
108+
use crate::collector::InliningMap;
109+
use crate::collector::{self, MonoItemCollectionMode};
110110

111111
pub struct PartitioningCx<'a, 'tcx> {
112112
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)