-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Fix tail calling intrinsics #144815
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
Fix tail calling intrinsics #144815
Conversation
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
The job Click to see the possible cause of the failure (guessed by this bot)
|
The fact that fn main() {
let _: unsafe fn(()) = std::mem::transmute::<(), ()>;
}
|
@theemathas's comment reminded me about #106281 (comment), so I went and wrote rust-lang/rfcs#3844 to propose the alternative here: that we just make |
Rvalue::NullaryOp(null_op, tp_ty), | ||
))), | ||
)); | ||
terminator.kind = TerminatorKind::Goto { target }; | ||
terminator.kind = cont.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I opened the code change thinking "well, if this is small then whatever we can just do it", but needing all these cont
s is kinda annoying, and I definitely don't think I'd (personally) be excited to write double the tests to make sure that the call and the become
both work the next time I add something to this fine.
How many intrinsics exist in the wild that are allowed to be called from stable? Could we do something simpler just for those? Then we could just do an rust-lang/compiler-team#620 ICE for TailCall'ing any other intrinsic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many intrinsics exist in the wild that are allowed to be called from stable?
From searching for #[stable
in https://doc.rust-lang.org/stable/src/core/intrinsics/mod.rs.html#3830, it appears it's only transmute
(there are a few other stable functions, but they are wrapper functions, not intrinsics directly)
Gives this and #144815 (comment) I'm inclined to say it's fine to forbid tail-calling intrinsics. I think I'll change this PR to make it an error to tail call an intrinsic.
…mpiler-errors,scottmcm Forbid tail calling intrinsics There is only one intrinsic that can be called on stable, as far as I can find, (`transmute`). And in general tail calling intrinsics doesn't make much sense. Alternative to rust-lang#144815 (and thus closes rust-lang#144815) Fixes rust-lang#144806 r? `@scottmcm`
…mpiler-errors,scottmcm Forbid tail calling intrinsics There is only one intrinsic that can be called on stable, as far as I can find, (`transmute`). And in general tail calling intrinsics doesn't make much sense. Alternative to rust-lang#144815 (and thus closes rust-lang#144815) Fixes rust-lang#144806 r? ``@scottmcm``
Rollup merge of #144851 - WaffleLapkin:instrinsic-deny, r=compiler-errors,scottmcm Forbid tail calling intrinsics There is only one intrinsic that can be called on stable, as far as I can find, (`transmute`). And in general tail calling intrinsics doesn't make much sense. Alternative to #144815 (and thus closes #144815) Fixes #144806 r? ``@scottmcm``
…rors,scottmcm Forbid tail calling intrinsics There is only one intrinsic that can be called on stable, as far as I can find, (`transmute`). And in general tail calling intrinsics doesn't make much sense. Alternative to rust-lang/rust#144815 (and thus closes rust-lang/rust#144815) Fixes rust-lang/rust#144806 r? ``@scottmcm``
Tail-calling intrinsics used to ICE/miscompile, this PR fixes that.
The reason I think we should explicitly support calling intrinsics, rather than banning it, is that I don't think we want to expose to users if a function is an intrinsic or not. This is especially relevant with something like
std::mem::transmute
which is a direct export of the intrinsic, rather than a wrapper function.The fix has two parts:
cg_ssa
I added code which transforms a tail call to an intrinsic into intrinsic desugaring+ret. This feels like a hack, but I don't really see a better way. (cc @scottmcm, maybe you have an opinion?)Fixes #144806