Skip to content

Remove substDealias #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions compiler/src/dotty/tools/dotc/core/Substituters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,6 @@ trait Substituters { this: Context =>
}
}

final def substDealias(tp: Type, from: List[Symbol], to: List[Type], theMap: SubstDealiasMap): Type = {
tp match {
case tp: NamedType =>
val sym = tp.symbol
var fs = from
var ts = to
while (fs.nonEmpty) {
if (fs.head eq sym) return ts.head
fs = fs.tail
ts = ts.tail
}
if (sym.isStatic && !existsStatic(from) || (tp.prefix `eq` NoPrefix)) tp
else {
tp.info match {
case TypeAlias(alias) =>
val alias1 = substDealias(alias, from, to, theMap)
if (alias1 ne alias) return alias1
case _ =>
}
tp.derivedSelect(substDealias(tp.prefix, from, to, theMap))
}
case _: ThisType | _: BoundType =>
tp
case _ =>
(if (theMap != null) theMap else new SubstDealiasMap(from, to))
.mapOver(tp)
}
}

final def substSym(tp: Type, from: List[Symbol], to: List[Symbol], theMap: SubstSymMap): Type =
tp match {
case tp: NamedType =>
Expand Down Expand Up @@ -210,10 +181,6 @@ trait Substituters { this: Context =>
def apply(tp: Type): Type = subst(tp, from, to, this)
}

final class SubstDealiasMap(from: List[Symbol], to: List[Type]) extends DeepTypeMap {
override def apply(tp: Type): Type = substDealias(tp, from, to, this)
}

final class SubstSymMap(from: List[Symbol], to: List[Symbol]) extends DeepTypeMap {
def apply(tp: Type): Type = substSym(tp, from, to, this)
}
Expand Down
11 changes: 0 additions & 11 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1307,17 +1307,6 @@ object Types {
}
}

/** Same as `subst` but follows aliases as a fallback. When faced with a reference
* to an alias type, where normal substitution does not yield a new type, the
* substitution is instead applied to the alias. If that yields a new type,
* this type is returned, otherwise the original type (not the alias) is returned.
* A use case for this method is if one wants to substitute the type parameters
* of a class and also wants to substitute any parameter accessors that alias
* the type parameters.
*/
final def substDealias(from: List[Symbol], to: List[Type])(implicit ctx: Context): Type =
ctx.substDealias(this, from, to, null)

/** Substitute all types of the form `TypeParamRef(from, N)` by
* `TypeParamRef(to, N)`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ trait FullParameterization {
/** Replace class type parameters by the added type parameters of the polytype `pt` */
def mapClassParams(tp: Type, pt: PolyType): Type = {
val classParamsRange = (mtparamCount until mtparamCount + ctparams.length).toList
tp.substDealias(ctparams, classParamsRange map (pt.paramRefs(_)))
tp.subst(ctparams, classParamsRange map (pt.paramRefs(_)))
}

/** The bounds for the added type parameters of the polytype `pt` */
Expand Down Expand Up @@ -206,8 +206,7 @@ trait FullParameterization {

new TreeTypeMap(
typeMap = rewireType(_)
.substDealias(origTParams, trefs)
.subst(origVParams, argRefs.map(_.tpe))
.subst(origTParams ++ origVParams, trefs ++ argRefs.map(_.tpe))
.substThisUnlessStatic(origClass, thisRef.tpe),
treeMap = {
case tree: This if tree.symbol == origClass => thisRef
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/TailRec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ class TailRec extends MiniPhase with FullParameterization {
val origVParams = tree.vparamss.flatten map (_.symbol)
new TreeTypeMap(
typeMap = identity(_)
.substDealias(origTParams, trefs)
.subst(origVParams, vrefss.flatten.map(_.tpe)),
oldOwners = origMeth :: Nil,
.subst(origTParams ++ origVParams, trefs ++ vrefss.flatten.map(_.tpe)),
oldOwners = origMeth :: Nil,
newOwners = label :: Nil
).transform(rhsSemiTransformed)
})
Expand Down