Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Mode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ object Mode {
* that TypeParamRefs can be sub- and supertypes of anything. See TypeComparer.
*/
val TypevarsMissContext = newMode(4, "TypevarsMissContext")

val CheckCyclic = newMode(5, "CheckCyclic")

/** We are looking at the arguments of a supercall */
Expand Down
17 changes: 10 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,20 @@ object Implicits {
/** The implicit references */
def refs: List[ImplicitRef]

private var SingletonClass: ClassSymbol = null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private[this] to avoid generating accessors?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add a cache for SingletonClass?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reason as for the caches in TypeComparer. It's used a lot and as a lazy val access is not super fast. It was one of the performance tweaks I applied after we saw a slip. Not sure it was the one that made the difference.


/** Widen type so that it is neither a singleton type nor it inherits from scala.Singleton. */
private def widenSingleton(tp: Type)(implicit ctx: Context): Type = {
if (SingletonClass == null) SingletonClass = defn.SingletonClass
val wtp = tp.widenSingleton
if (wtp.derivesFrom(SingletonClass)) defn.AnyType else wtp
}

/** Return those references in `refs` that are compatible with type `pt`. */
protected def filterMatching(pt: Type)(implicit ctx: Context): List[Candidate] = track("filterMatching") {

def refMatches(ref: TermRef)(implicit ctx: Context) = /*trace(i"refMatches $ref $pt")*/ {

/** Widen type so that it is neither a singleton type nor it inherits from scala.Singleton. */
def widenSingleton(tp: Type): Type = {
val wtp = tp.widenSingleton
if (wtp.derivesFrom(defn.SingletonClass)) defn.AnyType else wtp
}

def discardForView(tpw: Type, argType: Type): Boolean = tpw match {
case mt: MethodType =>
mt.isImplicitMethod ||
Expand Down Expand Up @@ -150,7 +153,7 @@ object Implicits {
val res = adjustSingletonArg(tp.resType)
if (res `eq` tp.resType) tp else tp.derivedLambdaType(resType = res)
case tp: MethodType =>
tp.derivedLambdaType(paramInfos = tp.paramInfos.map(widenSingleton))
tp.derivedLambdaType(paramInfos = tp.paramInfos.mapConserve(widenSingleton))
case _ => tp
}

Expand Down