No maximum. In practice, the number is typically very small.
This particular function is one of a dozen with the same issue, so it would take some work to change them all and measure the effect. Looking at the generated code:
@inline(never)
var leftMost: Expr {
var expr = self
while expr.count > 0 { expr = expr.args[0] }
return expr
}
generates
Calculator`Expr.leftMost.getter:
0x1030cf244 <+0>: stp x22, x21, [sp, #-0x30]!
0x1030cf248 <+4>: stp x20, x19, [sp, #0x10]
0x1030cf24c <+8>: stp x29, x30, [sp, #0x20]
0x1030cf250 <+12>: add x29, sp, #0x20
0x1030cf254 <+16>: ldr x21, [x20, #0x38]
0x1030cf258 <+20>: ldr x19, [x21, #0x10]
0x1030cf25c <+24>: mov x0, x20
0x1030cf260 <+28>: bl 0x1035c1688 ; symbol stub for: swift_retain
-> 0x1030cf264 <+32>: cbz x19, 0x1030cf290 ; <+76> at Expr.swift
0x1030cf268 <+36>: ldr x19, [x21, #0x20]
0x1030cf26c <+40>: mov x0, x19
0x1030cf270 <+44>: bl 0x1035c1688 ; symbol stub for: swift_retain
0x1030cf274 <+48>: mov x0, x20
0x1030cf278 <+52>: bl 0x1035c1670 ; symbol stub for: swift_release
0x1030cf27c <+56>: ldr x21, [x19, #0x38]
0x1030cf280 <+60>: ldr x8, [x21, #0x10]
0x1030cf284 <+64>: mov x20, x19
0x1030cf288 <+68>: cbnz x8, 0x1030cf268 ; <+36> [inlined] generic specialization <Graphing_Calculator.Expr> of Swift.ContiguousArray.subscript.getter : (Swift.Int) -> τ_0_0 at <compiler-generated>
0x1030cf28c <+72>: b 0x1030cf294 ; <+80> at Expr.swift:223:9
0x1030cf290 <+76>: mov x19, x20
0x1030cf294 <+80>: mov x0, x19
0x1030cf298 <+84>: ldp x29, x30, [sp, #0x20]
0x1030cf29c <+88>: ldp x20, x19, [sp, #0x10]
0x1030cf2a0 <+92>: ldp x22, x21, [sp], #0x30
0x1030cf2a4 <+
while
@inline(never)
var leftMost: Expr {
unowned var expr = self
while expr.count > 0 { expr = expr.args[0] }
return expr
generates
Graphing Calculator`Expr.leftMost.getter:
0x100ba77e4 <+0>: stp x22, x21, [sp, #-0x30]!
0x100ba77e8 <+4>: stp x20, x19, [sp, #0x10]
0x100ba77ec <+8>: stp x29, x30, [sp, #0x20]
0x100ba77f0 <+12>: add x29, sp, #0x20
-> 0x100ba77f4 <+16>: mov x0, x20
0x100ba77f8 <+20>: bl 0x1010997c0 ; symbol stub for: swift_unownedRetainStrong
0x100ba77fc <+24>: ldr x8, [x20, #0x38]
0x100ba7800 <+28>: ldr x19, [x8, #0x10]
0x100ba7804 <+32>: bl 0x1010997b4 ; symbol stub for: swift_unownedRetain
0x100ba7808 <+36>: bl 0x101099670 ; symbol stub for: swift_release
0x100ba780c <+40>: cbz x19, 0x100ba7860 ; <+124> at Expr.swift
0x100ba7810 <+44>: mov x0, x20
0x100ba7814 <+48>: bl 0x1010997c0 ; symbol stub for: swift_unownedRetainStrong
0x100ba7818 <+52>: ldr x8, [x20, #0x38]
0x100ba781c <+56>: ldr x9, [x8, #0x10]
0x100ba7820 <+60>: cbz x9, 0x100ba7884 ; <+160> [inlined] Swift runtime failure: Index out of range at <compiler-generated>
0x100ba7824 <+64>: ldr x19, [x8, #0x20]
0x100ba7828 <+68>: mov x0, x19
0x100ba782c <+72>: bl 0x1010997b4 ; symbol stub for: swift_unownedRetain
0x100ba7830 <+76>: mov x0, x20
0x100ba7834 <+80>: bl 0x1010997a8 ; symbol stub for: swift_unownedRelease
0x100ba7838 <+84>: mov x0, x20
0x100ba783c <+88>: bl 0x101099670 ; symbol stub for: swift_release
0x100ba7840 <+92>: mov x0, x19
0x100ba7844 <+96>: bl 0x1010997c0 ; symbol stub for: swift_unownedRetainStrong
0x100ba7848 <+100>: ldr x8, [x19, #0x38]
0x100ba784c <+104>: ldr x21, [x8, #0x10]
0x100ba7850 <+108>: bl 0x101099670 ; symbol stub for: swift_release
0x100ba7854 <+112>: mov x20, x19
0x100ba7858 <+116>: cbnz x21, 0x100ba7810 ; <+44> at Expr.swift:222:39
0x100ba785c <+120>: b 0x100ba7864 ; <+128> at Expr.swift:223:16
0x100ba7860 <+124>: mov x19, x20
0x100ba7864 <+128>: mov x0, x19
0x100ba7868 <+132>: bl 0x1010997c0 ; symbol stub for: swift_unownedRetainStrong
0x100ba786c <+136>: bl 0x1010997a8 ; symbol stub for: swift_unownedRelease
0x100ba7870 <+140>: mov x0, x19
0x100ba7874 <+144>: ldp x29, x30, [sp, #0x20]
0x100ba7878 <+148>: ldp x20, x19, [sp, #0x10]
0x100ba787c <+152>: ldp x22, x21, [sp], #0x30
0x100ba7880 <+156>: ret
0x100ba7884 <+160>: brk #0x1
but I am in over my depths to interpret any of that.