-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mapping and pickling of annotated types
`Annotation.mapWith` maps an `Annotation` with a type map `tm`. Before actually applying `tm` to the annotation’s `tree`, it first checks if `tm` would result in any change by applying it to the types of the annotation’s arguments, and checking if the mapped types are different. This optimization had two problems: it didn’t include type parameters, and used `frozen_=:=` to compare types, which failed to detected some changes. This commit changes `Annotation.arguments` to also include type parameters, and, and changes `Annotation.MapWith` to use `==` to compare types instead of `frozen_=:=`. Furthermore, in case of changes, the symbol in the annotation's tree should be copied to make sure that the same symbol is not used for different trees. This commit achieves this by using a custom `TreeTypeMap` with an overridden `withMappedSyms` method where `Symbols.mapSymbols` is called with the argument `mapAlways = true`. Finally, positons of trees that appear inside `AnnotatedType` only were not pickled. This commit also fixes this.
- Loading branch information
Showing
15 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class qualified[T](f: T => Boolean) extends annotation.StaticAnnotation | ||
|
||
class Box[T](val x: T) | ||
class Box2(val x: Int) | ||
|
||
class A(a: String @qualified((x: Int) => Box(3).x == 3)) // crash | ||
class A2(a2: String @qualified((x: Int) => Box2(3).x == 3)) // works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import scala.annotation.Annotation | ||
class myRefined(f: ? => Boolean) extends Annotation | ||
|
||
def test(axes: Int) = true | ||
|
||
trait Tensor: | ||
def mean(axes: Int): Int @myRefined(_ => test(axes)) | ||
|
||
class TensorImpl() extends Tensor: | ||
def mean(axes: Int) = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class qualified[T](predicate: T => Boolean) extends annotation.StaticAnnotation | ||
|
||
class EqualPair(val x: Int, val y: Int @qualified[Int](it => it == x)) | ||
|
||
@main def main = | ||
val p = EqualPair(42, 42) | ||
val y = p.y | ||
println(42) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class qualified[T](predicate: T => Boolean) extends annotation.StaticAnnotation | ||
|
||
def f(x: Int): Int @qualified[Int](it => it == x) = ??? | ||
|
||
@main def main = | ||
val z = f(42) | ||
() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Annot[T] extends scala.annotation.Annotation | ||
|
||
class D[T](val f: Int@Annot[T]) | ||
|
||
object A{ | ||
def main(a:Array[String]) = { | ||
val c = new D[Int](1) | ||
c.f | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[[syntax trees at end of typer]] // tests/printing/annot-18064.scala | ||
package <empty> { | ||
class myAnnot[T >: Nothing <: Any]() extends annotation.Annotation() { | ||
T | ||
} | ||
trait Tensor[T >: Nothing <: Any]() extends Object { | ||
T | ||
def add: Tensor[Tensor.this.T] @myAnnot[T] | ||
} | ||
class TensorImpl[A >: Nothing <: Any]() extends Object(), Tensor[ | ||
TensorImpl.this.A] { | ||
A | ||
def add: Tensor[A] @myAnnot[A] = this | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class myAnnot[T]() extends annotation.Annotation | ||
|
||
trait Tensor[T]: | ||
def add: Tensor[T] @myAnnot[T]() | ||
|
||
class TensorImpl[A]() extends Tensor[A]: | ||
def add /* : Tensor[A] @myAnnot[A] */ = this |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[[syntax trees at end of typer]] // tests/printing/annot-19846b.scala | ||
package <empty> { | ||
class lambdaAnnot(g: () => Int) extends scala.annotation.Annotation(), | ||
annotation.StaticAnnotation { | ||
private[this] val g: () => Int | ||
} | ||
final lazy module val Test: Test = new Test() | ||
final module class Test() extends Object() { this: Test.type => | ||
val y: Int = ??? | ||
val z: | ||
Int @lambdaAnnot( | ||
{ | ||
def $anonfun(): Int = Test.y | ||
closure($anonfun) | ||
} | ||
) | ||
= f(Test.y) | ||
} | ||
final lazy module val annot-19846b$package: annot-19846b$package = | ||
new annot-19846b$package() | ||
final module class annot-19846b$package() extends Object() { | ||
this: annot-19846b$package.type => | ||
def f(x: Int): | ||
Int @lambdaAnnot( | ||
{ | ||
def $anonfun(): Int = x | ||
closure($anonfun) | ||
} | ||
) | ||
= x | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class lambdaAnnot(g: () => Int) extends annotation.StaticAnnotation | ||
|
||
def f(x: Int): Int @lambdaAnnot(() => x) = x | ||
|
||
object Test: | ||
val y: Int = ??? | ||
val z /* : Int @lambdaAnnot(() => y) */ = f(y) |