Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3329559

Browse files
authored
Rollup merge of rust-lang#132385 - workingjubilee:move-abi-to-rustc-abi, r=jieyouxu,compiler-errors
compiler: Move `rustc_target::spec::abi::Abi` to `rustc_abi::ExternAbi` Lift `enum Abi` from its rather odd place in the middle of rustc_target, and make it available again from rustc_abi. You know, the crate where you would expect the enum that describes all the ABIs to be? The platform-neutral ones, at least. This will help further refactoring of how we handle ABIs in the near future[^0]. Rename `Abi` to `ExternAbi` because quite a lot of the compiler overloads the concept of "ABI" enough that the existing name is imprecise and it is often renamed _anyway_. Often this was to avoid conflicts with the *other* type formerly known as `Abi` (now named BackendRepr[^1]), but sometimes it is just for clarity, and this name seems more self-explanatory. It does get reexported, though, using its old name, to reduce the odds of merge-conflicting over the entire tree. All of `ExternAbi`'s friends come along for the ride, which costs adding some optional dependencies to the rustc_abi crate. However, all of this also allows simply moving three crates entirely off rustc_target: - rustc_hir_pretty - rustc_lint_defs - rustc_mir_build This odd selection is mostly to demonstrate a secondary motivation: The majority of the front-end of the compiler should be as target-agnostic as possible, and it is easier to assure this if they simply don't depend on the crate that describes targets. Note that I didn't migrate crates that don't benefit from it in this way yet, and I didn't survey every last crate. [^0]: This is being undertaken as part of rust-lang#119183 [^1]: rust-lang#132246
2 parents a7bdfe2 + 8a0e640 commit 3329559

File tree

20 files changed

+47
-25
lines changed

20 files changed

+47
-25
lines changed

Cargo.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,9 +3204,11 @@ dependencies = [
32043204
"rand",
32053205
"rand_xoshiro",
32063206
"rustc_data_structures",
3207+
"rustc_feature",
32073208
"rustc_index",
32083209
"rustc_macros",
32093210
"rustc_serialize",
3211+
"rustc_span",
32103212
"tracing",
32113213
]
32123214

@@ -3749,11 +3751,11 @@ dependencies = [
37493751
name = "rustc_hir_pretty"
37503752
version = "0.0.0"
37513753
dependencies = [
3754+
"rustc_abi",
37523755
"rustc_ast",
37533756
"rustc_ast_pretty",
37543757
"rustc_hir",
37553758
"rustc_span",
3756-
"rustc_target",
37573759
]
37583760

37593761
[[package]]
@@ -3938,14 +3940,14 @@ dependencies = [
39383940
name = "rustc_lint_defs"
39393941
version = "0.0.0"
39403942
dependencies = [
3943+
"rustc_abi",
39413944
"rustc_ast",
39423945
"rustc_data_structures",
39433946
"rustc_error_messages",
39443947
"rustc_hir",
39453948
"rustc_macros",
39463949
"rustc_serialize",
39473950
"rustc_span",
3948-
"rustc_target",
39493951
"serde",
39503952
]
39513953

@@ -4054,6 +4056,7 @@ version = "0.0.0"
40544056
dependencies = [
40554057
"either",
40564058
"itertools",
4059+
"rustc_abi",
40574060
"rustc_apfloat",
40584061
"rustc_arena",
40594062
"rustc_ast",
@@ -4069,7 +4072,6 @@ dependencies = [
40694072
"rustc_pattern_analysis",
40704073
"rustc_session",
40714074
"rustc_span",
4072-
"rustc_target",
40734075
"rustc_trait_selection",
40744076
"tracing",
40754077
]

compiler/rustc_abi/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ bitflags = "2.4.1"
99
rand = { version = "0.8.4", default-features = false, optional = true }
1010
rand_xoshiro = { version = "0.6.0", optional = true }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
12+
rustc_feature = { path = "../rustc_feature", optional = true }
1213
rustc_index = { path = "../rustc_index", default-features = false }
1314
rustc_macros = { path = "../rustc_macros", optional = true }
1415
rustc_serialize = { path = "../rustc_serialize", optional = true }
16+
rustc_span = { path = "../rustc_span", optional = true }
1517
tracing = "0.1"
1618
# tidy-alphabetical-end
1719

@@ -22,8 +24,10 @@ default = ["nightly", "randomize"]
2224
# without depending on rustc_data_structures, rustc_macros and rustc_serialize
2325
nightly = [
2426
"dep:rustc_data_structures",
27+
"dep:rustc_feature",
2528
"dep:rustc_macros",
2629
"dep:rustc_serialize",
30+
"dep:rustc_span",
2731
"rustc_index/nightly",
2832
]
2933
randomize = ["dep:rand", "dep:rand_xoshiro", "nightly"]

compiler/rustc_target/src/spec/abi/mod.rs renamed to compiler/rustc_abi/src/extern_abi/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use rustc_span::{Span, Symbol};
77
#[cfg(test)]
88
mod tests;
99

10+
use ExternAbi as Abi;
11+
1012
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
1113
#[derive(HashStable_Generic, Encodable, Decodable)]
12-
pub enum Abi {
14+
pub enum ExternAbi {
1315
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
1416
// hashing tests. These are used in many places, so giving them stable values reduces test
1517
// churn. The specific values are meaningless.

compiler/rustc_abi/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![cfg_attr(feature = "nightly", allow(internal_features))]
33
#![cfg_attr(feature = "nightly", doc(rust_logo))]
4+
#![cfg_attr(feature = "nightly", feature(assert_matches))]
45
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
56
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
67
#![cfg_attr(feature = "nightly", feature(step_trait))]
@@ -28,8 +29,15 @@ mod layout;
2829
#[cfg(test)]
2930
mod tests;
3031

32+
#[cfg(feature = "nightly")]
33+
mod extern_abi;
34+
3135
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
3236
#[cfg(feature = "nightly")]
37+
pub use extern_abi::{
38+
AbiDisabled, AbiUnsupported, ExternAbi, all_names, enabled_names, is_enabled, is_stable, lookup,
39+
};
40+
#[cfg(feature = "nightly")]
3341
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
3442
pub use layout::{LayoutCalculator, LayoutCalculatorError};
3543

compiler/rustc_hir_pretty/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1011
rustc_hir = { path = "../rustc_hir" }
1112
rustc_span = { path = "../rustc_span" }
12-
rustc_target = { path = "../rustc_target" }
1313
# tidy-alphabetical-end

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use std::cell::Cell;
1010
use std::vec;
1111

12+
use rustc_abi::ExternAbi;
1213
use rustc_ast::util::parser::{self, AssocOp, Fixity};
1314
use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent};
1415
use rustc_ast_pretty::pp::{self, Breaks};
@@ -20,7 +21,6 @@ use rustc_hir::{
2021
use rustc_span::FileName;
2122
use rustc_span::source_map::SourceMap;
2223
use rustc_span::symbol::{Ident, Symbol, kw};
23-
use rustc_target::spec::abi::Abi;
2424
use {rustc_ast as ast, rustc_hir as hir};
2525

2626
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String {
@@ -2240,7 +2240,7 @@ impl<'a> State<'a> {
22402240

22412241
fn print_ty_fn(
22422242
&mut self,
2243-
abi: Abi,
2243+
abi: ExternAbi,
22442244
safety: hir::Safety,
22452245
decl: &hir::FnDecl<'_>,
22462246
name: Option<Symbol>,
@@ -2276,7 +2276,7 @@ impl<'a> State<'a> {
22762276

22772277
self.print_safety(header.safety);
22782278

2279-
if header.abi != Abi::Rust {
2279+
if header.abi != ExternAbi::Rust {
22802280
self.word_nbsp("extern");
22812281
self.word_nbsp(header.abi.to_string());
22822282
}

compiler/rustc_lint_defs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_data_structures = { path = "../rustc_data_structures" }
1011
rustc_error_messages = { path = "../rustc_error_messages" }
1112
rustc_hir = { path = "../rustc_hir" }
1213
rustc_macros = { path = "../rustc_macros" }
1314
rustc_serialize = { path = "../rustc_serialize" }
1415
rustc_span = { path = "../rustc_span" }
15-
rustc_target = { path = "../rustc_target" }
1616
serde = { version = "1.0.125", features = ["derive"] }
1717
# tidy-alphabetical-end

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![warn(unreachable_pub)]
33
// tidy-alphabetical-end
44

5+
use rustc_abi::ExternAbi;
56
use rustc_ast::node_id::NodeId;
67
use rustc_ast::{AttrId, Attribute};
78
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
@@ -15,7 +16,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1516
pub use rustc_span::edition::Edition;
1617
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
1718
use rustc_span::{Span, Symbol, sym};
18-
use rustc_target::spec::abi::Abi;
1919
use serde::{Deserialize, Serialize};
2020

2121
pub use self::Level::*;
@@ -602,7 +602,7 @@ pub enum BuiltinLintDiag {
602602
path: String,
603603
since_kind: DeprecatedSinceKind,
604604
},
605-
MissingAbi(Span, Abi),
605+
MissingAbi(Span, ExternAbi),
606606
UnusedDocComment(Span),
607607
UnusedBuiltinAttribute {
608608
attr_name: Symbol,

compiler/rustc_mir_build/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ edition = "2021"
77
# tidy-alphabetical-start
88
either = "1.5.0"
99
itertools = "0.12"
10+
11+
rustc_abi = { path = "../rustc_abi" }
1012
rustc_apfloat = "0.2.0"
1113
rustc_arena = { path = "../rustc_arena" }
1214
rustc_ast = { path = "../rustc_ast" }
@@ -22,7 +24,6 @@ rustc_middle = { path = "../rustc_middle" }
2224
rustc_pattern_analysis = { path = "../rustc_pattern_analysis" }
2325
rustc_session = { path = "../rustc_session" }
2426
rustc_span = { path = "../rustc_span" }
25-
rustc_target = { path = "../rustc_target" }
2627
rustc_trait_selection = { path = "../rustc_trait_selection" }
2728
tracing = "0.1"
2829
# tidy-alphabetical-end

0 commit comments

Comments
 (0)