Skip to content

Commit 3a36964

Browse files
committed
add section on hiding generated methods
1 parent f1fdf2a commit 3a36964

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

content/unroll-default-arguments.md

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,19 @@ is defined but not implemented. Such an un-implemented abstract method is someth
579579
we want to avoid, even if our artifact version constraints mean it should technically
580580
never get called.
581581

582+
### Hiding Generated Forwarder Methods
583+
584+
As the generated forwarder methods are intended only for binary compatibility purposes,
585+
we should generally hide them: IDEs, downstream compilers, ScalaDoc, etc. should behave as
586+
if the generated methods do not exist.
587+
588+
This is done in two different ways:
589+
590+
1. In Scala 2, we generate the methods in a post-`pickler` phase. This ensures they do
591+
not appear in the scala signature, and thus are not exposed to downstream tooling
592+
593+
2. In Scala 3, the generated methods are flagged as `Invisible`
594+
582595
## Limitations
583596

584597
### Only the one parameter list of multi-parameter list methods can be `@unroll`ed.
@@ -825,25 +838,6 @@ object Unrolled{
825838
```
826839

827840

828-
### Should the Generated Methods be Deprecated or Invisible?
829-
830-
It is not clear to me if we should discourage usage of the generated forwarders
831-
methods, or hide them:
832-
833-
1. On one hand, downstream code should not be compiling against these methods: they are
834-
purely for binary compatibility
835-
836-
2. On the other hand, downstream code does not control which overload of the method is
837-
selected: that is up to the Scala compiler and how overloading interacts with default
838-
parameter values. I have encountered scenarios with manually-written forwarders where
839-
selected over the "primary" implementation
840-
841-
3. The forwarders are meant to have the exact same semantics as the "primary" implementation.
842-
Thus it _does not matter_ whether you call the primary and pass it a default value,
843-
or you call a forwarder which then calls the primary and passes it the same default value.
844-
845-
For now, I have left the generated methods "as is", though choosing to hide them or deprecate
846-
them or something else is definitely an option
847841

848842
### Generating Forwarders For Parameter Type Widening or Result Type Narrowing
849843

0 commit comments

Comments
 (0)