Skip to content

Commit

Permalink
Revert copying all symbols in AnnotatedTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel committed Aug 29, 2024
1 parent ab70f18 commit 2419176
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 57 deletions.
15 changes: 3 additions & 12 deletions compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import Decorators.*
* @param newOwners New owners, replacing previous owners.
* @param substFrom The symbols that need to be substituted.
* @param substTo The substitution targets.
* @param cpy A tree copier that is used to create new trees.
* @param alwaysCopySymbols If set, symbols are always copied, even when they
* are not impacted by the transformation.
*
* The reason the substitution is broken out from the rest of the type map is
* that all symbols have to be substituted at the same time. If we do not do this,
Expand All @@ -41,9 +38,7 @@ class TreeTypeMap(
val newOwners: List[Symbol] = Nil,
val substFrom: List[Symbol] = Nil,
val substTo: List[Symbol] = Nil,
cpy: tpd.TreeCopier = tpd.cpy,
alwaysCopySymbols: Boolean = false,
)(using Context) extends tpd.TreeMap(cpy) {
cpy: tpd.TreeCopier = tpd.cpy)(using Context) extends tpd.TreeMap(cpy) {
import tpd.*

def copy(
Expand All @@ -53,7 +48,7 @@ class TreeTypeMap(
newOwners: List[Symbol],
substFrom: List[Symbol],
substTo: List[Symbol])(using Context): TreeTypeMap =
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols)
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)

/** If `sym` is one of `oldOwners`, replace by corresponding symbol in `newOwners` */
def mapOwner(sym: Symbol): Symbol = sym.subst(oldOwners, newOwners)
Expand Down Expand Up @@ -212,7 +207,7 @@ class TreeTypeMap(
* between original and mapped symbols.
*/
def withMappedSyms(syms: List[Symbol]): TreeTypeMap =
withMappedSyms(syms, mapSymbols(syms, this, mapAlways = alwaysCopySymbols))
withMappedSyms(syms, mapSymbols(syms, this))

/** The tree map with the substitution between originals `syms`
* and mapped symbols `mapped`. Also goes into mapped classes
Expand All @@ -234,10 +229,6 @@ class TreeTypeMap(
tmap1
}

def withAlwaysCopySymbols: TreeTypeMap =
if alwaysCopySymbols then this
else new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols = true)

override def toString =
def showSyms(syms: List[Symbol]) =
syms.map(sym => s"$sym#${sym.id}").mkString(", ")
Expand Down
12 changes: 3 additions & 9 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package dotc
package core

import Symbols.*, Types.*, Contexts.*, Constants.*, Phases.*
import ast.{tpd, untpd, TreeTypeMap}
import tpd.*
import util.Spans.{Span, NoSpan}
import ast.tpd, tpd.*
import util.Spans.Span
import printing.{Showable, Printer}
import printing.Texts.Text

Expand Down Expand Up @@ -69,12 +68,7 @@ object Annotations {
foldOver(if !tp1.exists || (tp1 frozen_=:= tree.tpe) then x else tp1, tree)
val diff = findDiff(NoType, args)
if tm.isRange(diff) then EmptyAnnotation
else if diff.exists then
// If the annotation has been transformed, we need to make sure that the
// symbol are copied so that we don't end up with the same symbol in different
// trees, which would lead to a crash in pickling.
val mappedTree = TreeTypeMap(typeMap = tm, alwaysCopySymbols = true).transform(tree)
derivedAnnotation(mappedTree)
else if diff.exists then derivedAnnotation(tm.mapOver(tree))
else this

/** Does this annotation refer to a parameter of `tl`? */
Expand Down
11 changes: 2 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dotty.tools
package dotc
package transform

import dotty.tools.dotc.ast.{Trees, TreeTypeMap, tpd, untpd, desugar}
import dotty.tools.dotc.ast.{Trees, tpd, untpd, desugar}
import scala.collection.mutable
import core.*
import dotty.tools.dotc.typer.Checking
Expand Down Expand Up @@ -158,14 +158,7 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
val saved = inJavaAnnot
inJavaAnnot = annot.symbol.is(JavaDefined)
if (inJavaAnnot) checkValidJavaAnnotation(annot)
try
val res = transform(annot)
if res ne annot then
// If the annotation has been transformed, we need to make sure that the
// symbol are copied so that we don't end up with the same symbol in different
// trees, which would lead to a crash in pickling.
TreeTypeMap(alwaysCopySymbols = true)(res)
else res
try transform(annot)
finally inJavaAnnot = saved
}

Expand Down
7 changes: 0 additions & 7 deletions tests/pos/annot-17939.scala

This file was deleted.

5 changes: 0 additions & 5 deletions tests/pos/annot-17939c.scala

This file was deleted.

8 changes: 0 additions & 8 deletions tests/pos/annot-19846.scala

This file was deleted.

7 changes: 0 additions & 7 deletions tests/pos/annot-19846b.scala

This file was deleted.

0 comments on commit 2419176

Please sign in to comment.