Skip to content

Commit f59fdd8

Browse files
authored
Merge pull request #3215 from dotty-staging/optimize-applied-type
Simplify substituters
2 parents 58b5203 + 3147d48 commit f59fdd8

File tree

1 file changed

+0
-67
lines changed

1 file changed

+0
-67
lines changed

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

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ trait Substituters { this: Context =>
1616
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
1717
case _: ThisType | NoPrefix =>
1818
tp
19-
case tp: RefinedType => // @!!! remove
20-
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
21-
case tp: TypeAlias =>
22-
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
2319
case _ =>
2420
(if (theMap != null) theMap else new SubstBindingMap(from, to))
2521
.mapOver(tp)
@@ -34,10 +30,6 @@ trait Substituters { this: Context =>
3430
else tp.derivedSelect(subst1(tp.prefix, from, to, theMap))
3531
case _: ThisType | _: BoundType | NoPrefix =>
3632
tp
37-
case tp: RefinedType =>
38-
tp.derivedRefinedType(subst1(tp.parent, from, to, theMap), tp.refinedName, subst1(tp.refinedInfo, from, to, theMap))
39-
case tp: TypeAlias =>
40-
tp.derivedTypeAlias(subst1(tp.alias, from, to, theMap))
4133
case _ =>
4234
(if (theMap != null) theMap else new Subst1Map(from, to))
4335
.mapOver(tp)
@@ -54,10 +46,6 @@ trait Substituters { this: Context =>
5446
else tp.derivedSelect(subst2(tp.prefix, from1, to1, from2, to2, theMap))
5547
case _: ThisType | _: BoundType | NoPrefix =>
5648
tp
57-
case tp: RefinedType =>
58-
tp.derivedRefinedType(subst2(tp.parent, from1, to1, from2, to2, theMap), tp.refinedName, subst2(tp.refinedInfo, from1, to1, from2, to2, theMap))
59-
case tp: TypeAlias =>
60-
tp.derivedTypeAlias(subst2(tp.alias, from1, to1, from2, to2, theMap))
6149
case _ =>
6250
(if (theMap != null) theMap else new Subst2Map(from1, to1, from2, to2))
6351
.mapOver(tp)
@@ -79,10 +67,6 @@ trait Substituters { this: Context =>
7967
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
8068
case _: ThisType | _: BoundType | NoPrefix =>
8169
tp
82-
case tp: RefinedType =>
83-
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
84-
case tp: TypeAlias =>
85-
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
8670
case _ =>
8771
(if (theMap != null) theMap else new SubstMap(from, to))
8872
.mapOver(tp)
@@ -112,10 +96,6 @@ trait Substituters { this: Context =>
11296
}
11397
case _: ThisType | _: BoundType | NoPrefix =>
11498
tp
115-
case tp: RefinedType =>
116-
tp.derivedRefinedType(substDealias(tp.parent, from, to, theMap), tp.refinedName, substDealias(tp.refinedInfo, from, to, theMap))
117-
case tp: TypeAlias =>
118-
tp.derivedTypeAlias(substDealias(tp.alias, from, to, theMap))
11999
case _ =>
120100
(if (theMap != null) theMap else new SubstDealiasMap(from, to))
121101
.mapOver(tp)
@@ -151,10 +131,6 @@ trait Substituters { this: Context =>
151131
tp
152132
case _: ThisType | _: BoundType | NoPrefix =>
153133
tp
154-
case tp: RefinedType =>
155-
tp.derivedRefinedType(substSym(tp.parent, from, to, theMap), tp.refinedName, substSym(tp.refinedInfo, from, to, theMap))
156-
case tp: TypeAlias =>
157-
tp.derivedTypeAlias(substSym(tp.alias, from, to, theMap))
158134
case _ =>
159135
(if (theMap != null) theMap else new SubstSymMap(from, to))
160136
.mapOver(tp)
@@ -169,10 +145,6 @@ trait Substituters { this: Context =>
169145
else tp.derivedSelect(substThis(tp.prefix, from, to, theMap))
170146
case _: BoundType | NoPrefix =>
171147
tp
172-
case tp: RefinedType =>
173-
tp.derivedRefinedType(substThis(tp.parent, from, to, theMap), tp.refinedName, substThis(tp.refinedInfo, from, to, theMap))
174-
case tp: TypeAlias =>
175-
tp.derivedTypeAlias(substThis(tp.alias, from, to, theMap))
176148
case _ =>
177149
(if (theMap != null) theMap else new SubstThisMap(from, to))
178150
.mapOver(tp)
@@ -187,10 +159,6 @@ trait Substituters { this: Context =>
187159
else tp.derivedSelect(substRecThis(tp.prefix, from, to, theMap))
188160
case _: ThisType | _: BoundType | NoPrefix =>
189161
tp
190-
case tp: RefinedType =>
191-
tp.derivedRefinedType(substRecThis(tp.parent, from, to, theMap), tp.refinedName, substRecThis(tp.refinedInfo, from, to, theMap))
192-
case tp: TypeAlias =>
193-
tp.derivedTypeAlias(substRecThis(tp.alias, from, to, theMap))
194162
case _ =>
195163
(if (theMap != null) theMap else new SubstRecThisMap(from, to))
196164
.mapOver(tp)
@@ -205,10 +173,6 @@ trait Substituters { this: Context =>
205173
else tp.derivedSelect(substParam(tp.prefix, from, to, theMap))
206174
case _: ThisType | NoPrefix =>
207175
tp
208-
case tp: RefinedType =>
209-
tp.derivedRefinedType(substParam(tp.parent, from, to, theMap), tp.refinedName, substParam(tp.refinedInfo, from, to, theMap))
210-
case tp: TypeAlias =>
211-
tp.derivedTypeAlias(substParam(tp.alias, from, to, theMap))
212176
case _ =>
213177
(if (theMap != null) theMap else new SubstParamMap(from, to))
214178
.mapOver(tp)
@@ -223,10 +187,6 @@ trait Substituters { this: Context =>
223187
else tp.derivedSelect(substParams(tp.prefix, from, to, theMap))
224188
case _: ThisType | NoPrefix =>
225189
tp
226-
case tp: RefinedType =>
227-
tp.derivedRefinedType(substParams(tp.parent, from, to, theMap), tp.refinedName, substParams(tp.refinedInfo, from, to, theMap))
228-
case tp: TypeAlias =>
229-
tp.derivedTypeAlias(substParams(tp.alias, from, to, theMap))
230190
case _ =>
231191
(if (theMap != null) theMap else new SubstParamsMap(from, to))
232192
.mapOver(tp)
@@ -276,31 +236,4 @@ trait Substituters { this: Context =>
276236
final class SubstParamsMap(from: BindingType, to: List[Type]) extends DeepTypeMap {
277237
def apply(tp: Type) = substParams(tp, from, to, this)
278238
}
279-
280-
/** A map for "cycle safe substitutions" which do not force the denotation
281-
* of a TypeRef unless the name matches up with one of the substituted symbols.
282-
*/
283-
final class SafeSubstMap(from: List[Symbol], to: List[Type]) extends TypeMap {
284-
def apply(tp: Type): Type = tp match {
285-
case tp: NamedType =>
286-
try {
287-
var sym: Symbol = null
288-
var fs = from
289-
var ts = to
290-
while (fs.nonEmpty) {
291-
if (fs.head.name == tp.name) {
292-
if (sym == null) sym = tp.symbol
293-
if (fs.head eq sym) return ts.head
294-
}
295-
fs = fs.tail
296-
ts = ts.tail
297-
}
298-
tp.withPrefix(apply(tp.prefix))
299-
}
300-
catch {
301-
case ex: CyclicReference => tp.derivedSelect(apply(tp.prefix))
302-
}
303-
case _ => mapOver(tp)
304-
}
305-
}
306239
}

0 commit comments

Comments
 (0)