Skip to content

Commit 41b5796

Browse files
committed
Auto merge of #134952 - Zalathar:rollup-i6g97md, r=Zalathar
Rollup of 8 pull requests Successful merges: - #134919 (bootstrap: Make `./x test compiler` actually run the compiler unit tests) - #134927 (Make slice::as_flattened_mut unstably const) - #134930 (ptr docs: make it clear that we are talking only about memory accesses) - #134932 (explicitly set float ABI for all ARM targets) - #134933 (Make sure we check the future type is `Sized` in `AsyncFn*`) - #134934 (Fix typos) - #134941 (compiler: Add a statement-of-intent to `rustc_abi`) - #134949 (Convert some `Into` impls into `From` impls) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 80f5a81 + 2491eda commit 41b5796

File tree

84 files changed

+440
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+440
-162
lines changed

compiler/rustc_abi/src/lib.rs

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,38 @@
88
#![warn(unreachable_pub)]
99
// tidy-alphabetical-end
1010

11+
/*! ABI handling for rustc
12+
13+
## What is an "ABI"?
14+
15+
Literally, "application binary interface", which means it is everything about how code interacts,
16+
at the machine level, with other code. This means it technically covers all of the following:
17+
- object binary format for e.g. relocations or offset tables
18+
- in-memory layout of types
19+
- procedure calling conventions
20+
21+
When we discuss "ABI" in the context of rustc, we are probably discussing calling conventions.
22+
To describe those `rustc_abi` also covers type layout, as it must for values passed on the stack.
23+
Despite `rustc_abi` being about calling conventions, it is good to remember these usages exist.
24+
You will encounter all of them and more if you study target-specific codegen enough!
25+
Even in general conversation, when someone says "the Rust ABI is unstable", it may allude to
26+
either or both of
27+
- `repr(Rust)` types have a mostly-unspecified layout
28+
- `extern "Rust" fn(A) -> R` has an unspecified calling convention
29+
30+
## Crate Goal
31+
32+
ABI is a foundational concept, so the `rustc_abi` crate serves as an equally foundational crate.
33+
It cannot carry all details relevant to an ABI: those permeate code generation and linkage.
34+
Instead, `rustc_abi` is intended to provide the interface for reasoning about the binary interface.
35+
It should contain traits and types that other crates then use in their implementation.
36+
For example, a platform's `extern "C" fn` calling convention will be implemented in `rustc_target`
37+
but `rustc_abi` contains the types for calculating layout and describing register-passing.
38+
This makes it easier to describe things in the same way across targets, codegen backends, and
39+
even other Rust compilers, such as rust-analyzer!
40+
41+
*/
42+
1143
use std::fmt;
1244
#[cfg(feature = "nightly")]
1345
use std::iter::Step;

compiler/rustc_ast/src/ast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,15 @@ impl AngleBracketedArg {
241241
}
242242
}
243243

