Make FnAbiError Copy.
This commit is contained in:
parent
e52131efad
commit
4435dfec0f
10 changed files with 35 additions and 42 deletions
|
@ -274,7 +274,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
@ -396,7 +396,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
|
|
@ -354,7 +354,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
|
|
@ -397,7 +397,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
|
|
@ -920,7 +920,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> ! {
|
) -> ! {
|
||||||
|
|
|
@ -341,12 +341,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> FnAbiOfHelpers<'tcx> for InterpCx
|
||||||
|
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
_span: Span,
|
_span: Span,
|
||||||
_fn_abi_request: FnAbiRequest<'tcx>,
|
_fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> InterpErrorInfo<'tcx> {
|
) -> InterpErrorInfo<'tcx> {
|
||||||
match err {
|
match err {
|
||||||
FnAbiError::Layout(err) => err_inval!(Layout(*err)).into(),
|
FnAbiError::Layout(err) => err_inval!(Layout(err)).into(),
|
||||||
FnAbiError::AdjustForForeignAbi(err) => {
|
FnAbiError::AdjustForForeignAbi(err) => {
|
||||||
err_inval!(FnAbiAdjustForForeignAbi(err)).into()
|
err_inval!(FnAbiAdjustForForeignAbi(err)).into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub enum InvalidProgramInfo<'tcx> {
|
||||||
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
|
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
|
||||||
/// (which unfortunately typeck does not reject).
|
/// (which unfortunately typeck does not reject).
|
||||||
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
|
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
|
||||||
FnAbiAdjustForForeignAbi(&'tcx call::AdjustForForeignAbiError),
|
FnAbiAdjustForForeignAbi(call::AdjustForForeignAbiError),
|
||||||
/// An invalid transmute happened.
|
/// An invalid transmute happened.
|
||||||
TransmuteSizeDiff(Ty<'tcx>, Ty<'tcx>),
|
TransmuteSizeDiff(Ty<'tcx>, Ty<'tcx>),
|
||||||
/// SizeOf of unsized type was requested.
|
/// SizeOf of unsized type was requested.
|
||||||
|
|
|
@ -1217,8 +1217,7 @@ rustc_queries! {
|
||||||
/// instead, where the instance is an `InstanceDef::Virtual`.
|
/// instead, where the instance is an `InstanceDef::Virtual`.
|
||||||
query fn_abi_of_fn_ptr(
|
query fn_abi_of_fn_ptr(
|
||||||
key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
|
key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
|
||||||
) -> Result<abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
|
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
|
||||||
storage(ArenaCacheSelector<'tcx>)
|
|
||||||
desc { "computing call ABI of `{}` function pointers", key.value.0 }
|
desc { "computing call ABI of `{}` function pointers", key.value.0 }
|
||||||
remap_env_constness
|
remap_env_constness
|
||||||
}
|
}
|
||||||
|
@ -1230,8 +1229,7 @@ rustc_queries! {
|
||||||
/// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
|
/// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
|
||||||
query fn_abi_of_instance(
|
query fn_abi_of_instance(
|
||||||
key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
|
key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
|
||||||
) -> Result<abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
|
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
|
||||||
storage(ArenaCacheSelector<'tcx>)
|
|
||||||
desc { "computing call ABI of `{}`", key.value.0 }
|
desc { "computing call ABI of `{}`", key.value.0 }
|
||||||
remap_env_constness
|
remap_env_constness
|
||||||
}
|
}
|
||||||
|
|
|
@ -2839,7 +2839,7 @@ pub fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error produced by attempting to compute or adjust a `FnAbi`.
|
/// Error produced by attempting to compute or adjust a `FnAbi`.
|
||||||
#[derive(Clone, Debug, HashStable)]
|
#[derive(Copy, Clone, Debug, HashStable)]
|
||||||
pub enum FnAbiError<'tcx> {
|
pub enum FnAbiError<'tcx> {
|
||||||
/// Error produced by a `layout_of` call, while computing `FnAbi` initially.
|
/// Error produced by a `layout_of` call, while computing `FnAbi` initially.
|
||||||
Layout(LayoutError<'tcx>),
|
Layout(LayoutError<'tcx>),
|
||||||
|
@ -2893,7 +2893,7 @@ pub trait FnAbiOfHelpers<'tcx>: LayoutOfHelpers<'tcx> {
|
||||||
/// (and any `FnAbiError`s are turned into fatal errors or ICEs).
|
/// (and any `FnAbiError`s are turned into fatal errors or ICEs).
|
||||||
fn handle_fn_abi_err(
|
fn handle_fn_abi_err(
|
||||||
&self,
|
&self,
|
||||||
err: &'tcx FnAbiError<'tcx>,
|
err: FnAbiError<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_abi_request: FnAbiRequest<'tcx>,
|
fn_abi_request: FnAbiRequest<'tcx>,
|
||||||
) -> <Self::FnAbiOfResult as MaybeResult<&'tcx FnAbi<'tcx, Ty<'tcx>>>>::Error;
|
) -> <Self::FnAbiOfResult as MaybeResult<&'tcx FnAbi<'tcx, Ty<'tcx>>>>::Error;
|
||||||
|
@ -2915,11 +2915,9 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
|
||||||
let span = self.layout_tcx_at_span();
|
let span = self.layout_tcx_at_span();
|
||||||
let tcx = self.tcx().at(span);
|
let tcx = self.tcx().at(span);
|
||||||
|
|
||||||
MaybeResult::from(
|
MaybeResult::from(tcx.fn_abi_of_fn_ptr(self.param_env().and((sig, extra_args))).map_err(
|
||||||
tcx.fn_abi_of_fn_ptr(self.param_env().and((sig, extra_args))).as_ref().map_err(|err| {
|
|err| self.handle_fn_abi_err(err, span, FnAbiRequest::OfFnPtr { sig, extra_args }),
|
||||||
self.handle_fn_abi_err(err, span, FnAbiRequest::OfFnPtr { sig, extra_args })
|
))
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
|
/// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
|
||||||
|
@ -2938,21 +2936,14 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
|
||||||
let tcx = self.tcx().at(span);
|
let tcx = self.tcx().at(span);
|
||||||
|
|
||||||
MaybeResult::from(
|
MaybeResult::from(
|
||||||
tcx.fn_abi_of_instance(self.param_env().and((instance, extra_args))).as_ref().map_err(
|
tcx.fn_abi_of_instance(self.param_env().and((instance, extra_args))).map_err(|err| {
|
||||||
|err| {
|
// HACK(eddyb) at least for definitions of/calls to `Instance`s,
|
||||||
// HACK(eddyb) at least for definitions of/calls to `Instance`s,
|
// we can get some kind of span even if one wasn't provided.
|
||||||
// we can get some kind of span even if one wasn't provided.
|
// However, we don't do this early in order to avoid calling
|
||||||
// However, we don't do this early in order to avoid calling
|
// `def_span` unconditionally (which may have a perf penalty).
|
||||||
// `def_span` unconditionally (which may have a perf penalty).
|
let span = if !span.is_dummy() { span } else { tcx.def_span(instance.def_id()) };
|
||||||
let span =
|
self.handle_fn_abi_err(err, span, FnAbiRequest::OfInstance { instance, extra_args })
|
||||||
if !span.is_dummy() { span } else { tcx.def_span(instance.def_id()) };
|
}),
|
||||||
self.handle_fn_abi_err(
|
|
||||||
err,
|
|
||||||
span,
|
|
||||||
FnAbiRequest::OfInstance { instance, extra_args },
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2962,7 +2953,7 @@ impl<'tcx, C: FnAbiOfHelpers<'tcx>> FnAbiOf<'tcx> for C {}
|
||||||
fn fn_abi_of_fn_ptr<'tcx>(
|
fn fn_abi_of_fn_ptr<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
query: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
|
query: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
|
||||||
) -> Result<FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
||||||
let (param_env, (sig, extra_args)) = query.into_parts();
|
let (param_env, (sig, extra_args)) = query.into_parts();
|
||||||
|
|
||||||
LayoutCx { tcx, param_env }.fn_abi_new_uncached(
|
LayoutCx { tcx, param_env }.fn_abi_new_uncached(
|
||||||
|
@ -2977,7 +2968,7 @@ fn fn_abi_of_fn_ptr<'tcx>(
|
||||||
fn fn_abi_of_instance<'tcx>(
|
fn fn_abi_of_instance<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
query: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
|
query: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
|
||||||
) -> Result<FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
||||||
let (param_env, (instance, extra_args)) = query.into_parts();
|
let (param_env, (instance, extra_args)) = query.into_parts();
|
||||||
|
|
||||||
let sig = instance.fn_sig_for_fn_abi(tcx, param_env);
|
let sig = instance.fn_sig_for_fn_abi(tcx, param_env);
|
||||||
|
@ -3010,7 +3001,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
codegen_fn_attr_flags: CodegenFnAttrFlags,
|
codegen_fn_attr_flags: CodegenFnAttrFlags,
|
||||||
// FIXME(eddyb) replace this with something typed, like an `enum`.
|
// FIXME(eddyb) replace this with something typed, like an `enum`.
|
||||||
force_thin_self_ptr: bool,
|
force_thin_self_ptr: bool,
|
||||||
) -> Result<FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
||||||
debug!("fn_abi_new_uncached({:?}, {:?})", sig, extra_args);
|
debug!("fn_abi_new_uncached({:?}, {:?})", sig, extra_args);
|
||||||
|
|
||||||
let sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, sig);
|
let sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, sig);
|
||||||
|
@ -3174,7 +3165,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||||
};
|
};
|
||||||
self.fn_abi_adjust_for_abi(&mut fn_abi, sig.abi)?;
|
self.fn_abi_adjust_for_abi(&mut fn_abi, sig.abi)?;
|
||||||
debug!("fn_abi_new_uncached = {:?}", fn_abi);
|
debug!("fn_abi_new_uncached = {:?}", fn_abi);
|
||||||
Ok(fn_abi)
|
Ok(self.tcx.arena.alloc(fn_abi))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fn_abi_adjust_for_abi(
|
fn fn_abi_adjust_for_abi(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::abi::{self, Abi, Align, FieldsShape, Size};
|
use crate::abi::{self, Abi, Align, FieldsShape, Size};
|
||||||
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
|
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
|
||||||
use crate::spec::{self, HasTargetSpec};
|
use crate::spec::{self, HasTargetSpec};
|
||||||
|
use rustc_span::Symbol;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
mod aarch64;
|
mod aarch64;
|
||||||
|
@ -623,10 +624,10 @@ pub struct FnAbi<'a, Ty> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
|
||||||
#[derive(Clone, Debug, HashStable_Generic)]
|
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||||
pub enum AdjustForForeignAbiError {
|
pub enum AdjustForForeignAbiError {
|
||||||
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
|
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
|
||||||
Unsupported { arch: String, abi: spec::abi::Abi },
|
Unsupported { arch: Symbol, abi: spec::abi::Abi },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for AdjustForForeignAbiError {
|
impl fmt::Display for AdjustForForeignAbiError {
|
||||||
|
@ -703,7 +704,10 @@ impl<'a, Ty> FnAbi<'a, Ty> {
|
||||||
"asmjs" => wasm::compute_c_abi_info(cx, self),
|
"asmjs" => wasm::compute_c_abi_info(cx, self),
|
||||||
"bpf" => bpf::compute_abi_info(self),
|
"bpf" => bpf::compute_abi_info(self),
|
||||||
arch => {
|
arch => {
|
||||||
return Err(AdjustForForeignAbiError::Unsupported { arch: arch.to_string(), abi });
|
return Err(AdjustForForeignAbiError::Unsupported {
|
||||||
|
arch: Symbol::intern(arch),
|
||||||
|
abi,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue