ty::layout: intern FnAbis as &'tcx.

This commit is contained in:
Eduard-Mihai Burtescu 2021-08-26 21:58:34 +03:00
parent 0c02e3f550
commit 344df76fed
7 changed files with 29 additions and 23 deletions

View file

@ -11,7 +11,8 @@
macro_rules! arena_types {
($macro:path, $tcx:lifetime) => (
$macro!([
[] layouts: rustc_target::abi::Layout,
[] layout: rustc_target::abi::Layout,
[] fn_abi: rustc_target::abi::call::FnAbi<$tcx, rustc_middle::ty::Ty<$tcx>>,
// AdtDef are interned and compared by address
[] adt_def: rustc_middle::ty::AdtDef,
[] steal_thir: rustc_data_structures::steal::Steal<rustc_middle::thir::Thir<$tcx>>,

View file

@ -55,6 +55,7 @@ use rustc_span::def_id::{DefPathHash, StableCrateId};
use rustc_span::source_map::{MultiSpan, SourceMap};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::call::FnAbi;
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
use rustc_target::spec::abi;
@ -135,6 +136,7 @@ pub struct CtxtInterners<'tcx> {
const_allocation: InternedSet<'tcx, Allocation>,
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
layout: InternedSet<'tcx, Layout>,
fn_abi: InternedSet<'tcx, FnAbi<'tcx, Ty<'tcx>>>,
}
impl<'tcx> CtxtInterners<'tcx> {
@ -155,6 +157,7 @@ impl<'tcx> CtxtInterners<'tcx> {
const_allocation: Default::default(),
bound_variable_kinds: Default::default(),
layout: Default::default(),
fn_abi: Default::default(),
}
}
@ -1959,6 +1962,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.0.interners.const_allocation.len()
)?;
writeln!(fmt, "Layout interner: #{}", self.0.interners.layout.len())?;
writeln!(fmt, "FnAbi interner: #{}", self.0.interners.fn_abi.len())?;
Ok(())
}
@ -2083,6 +2087,7 @@ direct_interners! {
const_: mk_const(Const<'tcx>),
const_allocation: intern_const_alloc(Allocation),
layout: intern_layout(Layout),
fn_abi: intern_fn_abi(FnAbi<'tcx, Ty<'tcx>>),
}
macro_rules! slice_interners {

View file

@ -2838,21 +2838,21 @@ where
///
/// NB: this doesn't handle virtual calls - those should use `FnAbi::of_instance`
/// instead, where the instance is an `InstanceDef::Virtual`.
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self;
/// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
/// direct calls to an `fn`.
///
/// NB: that includes virtual calls, which are represented by "direct calls"
/// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self;
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self;
}
impl<'tcx, C> FnAbiExt<'tcx, C> for call::FnAbi<'tcx, Ty<'tcx>>
where
C: HasTyCtxt<'tcx> + HasParamEnv<'tcx>,
{
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
fn of_fn_ptr(cx: &C, sig: ty::PolyFnSig<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self {
call::FnAbi::new_internal(
&LayoutCx { tcx: cx.tcx(), param_env: cx.param_env() },
sig,
@ -2872,7 +2872,7 @@ where
})
}
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> Self {
fn of_instance(cx: &C, instance: ty::Instance<'tcx>, extra_args: &[Ty<'tcx>]) -> &'tcx Self {
let sig = instance.fn_sig_for_fn_abi(cx.tcx());
let caller_location = if instance.def.requires_caller_location(cx.tcx()) {
@ -2912,7 +2912,7 @@ where
/// Implementation detail of computing `FnAbi`s, shouldn't be exported.
// FIXME(eddyb) move this off of being generic on `C: LayoutOf`, and
// explicitly take `LayoutCx` *or* `TyCtxt` and `ParamEnvAnd<...>`.
trait FnAbiInternalExt<'tcx, C>: Sized
trait FnAbiInternalExt<'tcx, C>
where
C: LayoutOf<'tcx, LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>>
+ HasTargetSpec,
@ -2927,7 +2927,7 @@ where
codegen_fn_attr_flags: CodegenFnAttrFlags,
// FIXME(eddyb) replace this with something typed, like an `enum`.
make_self_ptr_thin: bool,
) -> Result<Self, FnAbiError<'tcx>>;
) -> Result<&'tcx Self, FnAbiError<'tcx>>;
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) -> Result<(), FnAbiError<'tcx>>;
}
@ -2943,7 +2943,7 @@ where
caller_location: Option<Ty<'tcx>>,
codegen_fn_attr_flags: CodegenFnAttrFlags,
force_thin_self_ptr: bool,
) -> Result<Self, FnAbiError<'tcx>> {
) -> Result<&'tcx Self, FnAbiError<'tcx>> {
debug!("FnAbi::new_internal({:?}, {:?})", sig, extra_args);
let sig = cx.tcx().normalize_erasing_late_bound_regions(cx.param_env(), sig);
@ -3106,7 +3106,7 @@ where
};
fn_abi.adjust_for_abi(cx, sig.abi)?;
debug!("FnAbi::new_internal = {:?}", fn_abi);
Ok(fn_abi)
Ok(cx.tcx().intern_fn_abi(fn_abi))
}
fn adjust_for_abi(&mut self, cx: &C, abi: SpecAbi) -> Result<(), FnAbiError<'tcx>> {