Skip to content

Commit af49554

Browse files
committed
move rustc_codegen_ssa::target_features somewhere where it can be used by all codegen backends
1 parent e7f4317 commit af49554

File tree

10 files changed

+55
-52
lines changed

10 files changed

+55
-52
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
codegen_ssa_L4Bender_exporting_symbols_unimplemented = exporting symbols not implemented yet for L4Bender
22
3-
codegen_ssa_aarch64_softfloat_neon = enabling the `neon` target feature on the current target is unsound due to ABI issues
4-
53
codegen_ssa_add_native_library = failed to add native library {$library_path}: {$error}
64
75
codegen_ssa_aix_strip_not_used = using host's `strip` binary to cross-compile to AIX which is not guaranteed to work
@@ -70,9 +68,6 @@ codegen_ssa_failed_to_write = failed to write {$path}: {$error}
7068
7169
codegen_ssa_field_associated_value_expected = associated value expected for `{$name}`
7270
73-
codegen_ssa_forbidden_target_feature_attr =
74-
target feature `{$feature}` cannot be enabled with `#[target_feature]`: {$reason}
75-
7671
codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extension} files were produced
7772
7873
codegen_ssa_ignoring_output = ignoring -o because multiple .{$extension} files were produced
@@ -278,10 +273,6 @@ codegen_ssa_symbol_file_write_failure = failed to write symbols file: {$error}
278273
codegen_ssa_target_feature_disable_or_enable =
279274
the target features {$features} must all be either enabled or disabled together
280275
281-
codegen_ssa_target_feature_safe_trait = `#[target_feature(..)]` cannot be applied to safe trait method
282-
.label = cannot be applied to safe trait method
283-
.label_def = not an `unsafe` function
284-
285276
codegen_ssa_thorin_decompress_data = failed to decompress compressed section
286277
287278
codegen_ssa_thorin_duplicate_unit = duplicate split compilation unit ({$unit})

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_middle::middle::codegen_fn_attrs::{
1616
use rustc_middle::mir::mono::Linkage;
1717
use rustc_middle::query::Providers;
1818
use rustc_middle::span_bug;
19+
use rustc_middle::target_features::{check_target_feature_trait_unsafe, from_target_feature_attr};
1920
use rustc_middle::ty::{self as ty, TyCtxt};
2021
use rustc_session::parse::feature_err;
2122
use rustc_session::{Session, lint};
@@ -24,7 +25,6 @@ use rustc_target::spec::SanitizerSet;
2425
use tracing::debug;
2526

2627
use crate::errors;
27-
use crate::target_features::{check_target_feature_trait_unsafe, from_target_feature_attr};
2828

2929
fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
3030
use rustc_middle::mir::mono::Linkage::*;

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,25 +1182,6 @@ pub(crate) struct InvalidLinkOrdinalFormat {
11821182
pub span: Span,
11831183
}
11841184

1185-
#[derive(Diagnostic)]
1186-
#[diag(codegen_ssa_target_feature_safe_trait)]
1187-
pub(crate) struct TargetFeatureSafeTrait {
1188-
#[primary_span]
1189-
#[label]
1190-
pub span: Span,
1191-
#[label(codegen_ssa_label_def)]
1192-
pub def: Span,
1193-
}
1194-
1195-
#[derive(Diagnostic)]
1196-
#[diag(codegen_ssa_forbidden_target_feature_attr)]
1197-
pub struct ForbiddenTargetFeatureAttr<'a> {
1198-
#[primary_span]
1199-
pub span: Span,
1200-
pub feature: &'a str,
1201-
pub reason: &'a str,
1202-
}
1203-
12041185
#[derive(Diagnostic)]
12051186
#[diag(codegen_ssa_failed_to_get_layout)]
12061187
pub struct FailedToGetLayout<'tcx> {
@@ -1316,7 +1297,3 @@ pub(crate) struct XcrunSdkPathWarning {
13161297
pub sdk_name: &'static str,
13171298
pub stderr: String,
13181299
}
1319-
1320-
#[derive(LintDiagnostic)]
1321-
#[diag(codegen_ssa_aarch64_softfloat_neon)]
1322-
pub(crate) struct Aarch64SoftfloatNeon;

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pub mod meth;
5858
pub mod mir;
5959
pub mod mono_item;
6060
pub mod size_of_val;
61-
pub mod target_features;
6261
pub mod traits;
6362

