Skip to content

Commit

Permalink
Auto merge of #134952 - Zalathar:rollup-i6g97md, r=Zalathar
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 31, 2024
2 parents 80f5a81 + 2491eda commit 41b5796
Show file tree
Hide file tree
Showing 84 changed files with 440 additions and 162 deletions.
32 changes: 32 additions & 0 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@
#![warn(unreachable_pub)]
// tidy-alphabetical-end

/*! ABI handling for rustc
## What is an "ABI"?
Literally, "application binary interface", which means it is everything about how code interacts,
at the machine level, with other code. This means it technically covers all of the following:
- object binary format for e.g. relocations or offset tables
- in-memory layout of types
- procedure calling conventions
When we discuss "ABI" in the context of rustc, we are probably discussing calling conventions.
To describe those `rustc_abi` also covers type layout, as it must for values passed on the stack.
Despite `rustc_abi` being about calling conventions, it is good to remember these usages exist.
You will encounter all of them and more if you study target-specific codegen enough!
Even in general conversation, when someone says "the Rust ABI is unstable", it may allude to
either or both of
- `repr(Rust)` types have a mostly-unspecified layout
- `extern "Rust" fn(A) -> R` has an unspecified calling convention
## Crate Goal
ABI is a foundational concept, so the `rustc_abi` crate serves as an equally foundational crate.
It cannot carry all details relevant to an ABI: those permeate code generation and linkage.
Instead, `rustc_abi` is intended to provide the interface for reasoning about the binary interface.
It should contain traits and types that other crates then use in their implementation.
For example, a platform's `extern "C" fn` calling convention will be implemented in `rustc_target`
but `rustc_abi` contains the types for calculating layout and describing register-passing.
This makes it easier to describe things in the same way across targets, codegen backends, and
even other Rust compilers, such as rust-analyzer!
*/

use std::fmt;
#[cfg(feature = "nightly")]
use std::iter::Step;
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ impl AngleBracketedArg {
}
}

