Skip to content

Commit 416e315

Browse files
committed
Add SIP compliant by-name implicits
* Replaced existing implementation of by-name implicits with a SIP compliant one. * Ported the Scala 2 tests. * Removed now redundant -Xmin-implicit-search-depth.
1 parent 2d23cba commit 416e315

38 files changed

+1796
-172
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class ScalaSettings extends Settings.SettingGroup {
6262
*/
6363
val Xhelp: Setting[Boolean] = BooleanSetting("-X", "Print a synopsis of advanced options.")
6464
val XnoForwarders: Setting[Boolean] = BooleanSetting("-Xno-forwarders", "Do not generate static forwarders in mirror classes.")
65-
val XminImplicitSearchDepth: Setting[Int] = IntSetting("-Xmin-implicit-search-depth", "Set number of levels of implicit searches undertaken before checking for divergence.", 5)
6665
val XmaxInlines: Setting[Int] = IntSetting("-Xmax-inlines", "Maximal number of successive inlines", 32)
6766
val XmaxClassfileName: Setting[Int] = IntSetting("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, 72 to 255)
6867
val Xmigration: Setting[ScalaVersion] = VersionSetting("-Xmigration", "Warn about constructs whose behavior may have changed since version.")

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
1616
import util.{FreshNameCreator, NoSource, SimpleIdentityMap, SourceFile}
17-
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, TypeAssigner, Typer}
17+
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer}
1818
import Implicits.ContextualImplicits
1919
import config.Settings._
2020
import config.Config
@@ -555,7 +555,7 @@ object Contexts {
555555
moreProperties = Map.empty
556556
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
557557
typeComparer = new TypeComparer(this)
558-
searchHistory = new SearchHistory(0, Map())
558+
searchHistory = new SearchRoot
559559
gadt = EmptyGADTMap
560560
}
561561

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ trait Symbols { this: Context =>
265265
newConstructor(cls, EmptyFlags, Nil, Nil)
266266

267267
/** Create a synthetic lazy implicit value */
268-
def newLazyImplicit(info: Type): TermSymbol =
269-
newSymbol(owner, LazyImplicitName.fresh(), Lazy, info)
268+
def newLazyImplicit(info: Type, coord: Coord = NoCoord): TermSymbol =
269+
newSymbol(owner, LazyImplicitName.fresh(), EmptyFlags, info, coord = coord)
270270

271271
/** Create a symbol representing a selftype declaration for class `cls`. */
272272
def newSelfSym(cls: ClassSymbol, name: TermName = nme.WILDCARD, selfInfo: Type = NoType): TermSymbol =

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,14 @@ object Types {
14511451
case _ => this
14521452
}
14531453

1454+
/** The set of distinct symbols referred to by this type, after all aliases are expanded */
1455+
def coveringSet(implicit ctx: Context): Set[Symbol] =
1456+
(new CoveringSetAccumulator).apply(Set.empty[Symbol], this)
1457+
1458+
/** The number of applications and refinements in this type, after all aliases are expanded */
1459+
def typeSize(implicit ctx: Context): Int =
1460+
(new TypeSizeAccumulator).apply(0, this)
1461+
14541462
/** Convert to text */
14551463
def toText(printer: Printer): Text = printer.toText(this)
14561464

@@ -4890,6 +4898,39 @@ object Types {
48904898
}
48914899
}
48924900

4901+
class TypeSizeAccumulator(implicit ctx: Context) extends TypeAccumulator[Int] {
4902+
def apply(n: Int, tp: Type): Int = tp match {
4903+
case tp: AppliedType =>
4904+
foldOver(n + 1, tp)
4905+
case tp: RefinedType =>
4906+
foldOver(n + 1, tp)
4907+
case tp: TypeRef if tp.info.isTypeAlias =>
4908+
apply(n, tp.superType)
4909+
case _ =>
4910+
foldOver(n, tp)
4911+
}
4912+
}
4913+
4914+
class CoveringSetAccumulator(implicit ctx: Context) extends TypeAccumulator[Set[Symbol]] {
4915+
def apply(cs: Set[Symbol], tp: Type): Set[Symbol] = {
4916+
val sym = tp.typeSymbol
4917+
tp match {
4918+
case tp if tp.isTopType || tp.isBottomType =>
4919+
cs
4920+
case tp: AppliedType =>
4921+
foldOver(cs+sym, tp)
4922+
case tp: RefinedType =>
4923+
foldOver(cs+sym, tp)
4924+
case tp: TypeRef if tp.info.isTypeAlias =>
4925+
apply(cs, tp.superType)
4926+
case tp: TypeBounds =>
4927+
foldOver(cs, tp)
4928+
case other =>
4929+
foldOver(cs+sym, tp)
4930+
}
4931+
}
4932+
}
4933+
48934934
// ----- Name Filters --------------------------------------------------
48944935

48954936
/** A name filter selects or discards a member name of a type `pre`.

0 commit comments

Comments
 (0)