6463
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
@@ -273,7 +272,6 @@ pub enum CodegenErrors {
273272
pub fn provide(providers: &mut Providers) {
274273
crate::back::symbol_export::provide(providers);
275274
crate::base::provide(providers);
276-
crate::target_features::provide(providers);
277275
crate::codegen_attrs::provide(providers);
278276
providers.queries.global_backend_features = |_tcx: TyCtxt<'_>, ()| vec![];
279277
}

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
786786
limits::provide(providers);
787787
proc_macro_decls::provide(providers);
788788
rustc_const_eval::provide(providers);
789-
rustc_middle::hir::provide(providers);
789+
rustc_middle::provide(providers);
790790
rustc_borrowck::provide(providers);
791791
rustc_incremental::provide(providers);
792792
rustc_mir_build::provide(providers);

compiler/rustc_middle/messages.ftl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
middle_aarch64_softfloat_neon = enabling the `neon` target feature on the current target is unsound due to ABI issues
2+
13
middle_assert_async_resume_after_drop = `async fn` resumed after async drop
24
35
middle_assert_async_resume_after_panic = `async fn` resumed after panicking
@@ -78,6 +80,9 @@ middle_erroneous_constant = erroneous constant encountered
7880
middle_failed_writing_file =
7981
failed to write file {$path}: {$error}"
8082
83+
middle_forbidden_target_feature_attr =
84+
target feature `{$feature}` cannot be enabled with `#[target_feature]`: {$reason}
85+
8186
middle_layout_cycle =
8287
a cycle occurred during layout computation
8388
@@ -112,6 +117,10 @@ middle_strict_coherence_needs_negative_coherence =
112117
to use `strict_coherence` on this trait, the `with_negative_coherence` feature must be enabled
113118
.label = due to this attribute
114119
120+
middle_target_feature_safe_trait = `#[target_feature(..)]` cannot be applied to safe trait method
121+
.label = cannot be applied to safe trait method
122+
.label_def = not an `unsafe` function
123+
115124
middle_type_length_limit = reached the type-length limit while instantiating `{$shrunk}`
116125
117126
middle_unsupported_union = we don't support unions yet: '{$ty_name}'

compiler/rustc_middle/src/error.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{fmt, io};
33

44
use rustc_errors::codes::*;
55
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage};
6-
use rustc_macros::{Diagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
77
use rustc_span::{Span, Symbol};
88

99
use crate::ty::Ty;
@@ -170,3 +170,26 @@ pub(crate) struct TypeLengthLimit {
170170
pub path: PathBuf,
171171
pub type_length: usize,
172172
}
173+
174+
#[derive(Diagnostic)]
175+
#[diag(middle_forbidden_target_feature_attr)]
176+
pub struct ForbiddenTargetFeatureAttr<'a> {
177+
#[primary_span]
178+
pub span: Span,
179+
pub feature: &'a str,
180+
pub reason: &'a str,
181+
}
182+
183+
#[derive(LintDiagnostic)]
184+
#[diag(middle_aarch64_softfloat_neon)]
185+
pub(crate) struct Aarch64SoftfloatNeon;
186+
187+
#[derive(Diagnostic)]
188+
#[diag(middle_target_feature_safe_trait)]
189+
pub(crate) struct TargetFeatureSafeTrait {
190+
#[primary_span]
191+
#[label]
192+
pub span: Span,
193+
#[label(middle_label_def)]
194+
pub def: Span,
195+
}

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'tcx> TyCtxt<'tcx> {
177177
}
178178
}
179179

