8000 Migration improvements by soc · Pull Request #49 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Migration improvements #49

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

Closed
wants to merge 1 commit into from
Closed

Migration improvements #49

wants to merge 1 commit into from

Conversation

soc
Copy link
Contributor
@soc soc commented Dec 8, 2011

Don't show migration messages from 2.7 for people needing migration
advice for their 2.9 -> 2.10 move, but keep all the information
for developers needing it.

Xmigration accepts a specific version like -Xmigration:2.8 now.
This will show only migration warnings since that version.

Default for -Xmigration is "2.9".

Adjusted tests, added some new. All tests pass.

Fixes SI-4990.

Don't show migration messages from 2.7 for people needing migration
advice for their 2.9 -> 2.10 move, but keep all the information
for developers needing it.

Xmigration accepts a specific version like -Xmigration:2.8 now.
This will show only migration warnings since that version.

Default for -Xmigration is "2.9".

Adjusted tests, added some new. All tests pass.

Fixes SI-4990.
@soc
Copy link
Contributor Author
soc commented Dec 22, 2011

Let me know if this needs adjustments, please.

@paulp
Copy link
Contributor
paulp commented Jan 9, 2012

Although I know the distribution has many of them, "catch _ => ..." is unacceptable. I'll try to incorporate this patch, I just haven't done it because I want to do something different wrt versions and I have no time.

@scala-jenkins
Copy link

jenkins job pr-scala-testsuite-linux-opt: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/14/

@adriaanm
Copy link
Contributor

It'd be great if you could rework this patch to incorporate Paul's feedback and submit a new pull request. Thanks!

@adriaanm adriaanm closed this May 19, 2012
@soc
Copy link
Contributor Author
soc commented May 20, 2012

@adriaanm Ok, will do that. I assumed from Paul's comments that he intended to change the things regarding the versions himself.
One problem without solution (currently) is how to make third-party users usages of migration annotation work. If, for example the version of some third-party lib adds an annotation with version "1.5", it won't be shown anymore, because the compiler only knows his own version numbers.

