Skip to content

Commit 3335df2

Browse files
committed
Bless
1 parent 7914284 commit 3335df2

18 files changed

+169
-185
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,6 +4207,7 @@ dependencies = [
42074207
name = "rustc_monomorphize"
42084208
version = "0.0.0"
42094209
dependencies = [
4210+
"rustc_abi",
42104211
"rustc_ast",
42114212
"rustc_attr_data_structures",
42124213
"rustc_data_structures",

compiler/rustc_mir_transform/messages.ftl

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
1-
mir_transform_abi_error_disabled_vector_type =
2-
this function {$is_call ->
3-
[true] call
4-
*[false] definition
5-
} uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
6-
[true] {" "}in the caller
7-
*[false] {""}
8-
}
9-
.label = function {$is_call ->
10-
[true] called
11-
*[false] defined
12-
} here
13-
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
14-
15-
mir_transform_abi_error_unsupported_vector_type =
16-
this function {$is_call ->
17-
[true] call
18-
*[false] definition
19-
} uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
20-
.label = function {$is_call ->
21-
[true] called
22-
*[false] defined
23-
} here
24-
25-
mir_transform_abi_required_target_feature =
26-
this function {$is_call ->
27-
[true] call
28-
*[false] definition
29-
} uses ABI "{$abi}" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
30-
[true] {" "}in the caller
31-
*[false] {""}
32-
}
33-
.label = function {$is_call ->
34-
[true] called
35-
*[false] defined
36-
} here
37-
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
38-
391
mir_transform_arithmetic_overflow = this arithmetic operation will overflow
402
mir_transform_const_defined_here = `const` item defined here
413
@@ -74,11 +36,6 @@ mir_transform_force_inline_attr =
7436
mir_transform_force_inline_justification =
7537
`{$callee}` is required to be inlined to: {$sym}
7638
77-
mir_transform_large_assignments =
78-
moving {$size} bytes
79-
.label = value moved from here
80-
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
81-
8239
mir_transform_must_not_suspend = {$pre}`{$def_path}`{$post} held across a suspend point, but should not be
8340
.label = the value is held across this suspend point
8441
.note = {$reason}
@@ -122,12 +79,3 @@ mir_transform_unconditional_recursion = function cannot return without recursing
12279
mir_transform_unconditional_recursion_call_site_label = recursive call site
12380
12481
mir_transform_unknown_pass_name = MIR pass `{$name}` is unknown and will be ignored
125-
126-
mir_transform_unnecessary_transmute = unnecessary transmute
127-
128-
mir_transform_wasm_c_abi_transition =
129-
this function {$is_call ->
130-
[true] call
131-
*[false] definition
132-
} involves an argument of type `{$ty}` which is affected by the wasm ABI transition
133-
.help = the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target

compiler/rustc_mir_transform/src/errors.rs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_errors::codes::*;
22
use rustc_errors::{Diag, LintDiagnostic};
33
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
44
use rustc_middle::mir::AssertKind;
5-
use rustc_middle::ty::{Ty, TyCtxt};
5+
use rustc_middle::ty::TyCtxt;
66
use rustc_session::lint::{self, Lint};
77
use rustc_span::def_id::DefId;
88
use rustc_span::{Ident, Span, Symbol};
@@ -117,16 +117,6 @@ pub(crate) struct FnItemRef {
117117
pub ident: Ident,
118118
}
119119

