Put FnAbiError
behind reference to shrink result
The `FnAbi` is just a pointer, so the error type should not be bigger.
This commit is contained in:
parent
3019c1cb2a
commit
4be84771a7
@ -71,8 +71,8 @@ impl<T> EraseType for Result<&'_ T, traits::CodegenObligationError> {
|
|||||||
type Result = [u8; size_of::<Result<&'static (), traits::CodegenObligationError>>()];
|
type Result = [u8; size_of::<Result<&'static (), traits::CodegenObligationError>>()];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EraseType for Result<&'_ T, ty::layout::FnAbiError<'_>> {
|
impl<T> EraseType for Result<&'_ T, &'_ ty::layout::FnAbiError<'_>> {
|
||||||
type Result = [u8; size_of::<Result<&'static (), ty::layout::FnAbiError<'static>>>()];
|
type Result = [u8; size_of::<Result<&'static (), &'static ty::layout::FnAbiError<'static>>>()];
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> EraseType for Result<(&'_ T, rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed> {
|
impl<T> EraseType for Result<(&'_ T, rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed> {
|
||||||
|
@ -1394,7 +1394,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<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
|
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
|
||||||
desc { "computing call ABI of `{}` function pointers", key.value.0 }
|
desc { "computing call ABI of `{}` function pointers", key.value.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1405,7 +1405,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<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
|
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, &'tcx ty::layout::FnAbiError<'tcx>> {
|
||||||
desc { "computing call ABI of `{}`", key.value.0 }
|
desc { "computing call ABI of `{}`", key.value.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,18 +1260,6 @@ pub enum FnAbiError<'tcx> {
|
|||||||
AdjustForForeignAbi(call::AdjustForForeignAbiError),
|
AdjustForForeignAbi(call::AdjustForForeignAbiError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> From<LayoutError<'tcx>> for FnAbiError<'tcx> {
|
|
||||||
fn from(err: LayoutError<'tcx>) -> Self {
|
|
||||||
Self::Layout(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<call::AdjustForForeignAbiError> for FnAbiError<'_> {
|
|
||||||
fn from(err: call::AdjustForForeignAbiError) -> Self {
|
|
||||||
Self::AdjustForForeignAbi(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'b> IntoDiagnostic<'a, !> for FnAbiError<'b> {
|
impl<'a, 'b> IntoDiagnostic<'a, !> for FnAbiError<'b> {
|
||||||
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> {
|
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, !> {
|
||||||
match self {
|
match self {
|
||||||
@ -1331,7 +1319,7 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
|
|||||||
let tcx = self.tcx().at(span);
|
let tcx = self.tcx().at(span);
|
||||||
|
|
||||||
MaybeResult::from(tcx.fn_abi_of_fn_ptr(self.param_env().and((sig, extra_args))).map_err(
|
MaybeResult::from(tcx.fn_abi_of_fn_ptr(self.param_env().and((sig, extra_args))).map_err(
|
||||||
|err| self.handle_fn_abi_err(err, span, FnAbiRequest::OfFnPtr { sig, extra_args }),
|
|err| self.handle_fn_abi_err(*err, span, FnAbiRequest::OfFnPtr { sig, extra_args }),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1358,7 +1346,11 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
|
|||||||
// 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 = if !span.is_dummy() { span } else { tcx.def_span(instance.def_id()) };
|
||||||
self.handle_fn_abi_err(err, span, FnAbiRequest::OfInstance { instance, extra_args })
|
self.handle_fn_abi_err(
|
||||||
|
*err,
|
||||||
|
span,
|
||||||
|
FnAbiRequest::OfInstance { instance, extra_args },
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv {
|
|||||||
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<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
|
||||||
let (param_env, (sig, extra_args)) = query.into_parts();
|
let (param_env, (sig, extra_args)) = query.into_parts();
|
||||||
|
|
||||||
let cx = LayoutCx { tcx, param_env };
|
let cx = LayoutCx { tcx, param_env };
|
||||||
@ -212,7 +212,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<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
|
||||||
let (param_env, (instance, extra_args)) = query.into_parts();
|
let (param_env, (instance, extra_args)) = query.into_parts();
|
||||||
|
|
||||||
let sig = fn_sig_for_fn_abi(tcx, instance, param_env);
|
let sig = fn_sig_for_fn_abi(tcx, instance, param_env);
|
||||||
@ -331,7 +331,7 @@ fn fn_abi_new_uncached<'tcx>(
|
|||||||
fn_def_id: Option<DefId>,
|
fn_def_id: Option<DefId>,
|
||||||
// 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<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
|
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, &'tcx FnAbiError<'tcx>> {
|
||||||
let sig = cx.tcx.normalize_erasing_late_bound_regions(cx.param_env, sig);
|
let sig = cx.tcx.normalize_erasing_late_bound_regions(cx.param_env, sig);
|
||||||
|
|
||||||
let conv = conv_from_spec_abi(cx.tcx(), sig.abi);
|
let conv = conv_from_spec_abi(cx.tcx(), sig.abi);
|
||||||
@ -376,7 +376,7 @@ fn fn_abi_new_uncached<'tcx>(
|
|||||||
let is_drop_in_place =
|
let is_drop_in_place =
|
||||||
fn_def_id.is_some() && fn_def_id == cx.tcx.lang_items().drop_in_place_fn();
|
fn_def_id.is_some() && fn_def_id == cx.tcx.lang_items().drop_in_place_fn();
|
||||||
|
|
||||||
let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, FnAbiError<'tcx>> {
|
let arg_of = |ty: Ty<'tcx>, arg_idx: Option<usize>| -> Result<_, &'tcx FnAbiError<'tcx>> {
|
||||||
let span = tracing::debug_span!("arg_of");
|
let span = tracing::debug_span!("arg_of");
|
||||||
let _entered = span.enter();
|
let _entered = span.enter();
|
||||||
let is_return = arg_idx.is_none();
|
let is_return = arg_idx.is_none();
|
||||||
@ -386,7 +386,8 @@ fn fn_abi_new_uncached<'tcx>(
|
|||||||
_ => bug!("argument to drop_in_place is not a raw ptr: {:?}", ty),
|
_ => bug!("argument to drop_in_place is not a raw ptr: {:?}", ty),
|
||||||
});
|
});
|
||||||
|
|
||||||
let layout = cx.layout_of(ty).map_err(|err| *err)?;
|
let layout =
|
||||||
|
cx.layout_of(ty).map_err(|err| &*cx.tcx.arena.alloc(FnAbiError::Layout(*err)))?;
|
||||||
let layout = if force_thin_self_ptr && arg_idx == Some(0) {
|
let layout = if force_thin_self_ptr && arg_idx == Some(0) {
|
||||||
// Don't pass the vtable, it's not an argument of the virtual fn.
|
// Don't pass the vtable, it's not an argument of the virtual fn.
|
||||||
// Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait`
|
// Instead, pass just the data pointer, but give it the type `*const/mut dyn Trait`
|
||||||
@ -454,7 +455,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
|
|||||||
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
|
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
|
||||||
abi: SpecAbi,
|
abi: SpecAbi,
|
||||||
fn_def_id: Option<DefId>,
|
fn_def_id: Option<DefId>,
|
||||||
) -> Result<(), FnAbiError<'tcx>> {
|
) -> Result<(), &'tcx FnAbiError<'tcx>> {
|
||||||
if abi == SpecAbi::Unadjusted {
|
if abi == SpecAbi::Unadjusted {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -548,7 +549,9 @@ fn fn_abi_adjust_for_abi<'tcx>(
|
|||||||
fixup(arg, Some(arg_idx));
|
fixup(arg, Some(arg_idx));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fn_abi.adjust_for_foreign_abi(cx, abi)?;
|
fn_abi
|
||||||
|
.adjust_for_foreign_abi(cx, abi)
|
||||||
|
.map_err(|err| &*cx.tcx.arena.alloc(FnAbiError::AdjustForForeignAbi(err)))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user