Skip to content

Commit 4435dfe

Browse files
committed
Make FnAbiError Copy.
1 parent e52131e commit 4435dfe

File tree

10 files changed

+35
-42
lines changed

10 files changed

+35
-42
lines changed

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
274274
#[inline]
275275
fn handle_fn_abi_err(
276276
&self,
277-
err: &'tcx FnAbiError<'tcx>,
277+
err: FnAbiError<'tcx>,
278278
span: Span,
279279
fn_abi_request: FnAbiRequest<'tcx>,
280280
) -> ! {
@@ -396,7 +396,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
396396
#[inline]
397397
fn handle_fn_abi_err(
398398
&self,
399-
err: &'tcx FnAbiError<'tcx>,
399+
err: FnAbiError<'tcx>,
400400
span: Span,
401401
fn_abi_request: FnAbiRequest<'tcx>,
402402
) -> ! {

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
354354
#[inline]
355355
fn handle_fn_abi_err(
356356
&self,
357-
err: &'tcx FnAbiError<'tcx>,
357+
err: FnAbiError<'tcx>,
358358
span: Span,
359359
fn_abi_request: FnAbiRequest<'tcx>,
360360
) -> ! {

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
397397
#[inline]
398398
fn handle_fn_abi_err(
399399
&self,
400-
err: &'tcx FnAbiError<'tcx>,
400+
err: FnAbiError<'tcx>,
401401
span: Span,
402402
fn_abi_request: FnAbiRequest<'tcx>,
403403
) -> ! {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for Builder<'_, '_, 'tcx> {
105105
#[inline]
106106
fn handle_fn_abi_err(
107107
&self,
108-
err: &'tcx FnAbiError<'tcx>,
108+
err: FnAbiError<'tcx>,
109109
span: Span,
110110
fn_abi_request: FnAbiRequest<'tcx>,
111111
) -> ! {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
920920
#[inline]
921921
fn handle_fn_abi_err(
922922
&self,
923-
err: &'tcx FnAbiError<'tcx>,
923+
err: FnAbiError<'tcx>,
924924
span: Span,
925925
fn_abi_request: FnAbiRequest<'tcx>,
926926
) -> ! {

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> FnAbiOfHelpers<'tcx> for InterpCx
341341

342342
fn handle_fn_abi_err(
343343
&self,
344-
err: &'tcx FnAbiError<'tcx>,
344+
err: FnAbiError<'tcx>,
345345
_span: Span,
346346
_fn_abi_request: FnAbiRequest<'tcx>,
347347
) -> InterpErrorInfo<'tcx> {
348348
match err {
349-
FnAbiError::Layout(err) => err_inval!(Layout(*err)).into(),
349+
FnAbiError::Layout(err) => err_inval!(Layout(err)).into(),
350350
FnAbiError::AdjustForForeignAbi(err) => {
351351
err_inval!(FnAbiAdjustForForeignAbi(err)).into()
352352
}

compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub enum InvalidProgramInfo<'tcx> {
144144
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
145145
/// (which unfortunately typeck does not reject).
146146
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
147-
FnAbiAdjustForForeignAbi(&'tcx call::AdjustForForeignAbiError),
147+
FnAbiAdjustForForeignAbi(call::AdjustForForeignAbiError),
148148
/// An invalid transmute happened.
149149
TransmuteSizeDiff(Ty<'tcx>, Ty<'tcx>),
150150
/// SizeOf of unsized type was requested.

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,7 @@ rustc_queries! {
12171217
/// instead, where the instance is an `InstanceDef::Virtual`.
12181218
query fn_abi_of_fn_ptr(
12191219
key: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1220-
) -> Result<abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1221-
storage(ArenaCacheSelector<'tcx>)
1220+
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
12221221
desc { "computing call ABI of `{}` function pointers", key.value.0 }
12231222
remap_env_constness
12241223
}
@@ -1230,8 +1229,7 @@ rustc_queries! {
12301229
/// to an `InstanceDef::Virtual` instance (of `<dyn Trait as Trait>::fn`).
12311230
query fn_abi_of_instance(
12321231
key: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>
1233-
) -> Result<abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
1234-
storage(ArenaCacheSelector<'tcx>)
1232+
) -> Result<&'tcx abi::call::FnAbi<'tcx, Ty<'tcx>>, ty::layout::FnAbiError<'tcx>> {
12351233
desc { "computing call ABI of `{}`", key.value.0 }
12361234
remap_env_constness
12371235
}

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,7 @@ pub fn conv_from_spec_abi(tcx: TyCtxt<'_>, abi: SpecAbi) -> Conv {
28392839
}
28402840

28412841
/// Error produced by attempting to compute or adjust a `FnAbi`.
2842-
#[derive(Clone, Debug, HashStable)]
2842+
#[derive(Copy, Clone, Debug, HashStable)]
28432843
pub enum FnAbiError<'tcx> {
28442844
/// Error produced by a `layout_of` call, while computing `FnAbi` initially.
28452845
Layout(LayoutError<'tcx>),
@@ -2893,7 +2893,7 @@ pub trait FnAbiOfHelpers<'tcx>: LayoutOfHelpers<'tcx> {
28932893
/// (and any `FnAbiError`s are turned into fatal errors or ICEs).
28942894
fn handle_fn_abi_err(
28952895
&self,
2896-
err: &'tcx FnAbiError<'tcx>,
2896+
err: FnAbiError<'tcx>,
28972897
span: Span,
28982898
fn_abi_request: FnAbiRequest<'tcx>,
28992899
) -> <Self::FnAbiOfResult as MaybeResult<&'tcx FnAbi<'tcx, Ty<'tcx>>>>::Error;
@@ -2915,11 +2915,9 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
29152915
let span = self.layout_tcx_at_span();
29162916
let tcx = self.tcx().at(span);
29172917

2918-
MaybeResult::from(
2919-
tcx.fn_abi_of_fn_ptr(self.param_env().and((sig, extra_args))).as_ref().map_err(|err| {
2920-
self.handle_fn_abi_err(err, span, FnAbiRequest::OfFnPtr { sig, extra_args })
2921-
}),
2922-
)
2918+
MaybeResult::from(tcx.fn_abi_of_fn_ptr(self.param_env().and((sig, extra_args))).map_err(
2919+
|err| self.handle_fn_abi_err(err, span, FnAbiRequest::OfFnPtr { sig, extra_args }),
2920+
))
29232921
}
29242922

29252923
/// Compute a `FnAbi` suitable for declaring/defining an `fn` instance, and for
@@ -2938,21 +2936,14 @@ pub trait FnAbiOf<'tcx>: FnAbiOfHelpers<'tcx> {
29382936
let tcx = self.tcx().at(span);
29392937

29402938
MaybeResult::from(
2941-
tcx.fn_abi_of_instance(self.param_env().and((instance, extra_args))).as_ref().map_err(
2942-
|err| {
2943-
// HACK(eddyb) at least for definitions of/calls to `Instance`s,
2944-
// we can get some kind of span even if one wasn't provided.
2945-
// However, we don't do this early in order to avoid calling
2946-
// `def_span` unconditionally (which may have a perf penalty).
2947-
let span =
2948-
if !span.is_dummy() { span } else { tcx.def_span(instance.def_id()) };
2949-
self.handle_fn_abi_err(
2950-
err,
2951-
span,
2952-
FnAbiRequest::OfInstance { instance, extra_args },
2953-
)
2954-
},
2955-
),
2939+
tcx.fn_abi_of_instance(self.param_env().and((instance, extra_args))).map_err(|err| {
2940+
// HACK(eddyb) at least for definitions of/calls to `Instance`s,
2941+
// we can get some kind of span even if one wasn't provided.
2942+
// However, we don't do this early in order to avoid calling
2943+
// `def_span` unconditionally (which may have a perf penalty).
2944+
let span = if !span.is_dummy() { span } else { tcx.def_span(instance.def_id()) };
2945+
self.handle_fn_abi_err(err, span, FnAbiRequest::OfInstance { instance, extra_args })
2946+
}),
29562947
)
29572948
}
29582949
}
@@ -2962,7 +2953,7 @@ impl<'tcx, C: FnAbiOfHelpers<'tcx>> FnAbiOf<'tcx> for C {}
29622953
fn fn_abi_of_fn_ptr<'tcx>(
29632954
tcx: TyCtxt<'tcx>,
29642955
query: ty::ParamEnvAnd<'tcx, (ty::PolyFnSig<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
2965-
) -> Result<FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
2956+
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
29662957
let (param_env, (sig, extra_args)) = query.into_parts();
29672958

29682959
LayoutCx { tcx, param_env }.fn_abi_new_uncached(
@@ -2977,7 +2968,7 @@ fn fn_abi_of_fn_ptr<'tcx>(
29772968
fn fn_abi_of_instance<'tcx>(
29782969
tcx: TyCtxt<'tcx>,
29792970
query: ty::ParamEnvAnd<'tcx, (ty::Instance<'tcx>, &'tcx ty::List<Ty<'tcx>>)>,
2980-
) -> Result<FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
2971+
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
29812972
let (param_env, (instance, extra_args)) = query.into_parts();
29822973

29832974
let sig = instance.fn_sig_for_fn_abi(tcx, param_env);
@@ -3010,7 +3001,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
30103001
codegen_fn_attr_flags: CodegenFnAttrFlags,
30113002
// FIXME(eddyb) replace this with something typed, like an `enum`.
30123003
force_thin_self_ptr: bool,
3013-
) -> Result<FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
3004+
) -> Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, FnAbiError<'tcx>> {
30143005
debug!("fn_abi_new_uncached({:?}, {:?})", sig, extra_args);
30153006

30163007
let sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, sig);
@@ -3174,7 +3165,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
31743165
};
31753166
self.fn_abi_adjust_for_abi(&mut fn_abi, sig.abi)?;
31763167
debug!("fn_abi_new_uncached = {:?}", fn_abi);
3177-
Ok(fn_abi)
3168+
Ok(self.tcx.arena.alloc(fn_abi))
31783169
}
31793170

31803171
fn fn_abi_adjust_for_abi(

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::abi::{self, Abi, Align, FieldsShape, Size};
22
use crate::abi::{HasDataLayout, TyAbiInterface, TyAndLayout};
33
use crate::spec::{self, HasTargetSpec};
4+
use rustc_span::Symbol;
45
use std::fmt;
56

67
mod aarch64;
@@ -623,10 +624,10 @@ pub struct FnAbi<'a, Ty> {
623624
}
624625

625626
/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
626-
#[derive(Clone, Debug, HashStable_Generic)]
627+
#[derive(Copy, Clone, Debug, HashStable_Generic)]
627628
pub enum AdjustForForeignAbiError {
628629
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
629-
Unsupported { arch: String, abi: spec::abi::Abi },
630+
Unsupported { arch: Symbol, abi: spec::abi::Abi },
630631
}
631632

632633
impl fmt::Display for AdjustForForeignAbiError {
@@ -703,7 +704,10 @@ impl<'a, Ty> FnAbi<'a, Ty> {
703704
"asmjs" => wasm::compute_c_abi_info(cx, self),
704705
"bpf" => bpf::compute_abi_info(self),
705706
arch => {
706-
return Err(AdjustForForeignAbiError::Unsupported { arch: arch.to_string(), abi });
707+
return Err(AdjustForForeignAbiError::Unsupported {
708+
arch: Symbol::intern(arch),
709+
abi,
710+
});
707711
}
708712
}
709713

0 commit comments

Comments
 (0)