Skip to content

Do proper signature equality checking for tail calls#156007

Open
WaffleLapkin wants to merge 4 commits intorust-lang:mainfrom
WaffleLapkin:tail-call-proper-sig-eq
Open

Do proper signature equality checking for tail calls#156007
WaffleLapkin wants to merge 4 commits intorust-lang:mainfrom
WaffleLapkin:tail-call-proper-sig-eq

Conversation

@WaffleLapkin
Copy link
Copy Markdown
Member

@WaffleLapkin WaffleLapkin commented Apr 30, 2026

For tail calls to be valid, we need some support from the ABI, specifically the caller of the function needs to be able to do all necessary cleanup after the tail called function returns. This can be achieved with a callee-cleanup ABI, but we want to permit tail calls for other ABIs as well (in particular, extern "rust").

In such cases the property that we are looking for is "the caller and callee require the same cleanup". We approximate this with "caller and callee have the same ABI" and we approximate that with "caller and callee have the same signatures (modulo subtyping)".

Previously the code would compare FnSigs with ==, which would not support subtyping and produced other weird results. This PR changes tail call checks to use type checking machinery and in particular eq.

It also fixes handling of opaque types, given the next trait solver is enabled.

r? types

@WaffleLapkin WaffleLapkin added the F-explicit_tail_calls `#![feature(explicit_tail_calls)]` label Apr 30, 2026
@rustbot rustbot added 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 Apr 30, 2026
@rust-log-analyzer

This comment has been minimized.

become foo(x, y);
//~^ ERROR mismatched signatures
//[current]~^ ERROR mismatched signatures
}
Copy link
Copy Markdown
Contributor

@folkertdev folkertdev Apr 30, 2026

Choose a reason for hiding this comment

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

cc #144953

What exactly makes RPIT not work for the old trait solver?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not quite sure (lcnr can probably explain better), but something something opaque types are more annoying to handle in the old solver and in this case they are not being revealed as their hidden type.

@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin force-pushed the tail-call-proper-sig-eq branch from 15bd832 to 1ce7add Compare May 1, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants