Skip to content

Add SIP compliant by-name implicits #5461

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 5 commits into from
Dec 4, 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
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class ScalaSettings extends Settings.SettingGroup {
*/
val Xhelp: Setting[Boolean] = BooleanSetting("-X", "Print a synopsis of advanced options.")
val XnoForwarders: Setting[Boolean] = BooleanSetting("-Xno-forwarders", "Do not generate static forwarders in mirror classes.")
val XminImplicitSearchDepth: Setting[Int] = IntSetting("-Xmin-implicit-search-depth", "Set number of levels of implicit searches undertaken before checking for divergence.", 5)
val XmaxInlines: Setting[Int] = IntSetting("-Xmax-inlines", "Maximal number of successive inlines", 32)
val XmaxClassfileName: Setting[Int] = IntSetting("-Xmax-classfile-name", "Maximum filename length for generated classes", 255, 72 to 255)
val Xmigration: Setting[ScalaVersion] = VersionSetting("-Xmigration", "Warn about constructs whose behavior may have changed since version.")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Uniques._
import ast.Trees._
import ast.untpd
import util.{FreshNameCreator, NoSource, SimpleIdentityMap, SourceFile}
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, TypeAssigner, Typer}
import typer.{Implicits, ImportInfo, Inliner, NamerContextOps, SearchHistory, SearchRoot, TypeAssigner, Typer}
import Implicits.ContextualImplicits
import config.Settings._
import config.Config
Expand Down Expand Up @@ -555,7 +555,7 @@ object Contexts {
moreProperties = Map.empty
store = initialStore.updated(settingsStateLoc, settingsGroup.defaultState)
typeComparer = new TypeComparer(this)
searchHistory = new SearchHistory(0, Map())
searchHistory = new SearchRoot
gadt = EmptyGADTMap
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ trait Symbols { this: Context =>
def newDefaultConstructor(cls: ClassSymbol): TermSymbol =
newConstructor(cls, EmptyFlags, Nil, Nil)

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

/** Create a symbol representing a selftype declaration for class `cls`. */
def newSelfSym(cls: ClassSymbol, name: TermName = nme.WILDCARD, selfInfo: Type = NoType): TermSymbol =
Expand Down
41 changes: 41 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,14 @@ object Types {
case _ => this
}

/** The set of distinct symbols referred to by this type, after all aliases are expanded */
def coveringSet(implicit ctx: Context): Set[Symbol] =
(new CoveringSetAccumulator).apply(Set.empty[Symbol], this)

/** The number of applications and refinements in this type, after all aliases are expanded */
def typeSize(implicit ctx: Context): Int =
(new TypeSizeAccumulator).apply(0, this)

/** Convert to text */
def toText(printer: Printer): Text = printer.toText(this)

Expand Down Expand Up @@ -4902,6 +4910,39 @@ object Types {
}
}

class TypeSizeAccumulator(implicit ctx: Context) extends TypeAccumulator[Int] {
def apply(n: Int, tp: Type): Int = tp match {
case tp: AppliedType =>
foldOver(n + 1, tp)
case tp: RefinedType =>
foldOver(n + 1, tp)
case tp: TypeRef if tp.info.isTypeAlias =>
apply(n, tp.superType)
case _ =>
foldOver(n, tp)
}
}

class CoveringSetAccumulator(implicit ctx: Context) extends TypeAccumulator[Set[Symbol]] {
def apply(cs: Set[Symbol], tp: Type): Set[Symbol] = {
val sym = tp.typeSymbol
tp match {
case tp if tp.isTopType || tp.isBottomType =>
cs
case tp: AppliedType =>
foldOver(cs + sym, tp)
case tp: RefinedType =>
foldOver(cs + sym, tp)
case tp: TypeRef if tp.info.isTypeAlias =>
apply(cs, tp.superType)
case tp: TypeBounds =>
foldOver(cs, tp)
case other =>
foldOver(cs + sym, tp)
}
}
}

// ----- Name Filters --------------------------------------------------

/** A name filter selects or discards a member name of a type `pre`.
Expand Down
Loading