180-
pub fn provide(providers: &mut Providers) {
180+
pub(crate) fn provide(providers: &mut Providers) {
181181
providers.hir_crate_items = map::hir_crate_items;
182182
providers.crate_hash = map::crate_hash;
183183
providers.hir_module_items = map::hir_module_items;

compiler/rustc_middle/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub mod lint;
7878
pub mod metadata;
7979
pub mod middle;
8080
pub mod mir;
81+
pub mod target_features;
8182
pub mod thir;
8283
pub mod traits;
8384
pub mod ty;
@@ -93,3 +94,8 @@ pub mod dep_graph;
9394
extern crate self as rustc_middle;
9495

9596
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
97+
98+
pub fn provide(providers: &mut util::Providers) {
99+
hir::provide(providers);
100+
target_features::provide(providers);
101+
}

compiler/rustc_codegen_ssa/src/target_features.rs renamed to compiler/rustc_middle/src/target_features.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1+
//! Shared utilities for dealing with target features that haven't (yet) found a better home.
12
use rustc_attr_data_structures::InstructionSetAttr;
23
use rustc_data_structures::fx::FxIndexSet;
34
use rustc_data_structures::unord::{UnordMap, UnordSet};
45
use rustc_errors::Applicability;
56
use rustc_hir as hir;
67
use rustc_hir::def::DefKind;
78
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
8-
use rustc_middle::middle::codegen_fn_attrs::TargetFeature;
9-
use rustc_middle::query::Providers;
10-
use rustc_middle::ty::TyCtxt;
11-
use rustc_session::lint::builtin::AARCH64_SOFTFLOAT_NEON;
9+
use rustc_lint_defs::builtin::AARCH64_SOFTFLOAT_NEON;
1210
use rustc_session::parse::feature_err;
1311
use rustc_span::{Span, Symbol, sym};
1412
use rustc_target::target_features::{self, Stability};
1513

16-
use crate::errors;
14+
use crate::error;
15+
use crate::middle::codegen_fn_attrs::TargetFeature;
16+
use crate::query::Providers;
17+
use crate::ty::TyCtxt;
1718

1819
/// Compute the enabled target features from the `#[target_feature]` function attribute.
1920
/// Enabled target features are added to `target_features`.
20-
pub(crate) fn from_target_feature_attr(
21+
pub fn from_target_feature_attr(
2122
tcx: TyCtxt<'_>,
2223
did: LocalDefId,
2324
attr: &hir::Attribute,
@@ -67,7 +68,7 @@ pub(crate) fn from_target_feature_attr(
6768
// Only allow target features whose feature gates have been enabled
6869
// and which are permitted to be toggled.
6970
if let Err(reason) = stability.toggle_allowed() {
70-
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
71+
tcx.dcx().emit_err(error::ForbiddenTargetFeatureAttr {
7172
span: item.span(),
7273
feature,
7374
reason,
@@ -101,10 +102,10 @@ pub(crate) fn from_target_feature_attr(
101102
AARCH64_SOFTFLOAT_NEON,
102103
tcx.local_def_id_to_hir_id(did),
103104
item.span(),
104-
errors::Aarch64SoftfloatNeon,
105+
error::Aarch64SoftfloatNeon,
105106
);
106107
} else {
107-
tcx.dcx().emit_err(errors::ForbiddenTargetFeatureAttr {
108+
tcx.dcx().emit_err(error::ForbiddenTargetFeatureAttr {
108109
span: item.span(),
109110
feature: name.as_str(),
110111
reason: "this feature is incompatible with the target ABI",
@@ -143,14 +144,12 @@ fn asm_target_features(tcx: TyCtxt<'_>, did: DefId) -> &FxIndexSet<Symbol> {
143144

144145
/// Checks the function annotated with `#[target_feature]` is not a safe
145146
/// trait method implementation, reporting an error if it is.
146-
pub(crate) fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
147+
pub fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
147148
if let DefKind::AssocFn = tcx.def_kind(id) {
148149
let parent_id = tcx.local_parent(id);
149150
if let DefKind::Trait | DefKind::Impl { of_trait: true } = tcx.def_kind(parent_id) {
150-
tcx.dcx().emit_err(errors::TargetFeatureSafeTrait {
151-
span: attr_span,
152-
def: tcx.def_span(id),
153-
});
151+
tcx.dcx()
152+
.emit_err(error::TargetFeatureSafeTrait { span: attr_span, def: tcx.def_span(id) });
154153
}
155154
}
156155
}

0 commit comments

Comments
 (0)