Skip to content

Commit 2419176

Browse files
committed
Revert copying all symbols in AnnotatedTypes
1 parent ab70f18 commit 2419176

File tree

7 files changed

+8
-57
lines changed

7 files changed

+8
-57
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

+3-12
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import Decorators.*
2121
* @param newOwners New owners, replacing previous owners.
2222
* @param substFrom The symbols that need to be substituted.
2323
* @param substTo The substitution targets.
24-
* @param cpy A tree copier that is used to create new trees.
25-
* @param alwaysCopySymbols If set, symbols are always copied, even when they
26-
* are not impacted by the transformation.
2724
*
2825
* The reason the substitution is broken out from the rest of the type map is
2926
* that all symbols have to be substituted at the same time. If we do not do this,
@@ -41,9 +38,7 @@ class TreeTypeMap(
4138
val newOwners: List[Symbol] = Nil,
4239
val substFrom: List[Symbol] = Nil,
4340
val substTo: List[Symbol] = Nil,
44-
cpy: tpd.TreeCopier = tpd.cpy,
45-
alwaysCopySymbols: Boolean = false,
46-
)(using Context) extends tpd.TreeMap(cpy) {
41+
cpy: tpd.TreeCopier = tpd.cpy)(using Context) extends tpd.TreeMap(cpy) {
4742
import tpd.*
4843

4944
def copy(
@@ -53,7 +48,7 @@ class TreeTypeMap(
5348
newOwners: List[Symbol],
5449
substFrom: List[Symbol],
5550
substTo: List[Symbol])(using Context): TreeTypeMap =
56-
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols)
51+
new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo)
5752

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

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

237-
def withAlwaysCopySymbols: TreeTypeMap =
238-
if alwaysCopySymbols then this
239-
else new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo, cpy, alwaysCopySymbols = true)
240-
241232
override def toString =
242233
def showSyms(syms: List[Symbol]) =
243234
syms.map(sym => s"$sym#${sym.id}").mkString(", ")

compiler/src/dotty/tools/dotc/core/Annotations.scala

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package dotc
33
package core
44

55
import Symbols.*, Types.*, Contexts.*, Constants.*, Phases.*
6-
import ast.{tpd, untpd, TreeTypeMap}
7-
import tpd.*
8-
import util.Spans.{Span, NoSpan}
6+
import ast.tpd, tpd.*
7+
import util.Spans.Span
98
import printing.{Showable, Printer}
109
import printing.Texts.Text
1110

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

8074
/** Does this annotation refer to a parameter of `tl`? */

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

+2-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package transform
44

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

tests/pos/annot-17939.scala

-7
This file was deleted.

tests/pos/annot-17939c.scala

-5
This file was deleted.

tests/pos/annot-19846.scala

-8
This file was deleted.

tests/pos/annot-19846b.scala

-7
This file was deleted.

0 commit comments

Comments
 (0)