120-
#[derive(LintDiagnostic)]
121-
#[diag(mir_transform_large_assignments)]
122-
#[note]
123-
pub(crate) struct LargeAssignmentsLint {
124-
#[label]
125-
pub span: Span,
126-
pub size: u64,
127-
pub limit: u64,
128-
}
129-
130120
#[derive(Diagnostic)]
131121
#[diag(mir_transform_exceeds_mcdc_test_vector_limit)]
132122
pub(crate) struct MCDCExceedsTestVectorLimit {
@@ -193,49 +183,3 @@ pub(crate) struct ForceInlineFailure {
193183
pub(crate) struct ForceInlineJustification {
194184
pub sym: Symbol,
195185
}
196-
197-
#[derive(Diagnostic)]
198-
#[diag(mir_transform_abi_error_disabled_vector_type)]
199-
#[help]
200-
pub(crate) struct AbiErrorDisabledVectorType<'a> {
201-
#[primary_span]
202-
#[label]
203-
pub span: Span,
204-
pub required_feature: &'a str,
205-
pub ty: Ty<'a>,
206-
/// Whether this is a problem at a call site or at a declaration.
207-
pub is_call: bool,
208-
}
209-
210-
#[derive(Diagnostic)]
211-
#[diag(mir_transform_abi_error_unsupported_vector_type)]
212-
pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
213-
#[primary_span]
214-
#[label]
215-
pub span: Span,
216-
pub ty: Ty<'a>,
217-
/// Whether this is a problem at a call site or at a declaration.
218-
pub is_call: bool,
219-
}
220-
221-
#[derive(Diagnostic)]
222-
#[diag(mir_transform_abi_required_target_feature)]
223-
#[help]
224-
pub(crate) struct AbiRequiredTargetFeature<'a> {
225-
#[primary_span]
226-
#[label]
227-
pub span: Span,
228-
pub required_feature: &'a str,
229-
pub abi: &'a str,
230-
/// Whether this is a problem at a call site or at a declaration.
231-
pub is_call: bool,
232-
}
233-
234-
#[derive(LintDiagnostic)]
235-
#[diag(mir_transform_wasm_c_abi_transition)]
236-
#[help]
237-
pub(crate) struct WasmCAbiTransition<'a> {
238-
pub ty: Ty<'a>,
239-
/// Whether this is a problem at a call site or at a declaration.
240-
pub is_call: bool,
241-
}

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ mod errors;
5454
mod ffi_unwind_calls;
5555
mod lint;
5656
mod lint_tail_expr_drop_order;
57-
mod mono_checks;
5857
mod patch;
5958
mod shim;
6059
mod ssa;
@@ -214,7 +213,6 @@ pub fn provide(providers: &mut Providers) {
214213
ffi_unwind_calls::provide(providers);
215214
shim::provide(providers);
216215
cross_crate_inline::provide(providers);
217-
mono_checks::provide(providers);
218216
providers.queries = query::Providers {
219217
mir_keys,
220218
mir_built,
@@ -889,8 +887,6 @@ pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> &
889887
body
890888
};
891889

892-
mono_checks::check_mono_item(tcx, instance, body);
893-
894890
body
895891
}
896892

