Open mbovel opened 1 year ago
Output when adding -Ydebug-tree-with-id 1029
(where 1029
is the ID of the block in the annotation):
Could the culprit be the following?
Should we map symbols in this case?
Just to see if it changes something, I tried to always map symbols to fresh ones in transformAnnot
with:
diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala
index ac3dc15092a..43409e5125b 100644
--- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -19,6 +19,7 @@ import config.Feature
import util.SrcPos
import reporting._
import NameKinds.WildcardParamName
+import dotty.tools.dotc.ast.TreeTypeMap
object PostTyper {
val name: String = "posttyper"
@@ -84,6 +85,12 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
val synthMbr: SyntheticMembers = new SyntheticMembers(thisPhase)
val beanProps: BeanProperties = new BeanProperties(thisPhase)
+ def withFreshSymbols(tree: Tree)(using Context): Tree =
+ val tm = new TreeTypeMap():
+ override def withMappedSyms(syms: List[Symbol]): TreeTypeMap =
+ withMappedSyms(syms, mapSymbols(syms, this, mapAlways = true))
+ tm(tree)
+
private def newPart(tree: Tree): Option[New] = methPart(tree) match {
case Select(nu: New, _) => Some(nu)
case _ => None
@@ -135,7 +142,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
val saved = inJavaAnnot
inJavaAnnot = annot.symbol.is(JavaDefined)
if (inJavaAnnot) checkValidJavaAnnotation(annot)
- try transform(annot)
+ try
+ val res = transform(annot)
+ if res != annot then withFreshSymbols(res) else annot
finally inJavaAnnot = saved
}
With this change, the file compiles, but the pickling test fails:
$ diff before-pickling.txt after-pickling.txt
50,52c50,51
< x: scala.Int@tests/pos/tasty-no-address.scala<149..152>@tests/pos/tasty-no-address.scala[146..152]@@(x=
< tests/pos/tasty-no-address.scala:<146..146>)
< ): scala.Boolean =
---
> x: scala.Int@tests/pos/tasty-no-address.scala<149..152>@tests/pos/tasty-no-address.scala<149..152>@@(x=?))
> : scala.Boolean =
64,66c63,65
< tests/pos/tasty-no-address.scala<157..163>
< .x:scala.Int>@tests/pos/tasty-no-address.scala<157..165>
< .==:((x: scala.Int): scala.Boolean)>@tests/pos/tasty-no-address.scala<157..168>
---
> tests/pos/tasty-no-address.scala<157..162>
> .x:scala.Int>@tests/pos/tasty-no-address.scala<157..162>
> .==:((x: scala.Int): scala.Boolean)>@tests/pos/tasty-no-address.scala<157..162>
69,71c68,70
< @tests/pos/tasty-no-address.scala[145..154..170]@@($anonfun=tests/pos/tasty-no-address.scala:<154..154>)
< <closure(<$anonfun:(x: scala.Int): scala.Boolean>@tests/pos/tasty-no-address.scala<170..170>):scala.Int =>
< scala.Boolean>@tests/pos/tasty-no-address.scala<170..170>
---
> @tests/pos/tasty-no-address.scala<149..152>@@($anonfun=?)
> <closure(<$anonfun:(x: scala.Int): scala.Boolean>@tests/pos/tasty-no-address.scala<152..152>):scala.Int =>
> scala.Boolean>@tests/pos/tasty-no-address.scala<152..152>
73c72
< :scala.Int => scala.Boolean>@tests/pos/tasty-no-address.scala<145..170>
---
> :scala.Int => scala.Boolean>@tests/pos/tasty-no-address.scala<149..152>
The TypeTree
of the field private[this] val a
is created by:
Maybe we should special case the relocate
map for AnnotatedType
? I tried applying withFreshSymbols
to its tree, but that doesn't help.
Minimizing a different failing case, I found the following, which I think is related:
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) = ???
Both the lambda and the subclassing appear to be necessary
Here is the error:
```
[info] running (fork) dotty.tools.dotc.Main -classpath /home/quentin/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.10/scala-library-2.13.10.jar:/home/quentin/Projects/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.3.2-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.3.2-RC1-bin-SNAPSHOT.jar tests/pos-custom-args/refinements/trying.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: unresolved symbols: parameter axes (line 7) #7891 when pickling tests/pos-custom-args/refinements/trying.scala
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.core.tasty.TreePickler.pickle(TreePickler.scala:829)
at dotty.tools.dotc.transform.Pickler.run$$anonfun$1$$anonfun$1(Pickler.scala:90)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.immutable.List.foreach(List.scala:333)
at dotty.tools.dotc.transform.Pickler.run$$anonfun$1(Pickler.scala:142)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.immutable.List.foreach(List.scala:333)
at dotty.tools.dotc.transform.Pickler.run(Pickler.scala:142)
at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:327)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:331)
at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:150)
at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
at dotty.tools.dotc.Run.compileSources(Run.scala:194)
at dotty.tools.dotc.Run.compile(Run.scala:179)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
at dotty.tools.dotc.Driver.process(Driver.scala:197)
at dotty.tools.dotc.Driver.process(Driver.scala:165)
at dotty.tools.dotc.Driver.process(Driver.scala:177)
at dotty.tools.dotc.Driver.main(Driver.scala:207)
at dotty.tools.dotc.Main.main(Main.scala)
unhandled exception while running pickler on tests/pos-custom-args/refinements/trying.scala
An unhandled exception was thrown in the compiler.
Please file a crash report here:
https://github.com/lampepfl/dotty/issues/new/choose
while compiling:
Compiler version
348729e88e7
Minimized code
Output (click arrow to expand)
Trees with IDs after
posttyper