-
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.
Improve mapping and pickling of annotated types
`Annotation.mapWith` maps an `Annotation` with a type map `tm`. As an optimization, this function first checks if `tm` would result in any change (by traversing the annotation’s argument trees with a `TreeAccumulator`) before applying `tm` to the whole annotation tree. This optimization had two problems: 1. it didn’t include type parameters, and 2. it used `frozen_=:=` to compare types, which didn’t work as expected with `NoType`. This commit fixes these issues. Additionally, positions of trees that appear only inside `AnnotatedType` were not pickled. This commit also fixes this.
- Loading branch information
Showing
13 changed files
with
123 additions
and
7 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,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,9 @@ | ||
//> using options "-Xprint:typer" | ||
|
||
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,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,9 @@ | ||
//> using options "-Xprint:typer" | ||
|
||
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) |