Skip to content

Commit 9c83d27

Browse files
Merge pull request #4335 from dotty-staging/opt-scala2Mode
Optimize scala2Mode
2 parents 3821b16 + 5a643d9 commit 9c83d27

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,17 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
292292
* the prefix "dotty.language.".
293293
*/
294294
def featureEnabled(owner: ClassSymbol, feature: TermName): Boolean = {
295-
def toPrefix(sym: Symbol): String =
296-
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
297-
else toPrefix(sym.owner) + sym.name + "."
298-
def featureName = toPrefix(owner) + feature
299-
def hasImport(implicit ctx: Context): Boolean = {
300-
if (ctx.importInfo eq null) false
301-
else {
302-
val isImportOwner = ctx.importInfo.site.widen.typeSymbol eq owner
303-
if (isImportOwner && ctx.importInfo.originals.contains(feature)) true
304-
else if (isImportOwner && ctx.importInfo.excluded.contains(feature)) false
305-
else {
306-
var c = ctx.outer
307-
while (c.importInfo eq ctx.importInfo) c = c.outer
308-
hasImport(c)
309-
}
310-
}
295+
val hasImport =
296+
ctx.importInfo != null &&
297+
ctx.importInfo.featureImported(owner, feature)(ctx.withPhase(ctx.typerPhase))
298+
def hasOption = {
299+
def toPrefix(sym: Symbol): String =
300+
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
301+
else toPrefix(sym.owner) + sym.name + "."
302+
val featureName = toPrefix(owner) + feature
303+
ctx.base.settings.language.value exists (s => s == featureName || s == "_")
311304
}
312-
def hasOption = ctx.base.settings.language.value exists (s => s == featureName || s == "_")
313-
hasImport(ctx.withPhase(ctx.typerPhase)) || hasOption
305+
hasImport || hasOption
314306
}
315307

316308
/** Is auto-tupling enabled? */

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ object Implicits {
7979
def discardForView(tpw: Type, argType: Type): Boolean = tpw match {
8080
case mt: MethodType =>
8181
mt.isImplicitMethod ||
82-
mt.paramInfos.length != 1 ||
82+
mt.paramInfos.lengthCompare(1) != 0 ||
8383
!ctx.test(implicit ctx => argType relaxed_<:< mt.paramInfos.head)
8484
case poly: PolyType =>
8585
// We do not need to call ProtoTypes#constrained on `poly` because

compiler/src/dotty/tools/dotc/typer/ImportInfo.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,27 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree],
138138
}
139139
private[this] var myUnimported: Symbol = _
140140

141+
/** Does this import clause or a preceding import clause import `owner.feature`? */
142+
def featureImported(owner: Symbol, feature: TermName)(implicit ctx: Context): Boolean = {
143+
def compute = {
144+
val isImportOwner = site.widen.typeSymbol `eq` owner
145+
if (isImportOwner && originals.contains(feature)) true
146+
else if (isImportOwner && excluded.contains(feature)) false
147+
else {
148+
var c = ctx.outer
149+
while (c.importInfo eq ctx.importInfo) c = c.outer
150+
(c.importInfo != null) && c.importInfo.featureImported(owner, feature)(c)
151+
}
152+
}
153+
if (lastOwner.ne(owner) || !lastResults.contains(feature)) {
154+
lastOwner = owner
155+
lastResults = lastResults.updated(feature, compute)
156+
}
157+
lastResults(feature)
158+
}
159+
160+
private[this] var lastOwner: Symbol = null
161+
private[this] var lastResults: SimpleIdentityMap[TermName, java.lang.Boolean] = SimpleIdentityMap.Empty
162+
141163
def toText(printer: Printer) = printer.toText(this)
142164
}

0 commit comments

Comments
 (0)