Skip to content

Commit dcd72a6

Browse files
authored
Rollup merge of #144232 - xacrimon:explicit-tail-call, r=WaffleLapkin
Implement support for `become` and explicit tail call codegen for the LLVM backend This PR implements codegen of explicit tail calls via `become` in `rustc_codegen_ssa` and support within the LLVM backend. Completes a task on (rust-lang/rust#112788). This PR implements all the necessary bits to make explicit tail calls usable, other backends have received stubs for now and will ICE if you use `become` on them. I suspect there is some bikeshedding to be done on how we should go about implementing this for other backends, but it should be relatively straightforward for GCC after this is merged. During development I also put together a POC bytecode VM based on tail call dispatch to test these changes out and analyze the codegen to make sure it generates expected assembly. That is available [here](https://github.com/xacrimon/tcvm).
2 parents 4f8d4ca + d852f7c commit dcd72a6

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ codegen_gcc_unwinding_inline_asm =
44
codegen_gcc_copy_bitcode = failed to copy bitcode to object file: {$err}
55
66
codegen_gcc_lto_bitcode_from_rlib = failed to get bitcode from object file for LTO ({$gcc_err})
7+
8+
codegen_gcc_explicit_tail_calls_unsupported = explicit tail calls with the 'become' keyword are not implemented in the GCC backend

src/builder.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi};
3434

3535
use crate::common::{SignType, TypeReflection, type_is_pointer};
3636
use crate::context::CodegenCx;
37+
use crate::errors;
3738
use crate::intrinsic::llvm;
3839
use crate::type_of::LayoutGccExt;
3940

@@ -1742,6 +1743,20 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
17421743
call
17431744
}
17441745

1746+
fn tail_call(
1747+
&mut self,
1748+
_llty: Self::Type,
1749+
_fn_attrs: Option<&CodegenFnAttrs>,
1750+
_fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
1751+
_llfn: Self::Value,
1752+
_args: &[Self::Value],
1753+
_funclet: Option<&Self::Funclet>,
1754+
_instance: Option<Instance<'tcx>>,
1755+
) {
1756+
// FIXME: implement support for explicit tail calls like rustc_codegen_llvm.
1757+
self.tcx.dcx().emit_fatal(errors::ExplicitTailCallsUnsupported);
1758+
}
1759+
17451760
fn zext(&mut self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<'gcc> {
17461761
// FIXME(antoyo): this does not zero-extend.
17471762
self.gcc_int_cast(value, dest_typ)

src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ pub(crate) struct CopyBitcode {
1919
pub(crate) struct LtoBitcodeFromRlib {
2020
pub gcc_err: String,
2121
}
22+
23+
#[derive(Diagnostic)]
24+
#[diag(codegen_gcc_explicit_tail_calls_unsupported)]
25+
pub(crate) struct ExplicitTailCallsUnsupported;

0 commit comments

Comments
 (0)