Skip to content

Commit ce62b37

Browse files
authored
Merge pull request #5461 from milessabin/topic/byname-implicits
Add SIP compliant by-name implicits
2 parents 57f0b8f + 32b6907 commit ce62b37

38 files changed

+1936
-172
lines changed

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

-1
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

+2-2
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

+2-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,8 @@ trait Symbols { this: Context =>
264264
def newDefaultConstructor(cls: ClassSymbol): TermSymbol =
265265
newConstructor(cls, EmptyFlags, Nil, Nil)
266266

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

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

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

+41
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,14 @@ object Types {
14631463
case _ => this
14641464
}
14651465

1466+
/** The set of distinct symbols referred to by this type, after all aliases are expanded */
1467+
def coveringSet(implicit ctx: Context): Set[Symbol] =
1468+
(new CoveringSetAccumulator).apply(Set.empty[Symbol], this)
1469+
1470+
/** The number of applications and refinements in this type, after all aliases are expanded */
1471+
def typeSize(implicit ctx: Context): Int =
1472+
(new TypeSizeAccumulator).apply(0, this)
1473+
14661474
/** Convert to text */
14671475
def toText(printer: Printer): Text = printer.toText(this)
14681476

@@ -4902,6 +4910,39 @@ object Types {
49024910
}
49034911
}
49044912

4913+
class TypeSizeAccumulator(implicit ctx: Context) extends TypeAccumulator[Int] {
4914+
def apply(n: Int, tp: Type): Int = tp match {
4915+
case tp: AppliedType =>
4916+
foldOver(n + 1, tp)
4917+
case tp: RefinedType =>
4918+
foldOver(n + 1, tp)
4919+
case tp: TypeRef if tp.info.isTypeAlias =>
4920+
apply(n, tp.superType)
4921+
case _ =>
4922+
foldOver(n, tp)
4923+
}
4924+
}
4925+
4926+
class CoveringSetAccumulator(implicit ctx: Context) extends TypeAccumulator[Set[Symbol]] {
4927+
def apply(cs: Set[Symbol], tp: Type): Set[Symbol] = {
4928+
val sym = tp.typeSymbol
4929+
tp match {
4930+
case tp if tp.isTopType || tp.isBottomType =>
4931+
cs
4932+
case tp: AppliedType =>
4933+
foldOver(cs + sym, tp)
4934+
case tp: RefinedType =>
4935+
foldOver(cs + sym, tp)
4936+
case tp: TypeRef if tp.info.isTypeAlias =>
4937+
apply(cs, tp.superType)
4938+
case tp: TypeBounds =>
4939+
foldOver(cs, tp)
4940+
case other =>
4941+
foldOver(cs + sym, tp)
4942+
}
4943+
}
4944+
}
4945+
49054946
// ----- Name Filters --------------------------------------------------
49064947

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

0 commit comments

Comments
 (0)