Skip to content

Commit 344df76

Browse files
committed
ty::layout: intern FnAbis as &'tcx.
1 parent 0c02e3f commit 344df76

File tree

7 files changed

+29
-23
lines changed

7 files changed

+29
-23
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
239239
pub(crate) instance: Instance<'tcx>,
240240
pub(crate) symbol_name: SymbolName<'tcx>,
241241
pub(crate) mir: &'tcx Body<'tcx>,
242-
pub(crate) fn_abi: Option<FnAbi<'tcx, Ty<'tcx>>>,
242+
pub(crate) fn_abi: Option<&'tcx FnAbi<'tcx, Ty<'tcx>>>,
243243

244244
pub(crate) bcx: FunctionBuilder<'clif>,
245245
pub(crate) block_map: IndexVec<BasicBlock, Block>,

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
124124
&self,
125125
fx: &mut FunctionCx<'a, 'tcx, Bx>,
126126
bx: &mut Bx,
127-
fn_abi: FnAbi<'tcx, Ty<'tcx>>,
127+
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
128128
fn_ptr: Bx::Value,
129129
llargs: &[Bx::Value],
130130
destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>,

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
2929

3030
cx: &'a Bx::CodegenCx,
3131

32-
fn_abi: FnAbi<'tcx, Ty<'tcx>>,
32+
fn_abi: &'tcx FnAbi<'tcx, Ty<'tcx>>,
3333

3434
/// When unwinding is initiated, we have to store this personality
3535
/// value somewhere so that we can load it and re-use it in the

compiler/rustc_middle/src/arena.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
macro_rules! arena_types {
1212
($macro:path, $tcx:lifetime) => (
1313
$macro!([
14-
[] layouts: rustc_target::abi::Layout,
14+
[] layout: rustc_target::abi::Layout,
15+
[] fn_abi: rustc_target::abi::call::FnAbi<$tcx, rustc_middle::ty::Ty<$tcx>>,
1516
// AdtDef are interned and compared by address
1617
[] adt_def: rustc_middle::ty::AdtDef,
1718
[] steal_thir: rustc_data_structures::steal::Steal<rustc_middle::thir::Thir<$tcx>>,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use rustc_span::def_id::{DefPathHash, StableCrateId};
5555
use rustc_span::source_map::{MultiSpan, SourceMap};
5656
use rustc_span::symbol::{kw, sym, Ident, Symbol};
5757
use rustc_span::{Span, DUMMY_SP};
58+
use rustc_target::abi::call::FnAbi;
5859
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
5960
use rustc_target::spec::abi;
6061

@@ -135,6 +136,7 @@ pub struct CtxtInterners<'tcx> {
135136
const_allocation: InternedSet<'tcx, Allocation>,
136137
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
137138
layout: InternedSet<'tcx, Layout>,
139+
fn_abi: InternedSet<'tcx, FnAbi<'tcx, Ty<'tcx>>>,
138140
}
139141

140142
impl<'tcx> CtxtInterners<'tcx> {
@@ -155,6 +157,7 @@ impl<'tcx> CtxtInterners<'tcx> {
155157
const_allocation: Default::default(),
156158
bound_variable_kinds: Default::default(),
157159
layout: Default::default(),
160+
fn_abi: Default::default(),
158161
}
159162
}
160163

@@ -1959,6 +1962,7 @@ impl<'tcx> TyCtxt<'tcx> {
19591962
self.0.interners.const_allocation.len()
19601963
)?;
19611964
writeln!(fmt, "Layout interner: #{}", self.0.interners.layout.len())?;
1965+
writeln!(fmt, "FnAbi interner: #{}", self.0.interners.fn_abi.len())?;
19621966

19631967
Ok(())
19641968
}
@@ -2083,6 +2087,7 @@ direct_interners! {
20832087
const_: mk_const(Const<'tcx>),
20842088
const_allocation: intern_const_alloc(Allocation),
20852089
layout: intern_layout(Layout),
2090+
fn_abi: intern_fn_abi(FnAbi<'tcx, Ty<'tcx>>),
20862091
}
20872092

20882093
macro_rules! slice_interners {

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,21 +2838,21 @@ where
28382838
///
28392839
/// NB: this doesn't handle virtual calls - those should use `FnAbi::of_instance`
28402840
/// instead, where the instance is an `InstanceDef::Virtual`.
2841-
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
2841+
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self;
28422842

28432843
/// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
28442844
/// direct calls to an `fn`.
28452845
///
28462846
/// NB: that includes virtual calls, which are represented by "direct calls"
28472847
/// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
2848-
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
2848+
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self;
28492849
}
28502850

28512851
impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>>
28522852
where
28532853
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
28542854
{
2855-
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
2855+
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self {
28562856
call::FnAbi::new_internal(
28572857
&LayoutCx { tcx: cx.tcx(), param_env: cx.param_env() },
28582858
sig,
@@ -2872,7 +2872,7 @@ where
28722872
})
28732873
}
28742874

2875-
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
2875+
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self {
28762876
let sig = instance.fn_sig_for_fn_abi(cx.tcx());
28772877

28782878
let caller_location = if instance.def.requires_caller_location(cx.tcx()) {
@@ -2912,7 +2912,7 @@ where
29122912
/// Implementation detail of computing `FnAbi`s, shouldn't be exported.
29132913
// FIXME(eddyb) move this off of being generic on `C: LayoutOf`, and
29142914
// explicitly take `LayoutCx` *or* `TyCtxt` and `ParamEnvAnd<...>`.
2915-
trait FnAbiInternalExt<'tcx, C>: Sized
2915+
trait FnAbiInternalExt<'tcx, C>
29162916
where
29172917
C: LayoutOf<'tcx, LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>>
29182918
+ HasTargetSpec,
@@ -2927,7 +2927,7 @@ where
29272927
codegen_fn_attr_flags: CodegenFnAttrFlags,
29282928
// FIXME(eddyb) replace this with something typed, like an `enum`.
29292929
make_self_ptr_thin: bool,
2930-
) -> Result<Self, FnAbiError<'tcx>>;
2930+
) -> Result<&'tcx Self, FnAbiError<'tcx>>;
29312931
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) -> Result<(), FnAbiError<'tcx>>;
29322932
}
29332933

@@ -2943,7 +2943,7 @@ where
29432943
caller_location: Option<Ty<'tcx>>,
29442944
codegen_fn_attr_flags: CodegenFnAttrFlags,
29452945
force_thin_self_ptr: bool,
2946-
) -> Result<Self, FnAbiError<'tcx>> {
2946+
) -> Result<&'tcx Self, FnAbiError<'tcx>> {
29472947
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);
29482948

