Skip to content

Simplify substituters #3215

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
Sep 30, 2017
Merged
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
67 changes: 0 additions & 67 deletions compiler/src/dotty/tools/dotc/core/Substituters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
case _: ThisType | NoPrefix =>
tp
case tp: RefinedType => // @!!! remove
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstBindingMap(from, to))
.mapOver(tp)
Expand All @@ -34,10 +30,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(subst1(tp.prefix, from, to, theMap))
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst1(tp.parent, from, to, theMap), tp.refinedName, subst1(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst1(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new Subst1Map(from, to))
.mapOver(tp)
Expand All @@ -54,10 +46,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(subst2(tp.prefix, from1, to1, from2, to2, theMap))
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst2(tp.parent, from1, to1, from2, to2, theMap), tp.refinedName, subst2(tp.refinedInfo, from1, to1, from2, to2, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst2(tp.alias, from1, to1, from2, to2, theMap))
case _ =>
(if (theMap != null) theMap else new Subst2Map(from1, to1, from2, to2))
.mapOver(tp)
Expand All @@ -79,10 +67,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(subst(tp.prefix, from, to, theMap))
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(subst(tp.parent, from, to, theMap), tp.refinedName, subst(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(subst(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstMap(from, to))
.mapOver(tp)
Expand Down Expand Up @@ -112,10 +96,6 @@ trait Substituters { this: Context =>
}
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substDealias(tp.parent, from, to, theMap), tp.refinedName, substDealias(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substDealias(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstDealiasMap(from, to))
.mapOver(tp)
Expand Down Expand Up @@ -151,10 +131,6 @@ trait Substituters { this: Context =>
tp
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substSym(tp.parent, from, to, theMap), tp.refinedName, substSym(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substSym(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstSymMap(from, to))
.mapOver(tp)
Expand All @@ -169,10 +145,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(substThis(tp.prefix, from, to, theMap))
case _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substThis(tp.parent, from, to, theMap), tp.refinedName, substThis(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substThis(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstThisMap(from, to))
.mapOver(tp)
Expand All @@ -187,10 +159,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(substRecThis(tp.prefix, from, to, theMap))
case _: ThisType | _: BoundType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substRecThis(tp.parent, from, to, theMap), tp.refinedName, substRecThis(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substRecThis(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstRecThisMap(from, to))
.mapOver(tp)
Expand All @@ -205,10 +173,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(substParam(tp.prefix, from, to, theMap))
case _: ThisType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substParam(tp.parent, from, to, theMap), tp.refinedName, substParam(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substParam(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstParamMap(from, to))
.mapOver(tp)
Expand All @@ -223,10 +187,6 @@ trait Substituters { this: Context =>
else tp.derivedSelect(substParams(tp.prefix, from, to, theMap))
case _: ThisType | NoPrefix =>
tp
case tp: RefinedType =>
tp.derivedRefinedType(substParams(tp.parent, from, to, theMap), tp.refinedName, substParams(tp.refinedInfo, from, to, theMap))
case tp: TypeAlias =>
tp.derivedTypeAlias(substParams(tp.alias, from, to, theMap))
case _ =>
(if (theMap != null) theMap else new SubstParamsMap(from, to))
.mapOver(tp)
Expand Down Expand Up @@ -276,31 +236,4 @@ trait Substituters { this: Context =>
final class SubstParamsMap(from: BindingType, to: List[Type]) extends DeepTypeMap {
def apply(tp: Type) = substParams(tp, from, to, this)
}

/** A map for "cycle safe substitutions" which do not force the denotation
* of a TypeRef unless the name matches up with one of the substituted symbols.
*/
final class SafeSubstMap(from: List[Symbol], to: List[Type]) extends TypeMap {
def apply(tp: Type): Type = tp match {
case tp: NamedType =>
try {
var sym: Symbol = null
var fs = from
var ts = to
while (fs.nonEmpty) {
if (fs.head.name == tp.name) {
if (sym == null) sym = tp.symbol
if (fs.head eq sym) return ts.head
}
fs = fs.tail
ts = ts.tail
}
tp.withPrefix(apply(tp.prefix))
}
catch {
case ex: CyclicReference => tp.derivedSelect(apply(tp.prefix))
}
case _ => mapOver(tp)
}
}
}