Skip to content

Reject tail calls of #[track_caller] functions #144762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WaffleLapkin
Copy link
Member

@WaffleLapkin WaffleLapkin commented Aug 1, 2025

To make tail calls possible either both functions need to be #[track_caller], or neither can. For simplicity I propose to just disallow using tail calling #[track_caller] functions / tail calling from #[track_caller] functions. I don't think #[track_caller] is useful with tail calls anyway.

However, we do need to have a quite late check, after monopolization (as otherwise you don't necessarily know if the callee has #[track_caller]).

I'm not very happy with this implementation -- error'ing in the backend seems like a hack and will probably lead to disagreements between backends. Ideally we'd have a mir specific check (that would also probably make getting the span easier...).

Fixes #144755

@rustbot
Copy link
Collaborator

rustbot commented Aug 1, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
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

@rustbot rustbot 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 Aug 1, 2025
@WaffleLapkin WaffleLapkin added the F-explicit_tail_calls `#![feature(explicit_tail_calls)]` label Aug 1, 2025
@WaffleLapkin
Copy link
Member Author

Hm. Alternatively, instead of rejecting callee being #[track_caller], we could use a shim (similarly to what happens when casting a #[track_caller] fn to a function pointer). I'm not sure how to do that though 🤔

@bjorn3
Copy link
Member

bjorn3 commented Aug 1, 2025

nit in PR description: s/monopolization/monomorphization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-explicit_tail_calls `#![feature(explicit_tail_calls)]` 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cannot guarantee tail call due to mismatched parameter counts
4 participants