impl Into<P<GenericArgs>> for AngleBracketedArgs {
fn into(self) -> P<GenericArgs> {
P(GenericArgs::AngleBracketed(self))
impl From<AngleBracketedArgs> for P<GenericArgs> {
fn from(val: AngleBracketedArgs) -> Self {
P(GenericArgs::AngleBracketed(val))
}
}

impl Into<P<GenericArgs>> for ParenthesizedArgs {
fn into(self) -> P<GenericArgs> {
P(GenericArgs::Parenthesized(self))
impl From<ParenthesizedArgs> for P<GenericArgs> {
fn from(val: ParenthesizedArgs) -> Self {
P(GenericArgs::Parenthesized(val))
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ impl<T> From<Vec<T>> for P<[T]> {
}
}

impl<T> Into<Vec<T>> for P<[T]> {
fn into(self) -> Vec<T> {
self.into_vec()
impl<T> From<P<[T]>> for Vec<T> {
fn from(val: P<[T]>) -> Self {
val.into_vec()
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl OwnedTargetMachine {
model: llvm::CodeModel,
reloc: llvm::RelocModel,
level: llvm::CodeGenOptLevel,
use_soft_fp: bool,
float_abi: llvm::FloatAbi,
function_sections: bool,
data_sections: bool,
unique_section_names: bool,
Expand Down Expand Up @@ -57,7 +57,7 @@ impl OwnedTargetMachine {
model,
reloc,
level,
use_soft_fp,
float_abi,
function_sections,
data_sections,
unique_section_names,
Expand Down
18 changes: 13 additions & 5 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_session::config::{
self, Lto, OutputType, Passes, RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath,
};
use rustc_span::{BytePos, InnerSpan, Pos, SpanData, SyntaxContext, sym};
use rustc_target::spec::{CodeModel, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
use rustc_target::spec::{CodeModel, FloatAbi, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
use tracing::debug;

use crate::back::lto::ThinBuffer;
Expand Down Expand Up @@ -181,6 +181,14 @@ pub(crate) fn to_llvm_code_model(code_model: Option<CodeModel>) -> llvm::CodeMod
}
}

fn to_llvm_float_abi(float_abi: Option<FloatAbi>) -> llvm::FloatAbi {
match float_abi {
None => llvm::FloatAbi::Default,
Some(FloatAbi::Soft) => llvm::FloatAbi::Soft,
Some(FloatAbi::Hard) => llvm::FloatAbi::Hard,
}
}

pub(crate) fn target_machine_factory(
sess: &Session,
optlvl: config::OptLevel,
Expand All @@ -189,12 +197,12 @@ pub(crate) fn target_machine_factory(
let reloc_model = to_llvm_relocation_model(sess.relocation_model());

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

let ffunction_sections =
Expand Down Expand Up @@ -290,7 +298,7 @@ pub(crate) fn target_machine_factory(
code_model,
reloc_model,
opt_level,
use_softfp,
float_abi,
ffunction_sections,
fdata_sections,
funique_section_names,
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ pub struct SanitizerOptions {
pub sanitize_kernel_address_recover: bool,
}

/// LLVMRelocMode
/// LLVMRustRelocModel
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum RelocModel {
Expand All @@ -538,6 +538,15 @@ pub enum RelocModel {
ROPI_RWPI,
}

/// LLVMRustFloatABI
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum FloatAbi {
Default,
Soft,
Hard,
}

/// LLVMRustCodeModel
#[derive(Copy, Clone)]
#[repr(C)]
Expand Down Expand Up @@ -2192,7 +2201,7 @@ unsafe extern "C" {
Model: CodeModel,
Reloc: RelocModel,
Level: CodeGenOptLevel,
UseSoftFP: bool,
FloatABIType: FloatAbi,
FunctionSections: bool,
DataSections: bool,
UniqueSectionNames: bool,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ impl From<Cow<'static, str>> for DiagMessage {
/// subdiagnostic derive refers to typed identifiers that are `DiagMessage`s, so need to be
/// able to convert between these, as much as they'll be converted back into `DiagMessage`
/// using `with_subdiagnostic_message` eventually. Don't use this other than for the derive.
impl Into<SubdiagMessage> for DiagMessage {
fn into(self) -> SubdiagMessage {
match self {
impl From<DiagMessage> for SubdiagMessage {
fn from(val: DiagMessage) -> Self {
match val {
DiagMessage::Str(s) => SubdiagMessage::Str(s),
DiagMessage::Translated(s) => SubdiagMessage::Translated(s),
DiagMessage::FluentIdentifier(id, None) => SubdiagMessage::FluentIdentifier(id),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ impl IntoDiagArg for DiagArgValue {
}
}

impl Into<FluentValue<'static>> for DiagArgValue {
fn into(self) -> FluentValue<'static> {
match self {
impl From<DiagArgValue> for FluentValue<'static> {
fn from(val: DiagArgValue) -> Self {
match val {
DiagArgValue::Str(s) => From::from(s),
DiagArgValue::Number(n) => From::from(n),
DiagArgValue::StrListSepByAnd(l) => fluent_value_from_str_list_sep_by_and(l),
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4072,33 +4072,33 @@ impl<'hir> OwnerNode<'hir> {
}
}

impl<'hir> Into<OwnerNode<'hir>> for &'hir Item<'hir> {
fn into(self) -> OwnerNode<'hir> {
OwnerNode::Item(self)
impl<'hir> From<&'hir Item<'hir>> for OwnerNode<'hir> {
fn from(val: &'hir Item<'hir>) -> Self {
OwnerNode::Item(val)
}
}

impl<'hir> Into<OwnerNode<'hir>> for &'hir ForeignItem<'hir> {
fn into(self) -> OwnerNode<'hir> {
OwnerNode::ForeignItem(self)
impl<'hir> From<&'hir ForeignItem<'hir>> for OwnerNode<'hir> {
fn from(val: &'hir ForeignItem<'hir>) -> Self {
OwnerNode::ForeignItem(val)
}
}

impl<'hir> Into<OwnerNode<'hir>> for &'hir ImplItem<'hir> {
fn into(self) -> OwnerNode<'hir> {
OwnerNode::ImplItem(self)
impl<'hir> From<&'hir ImplItem<'hir>> for OwnerNode<'hir> {
fn from(val: &'hir ImplItem<'hir>) -> Self {
OwnerNode::ImplItem(val)
}
}

impl<'hir> Into<OwnerNode<'hir>> for &'hir TraitItem<'hir> {
fn into(self) -> OwnerNode<'hir> {
OwnerNode::TraitItem(self)
impl<'hir> From<&'hir TraitItem<'hir>> for OwnerNode<'hir> {
fn from(val: &'hir TraitItem<'hir>) -> Self {
OwnerNode::TraitItem(val)
}
}

impl<'hir> Into<Node<'hir>> for OwnerNode<'hir> {
fn into(self) -> Node<'hir> {
match self {
impl<'hir> From<OwnerNode<'hir>> for Node<'hir> {
fn from(val: OwnerNode<'hir>) -> Self {
match val {
OwnerNode::Item(n) => Node::Item(n),
OwnerNode::ForeignItem(n) => Node::ForeignItem(n),
OwnerNode::ImplItem(n) => Node::ImplItem(n),
Expand Down
26 changes: 21 additions & 5 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,24 @@ static Reloc::Model fromRust(LLVMRustRelocModel RustReloc) {
report_fatal_error("Bad RelocModel.");
}

enum class LLVMRustFloatABI {
Default,
Soft,
Hard,
};

static FloatABI::ABIType fromRust(LLVMRustFloatABI RustFloatAbi) {
switch (RustFloatAbi) {
case LLVMRustFloatABI::Default:
return FloatABI::Default;
case LLVMRustFloatABI::Soft:
return FloatABI::Soft;
case LLVMRustFloatABI::Hard:
return FloatABI::Hard;
}
report_fatal_error("Bad FloatABI.");
}

/// getLongestEntryLength - Return the length of the longest entry in the table.
template <typename KV> static size_t getLongestEntryLength(ArrayRef<KV> Table) {
size_t MaxLen = 0;
Expand Down Expand Up @@ -358,7 +376,7 @@ extern "C" const char *LLVMRustGetHostCPUName(size_t *OutLen) {
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
const char *TripleStr, const char *CPU, const char *Feature,
const char *ABIStr, LLVMRustCodeModel RustCM, LLVMRustRelocModel RustReloc,
LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
LLVMRustCodeGenOptLevel RustOptLevel, LLVMRustFloatABI RustFloatABIType,
bool FunctionSections, bool DataSections, bool UniqueSectionNames,
bool TrapUnreachable, bool Singlethread, bool VerboseAsm,
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
Expand All @@ -369,6 +387,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);
auto CM = fromRust(RustCM);
auto FloatABIType = fromRust(RustFloatABIType);

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

TargetOptions Options = codegen::InitTargetOptionsFromCodeGenFlags(Trip);

Options.FloatABIType = FloatABI::Default;
if (UseSoftFloat) {
Options.FloatABIType = FloatABI::Soft;
}
Options.FloatABIType = FloatABIType;
Options.DataSections = DataSections;
Options.FunctionSections = FunctionSections;
Options.UniqueSectionNames = UniqueSectionNames;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ pub(crate) struct RawDefId {
index: u32,
}

impl Into<RawDefId> for DefId {
fn into(self) -> RawDefId {
RawDefId { krate: self.krate.as_u32(), index: self.index.as_u32() }
impl From<DefId> for RawDefId {
fn from(val: DefId) -> Self {
RawDefId { krate: val.krate.as_u32(), index: val.index.as_u32() }
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ impl ReportedErrorInfo {
}
}

impl Into<ErrorGuaranteed> for ReportedErrorInfo {
impl From<ReportedErrorInfo> for ErrorGuaranteed {
#[inline]
fn into(self) -> ErrorGuaranteed {
self.error
fn from(val: ReportedErrorInfo) -> Self {
val.error
}
}

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_middle/src/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use crate::ty::{self, GenericArgs, TyCtxt};
impl<'tcx> TyCtxt<'tcx> {
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
/// that can't take any generic arguments like const items or enum discriminants. If a
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
#[instrument(skip(self), level = "debug")]
pub fn const_eval_poly(self, def_id: DefId) -> EvalToConstValueResult<'tcx> {
// In some situations def_id will have generic parameters within scope, but they aren't allowed
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
// encountered.
let args = GenericArgs::identity_for_item(self, def_id);
let instance = ty::Instance::new(def_id, args);
Expand All @@ -32,12 +32,12 @@ impl<'tcx> TyCtxt<'tcx> {

/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
/// that can't take any generic arguments like const items or enum discriminants. If a
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
#[instrument(skip(self), level = "debug")]
pub fn const_eval_poly_to_alloc(self, def_id: DefId) -> EvalToAllocationRawResult<'tcx> {
// In some situations def_id will have generic parameters within scope, but they aren't allowed
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
// encountered.
let args = GenericArgs::identity_for_item(self, def_id);
let instance = ty::Instance::new(def_id, args);
Expand Down Expand Up @@ -201,12 +201,12 @@ impl<'tcx> TyCtxt<'tcx> {
impl<'tcx> TyCtxtEnsure<'tcx> {
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts
/// that can't take any generic arguments like const items or enum discriminants. If a
/// generic parameter is used within the constant `ErrorHandled::ToGeneric` will be returned.
/// generic parameter is used within the constant `ErrorHandled::TooGeneric` will be returned.
#[instrument(skip(self), level = "debug")]
pub fn const_eval_poly(self, def_id: DefId) {
// In some situations def_id will have generic parameters within scope, but they aren't allowed
// to be used. So we can't use `Instance::mono`, instead we feed unresolved generic parameters
// into `const_eval` which will return `ErrorHandled::ToGeneric` if any of them are
// into `const_eval` which will return `ErrorHandled::TooGeneric` if any of them are
// encountered.
let args = GenericArgs::identity_for_item(self.tcx, def_id);
let instance = ty::Instance::new(def_id, self.tcx.erase_regions(args));
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ pub enum AdtKind {
Enum,
}

impl Into<DataTypeKind> for AdtKind {
fn into(self) -> DataTypeKind {
match self {
impl From<AdtKind> for DataTypeKind {
fn from(val: AdtKind) -> Self {
match val {
AdtKind::Struct => DataTypeKind::Struct,
AdtKind::Union => DataTypeKind::Union,
AdtKind::Enum => DataTypeKind::Enum,
Expand Down
Loading

0 comments on commit 41b5796

Please sign in to comment.