Skip to content

Commit 5cee4f3

Browse files
committed
Auto merge of #116875 - nnethercote:rustc_monomorphize, r=wesleywiser
`rustc_monomorphize` cleanups Just some small improvements I found while looking over this code. r? `@wesleywiser`
2 parents 4578435 + a145b49 commit 5cee4f3

File tree

5 files changed

+12
-54
lines changed

5 files changed

+12
-54
lines changed

Diff for: Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4270,7 +4270,6 @@ dependencies = [
42704270
"rustc_errors",
42714271
"rustc_fluent_macro",
42724272
"rustc_hir",
4273-
"rustc_index",
42744273
"rustc_macros",
42754274
"rustc_middle",
42764275
"rustc_session",

Diff for: compiler/rustc_monomorphize/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_errors = { path = "../rustc_errors" }
1414
rustc_hir = { path = "../rustc_hir" }
1515
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
16-
rustc_index = { path = "../rustc_index" }
1716
rustc_macros = { path = "../rustc_macros" }
1817
rustc_middle = { path = "../rustc_middle" }
1918
rustc_session = { path = "../rustc_session" }

Diff for: compiler/rustc_monomorphize/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ monomorphize_type_length_limit = reached the type-length limit while instantiati
2727
monomorphize_unknown_cgu_collection_mode =
2828
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode
2929
30-
monomorphize_unknown_partition_strategy = unknown partitioning strategy
31-
3230
monomorphize_unused_generic_params = item has unused generic parameters
3331
3432
monomorphize_written_to_path = the full type name has been written to '{$path}'

Diff for: compiler/rustc_monomorphize/src/collector.rs

+12-46
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ use rustc_hir::lang_items::LangItem;
173173
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar};
174174
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
175175
use rustc_middle::mir::visit::Visitor as MirVisitor;
176-
use rustc_middle::mir::{self, Local, Location};
176+
use rustc_middle::mir::{self, Location};
177177
use rustc_middle::query::TyCtxtAt;
178178
use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion};
179179
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -874,14 +874,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
874874
self.super_operand(operand, location);
875875
self.check_operand_move_size(operand, location);
876876
}
877-
878-
fn visit_local(
879-
&mut self,
880-
_place_local: Local,
881-
_context: mir::visit::PlaceContext,
882-
_location: Location,
883-
) {
884-
}
885877
}
886878

887879
fn visit_drop_use<'tcx>(
@@ -1220,7 +1212,7 @@ impl<'v> RootCollector<'_, 'v> {
12201212
}
12211213

12221214
fn is_root(&self, def_id: LocalDefId) -> bool {
1223-
!item_requires_monomorphization(self.tcx, def_id)
1215+
!self.tcx.generics_of(def_id).requires_monomorphization(self.tcx)
12241216
&& match self.mode {
12251217
MonoItemCollectionMode::Eager => true,
12261218
MonoItemCollectionMode::Lazy => {
@@ -1283,11 +1275,6 @@ impl<'v> RootCollector<'_, 'v> {
12831275
}
12841276
}
12851277

1286-
fn item_requires_monomorphization(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1287-
let generics = tcx.generics_of(def_id);
1288-
generics.requires_monomorphization(tcx)
1289-
}
1290-
12911278
#[instrument(level = "debug", skip(tcx, output))]
12921279
fn create_mono_items_for_default_impls<'tcx>(
12931280
tcx: TyCtxt<'tcx>,
@@ -1394,17 +1381,6 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
13941381
}
13951382
}
13961383

1397-
fn add_assoc_fn<'tcx>(
1398-
tcx: TyCtxt<'tcx>,
1399-
def_id: Option<DefId>,
1400-
fn_ident: Ident,
1401-
skip_move_check_fns: &mut Vec<DefId>,
1402-
) {
1403-
if let Some(def_id) = def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, fn_ident)) {
1404-
skip_move_check_fns.push(def_id);
1405-
}
1406-
}
1407-
14081384
fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> {
14091385
for impl_def_id in tcx.inherent_impls(def_id) {
14101386
if let Some(new) = tcx.associated_items(impl_def_id).find_by_name_and_kind(
@@ -1420,26 +1396,16 @@ fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) ->
14201396
}
14211397

14221398
fn build_skip_move_check_fns(tcx: TyCtxt<'_>) -> Vec<DefId> {
1423-
let mut skip_move_check_fns = vec![];
1424-
add_assoc_fn(
1425-
tcx,
1426-
tcx.lang_items().owned_box(),
1427-
Ident::from_str("new"),
1428-
&mut skip_move_check_fns,
1429-
);
1430-
add_assoc_fn(
1431-
tcx,
1432-
tcx.get_diagnostic_item(sym::Arc),
1433-
Ident::from_str("new"),
1434-
&mut skip_move_check_fns,
1435-
);
1436-
add_assoc_fn(
1437-
tcx,
1438-
tcx.get_diagnostic_item(sym::Rc),
1439-
Ident::from_str("new"),
1440-
&mut skip_move_check_fns,
1441-
);
1442-
skip_move_check_fns
1399+
let fns = [
1400+
(tcx.lang_items().owned_box(), "new"),
1401+
(tcx.get_diagnostic_item(sym::Rc), "new"),
1402+
(tcx.get_diagnostic_item(sym::Arc), "new"),
1403+
];
1404+
fns.into_iter()
1405+
.filter_map(|(def_id, fn_name)| {
1406+
def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name)))
1407+
})
1408+
.collect::<Vec<_>>()
14431409
}
14441410

14451411
/// Scans the MIR in order to find function calls, closures, and drop-glue.

Diff for: compiler/rustc_monomorphize/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ pub struct LargeAssignmentsLint {
7575
pub limit: u64,
7676
}
7777

78-
#[derive(Diagnostic)]
79-
#[diag(monomorphize_unknown_partition_strategy)]
80-
pub struct UnknownPartitionStrategy;
81-
8278
#[derive(Diagnostic)]
8379
#[diag(monomorphize_symbol_already_defined)]
8480
pub struct SymbolAlreadyDefined {

0 commit comments

Comments
 (0)