Skip to content

Optimize scala2Mode #4335

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
Apr 20, 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
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)
}