compiler/rustc_monomorphize/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
1011
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_monomorphize/messages.ftl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,52 @@
1+
monomorphize_abi_error_disabled_vector_type =
2+
this function {$is_call ->
3+
[true] call
4+
*[false] definition
5+
} uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
6+
[true] {" "}in the caller
7+
*[false] {""}
8+
}
9+
.label = function {$is_call ->
10+
[true] called
11+
*[false] defined
12+
} here
13+
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
14+
15+
monomorphize_abi_error_unsupported_vector_type =
16+
this function {$is_call ->
17+
[true] call
18+
*[false] definition
19+
} uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
20+
.label = function {$is_call ->
21+
[true] called
22+
*[false] defined
23+
} here
24+
25+
monomorphize_abi_required_target_feature =
26+
this function {$is_call ->
27+
[true] call
28+
*[false] definition
29+
} uses ABI "{$abi}" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
30+
[true] {" "}in the caller
31+
*[false] {""}
32+
}
33+
.label = function {$is_call ->
34+
[true] called
35+
*[false] defined
36+
} here
37+
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
38+
139
monomorphize_couldnt_dump_mono_stats =
240
unexpected error occurred while dumping monomorphization stats: {$error}
341
442
monomorphize_encountered_error_while_instantiating =
543
the above error was encountered while instantiating `{$formatted_item}`
644
45+
monomorphize_large_assignments =
46+
moving {$size} bytes
47+
.label = value moved from here
48+
.note = The current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]`
49+
750
monomorphize_no_optimized_mir =
851
missing optimized MIR for `{$instance}` in the crate `{$crate_name}`
952
.note = missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?)
@@ -17,4 +60,11 @@ monomorphize_start_not_found = using `fn main` requires the standard library
1760
1861
monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined
1962
63+
monomorphize_wasm_c_abi_transition =
64+
this function {$is_call ->
65+
[true] call
66+
*[false] definition
67+
} involves an argument of type `{$ty}` which is affected by the wasm ABI transition
68+
.help = the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target
69+
2070
monomorphize_written_to_path = the full type name has been written to '{$path}'

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ fn collect_items_of_instance<'tcx>(
12321232
mode: CollectionMode,
12331233
) -> (MonoItems<'tcx>, MonoItems<'tcx>) {
12341234
// This item is getting monomorphized, do mono-time checks.
1235-
//tcx.ensure_ok().check_mono_item(instance);
1235+
tcx.ensure_ok().check_mono_item(instance);
12361236

12371237
let body = tcx.instance_mir(instance.def);
12381238
// Naively, in "used" collection mode, all functions get added to *both* `used_items` and

compiler/rustc_monomorphize/src/errors.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::path::PathBuf;
22

3-
use rustc_macros::Diagnostic;
3+
use rustc_macros::{Diagnostic, LintDiagnostic};
4+
use rustc_middle::ty::Ty;
45
use rustc_span::{Span, Symbol};
56

67
#[derive(Diagnostic)]
@@ -26,6 +27,16 @@ pub(crate) struct NoOptimizedMir {
2627
pub instance: String,
2728
}
2829

30+
#[derive(LintDiagnostic)]
31+
#[diag(monomorphize_large_assignments)]
32+
#[note]
33+
pub(crate) struct LargeAssignmentsLint {
34+
#[label]
35+
pub span: Span,
36+
pub size: u64,
37+
pub limit: u64,
38+
}
39+
2940
#[derive(Diagnostic)]
3041
#[diag(monomorphize_symbol_already_defined)]
3142
pub(crate) struct SymbolAlreadyDefined {
@@ -52,3 +63,49 @@ pub(crate) struct EncounteredErrorWhileInstantiating {
5263
#[diag(monomorphize_start_not_found)]
5364
#[help]
5465
pub(crate) struct StartNotFound;
66+
67+
#[derive(Diagnostic)]
68+
#[diag(monomorphize_abi_error_disabled_vector_type)]
69+
#[help]
70+
pub(crate) struct AbiErrorDisabledVectorType<'a> {
71+
#[primary_span]
72+
#[label]
73+
pub span: Span,
74+
pub required_feature: &'a str,
75+
pub ty: Ty<'a>,
76+
/// Whether this is a problem at a call site or at a declaration.
77+
pub is_call: bool,
78+
}
79+
80+
#[derive(Diagnostic)]
81+
#[diag(monomorphize_abi_error_unsupported_vector_type)]
82+
pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
83+
#[primary_span]
84+
#[label]
85+
pub span: Span,
86+
pub ty: Ty<'a>,
87+
/// Whether this is a problem at a call site or at a declaration.
88+
pub is_call: bool,
89+
}
90+
91+
#[derive(Diagnostic)]
92+
#[diag(monomorphize_abi_required_target_feature)]
93+
#[help]
94+
pub(crate) struct AbiRequiredTargetFeature<'a> {
95+
#[primary_span]
96+
#[label]
97+
pub span: Span,
98+
pub required_feature: &'a str,
99+
pub abi: &'a str,
100+
/// Whether this is a problem at a call site or at a declaration.
101+
pub is_call: bool,
102+
}
103+
104+
#[derive(LintDiagnostic)]
105+
#[diag(monomorphize_wasm_c_abi_transition)]
106+
#[help]
107+
pub(crate) struct WasmCAbiTransition<'a> {
108+
pub ty: Ty<'a>,
109+
/// Whether this is a problem at a call site or at a declaration.
110+
pub is_call: bool,
111+
}

compiler/rustc_monomorphize/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_span::ErrorGuaranteed;
1616

1717
mod collector;
1818
mod errors;
19+
mod mono_checks;
1920
mod partitioning;
2021
mod util;
2122

@@ -50,4 +51,5 @@ fn custom_coerce_unsize_info<'tcx>(
5051

5152
pub fn provide(providers: &mut Providers) {
5253
partitioning::provide(providers);
54+
mono_checks::provide(providers);
5355
}

compiler/rustc_mir_transform/src/mono_checks/abi_check.rs renamed to compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &m
243243
pub(crate) fn check_feature_dependent_abi<'tcx>(
244244
tcx: TyCtxt<'tcx>,
245245
instance: Instance<'tcx>,
246-
body: &mir::Body<'tcx>,
246+
body: &'tcx mir::Body<'tcx>,
247247
) {
248248
check_instance_abi(tcx, instance);
249249
check_callees_abi(tcx, instance, body);

compiler/rustc_mir_transform/src/mono_checks/mod.rs renamed to compiler/rustc_monomorphize/src/mono_checks/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,22 @@
22
//! monomorphization of all functions. This lets us implement monomorphization-time
33
//! checks in a way that is friendly to incremental compilation.
44
5-
use rustc_middle::mir::Body;
65
use rustc_middle::query::Providers;
76
use rustc_middle::ty::{Instance, TyCtxt};
87

98
mod abi_check;
109
mod move_check;
1110

12-
pub(super) fn check_mono_item<'tcx>(
13-
tcx: TyCtxt<'tcx>,
14-
instance: Instance<'tcx>,
15-
body: &Body<'tcx>,
16-
) {
11+
fn check_mono_item<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
12+
let body = tcx.instance_mir(instance.def);
1713
abi_check::check_feature_dependent_abi(tcx, instance, body);
1814
move_check::check_moves(tcx, instance, body);
1915
}
2016

2117
pub(super) fn provide(providers: &mut Providers) {
2218
*providers = Providers {
19+
check_mono_item,
2320
skip_move_check_fns: move_check::skip_move_check_fns,
24-
check_mono_item: |tcx, instance| {
25-
let body = tcx.codegen_mir(instance);
26-
check_mono_item(tcx, instance, body)
27-
},
2821
..*providers
2922
}
3023
}

0 commit comments

Comments
 (0)