29492949
let sig = cx.tcx().normalize_erasing_late_bound_regions(cx.param_env(), sig);
@@ -3106,7 +3106,7 @@ where
31063106
};
31073107
fn_abi.adjust_for_abi(cx, sig.abi)?;
31083108
debug!("FnAbi::new_internal = {:?}", fn_abi);
3109-
Ok(fn_abi)
3109+
Ok(cx.tcx().intern_fn_abi(fn_abi))
31103110
}
31113111

31123112
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) -> Result<(), FnAbiError<'tcx>> {

compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod x86;
2525
mod x86_64;
2626
mod x86_win64;
2727

28-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
28+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
2929
pub enum PassMode {
3030
/// Ignore the argument.
3131
///
@@ -60,7 +60,7 @@ pub use attr_impl::ArgAttribute;
6060
mod attr_impl {
6161
// The subset of llvm::Attribute needed for arguments, packed into a bitfield.
6262
bitflags::bitflags! {
63-
#[derive(Default)]
63+
#[derive(Default, HashStable_Generic)]
6464
pub struct ArgAttribute: u16 {
6565
const NoAlias = 1 << 1;
6666
const NoCapture = 1 << 2;
@@ -77,7 +77,7 @@ mod attr_impl {
7777
/// Sometimes an ABI requires small integers to be extended to a full or partial register. This enum
7878
/// defines if this extension should be zero-extension or sign-extension when necessary. When it is
7979
/// not necessary to extend the argument, this enum is ignored.
80-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
80+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
8181
pub enum ArgExtension {
8282
None,
8383
Zext,
@@ -86,7 +86,7 @@ pub enum ArgExtension {
8686

8787
/// A compact representation of LLVM attributes (at least those relevant for this module)
8888
/// that can be manipulated without interacting with LLVM's Attribute machinery.
89-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
89+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
9090
pub struct ArgAttributes {
9191
pub regular: ArgAttribute,
9292
pub arg_ext: ArgExtension,
@@ -127,14 +127,14 @@ impl ArgAttributes {
127127
}
128128
}
129129

130-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
130+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
131131
pub enum RegKind {
132132
Integer,
133133
Float,
134134
Vector,
135135
}
136136

137-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
137+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
138138
pub struct Reg {
139139
pub kind: RegKind,
140140
pub size: Size,
@@ -184,7 +184,7 @@ impl Reg {
184184

185185
/// An argument passed entirely registers with the
186186
/// same kind (e.g., HFA / HVA on PPC64 and AArch64).
187-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
187+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
188188
pub struct Uniform {
189189
pub unit: Reg,
190190

@@ -209,7 +209,7 @@ impl Uniform {
209209
}
210210
}
211211

212-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
212+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
213213
pub struct CastTarget {
214214
pub prefix: [Option<RegKind>; 8],
215215
pub prefix_chunk_size: Size,
@@ -437,7 +437,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
437437

438438
/// Information about how to pass an argument to,
439439
/// or return a value from, a function, under some ABI.
440-
#[derive(Debug)]
440+
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
441441
pub struct ArgAbi<'a, Ty> {
442442
pub layout: TyAndLayout<'a, Ty>,
443443

@@ -545,7 +545,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
545545
}
546546
}
547547

548-
#[derive(Copy, Clone, PartialEq, Debug)]
548+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
549549
pub enum Conv {
550550
// General language calling conventions, for which every target
551551
// should have its own backend (e.g. LLVM) support.
@@ -579,7 +579,7 @@ pub enum Conv {
579579
///
580580
/// I will do my best to describe this structure, but these
581581
/// comments are reverse-engineered and may be inaccurate. -NDM
582-
#[derive(Debug)]
582+
#[derive(PartialEq, Eq, Hash, Debug, HashStable_Generic)]
583583
pub struct FnAbi<'a, Ty> {
584584
/// The LLVM types of each argument.
585585
pub args: Vec<ArgAbi<'a, Ty>>,

0 commit comments

Comments
 (0)