244-
impl Into<P<GenericArgs>> for AngleBracketedArgs {
245-
fn into(self) -> P<GenericArgs> {
246-
P(GenericArgs::AngleBracketed(self))
244+
impl From<AngleBracketedArgs> for P<GenericArgs> {
245+
fn from(val: AngleBracketedArgs) -> Self {
246+
P(GenericArgs::AngleBracketed(val))
247247
}
248248
}
249249

250-
impl Into<P<GenericArgs>> for ParenthesizedArgs {
251-
fn into(self) -> P<GenericArgs> {
252-
P(GenericArgs::Parenthesized(self))
250+
impl From<ParenthesizedArgs> for P<GenericArgs> {
251+
fn from(val: ParenthesizedArgs) -> Self {
252+
P(GenericArgs::Parenthesized(val))
253253
}
254254
}
255255

compiler/rustc_ast/src/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ impl<T> From<Vec<T>> for P<[T]> {
158158
}
159159
}
160160

161-
impl<T> Into<Vec<T>> for P<[T]> {
162-
fn into(self) -> Vec<T> {
163-
self.into_vec()
161+
impl<T> From<P<[T]>> for Vec<T> {
162+
fn from(val: P<[T]>) -> Self {
163+
val.into_vec()
164164
}
165165
}
166166

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl OwnedTargetMachine {
2525
model: llvm::CodeModel,
2626
reloc: llvm::RelocModel,
2727
level: llvm::CodeGenOptLevel,
28-
use_soft_fp: bool,
28+
float_abi: llvm::FloatAbi,
2929
function_sections: bool,
3030
data_sections: bool,
3131
unique_section_names: bool,
@@ -57,7 +57,7 @@ impl OwnedTargetMachine {
5757
model,
5858
reloc,
5959
level,
60-
use_soft_fp,
60+
float_abi,
6161
function_sections,
6262
data_sections,
6363
unique_section_names,

compiler/rustc_codegen_llvm/src/back/write.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_session::config::{
2626
self, Lto, OutputType, Passes, RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath,
2727
};
2828
use rustc_span::{BytePos, InnerSpan, Pos, SpanData, SyntaxContext, sym};
29-
use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
29+
use rustc_target::spec::{CodeModel, FloatAbi, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
3030
use tracing::debug;
3131

3232
use crate::back::lto::ThinBuffer;
@@ -181,6 +181,14 @@ pub(crate) fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeMod
181181
}
182182
}
183183

184+
fn to_llvm_float_abi(float_abi: Option<FloatAbi>) -> llvm::FloatAbi {
185+
match float_abi {
186+
None => llvm::FloatAbi::Default,
187+
Some(FloatAbi::Soft) => llvm::FloatAbi::Soft,
188+
Some(FloatAbi::Hard) => llvm::FloatAbi::Hard,
189+
}
190+
}
191+
184192
pub(crate) fn target_machine_factory(
185193
sess: &Session,
186194
optlvl: config::OptLevel,
@@ -189,12 +197,12 @@ pub(crate) fn target_machine_factory(
189197
let reloc_model = to_llvm_relocation_model(sess.relocation_model());
190198

191199
let (opt_level, _) = to_llvm_opt_settings(optlvl);
192-
let use_softfp = if sess.target.arch == "arm" {
193-
sess.opts.cg.soft_float
200+
let float_abi = if sess.target.arch == "arm" && sess.opts.cg.soft_float {
201+
llvm::FloatAbi::Soft
194202
} else {
195203
// `validate_commandline_args_with_session_available` has already warned about this being
196204
// ignored. Let's make sure LLVM doesn't suddenly start using this flag on more targets.
197-
false
205+
to_llvm_float_abi(sess.target.llvm_floatabi)
198206
};
199207

200208
let ffunction_sections =
@@ -290,7 +298,7 @@ pub(crate) fn target_machine_factory(
290298
code_model,
291299
reloc_model,
292300
opt_level,
293-
use_softfp,
301+
float_abi,
294302
ffunction_sections,
295303
fdata_sections,
296304
funique_section_names,

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ pub struct SanitizerOptions {
526526
pub sanitize_kernel_address_recover: bool,
527527
}
528528

529-
/// LLVMRelocMode
529+
/// LLVMRustRelocModel
530530
#[derive(Copy, Clone, PartialEq)]
531531
#[repr(C)]
532532
pub enum RelocModel {
@@ -538,6 +538,15 @@ pub enum RelocModel {
538538
ROPI_RWPI,
539539
}
540540

541+
/// LLVMRustFloatABI
542+
#[derive(Copy, Clone, PartialEq)]
543+
#[repr(C)]
544+
pub enum FloatAbi {
545+
Default,
546+
Soft,
547+
Hard,
548+
}
549+
541550
/// LLVMRustCodeModel
542551
#[derive(Copy, Clone)]
543552
#[repr(C)]
@@ -2192,7 +2201,7 @@ unsafe extern "C" {
21922201
Model: CodeModel,
21932202
Reloc: RelocModel,
21942203
Level: CodeGenOptLevel,
2195-
UseSoftFP: bool,
2204+
FloatABIType: FloatAbi,
21962205
FunctionSections: bool,
21972206
DataSections: bool,
21982207
UniqueSectionNames: bool,

compiler/rustc_error_messages/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ impl From<Cow<'static, str>> for DiagMessage {
357357
/// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be
358358
/// able to convert between these, as much as they'll be converted back into `DiagMessage`
359359
/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive.
360-
impl Into<SubdiagMessage> for DiagMessage {
361-
fn into(self) -> SubdiagMessage {
362-
match self {
360+
impl From<DiagMessage> for SubdiagMessage {
361+
fn from(val: DiagMessage) -> Self {
362+
match val {
363363
DiagMessage::Str(s) => SubdiagMessage::Str(s),
364364
DiagMessage::Translated(s) => SubdiagMessage::Translated(s),
365365
DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::FluentIdentifier(id),

compiler/rustc_errors/src/diagnostic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ impl IntoDiagArg for DiagArgValue {
156156
}
157157
}
158158

159-
impl Into<FluentValue<'static>> for DiagArgValue {
160-
fn into(self) -> FluentValue<'static> {
161-
match self {
159+
impl From<DiagArgValue> for FluentValue<'static> {
160+
fn from(val: DiagArgValue) -> Self {
161+
match val {
162162
DiagArgValue::Str(s) => From::from(s),
163163
DiagArgValue::Number(n) => From::from(n),
164164
DiagArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l),

compiler/rustc_hir/src/hir.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -4072,33 +4072,33 @@ impl<'hir> OwnerNode<'hir> {
40724072
}
40734073
}
40744074

4075-
impl<'hir> Into<OwnerNode<'hir>> for &'hir Item<'hir> {
4076-
fn into(self) -> OwnerNode<'hir> {
4077-
OwnerNode::Item(self)
4075+
impl<'hir> From<&'hir Item<'hir>> for OwnerNode<'hir> {
4076+
fn from(val: &'hir Item<'hir>) -> Self {
4077+
OwnerNode::Item(val)
40784078
}
40794079
}
40804080

4081-
impl<'hir> Into<OwnerNode<'hir>> for &'hir ForeignItem<'hir> {
4082-
fn into(self) -> OwnerNode<'hir> {
4083-
OwnerNode::ForeignItem(self)
4081+
impl<'hir> From<&'hir ForeignItem<'hir>> for OwnerNode<'hir> {
4082+
fn from(val: &'hir ForeignItem<'hir>) -> Self {
4083+
OwnerNode::ForeignItem(val)
40844084
}
40854085
}
40864086

4087-
impl<'hir> Into<OwnerNode<'hir>> for &'hir ImplItem<'hir> {
4088-
fn into(self) -> OwnerNode<'hir> {
4089-
OwnerNode::ImplItem(self)
4087+
impl<'hir> From<&'hir ImplItem<'hir>> for OwnerNode<'hir> {
4088+
fn from(val: &'hir ImplItem<'hir>) -> Self {
4089+
OwnerNode::ImplItem(val)
40904090
}
40914091
}
40924092

4093-
impl<'hir> Into<OwnerNode<'hir>> for &'hir TraitItem<'hir> {
4094-
fn into(self) -> OwnerNode<'hir> {
4095-
OwnerNode::TraitItem(self)
4093+
impl<'hir> From<&'hir TraitItem<'hir>> for OwnerNode<'hir> {
4094+
fn from(val: &'hir TraitItem<'hir>) -> Self {
4095+
OwnerNode::TraitItem(val)
40964096
}
40974097
}
40984098

4099-
impl<'hir> Into<Node<'hir>> for OwnerNode<'hir> {
4100-
fn into(self) -> Node<'hir> {
4101-
match self {
4099+
impl<'hir> From<OwnerNode<'hir>> for Node<'hir> {
4100+
fn from(val: OwnerNode<'hir>) -> Self {
4101+
match val {
41024102
OwnerNode::Item(n) => Node::Item(n),
41034103
OwnerNode::ForeignItem(n) => Node::ForeignItem(n),
41044104
OwnerNode::ImplItem(n) => Node::ImplItem(n),

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+21-5
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,24 @@ static Reloc::Model fromRust(LLVMRustRelocModel RustReloc) {
308308
report_fatal_error("Bad RelocModel.");
309309
}
310310

311+
enum class LLVMRustFloatABI {
312+
Default,
313+
Soft,
314+
Hard,
315+
};
316+
317+
static FloatABI::ABIType fromRust(LLVMRustFloatABI RustFloatAbi) {
318+
switch (RustFloatAbi) {
319+
case LLVMRustFloatABI::Default:
320+
return FloatABI::Default;
321+
case LLVMRustFloatABI::Soft:
322+
return FloatABI::Soft;
323+
case LLVMRustFloatABI::Hard:
324+
return FloatABI::Hard;
325+
}
326+
report_fatal_error("Bad FloatABI.");
327+
}
328+
311329
/// getLongestEntryLength - Return the length of the longest entry in the table.
312330
template <typename KV> static size_t getLongestEntryLength(ArrayRef<KV> Table) {
313331
size_t MaxLen = 0;
@@ -358,7 +376,7 @@ extern "C" const char *LLVMRustGetHostCPUName(size_t *OutLen) {
358376
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
359377
const char *TripleStr, const char *CPU, const char *Feature,
360378
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocModel RustReloc,
361-
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
379+
LLVMRustCodeGenOptLevel RustOptLevel, LLVMRustFloatABI RustFloatABIType,
362380
bool FunctionSections, bool DataSections, bool UniqueSectionNames,
363381
bool TrapUnreachable, bool Singlethread, bool VerboseAsm,
364382
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
@@ -369,6 +387,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
369387
auto OptLevel = fromRust(RustOptLevel);
370388
auto RM = fromRust(RustReloc);
371389
auto CM = fromRust(RustCM);
390+
auto FloatABIType = fromRust(RustFloatABIType);
372391

373392
std::string Error;
374393
auto Trip = Triple(Triple::normalize(TripleStr));
@@ -381,10 +400,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
381400

382401
TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip);
383402

384-
Options.FloatABIType = FloatABI::Default;
385-
if (UseSoftFloat) {
386-
Options.FloatABIType = FloatABI::Soft;
387-
}
403+
Options.FloatABIType = FloatABIType;
388404
Options.DataSections = DataSections;
389405
Options.FunctionSections = FunctionSections;
390406
Options.UniqueSectionNames = UniqueSectionNames;

compiler/rustc_metadata/src/rmeta/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ pub(crate) struct RawDefId {
303303
index: u32,
304304
}
305305

306-
impl Into<RawDefId> for DefId {
307-
fn into(self) -> RawDefId {
308-
RawDefId { krate: self.krate.as_u32(), index: self.index.as_u32() }
306+
impl From<DefId> for RawDefId {
307+
fn from(val: DefId) -> Self {
308+
RawDefId { krate: val.krate.as_u32(), index: val.index.as_u32() }
309309
}
310310
}
311311

compiler/rustc_middle/src/mir/interpret/error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ impl ReportedErrorInfo {
8888
}
8989
}
9090

91-
impl Into<ErrorGuaranteed> for ReportedErrorInfo {
91+
impl From<ReportedErrorInfo> for ErrorGuaranteed {
9292
#[inline]
93-
fn into(self) -> ErrorGuaranteed {
94-
self.error
93+
fn from(val: ReportedErrorInfo) -> Self {
94+
val.error
9595
}
9696
}
9797

compiler/rustc_middle/src/mir/interpret/queries.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ use crate::ty::{self, GenericArgs, TyCtxt};
1616
impl<'tcx> TyCtxt<'tcx> {
1717
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
1818
/// that can't take any generic arguments like const items or enum discriminants. If a
19-
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
19+
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
2020
#[instrument(skip(self), level = "debug")]
2121
pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
2222
// In some situations def_id will have generic parameters within scope, but they aren't allowed
2323
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
24-
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
24+
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
2525
// encountered.
2626
let args = GenericArgs::identity_for_item(self, def_id);
2727
let instance = ty::Instance::new(def_id, args);
@@ -32,12 +32,12 @@ impl<'tcx> TyCtxt<'tcx> {
3232

3333
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
3434
/// that can't take any generic arguments like const items or enum discriminants. If a
35-
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
35+
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
3636
#[instrument(skip(self), level = "debug")]
3737
pub fn const_eval_poly_to_alloc(self, def_id: DefId) -> EvalToAllocationRawResult<'tcx> {
3838
// In some situations def_id will have generic parameters within scope, but they aren't allowed
3939
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
40-
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
40+
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
4141
// encountered.
4242
let args = GenericArgs::identity_for_item(self, def_id);
4343
let instance = ty::Instance::new(def_id, args);
@@ -201,12 +201,12 @@ impl<'tcx> TyCtxt<'tcx> {
201201
impl<'tcx> TyCtxtEnsure<'tcx> {
202202
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
203203
/// that can't take any generic arguments like const items or enum discriminants. If a
204-
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
204+
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
205205
#[instrument(skip(self), level = "debug")]
206206
pub fn const_eval_poly(self, def_id: DefId) {
207207
// In some situations def_id will have generic parameters within scope, but they aren't allowed
208208
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
209-
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
209+
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
210210
// encountered.
211211
let args = GenericArgs::identity_for_item(self.tcx, def_id);
212212
let instance = ty::Instance::new(def_id, self.tcx.erase_regions(args));

compiler/rustc_middle/src/ty/adt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ pub enum AdtKind {
249249
Enum,
250250
}
251251

252-
impl Into<DataTypeKind> for AdtKind {
253-
fn into(self) -> DataTypeKind {
254-
match self {
252+
impl From<AdtKind> for DataTypeKind {
253+
fn from(val: AdtKind) -> Self {
254+
match val {
255255
AdtKind::Struct => DataTypeKind::Struct,
256256
AdtKind::Union => DataTypeKind::Union,
257257
AdtKind::Enum => DataTypeKind::Enum,

0 commit comments

Comments
 (0)