-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
tail return
proposal
#1761
Comments
I agree, we need something to help complier. But I don't want it is a keyword. In my opinion, attribute is a good choice. |
Try to avoid "stealing" names that are commonly used in algorithms: head, tail, next, prev, iter, etc… |
Could it work if we made it so if you used |
I agree with using an attribute, to avoid stealing common variable names, for example: Also I think it's too early for this proposal. There are much more important things that would be better focused on right now. |
The "Tail Calls" section of this C++ proposal might also be a useful reference, if you'll pardon the self-citation. I personally agree that
|
|
Is the idea that you can write a That is quite heavy duty… and you would need full access to all source code used. But, having better functional programming support than C++ would be a great selling point. |
If you can move the constructor/destructor pair out of the resulting loop and get the same behaviour, why not? If the only observable effect is that you get fewer calls to malloc()/free() because reuse is possible, why not? Added: You could define a concept of «internal side effects» as a change in behaviour that is contained to the runtime/standard library. Then allow all of those «internal side effects» in functions that request |
In the ES spec (ECMA Script / javascript) proposals for tail call/return (and then revising the spec in that area for practical reasons) there were a few big issues for discussion and debated in terms of implementation:
|
There's the Carbon explorer (interpreter) and a production Carbon compiler is (or will be) based on LLVM. It's not obvious to me whether it will be feasible to transpile Carbon to C++ the way the original CFront transpiled C++ to C code (not to object code). Feasible meaning not just a proof-of-concept, but something you could use in production. C++ is Turing complete, but still, requiring TCE (Tail Call Elimination) could make transpilation harder. There's no definitive right answer and it's all trade-offs. I was just wondering whether it was an explicit goal or non-goal to rule in or out a CFront-like thing. (This question could possibly spin out as a separate issue). |
See the interoperability goals proposal:
But see also the following paragraph, about how C++ code generation will not necessarily support all Carbon features with full fidelity. This is only intended as an interoperability tool; we definitely don't expect or intend to go through a phase where all Carbon code is transpiled to C++, the way all C++ code was transpiled to C in the CFront era. |
@chandlerc Would you like to weigh in on the CFront-style transpiler is something we want to support? |
Just for reference: ATS is using |
I'm not opposed to some folks working on this if they want, but I think there are good reasons why neither the explorer nor the main toolchain should take this direction. For the explorer, I think its primary value is in simplicity and very clearly and unambiguously matching the intended semantics of the language. I would worry about trying to generate code via mapping into C/C++ source code here being very difficult to avoid accidental semantic effects from the target language. The most effective way I know to do this is to map it into a very low level of the target language, which works but is also somewhat difficult and labor intensive. It's not clear this provides enough value on top of the fairly simple and effective high level interpreter in the explorer. But this is just my impression, and I don't have the deepest understanding of the explorer so I may be missing things. For the toolchain, our goal is to allow this to become a production quality toolchain as the experiment matures and undertakes increasingly significant real-world evaluations. I suspect that compiling down to C/C++ source code would significantly hamper this because it would be hard to realize some of the specific value propositions of Carbon with this design. For example, I would expect such a toolchain to be somewhat brittle, have significantly worse compile times, and potentially generate poor performing code because of being forced to indirect through a source language rather than directly working with the underlying compiler infrastructure. The generics model of Carbon would also have to be entirely handled before emitting the low-level code, and I suspect a very large fraction of the complexity of any toolchain will be consumed in the generics and type checking infrastructure that won't be saved by lowering to C/C++. But again, while these points may argue against using this strategy for these two efforts, they don't necessarily argue against having such an implementation for other reasons. |
I don't think it's controversial that neither the explorer nor the main toolchain uses transpliation. I'm more concerned about other toolchains. My question is, if it comes down to "(1) e.g. Mandatory TCE (Tail Call Elimination); (2) Transpiling Carbon to C++ is viable; choose one", is there early guidance on Carbon's choice? |
This is a useful distillation and gets to my underlying hesitancy with transpilation. I do not think Carbon's semantics should be constrained by what we can transpile to C/C++. So I think that means if the only tradeoff is the above, it's option (1) all the way. There are lots of fancy, kludgy ways to transpile to get very precise functionality like this. If Carbon benefits from guaranteed TCE, then those will be necessary, and that's the cost of trying to transpile. I really want carbon to be free to innovate semantically here. |
It's tangential from |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the |
I want to work on this issue please assign this issue to me |
@Akashgola123 We typically won't assign issues. I've added some documentation for why. Please feel to work on it if you have time, but please through the proposal process to get a better understanding of what to expect. |
Also, just to note -- I've checked with josh11b, and as proposals can be a little more complex, I've unmarked this as a "good first issue". |
I think the Carbon project would welcome a proposal to add an explicit syntax that forces a tail call. This is aligned with our goals of predictable performance and giving the user explicit control.
My syntax suggestion:
tail return F(...);
.Background:
[[clang::musttail]]
attribute for guaranteed tail calls.The text was updated successfully, but these errors were encountered: