Skip to content

Commit 0bf6ad3

Browse files
authored
Unrolled build for rust-lang#132385
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 24254ef + 8a0e640 commit 0bf6ad3

File tree

20 files changed

+47
-25
lines changed

20 files changed

+47
-25
lines changed

Cargo.lock

+5-3
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

+4
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

+3-1
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

+8
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

+1-1
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

+3-3
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

+1-1
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

+2-2
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

+2-1
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

compiler/rustc_mir_build/src/build/custom/parse/instruction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_abi::{FieldIdx, VariantIdx};
12
use rustc_middle::mir::interpret::Scalar;
23
use rustc_middle::mir::tcx::PlaceTy;
34
use rustc_middle::mir::*;
@@ -6,7 +7,6 @@ use rustc_middle::ty;
67
use rustc_middle::ty::cast::mir_cast_kind;
78
use rustc_span::Span;
89
use rustc_span::source_map::Spanned;
9-
use rustc_target::abi::{FieldIdx, VariantIdx};
1010

1111
use super::{PResult, ParseCtxt, parse_by_kind};
1212
use crate::build::custom::ParseError;

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! See docs in build/expr/mod.rs
22
3+
use rustc_abi::Size;
34
use rustc_ast as ast;
45
use rustc_hir::LangItem;
56
use rustc_middle::mir::interpret::{
@@ -11,7 +12,6 @@ use rustc_middle::ty::{
1112
self, CanonicalUserType, CanonicalUserTypeAnnotation, Ty, TyCtxt, UserTypeAnnotationIndex,
1213
};
1314
use rustc_middle::{bug, mir, span_bug};
14-
use rustc_target::abi::Size;
1515
use tracing::{instrument, trace};
1616

1717
use crate::build::{Builder, parse_float_into_constval};

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::assert_matches::assert_matches;
44
use std::iter;
55

6+
use rustc_abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
67
use rustc_hir::def_id::LocalDefId;
78
use rustc_middle::hir::place::{Projection as HirProjection, ProjectionKind as HirProjectionKind};
89
use rustc_middle::middle::region;
@@ -12,7 +13,6 @@ use rustc_middle::thir::*;
1213
use rustc_middle::ty::{self, AdtDef, CanonicalUserTypeAnnotation, Ty, Variance};
1314
use rustc_middle::{bug, span_bug};
1415
use rustc_span::Span;
15-
use rustc_target::abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
1616
use tracing::{debug, instrument, trace};
1717

1818
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! See docs in `build/expr/mod.rs`.
22
3+
use rustc_abi::{BackendRepr, FieldIdx, Primitive};
34
use rustc_hir::lang_items::LangItem;
45
use rustc_index::{Idx, IndexVec};
56
use rustc_middle::bug;
@@ -13,7 +14,6 @@ use rustc_middle::ty::util::IntTypeExt;
1314
use rustc_middle::ty::{self, Ty, UpvarArgs};
1415
use rustc_span::source_map::Spanned;
1516
use rustc_span::{DUMMY_SP, Span};
16-
use rustc_target::abi::{BackendRepr, FieldIdx, Primitive};
1717
use tracing::debug;
1818

1919
use crate::build::expr::as_place::PlaceBase;

compiler/rustc_mir_build/src/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! This also includes code for pattern bindings in `let` statements and
66
//! function parameters.
77
8+
use rustc_abi::VariantIdx;
89
use rustc_data_structures::fx::FxIndexMap;
910
use rustc_data_structures::stack::ensure_sufficient_stack;
1011
use rustc_hir::{BindingMode, ByRef};
@@ -15,7 +16,6 @@ use rustc_middle::thir::{self, *};
1516
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
1617
use rustc_span::symbol::Symbol;
1718
use rustc_span::{BytePos, Pos, Span};
18-
use rustc_target::abi::VariantIdx;
1919
use tracing::{debug, instrument};
2020

2121
use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};

