Skip to content

Commit

Permalink
compiler: Directly use rustc_abi in metadata and middle
Browse files Browse the repository at this point in the history
Stop reexporting ReprOptions from middle::ty
  • Loading branch information
workingjubilee committed Nov 3, 2024
1 parent bdc083a commit 33edc68
Show file tree
Hide file tree
Showing 35 changed files with 92 additions and 101 deletions.
22 changes: 13 additions & 9 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::ControlFlow;
use std::path::{Path, PathBuf};

use rustc_abi::ExternAbi;
use rustc_ast::CRATE_NODE_ID;
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashSet;
Expand All @@ -17,7 +18,6 @@ use rustc_session::utils::NativeLibKind;
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::symbol::{Symbol, sym};
use rustc_target::spec::LinkSelfContainedComponents;
use rustc_target::spec::abi::Abi;

use crate::{errors, fluent_generated};

Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'tcx> Collector<'tcx> {

let sess = self.tcx.sess;

if matches!(abi, Abi::Rust | Abi::RustIntrinsic) {
if matches!(abi, ExternAbi::Rust | ExternAbi::RustIntrinsic) {
return;
}

Expand Down Expand Up @@ -625,7 +625,7 @@ impl<'tcx> Collector<'tcx> {

fn build_dll_import(
&self,
abi: Abi,
abi: ExternAbi,
import_name_type: Option<PeImportNameType>,
item: DefId,
) -> DllImport {
Expand All @@ -634,12 +634,14 @@ impl<'tcx> Collector<'tcx> {
// this logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but errors on unsupported inputs
let calling_convention = if self.tcx.sess.target.arch == "x86" {
match abi {
Abi::C { .. } | Abi::Cdecl { .. } => DllCallingConvention::C,
Abi::Stdcall { .. } => DllCallingConvention::Stdcall(self.i686_arg_list_size(item)),
ExternAbi::C { .. } | ExternAbi::Cdecl { .. } => DllCallingConvention::C,
ExternAbi::Stdcall { .. } => {
DllCallingConvention::Stdcall(self.i686_arg_list_size(item))
}
// On Windows, `extern "system"` behaves like msvc's `__stdcall`.
// `__stdcall` only applies on x86 and on non-variadic functions:
// https://learn.microsoft.com/en-us/cpp/cpp/stdcall?view=msvc-170
Abi::System { .. } => {
ExternAbi::System { .. } => {
let c_variadic =
self.tcx.type_of(item).instantiate_identity().fn_sig(self.tcx).c_variadic();

Expand All @@ -649,10 +651,10 @@ impl<'tcx> Collector<'tcx> {
DllCallingConvention::Stdcall(self.i686_arg_list_size(item))
}
}
Abi::Fastcall { .. } => {
ExternAbi::Fastcall { .. } => {
DllCallingConvention::Fastcall(self.i686_arg_list_size(item))
}
Abi::Vectorcall { .. } => {
ExternAbi::Vectorcall { .. } => {
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
}
_ => {
Expand All @@ -661,7 +663,9 @@ impl<'tcx> Collector<'tcx> {
}
} else {
match abi {
Abi::C { .. } | Abi::Win64 { .. } | Abi::System { .. } => DllCallingConvention::C,
ExternAbi::C { .. } | ExternAbi::Win64 { .. } | ExternAbi::System { .. } => {
DllCallingConvention::C
}
_ => {
self.tcx.dcx().emit_fatal(errors::UnsupportedAbi { span });
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use decoder::{DecodeContext, Metadata};
use def_path_hash_map::DefPathHashMapRef;
use encoder::EncodeContext;
pub use encoder::{EncodedMetadata, encode_metadata, rendered_const};
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_abi::{FieldIdx, ReprOptions, VariantIdx};
use rustc_ast::expand::StrippedCfgItem;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::svh::Svh;
Expand All @@ -27,7 +27,7 @@ use rustc_middle::middle::lib_features::FeatureStability;
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
use rustc_middle::ty::fast_reject::SimplifiedType;
use rustc_middle::ty::{
self, DeducedParamAttrs, ParameterizedOverTcx, ReprOptions, Ty, TyCtxt, UnusedGenericParams,
self, DeducedParamAttrs, ParameterizedOverTcx, Ty, TyCtxt, UnusedGenericParams,
};
use rustc_middle::util::Providers;
use rustc_middle::{mir, trivially_parameterized_over_tcx};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ macro_rules! arena_types {
($macro:path) => (
$macro!([
[] layout: rustc_abi::LayoutData<rustc_abi::FieldIdx, rustc_abi::VariantIdx>,
[] fn_abi: rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
[] fn_abi: rustc_target::callconv::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
// AdtDef are interned and compared by address
[decode] adt_def: rustc_middle::ty::AdtDefData,
[] steal_thir: rustc_data_structures::steal::Steal<rustc_middle::thir::Thir<'tcx>>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rustc_abi::ExternAbi;
use rustc_ast::visit::{VisitorResult, walk_list};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand All @@ -12,7 +13,6 @@ use rustc_middle::hir::nested_filter;
use rustc_span::def_id::StableCrateId;
use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_span::{ErrorGuaranteed, Span};
use rustc_target::spec::abi::Abi;
use {rustc_ast as ast, rustc_hir_pretty as pprust_hir};

use crate::hir::ModuleItems;
Expand Down Expand Up @@ -668,7 +668,7 @@ impl<'hir> Map<'hir> {
}
}

pub fn get_foreign_abi(self, hir_id: HirId) -> Abi {
pub fn get_foreign_abi(self, hir_id: HirId) -> ExternAbi {
let parent = self.get_parent_item(hir_id);
if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) =
self.tcx.hir_owner_node(parent)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/hir/place.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_hir::HirId;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_target::abi::{FieldIdx, VariantIdx};

use crate::ty;
use crate::ty::Ty;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_abi::Align;
use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_span::symbol::Symbol;
use rustc_target::abi::Align;
use rustc_target::spec::SanitizerSet;

use crate::mir::mono::Linkage;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{self, Debug, Display, Formatter};

use either::Either;
use rustc_abi::{HasDataLayout, Size};
use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_session::RemapFileNameExt;
use rustc_session::config::RemapPathScopeComponents;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi::{HasDataLayout, Size};

use crate::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, Scalar, alloc_range};
use crate::mir::{Promoted, pretty_print_const_value};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use either::{Left, Right};
use init_mask::*;
pub use init_mask::{InitChunk, InitChunkIter};
use provenance_map::*;
use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability;
use rustc_data_structures::intern::Interned;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_target::abi::{Align, HasDataLayout, Size};

use super::{
AllocId, BadBytesAccess, CtfeProvenance, InterpErrorKind, InterpResult, Pointer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ mod tests;
use std::ops::Range;
use std::{hash, iter};

use rustc_abi::Size;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_serialize::{Decodable, Encodable};
use rustc_target::abi::Size;
use rustc_type_ir::{TyDecoder, TyEncoder};

use super::AllocRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use std::cmp;

use rustc_abi::{HasDataLayout, Size};
use rustc_data_structures::sorted_map::SortedMap;
use rustc_macros::HashStable;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_target::abi::{HasDataLayout, Size};
use tracing::trace;

use super::{AllocError, AllocRange, AllocResult, CtfeProvenance, Provenance, alloc_range};
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use std::borrow::Cow;
use std::{convert, fmt, mem, ops};

use either::Either;
use rustc_abi::{Align, Size, VariantIdx, WrappingRange};
use rustc_ast_ir::Mutability;
use rustc_data_structures::sync::Lock;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_session::CtfeBacktrace;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_target::abi::{Align, Size, VariantIdx, WrappingRange, call};

use super::{AllocId, AllocRange, ConstAllocation, Pointer, Scalar};
use crate::error;
Expand Down Expand Up @@ -217,7 +217,7 @@ pub enum InvalidProgramInfo<'tcx> {
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
/// (which unfortunately typeck does not reject).
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
FnAbiAdjustForForeignAbi(call::AdjustForForeignAbiError),
FnAbiAdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
}

/// Details of why a pointer had to be in-bounds.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::io::{Read, Write};
use std::num::NonZero;
use std::{fmt, io};

use rustc_abi::{AddressSpace, Endian, HasDataLayout};
use rustc_ast::LitKind;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lock;
Expand All @@ -20,7 +21,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_serialize::{Decodable, Encodable};
use rustc_target::abi::{AddressSpace, Endian, HasDataLayout};
use tracing::{debug, trace};
// Also make the error macros available from this module.
pub use {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt;
use std::num::NonZero;

use rustc_abi::{HasDataLayout, Size};
use rustc_data_structures::static_assert_size;
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_target::abi::{HasDataLayout, Size};

use super::AllocId;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/interpret/value.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::fmt;

use either::{Either, Left, Right};
use rustc_abi::{HasDataLayout, Size};
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_target::abi::{HasDataLayout, Size};

use super::{
AllocId, CtfeProvenance, InterpResult, Pointer, PointerArithmetic, Provenance,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{iter, mem};
pub use basic_blocks::BasicBlocks;
use either::Either;
use polonius_engine::Atom;
use rustc_abi::{FieldIdx, VariantIdx};
pub use rustc_ast::Mutability;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
Expand All @@ -27,7 +28,6 @@ use rustc_serialize::{Decodable, Encodable};
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Symbol;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi::{FieldIdx, VariantIdx};
use tracing::trace;

pub use self::query::*;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use std::fs;
use std::io::{self, Write as _};
use std::path::{Path, PathBuf};

use rustc_abi::Size;
use rustc_ast::InlineAsmTemplatePiece;
use rustc_middle::mir::interpret::{
AllocBytes, AllocId, Allocation, GlobalAlloc, Pointer, Provenance, alloc_range,
read_target_uint,
};
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::*;
use rustc_target::abi::Size;
use tracing::trace;

use super::graphviz::write_mir_fn_graphviz;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::cell::Cell;
use std::fmt::{self, Debug};

use derive_where::derive_where;
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::LocalDefId;
Expand All @@ -12,7 +13,6 @@ use rustc_index::{Idx, IndexVec};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_span::Span;
use rustc_span::symbol::Symbol;
use rustc_target::abi::{FieldIdx, VariantIdx};
use smallvec::SmallVec;

use super::{ConstValue, SourceInfo};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This is in a dedicated file so that changes to this file can be reviewed more carefully.
//! The intention is that this file only contains datatype declarations, no code.
use rustc_abi::{FieldIdx, VariantIdx};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece, Mutability};
use rustc_data_structures::packed::Pu128;
use rustc_hir::CoroutineKind;
Expand All @@ -13,7 +14,6 @@ use rustc_span::Span;
use rustc_span::def_id::LocalDefId;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Symbol;
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_target::asm::InlineAsmRegOrRegClass;
use smallvec::SmallVec;

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_middle/src/query/erase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,10 @@ impl EraseType for Result<bool, &ty::layout::LayoutError<'_>> {
type Result = [u8; size_of::<Result<bool, &'static ty::layout::LayoutError<'static>>>()];
}

impl EraseType
for Result<rustc_target::abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>>
{
impl EraseType for Result<rustc_abi::TyAndLayout<'_, Ty<'_>>, &ty::layout::LayoutError<'_>> {
type Result = [u8; size_of::<
Result<
rustc_target::abi::TyAndLayout<'static, Ty<'static>>,
rustc_abi::TyAndLayout<'static, Ty<'static>>,
&'static ty::layout::LayoutError<'static>,
>,
>()];
Expand Down Expand Up @@ -253,13 +251,14 @@ trivial! {
Option<rustc_span::def_id::DefId>,
Option<rustc_span::def_id::LocalDefId>,
Option<rustc_span::Span>,
Option<rustc_target::abi::FieldIdx>,
Option<rustc_abi::FieldIdx>,
Option<rustc_target::spec::PanicStrategy>,
Option<usize>,
Option<rustc_middle::ty::IntrinsicDef>,
Result<(), rustc_errors::ErrorGuaranteed>,
Result<(), rustc_middle::traits::query::NoSolution>,
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
rustc_abi::ReprOptions,
rustc_ast::expand::allocator::AllocatorKind,
rustc_attr::ConstStability,
rustc_attr::DefaultBodyStability,
Expand Down Expand Up @@ -311,7 +310,6 @@ trivial! {
rustc_middle::ty::fast_reject::SimplifiedType,
rustc_middle::ty::ImplPolarity,
rustc_middle::ty::Representability,
rustc_middle::ty::ReprOptions,
rustc_middle::ty::UnusedGenericParams,
rustc_middle::ty::util::AlwaysRequiresDrop,
rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/query/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc_hir::hir_id::{HirId, OwnerId};
use rustc_query_system::query::{DefIdCache, DefaultCache, SingleCache, VecCache};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{DUMMY_SP, Span};
use rustc_target::abi;

use crate::infer::canonical::CanonicalQueryInput;
use crate::ty::fast_reject::SimplifiedType;
Expand Down Expand Up @@ -509,7 +508,7 @@ impl<'tcx> Key for (DefId, Ty<'tcx>, GenericArgsRef<'tcx>, ty::ParamEnv<'tcx>) {
}
}

impl<'tcx> Key for (Ty<'tcx>, abi::VariantIdx) {
impl<'tcx> Key for (Ty<'tcx>, rustc_abi::VariantIdx) {
type Cache<V> = DefaultCache<Self, V>;

fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
Expand Down
Loading

0 comments on commit 33edc68

Please sign in to comment.