Skip to content

Commit 339ed80

Browse files
committed
.
1 parent aaf81ef commit 339ed80

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

content/unroll-default-arguments.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,9 @@ use them when the given `p: Product` has a smaller `productArity` than the curre
468468

469469
6. `@unroll` only supports `final` methods. `object` methods and constructors are naturally
470470
final, but `class` or `trait` methods that are `@unroll`ed need to be explicitly marked `final`.
471-
Trying to implement the semantics of `@unroll` in the presence of downstream overrides,
472-
where the downstream overrides can be compiled against by different versions of the upstream
473-
code, has proved difficult. If we can come up with some implementation that works, we can
471+
It has proved difficult to implement the semantics of `@unroll` in the presence of downstream
472+
overrides, `super`, etc. where the downstream overrides can be compiled against by different
473+
versions of the upstream code. If we can come up with some implementation that works, we can
474474
lift this restriction later, but for now I have not managed to do so and so this restriction
475475
stays.
476476

@@ -696,6 +696,36 @@ allow anyone calling the original signature \to be forwarded to the narrower sig
696696

697697
This is not currently implemented in `@unroll`, but would be a straightforward addition.
698698

699+
### Incremental Forwarders or Direct Forwarders
700+
701+
Given this:
702+
703+
```scala
704+
def foo(s: String, n: Int = 1, @unroll b: Boolean = true, l: Long = 0) = s + n + b + l
705+
```
706+
707+
There are two ways to do the forwarders. First option, which I used in above, is
708+
to have each forwarder directly call the primary method:
709+
710+
```scala
711+
def foo(s: String, n: Int, b: Boolean) = foo(s, n, b, 0)
712+
def foo(s: String, n: Int) = foo(s, n, true, 0)
713+
```
714+
715+
Second option is to have each forwarder incrementally call the next forwarder, which
716+
will eventually end up calling the primary method:
717+
718+
```scala
719+
def foo(s: String, n: Int, b: Boolean) = foo(s, n, b, 0)
720+
def foo(s: String, n: Int) = foo(s, n, true)
721+
```
722+
723+
The first option results in shorter stack traces, while the second option results in
724+
roughly half as much generated bytecode in the method bodies (though it's still `O(n^2)`).
725+
726+
For now I chose the first option.
727+
728+
699729
## Implementation & Testing
700730

701731
This SIP has a full implementation for Scala {2.12, 2.13, 3} X {JVM, JS, Native}

0 commit comments

Comments
 (0)