Skip to content

Commit 5728b19

Browse files
committed
Some tweaks to improve performance
1 parent 69bfb34 commit 5728b19

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ object Mode {
3737
* that TypeParamRefs can be sub- and supertypes of anything. See TypeComparer.
3838
*/
3939
val TypevarsMissContext = newMode(4, "TypevarsMissContext")
40+
4041
val CheckCyclic = newMode(5, "CheckCyclic")
4142

4243
/** We are looking at the arguments of a supercall */

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,20 @@ object Implicits {
7171
/** The implicit references */
7272
def refs: List[ImplicitRef]
7373

74+
private var SingletonClass: ClassSymbol = null
75+
76+
/** Widen type so that it is neither a singleton type nor it inherits from scala.Singleton. */
77+
private def widenSingleton(tp: Type)(implicit ctx: Context): Type = {
78+
if (SingletonClass == null) SingletonClass = defn.SingletonClass
79+
val wtp = tp.widenSingleton
80+
if (wtp.derivesFrom(SingletonClass)) defn.AnyType else wtp
81+
}
82+
7483
/** Return those references in `refs` that are compatible with type `pt`. */
7584
protected def filterMatching(pt: Type)(implicit ctx: Context): List[Candidate] = track("filterMatching") {
7685

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

79-
/** Widen type so that it is neither a singleton type nor it inherits from scala.Singleton. */
80-
def widenSingleton(tp: Type): Type = {
81-
val wtp = tp.widenSingleton
82-
if (wtp.derivesFrom(defn.SingletonClass)) defn.AnyType else wtp
83-
}
84-
8588
def discardForView(tpw: Type, argType: Type): Boolean = tpw match {
8689
case mt: MethodType =>
8790
mt.isImplicitMethod ||
@@ -150,7 +153,7 @@ object Implicits {
150153
val res = adjustSingletonArg(tp.resType)
151154
if (res `eq` tp.resType) tp else tp.derivedLambdaType(resType = res)
152155
case tp: MethodType =>
153-
tp.derivedLambdaType(paramInfos = tp.paramInfos.map(widenSingleton))
156+
tp.derivedLambdaType(paramInfos = tp.paramInfos.mapConserve(widenSingleton))
154157
case _ => tp
155158
}
156159

0 commit comments

Comments
 (0)