Skip to content
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

Asymmetric generic signatures for HKT in covariant/contravariant types #21576

Open
WojciechMazur opened this issue Sep 11, 2024 · 2 comments
Open

Comments

@WojciechMazur
Copy link
Contributor

Based on apache/pekko#1474

In Scala 2.13 all generic param types of HKT (both covariant and invariant) are transformed into wildcard types.
In 3.3.4-RC1 / 3.5.0 contravariant types are preserved but erased.
In 3.3.3- both contravariant and covariant types were preserved and not erased

Compiler version

3.3.4 / 3.5.0

Minimized code

import scala.annotation.unchecked.uncheckedVariance

trait SubFlowDef[+F[+_]]
final class Flow1[-In]{
  type Repr[+O] = Flow1[In @uncheckedVariance]
}
final class Flow2[+Out]{
  type Repr[+O] = Flow2[O]
}
class SubFlow[In, Out](
    delegate1: SubFlowDef[Flow1[In]#Repr],
    delegate2: SubFlowDef[Flow2[Out]#Repr] 
)

Output

Based on javap outputs

Signatures:
Scala 3.3.4-RC1 / 3.5.0

  public SubFlow(SubFlowDef<?>, SubFlowDef<Flow2>);
    descriptor: (LSubFlowDef;LSubFlowDef;)V
    Signature: #9                           // (LSubFlowDef<*>;LSubFlowDef<LFlow2;>;)V

Scala 2.13

  public SubFlow(SubFlowDef<?>, SubFlowDef<?>);
    descriptor: (LSubFlowDef;LSubFlowDef;)V
    Signature: #12                          // (LSubFlowDef<*>;LSubFlowDef<*>;)V

Scala 3.3.3

  public SubFlow(SubFlowDef<Flow1<In>>, SubFlowDef<Flow2<java.lang.Object>>);
    descriptor: (LSubFlowDef;LSubFlowDef;)V
    Signature: #9                           // (LSubFlowDef<LFlow1<TIn;>;>;LSubFlowDef<LFlow2<Ljava/lang/Object;>;>;)V

Expectation

Probably both covariant and contravaraint types should have been replaced with wildcard types in generic signatures

@WojciechMazur WojciechMazur added itype:bug compat:scala2 area:backend stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 11, 2024
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Sep 12, 2024
@WojciechMazur
Copy link
Contributor Author

The bisect shows that behaviour between 3.5.0 and 3.3.3 changed in #19931
The change in typer led to a change in generic signatures emitted by the backend.

@WojciechMazur
Copy link
Contributor Author

The current generic signature for covariant HKT is incorrect (LSubFlowDef<LFlow2;>) and is invalid, it should be never emitted. We need to either restore old behaviour or emit wildcard types instead.
It means that both 3.5.0 and 3.5.1 releases are producing invalid generic signatures. We should fix in the next release

The PR introducing the change to LTS was reverted (#21609)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants