-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
foo(...)->f as b should be tail callable if both are aliases of the same type #1215
Comments
This should work for imports of functions, consts, and types, and in const definitions, too. The general rule would be that a cast In |
Implementing this requires modifying the parser and dropping cast expressions after type checking. This either needs an extra pass or special treatment of Please give feedback on the right approach to implement this. |
This depends on #217. As far as I know tail calls simply don't work in Rust. |
Let's say, they would. What would be right way to approach this (or answer for import, const). Do I really need to add another pass just for this? Is there anything to watch out for when changing the ast just before trans? |
I was focused on tail calls and didn't notice that this is mostly about treating machine types as ints, etc, which would obviously be nice. I would start by just adding a new method to ty, like are_trivially_castable, then using that in the few analysis passes where this might matter (typechecking for be, const checking) and then in the corresponding places in trans (we have a lot of these little situations where the analysis and translation are completely disconnected and just make the same assumptions and rely on tests to ensure correctness). The const case seems like a no-brainer - we can just support whatever constant scalar casting operations that the LLVMConst* functions get us, which is probably a lot more than just casts of the same machine type. Needs changes to middle::check_const and middle::trans::trans_const_expr. Changing import like that probably requires further discussion with people other than me. On first glance I wonder if there's some other solution. Putting the 'as' keyword into a non-expression context is a big step, though the implementation would probably just be a matter of changing the parser and type checker. |
Did this for "be" now, as you suggested. Consts coming up next, don't pull yet, will rebase: |
(cf @ignored Expr.Be and rust-lang#1215 for intended use)
Imagine a tail call
{ be foo() as int }
wherefoo()
returns ani32
and on the current arch it is known that integers are 32 bit wide.In this case, it should be ok to drop the cast and tail-call
foo()
.The idea for this came up when rewriting
std::math
, cfhttps://github.com/boggle/rust/blob/libmath/src/lib/math.rs
The text was updated successfully, but these errors were encountered: