Skip to content

Commit

Permalink
Merge pull request #4335 from dotty-staging/opt-scala2Mode
Browse files Browse the repository at this point in the history
Optimize scala2Mode
  • Loading branch information
nicolasstucki authored Apr 20, 2018
2 parents 3821b16 + 5a643d9 commit 9c83d27
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
28 changes: 10 additions & 18 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,17 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
* the prefix "dotty.language.".
*/
def featureEnabled(owner: ClassSymbol, feature: TermName): Boolean = {
def toPrefix(sym: Symbol): String =
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
else toPrefix(sym.owner) + sym.name + "."
def featureName = toPrefix(owner) + feature
def hasImport(implicit ctx: Context): Boolean = {
if (ctx.importInfo eq null) false
else {
val isImportOwner = ctx.importInfo.site.widen.typeSymbol eq owner
if (isImportOwner && ctx.importInfo.originals.contains(feature)) true
else if (isImportOwner && ctx.importInfo.excluded.contains(feature)) false
else {
var c = ctx.outer
while (c.importInfo eq ctx.importInfo) c = c.outer
hasImport(c)
}
}
val hasImport =
ctx.importInfo != null &&
ctx.importInfo.featureImported(owner, feature)(ctx.withPhase(ctx.typerPhase))
def hasOption = {
def toPrefix(sym: Symbol): String =
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
else toPrefix(sym.owner) + sym.name + "."
val featureName = toPrefix(owner) + feature
ctx.base.settings.language.value exists (s => s == featureName || s == "_")
}
def hasOption = ctx.base.settings.language.value exists (s => s == featureName || s == "_")
hasImport(ctx.withPhase(ctx.typerPhase)) || hasOption
hasImport || hasOption
}

/** Is auto-tupling enabled? */
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object Implicits {
def discardForView(tpw: Type, argType: Type): Boolean = tpw match {
case mt: MethodType =>
mt.isImplicitMethod ||
mt.paramInfos.length != 1 ||
mt.paramInfos.lengthCompare(1) != 0 ||
!ctx.test(implicit ctx => argType relaxed_<:< mt.paramInfos.head)
case poly: PolyType =>
// We do not need to call ProtoTypes#constrained on `poly` because
Expand Down
22 changes: 22 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/ImportInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,27 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
}
private[this] var myUnimported: Symbol = _

/** Does this import clause or a preceding import clause import `owner.feature`? */
def featureImported(owner: Symbol, feature: TermName)(implicit ctx: Context): Boolean = {
def compute = {
val isImportOwner = site.widen.typeSymbol `eq` owner
if (isImportOwner && originals.contains(feature)) true
else if (isImportOwner && excluded.contains(feature)) false
else {
var c = ctx.outer
while (c.importInfo eq ctx.importInfo) c = c.outer
(c.importInfo != null) && c.importInfo.featureImported(owner, feature)(c)
}
}
if (lastOwner.ne(owner) || !lastResults.contains(feature)) {
lastOwner = owner
lastResults = lastResults.updated(feature, compute)
}
lastResults(feature)
}

private[this] var lastOwner: Symbol = null
private[this] var lastResults: SimpleIdentityMap[TermName, java.lang.Boolean] = SimpleIdentityMap.Empty

def toText(printer: Printer) = printer.toText(this)
}

0 comments on commit 9c83d27

Please sign in to comment.