Skip to content

Implement support for become and explicit tail call codegen for the LLVM backend - #144232

Merged
bors merged 1 commit into
rust-lang:masterfrom
xacrimon:explicit-tail-call
Jul 31, 2025
Merged

Implement support for become and explicit tail call codegen for the LLVM backend#144232
bors merged 1 commit into
rust-lang:masterfrom
xacrimon:explicit-tail-call

Conversation

@xacrimon

@xacrimonxacrimon commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

This PR implements codegen of explicit tail calls via become in rustc_codegen_ssa and support within the LLVM backend. Completes a task on (#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.

@rustbot

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbotrustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@xacrimon
xacrimonforce-pushed the explicit-tail-call branch from 6a6d3c2 to f912c90CompareJuly 20, 2025 22:49
@rust-log-analyzer

This comment has been minimized.

@xacrimon
xacrimonforce-pushed the explicit-tail-call branch 2 times, most recently from b36cf15 to ac87434CompareJuly 20, 2025 23:10
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@xacrimon
xacrimonforce-pushed the explicit-tail-call branch from 138b2a7 to 3fac279CompareJuly 21, 2025 00:14
@rust-log-analyzer

This comment has been minimized.

@jeffparsons

Copy link
Copy Markdown
Contributor

I suspect there is quite a bit of bikeshedding on how we should go about implementing this for WASM

I thought LLVM already supported the Wasm tail-call instructions — what's the missing piece that needs bikeshedding?

@oli-obk

Copy link
Copy Markdown
Contributor

@rustbot author

it seems a tailcall test is still hitting a stack overflow, do you know why?

@rustbotrustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbotrustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 21, 2025
Comment threadcompiler/rustc_codegen_ssa/src/mir/block.rs Outdated
@xacrimon

xacrimon commented Jul 21, 2025

Copy link
Copy Markdown
ContributorAuthor

@rustbot author

it seems a tailcall test is still hitting a stack overflow, do you know why?

This was me mistakenly marking the rest @run-fail instead of @run-crash, that was intentional and it has now been fixed. That one is marked no-tce and doesn't use become. There is another one called tce instead of no-tce which uses become and is set to @run-pass.

@xacrimon

Copy link
Copy Markdown
ContributorAuthor

I suspect there is quite a bit of bikeshedding on how we should go about implementing this for WASM

I thought LLVM already supported the Wasm tail-call instructions — what's the missing piece that needs bikeshedding?

Ah, my knowledge is outdated then. I've edited my comment, though point still stands for backends that aren't llvm/gcc.

@xacrimon

Copy link
Copy Markdown
ContributorAuthor

@rustbot ready

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 21, 2025
@xacrimon
xacrimon requested review from bjorn3 and tmiaskoJuly 21, 2025 18:37
@xacrimon

Copy link
Copy Markdown
ContributorAuthor

@WaffleLapkin I'm going to go ahead and guess this is something you want to have a look at.

@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

Thanks! Glad we finally support it!

@bors

bors commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit ecf34e1 has been approved by oli-obk

It is now in the queue for this repository.

@WaffleLapkin

Copy link
Copy Markdown
Member

Thanks!
@bors r+

@bors

bors commented Jul 30, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit a448837 has been approved by WaffleLapkin

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Jul 31, 2025
…fleLapkin
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#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).
@ZalatharZalathar mentioned this pull request Jul 31, 2025
bors added a commit that referenced this pull request Jul 31, 2025
Rollup of 6 pull requests
Successful merges:
- #135975 (Implement `push_mut`)
- #143672 (Fix Box allocator drop elaboration)
- #144232 (Implement support for `become` and explicit tail call codegen for the LLVM backend)
- #144663 (coverage: Re-land "Enlarge empty spans during MIR instrumentation")
- #144683 (Simplify library dependencies on `compiler-builtins`)
- #144685 (Only extract lang items once in codegen_fn_attrs)
r? `@ghost`
`@rustbot` modify labels: rollup
@ZalatharZalathar mentioned this pull request Jul 31, 2025
bors added a commit that referenced this pull request Jul 31, 2025
Rollup of 6 pull requests
Successful merges:
- #135975 (Implement `push_mut`)
- #143672 (Fix Box allocator drop elaboration)
- #144232 (Implement support for `become` and explicit tail call codegen for the LLVM backend)
- #144663 (coverage: Re-land "Enlarge empty spans during MIR instrumentation")
- #144685 (Only extract lang items once in codegen_fn_attrs)
- #144717 (Move `rustc_middle::parameterized`)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 8628b78 into rust-lang:masterJul 31, 2025
10 checks passed
@rustbotrustbot added this to the 1.90.0 milestone Jul 31, 2025
rust-timer added a commit that referenced this pull request Jul 31, 2025
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 (#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).
@WaffleLapkinWaffleLapkin added the F-explicit_tail_calls `#![feature(explicit_tail_calls)]` label Aug 1, 2025
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 3, 2025
…ffleLapkin
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang#144232Closesrust-lang#144293
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 3, 2025
…ffleLapkin
Additional tce tests
r? ``@oli-obk``
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang#144232Closesrust-lang#144293
GuillaumeGomez pushed a commit to GuillaumeGomez/rust that referenced this pull request Aug 4, 2025
…fleLapkin
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#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).
tgross35 added a commit to tgross35/rust that referenced this pull request Aug 6, 2025
…ffleLapkin
Additional tce tests
r? ``@oli-obk``
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang#144232Closesrust-lang#144293
True,
}

/// Indicates to the call terminator codegen whether a cal

@L0uiscL0uiscAug 6, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final word on the line is misspelled - should be call if I'm not mistaken.

EDIT: I see the PR is merged last week. I'm not that familiar with GitHub's UI these days. Sorry for causing noise on a merged PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included a fix of this typo in #144865

Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 7, 2025
…ffleLapkin,tgross35
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang#144232Closesrust-lang#144293
rust-timer added a commit that referenced this pull request Aug 7, 2025
Rollup merge of #144650 - Borgerr:additional-tce-tests, r=WaffleLapkin,tgross35
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on #144232Closes#144293
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Aug 8, 2025
…n,tgross35
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang/rust#144232Closesrust-lang/rust#144293
github-actionsBot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Aug 11, 2025
…n,tgross35
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang/rust#144232Closesrust-lang/rust#144293
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 18, 2025
…n,tgross35
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang/rust#144232Closesrust-lang/rust#144293
Kobzol pushed a commit to Kobzol/rustc_codegen_gcc that referenced this pull request Dec 21, 2025
Rollup of 6 pull requests
Successful merges:
- rust-lang/rust#135975 (Implement `push_mut`)
- rust-lang/rust#143672 (Fix Box allocator drop elaboration)
- rust-lang/rust#144232 (Implement support for `become` and explicit tail call codegen for the LLVM backend)
- rust-lang/rust#144663 (coverage: Re-land "Enlarge empty spans during MIR instrumentation")
- rust-lang/rust#144685 (Only extract lang items once in codegen_fn_attrs)
- rust-lang/rust#144717 (Move `rustc_middle::parameterized`)
r? `@ghost`
`@rustbot` modify labels: rollup
Kobzol pushed a commit to Kobzol/rustc_codegen_gcc that referenced this pull request Dec 21, 2025
…n,tgross35
Additional tce tests
r? `@oli-obk`
Adds known-bug tests for LLVM emissions regarding indirect operands for TCE. Also includes a test, `indexer.rs`, referring to function_table behavior described by the RFC.
Depends on rust-lang/rust#144232Closesrust-lang/rust#144293
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.F-explicit_tail_calls`#![feature(explicit_tail_calls)]`S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

13 participants

@xacrimon@rustbot@rust-log-analyzer@jeffparsons@oli-obk@bors@fmease@jieyouxu@lqd@WaffleLapkin@bjorn3@L0uisc@tmiasko