Merged
Conversation
Member
Author
d9cc5e6 to
59524e6
Compare
156a760 to
a5a34d0
Compare
Member
Author
|
Member
Author
|
/rebuild |
3ca05b7 to
0b581ef
Compare
0b581ef to
3ebf76d
Compare
Member
Author
|
/rebuild |
Member
Author
|
The test failure in |
Type tags summoned with `universe.typeTag` or an implicit search are
expanded thusly:
```
object Test {
def materializeTag = reflect.runtime.universe.typeTag[Option[String]]
def main(args: Array[String]): Unit = {
val tag1 = materializeTag
val tag2 = materializeTag
println(tag1 eq tag2)
}
}
```
```
def materializeTag: reflect.runtime.universe.TypeTag[Option[String]] = scala.reflect.runtime.`package`.universe.typeTag[Option[String]](({
val $u: reflect.runtime.universe.type = scala.this.reflect.runtime.`package`.universe;
val $m: $u.Mirror = scala.this.reflect.runtime.`package`.universe.runtimeMirror(this.getClass().getClassLoader());
$u.TypeTag.apply[Option[String]]($m, {
final class $typecreator1 extends TypeCreator {
def <init>(): $typecreator1 = {
$typecreator1.super.<init>();
()
};
def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
$u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.ThisType($m.staticPackage("scala").asModule.moduleClass), $m.staticClass("scala.Option"), scala.collection.immutable.List.apply[$u.Type]($u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.SingleType($m.staticPackage("scala").asModule.moduleClass.asType.toTypeConstructor, $m.staticModule("scala.Predef")), $u.internal.reificationSupport.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), scala.collection.immutable.Nil)))
}
};
new $typecreator1()
})
}: reflect.runtime.universe.TypeTag[Option[String]]));
```
A new TypeTag is created time `def materializeTag` is called above; the program prints `false`.
This commit introduces a cache, keyed by the synthetic `$typecreator1`, and hosted in the `JavaMirror`.
We know that the `apply` method is a pure, so the caching is sound.
Using `ClassValue` means that we're not introducing a classloader leak.
We are extending the lifetime of the `TypeTag` and contained type itself, which represents a small
risk to existing applications, so I've included an opt-out System property.
3ebf76d to
35501d9
Compare
lrytz
approved these changes
Jul 17, 2019
Member
lrytz
left a comment
There was a problem hiding this comment.
Looks fine to me, leaving open for others to take a look.
diesalbla
approved these changes
Jul 22, 2019
Member
|
I'm not familiar with
so I thought it looks ok to me. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type tags summoned with
universe.typeTagor an implicit search areexpanded thusly:
A new TypeTag is created time
def materializeTagis called above; the program printsfalse.This commit introduces a cache, keyed by the synthetic
$typecreator1, and hosted in theJavaMirror.We know that the
applymethod is a pure, so the caching is sound.Using
ClassValuemeans that we're not introducing a classloader leak.We are extending the lifetime of the
TypeTagand contained type itself, which represents a smallrisk to existing applications, so I've included an opt-out System property.