compiler/rustc_mir_build/src/build/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use itertools::Itertools;
2+
use rustc_abi::{ExternAbi, FieldIdx};
23
use rustc_apfloat::Float;
34
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
45
use rustc_ast::attr;
@@ -20,8 +21,6 @@ use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt, TypeVisitableExt, TypingMode
2021
use rustc_middle::{bug, span_bug};
2122
use rustc_span::symbol::sym;
2223
use rustc_span::{Span, Symbol};
23-
use rustc_target::abi::FieldIdx;
24-
use rustc_target::spec::abi::Abi;
2524

2625
use super::lints;
2726
use crate::build::expr::as_place::PlaceBuilder;
@@ -467,7 +466,7 @@ fn construct_fn<'tcx>(
467466
if let DefKind::Closure = tcx.def_kind(fn_def) {
468467
// HACK(eddyb) Avoid having RustCall on closures,
469468
// as it adds unnecessary (and wrong) auto-tupling.
470-
abi = Abi::Rust;
469+
abi = ExternAbi::Rust;
471470
}
472471

473472
let arguments = &thir.params;
@@ -540,7 +539,7 @@ fn construct_fn<'tcx>(
540539

541540
let mut body = builder.finish();
542541

543-
body.spread_arg = if abi == Abi::RustCall {
542+
body.spread_arg = if abi == ExternAbi::RustCall {
544543
// RustCall pseudo-ABI untuples the last argument.
545544
Some(Local::new(arguments.len()))
546545
} else {

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use itertools::Itertools;
2+
use rustc_abi::{FIRST_VARIANT, FieldIdx};
23
use rustc_data_structures::stack::ensure_sufficient_stack;
34
use rustc_hir as hir;
45
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
@@ -18,7 +19,6 @@ use rustc_middle::ty::{
1819
};
1920
use rustc_middle::{bug, span_bug};
2021
use rustc_span::{Span, sym};
21-
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
2222
use tracing::{debug, info, instrument, trace};
2323

2424
use crate::errors;

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use either::Either;
2+
use rustc_abi::{FieldIdx, VariantIdx};
23
use rustc_apfloat::Float;
34
use rustc_hir as hir;
45
use rustc_index::Idx;
@@ -9,7 +10,6 @@ use rustc_middle::mir::interpret::ErrorHandled;
910
use rustc_middle::thir::{FieldPat, Pat, PatKind};
1011
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypingMode, ValTree};
1112
use rustc_span::Span;
12-
use rustc_target::abi::{FieldIdx, VariantIdx};
1313
use rustc_trait_selection::traits::ObligationCause;
1414
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
1515
use tracing::{debug, instrument, trace};

compiler/rustc_mir_build/src/thir/pattern/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod const_to_pat;
55

66
use std::cmp::Ordering;
77

8+
use rustc_abi::{FieldIdx, Integer};
89
use rustc_errors::codes::*;
910
use rustc_hir::def::{CtorOf, DefKind, Res};
1011
use rustc_hir::pat_util::EnumerateAndAdjustIterator;
@@ -20,7 +21,6 @@ use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, TyCtxt, TypeVisita
2021
use rustc_middle::{bug, span_bug};
2122
use rustc_span::def_id::LocalDefId;
2223
use rustc_span::{ErrorGuaranteed, Span};
23-
use rustc_target::abi::{FieldIdx, Integer};
2424
use tracing::{debug, instrument};
2525

2626
pub(crate) use self::check_match::check_match;

compiler/rustc_target/src/spec/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ use crate::json::{Json, ToJson};
5555
use crate::spec::abi::Abi;
5656
use crate::spec::crt_objects::CrtObjects;
5757

58-
pub mod abi;
5958
pub mod crt_objects;
6059

60+
pub mod abi {
61+
pub use rustc_abi::{
62+
AbiDisabled, AbiUnsupported, ExternAbi as Abi, all_names, enabled_names, is_enabled,
63+
is_stable, lookup,
64+
};
65+
}
66+
6167
mod base;
6268
pub use base::apple::{
6369
deployment_target_for_target as current_apple_deployment_target,

0 commit comments

Comments
 (0)