So either we have to specify that library writers should use the Scala version they target instead of their own library version (which doesn't make that much sense) or we need some way to differentiate between "Scala version numbers" and "other version numbers", so that the hiding only affects the Scala version numbers.

Any idea or suggestion?

retronym referenced this pull request in retronym/scala May 19, 2015
See also: https://github.com/retronym/indy-structural

```
qscalac -target:jvm-1.8 -Ybackend:GenBCode sandbox/structural.scala && qscala Test && javap -v 'Test$' | cat -v
warning: there was one feature warning; re-run with -feature for details
one warning found

QUACK! A
QUICK! A

Classfile /Users/jason/code/scala2/Test$.class
{
  public static final Test$ MODULE$;
    descriptor: LTest$;
    flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL

  public void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC
    Code:
      stack=4, locals=2, args_size=2
         0: getstatic     #19                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
         3: aload_0
         4: new           #21                 // class C
         7: dup
         8: invokespecial #22                 // Method C."<init>":()V
        11: invokevirtual #26                 // Method duckduck:(Ljava/lang/Object;)Ljava/lang/String;
        14: invokevirtual #30                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
        17: getstatic     #19                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
        20: aload_0
        21: new           #32                 // class D
        24: dup
        25: invokespecial #33                 // Method D."<init>":()V
        28: invokevirtual #26                 // Method duckduck:(Ljava/lang/Object;)Ljava/lang/String;
        31: invokevirtual #30                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
        34: return

  public java.lang.String duckduck(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/String;
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_1
         1: ldc           #38                 // String A
         3: invokedynamic #49,  0             // InvokeDynamic #0:"dyn:callMethod:quack":(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;
         8: checkcast     #51                 // class java/lang/String
        11: areturn

}
BootstrapMethods:
  0: #45 invokestatic jdk/internal/dynalink/DefaultBootstrapper.bootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
    Method arguments:

```
retronym referenced this pull request in retronym/scala May 19, 2015
See also: https://github.com/retronym/indy-structural

```
// sandbox/structural.scala
object Test {
  def main(args: Array[String]): Unit = {
    println(duckduck(new C))
    println(duckduck(new D))
  }

  def duckduck(a: { def quack(a: String): String }): String = {
    a.quack("A")
  }

}

class C {
  def quack(a: String) = "QUACK! " + a
}

class D {
  def quack(a: String) = "QUICK! " + a
}
```

```
qscalac -target:jvm-1.8 -Ybackend:GenBCode sandbox/structural.scala && qscala Test && javap -v 'Test$' | cat -v
warning: there was one feature warning; re-run with -feature for details
one warning found

QUACK! A
QUICK! A

Classfile /Users/jason/code/scala2/Test$.class
{
  public static final Test$ MODULE$;
    descriptor: LTest$;
    flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL

  public void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC
    Code:
      stack=4, locals=2, args_size=2
         0: getstatic     #19                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
         3: aload_0
         4: new           #21                 // class C
         7: dup
   
8000
      8: invokespecial #22                 // Method C."<init>":()V
        11: invokevirtual #26                 // Method duckduck:(Ljava/lang/Object;)Ljava/lang/String;
        14: invokevirtual #30                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
        17: getstatic     #19                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
        20: aload_0
        21: new           #32                 // class D
        24: dup
        25: invokespecial #33                 // Method D."<init>":()V
        28: invokevirtual #26                 // Method duckduck:(Ljava/lang/Object;)Ljava/lang/String;
        31: invokevirtual #30                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
        34: return

  public java.lang.String duckduck(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/String;
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_1
         1: ldc           #38                 // String A
         3: invokedynamic #49,  0             // InvokeDynamic #0:"dyn:callMethod:quack":(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;
         8: checkcast     #51                 // class java/lang/String
        11: areturn

}
BootstrapMethods:
  0: #45 invokestatic jdk/internal/dynalink/DefaultBootstrapper.bootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
    Method arguments:

```
retronym referenced this pull request in retronym/scala May 19, 2015
See also: https://github.com/retronym/indy-structural

```
// sandbox/structural.scala
object Test {
  def main(args: Array[String]): Unit = {
    println(duckduck(new C))
    println(duckduck(new D))
  }

  def duckduck(a: { def quack(a: String): String }): String = {
    a.quack("A")
  }

}

class C {
  def quack(a: String) = "QUACK! " + a
}

class D {
  def quack(a: String) = "QUICK! " + a
}
```

```
qscalac -target:jvm-1.8 -Ybackend:GenBCode sandbox/structural.scala && qscala Test && javap -v 'Test$' | cat -v
warning: there was one feature warning; re-run with -feature for details
one warning found

QUACK! A
QUICK! A

Classfile /Users/jason/code/scala2/Test$.class
{
  public static final Test$ MODULE$;
    descriptor: LTest$;
    flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL

  public void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC
    Code:
      stack=4, locals=2, args_size=2
         0: getstatic     #19                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
         3: aload_0
         4: new           #21                 // class C
         7: dup
         8: invokespecial #22                 // Method C."<init>":()V
        11: invokevirtual #26                 // Method duckduck:(Ljava/lang/Object;)Ljava/lang/String;
        14: invokevirtual #30                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
        17: getstatic     #19                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
        20: aload_0
        21: new           #32                 // class D
        24: dup
        25: invokespecial #33                 // Method D."<init>":()V
        28: invokevirtual #26                 // Method duckduck:(Ljava/lang/Object;)Ljava/lang/String;
        31: invokevirtual #30                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
        34: return

  public java.lang.String duckduck(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/String;
    flags: ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_1
         1: ldc           #38                 // String A
         3: invokedynamic #49,  0             // InvokeDynamic #0:"dyn:callMethod:quack":(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;
         8: checkcast     #51                 // class java/lang/String
        11: areturn

}
BootstrapMethods:
  0: #45 invokestatic jdk/internal/dynalink/DefaultBootstrapper.bootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
    Method arguments:

```
retronym referenced this pull request in retronym/scala May 4, 2016
Motivation:

  - Avoid introducing public virtual methods. (javac uses private methods,
    but we prefer to make the public to support important AOT inlining
    use cases)
     - No more need for unsightly expanded names in lambda stack traces!
     - CHA in on HotSpot is great at devirtualizing, but that doesn't mean
       we *should* emit non-virtual methods as virtual so pervasively.

```
// Entering paste mode (ctrl-D to finish)

package com.acme.wizzle.wozzle; class C { def foo = () => ??? }

// Exiting paste mode, now interpreting.

scala> new com.acme.wizzle.wozzle.C().foo
res0: () => Nothing = com.acme.wizzle.wozzle.C$$Lambda$1986/43856716@100f9bbe

scala> new com.acme.wizzle.wozzle.C().foo.apply()
scala.NotImplementedError: an implementation is missing
  at scala.Predef$.$qmark$qmark$qmark(Predef.scala:284)
  at com.acme.wizzle.wozzle.C.$anonfun$1(<pastie>:1)
  ... 30 elided

scala> :paste -raw
// Entering paste mode (ctrl-D to finish)

package p1; class StaticAllTheThings { def foo = () => ""; def bar = () => foo; def baz = () => this }

// Exiting paste mode, now interpreting.

scala> :javap -private -c p1.StaticAllTheThings
Compiled from "<pastie>"
public class p1.StaticAllTheThings {
  public scala.Function0<java.lang.String> foo();
    Code:
       0: invokedynamic #38,  0             // InvokeDynamic #0:apply:()Lscala/Function0;
       5: areturn

  public scala.Function0<scala.Function0<java.lang.String>> bar();
    Code:
       0: aload_0
       1: invokedynamic #49,  0             // InvokeDynamic #1:apply:(Lp1/StaticAllTheThings;)Lscala/Function0;
       6: areturn

  public scala.Function0<p1.StaticAllTheThings> baz();
    Code:
       0: aload_0
       1: invokedynamic #58,  0             // InvokeDynamic #2:apply:(Lp1/StaticAllTheThings;)Lscala/Function0;
       6: areturn

  public static final java.lang.String $anonfun$1();
    Code:
       0: ldc           #60                 // String
       2: areturn

  public static final scala.Function0 $anonfun$2(p1.StaticAllTheThings);
    Code:
       0: aload_0
       1: invokevirtual #63                 // Method foo:()Lscala/Function0;
       4: areturn

  public static final p1.StaticAllTheThings $anonfun$3(p1.StaticAllTheThings);
    Code:
       0: aload_0
       1: areturn

  public p1.StaticAllTheThings();
    Code:
       0: aload_0
       1: invokespecial #67                 // Method java/lang/Object."<init>":()V
       4: return

  private static java.lang.Object $deserializeLambda$(java.lang.invoke.SerializedLambda);
    Code:
       0: aload_0
       1: invokedynamic #79,  0             // InvokeDynamic #3:lambdaDeserialize:(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;
       6: areturn
}
```
retronym referenced this pull request in retronym/scala May 5, 2016
Motivation:

  - Avoid introducing public virtual methods. (javac uses private methods,
    but we prefer to make the public to support important AOT inlining
    use cases)
     - No more need for unsightly expanded names in lambda stack traces!
     - CHA in on HotSpot is great at devirtualizing, but that doesn't mean
       we *should* emit non-virtual methods as virtual so pervasively.

```
// Entering paste mode (ctrl-D to finish)

package com.acme.wizzle.wozzle; class C { def foo = () => ??? }

// Exiting paste mode, now interpreting.

scala> new com.acme.wizzle.wozzle.C().foo
res0: () => Nothing = com.acme.wizzle.wozzle.C$$Lambda$1986/43856716@100f9bbe

scala> new com.acme.wizzle.wozzle.C().foo.apply()
scala.NotImplementedError: an implementation is missing
  at scala.Predef$.$qmark$qmark$qmark(Predef.scala:284)
  at com.acme.wizzle.wozzle.C.$anonfun$1(<pastie>:1)
  ... 30 elided

scala> :paste -raw
// Entering paste mode (ctrl-D to finish)

package p1; class StaticAllTheThings { def foo = () => ""; def bar = () => foo; def baz = () => this }

// Exiting paste mode, now interpreting.

scala> :javap -private -c p1.StaticAllTheThings
Compiled from "<pastie>"
public class p1.StaticAllTheThings {
  public scala.Function0<java.lang.String> foo();
    Code:
       0: invokedynamic #38,  0             // InvokeDynamic #0:apply:()Lscala/Function0;
       5: areturn

  public scala.Function0<scala.Function0<java.lang.String>> bar();
    Code:
       0: aload_0
       1: invokedynamic #49,  0             // InvokeDynamic #1:apply:(Lp1/StaticAllTheThings;)Lscala/Function0;
       6: areturn

  public scala.Function0<p1.StaticAllTheThings> baz();
    Code:
       0: aload_0
       1: invokedynamic #58,  0             // InvokeDynamic #2:apply:(Lp1/StaticAllTheThings;)Lscala/Function0;
       6: areturn

  public static final java.lang.String $anonfun$1();
    Code:
       0: ldc           #60                 // String
       2: areturn

  public static final scala.Function0 $anonfun$2(p1.StaticAllTheThings);
    Code:
       0: aload_0
       1: invokevirtual #63                 // Method foo:()Lscala/Function0;
       4: areturn

  public static final p1.StaticAllTheThings $anonfun$3(p1.StaticAllTheThings);
    Code:
       0: aload_0
       1: areturn

  public p1.StaticAllTheThings();
    Code:
       0: aload_0
       1: invokespecial #67                 // Method java/lang/Object."<init>":()V
       4: return

  private static java.lang.Object $deserializeLambda$(java.lang.invoke.SerializedLambda);
    Code:
       0: aload_0
       1: invokedynamic #79,  0             // InvokeDynamic #3:lambdaDeserialize:(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;
       6: areturn
}
```
da-liii pushed a commit to da-liii/scala that referenced this pull request Nov 11, 2018
sjrd pushed a commit to sjrd/scala that referenced this pull request Mar 24, 2020
add tasty/dotc and tasty/scalac tasks for ease of use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet < 455B /span>
Development

Successfully merging this pull request may close these issues.

4 participants
0