missed optimization opportunity for elimination of retain/release and tail recursion #58549
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Describe the bug
Unnecessary retain/release seem to be inhibiting tail recursion optimization in
var leftMost: Expr { args.count == 0 ? self : args.first!.leftMost }To Reproduce
Compiling the above generated a recursive function with retain/release around each step.
Expected behavior
I expected the retain/release to be optimized away and the recursive call to be reduced to an iteration.
Environment (please complete the following information):
Additional context
(I think I checked this in a previous version of Xcode about a year ago, and at that time the compiler did do a tail recursion optimization, so this behavior may be a regression. However, my memory may be faulty confusing this with something else, and I can't remember which previous compiler version to check against.)
Discussion and disassembly are at https://forums.swift.org/t/arc-tail-recursion/57054
Writing the function without the tail recursion still leaves the retain/release around each step.
Jordan Rose writes at https://forums.swift.org/t/arc-tail-recursion/57054/7
The text was updated successfully, but these errors were encountered: