@@ -86,35 +86,25 @@ object Implicits {
86
86
// However, Predef.$conforms is not eligible, because it is a no-op.
87
87
//
88
88
// In principle, it would be cleanest if only implicit methods qualified
89
- // as implicit conversions. The reasons for deviating are as follows:
90
- // Keeping Function1: It's still used quite often (for instance, view
91
- // bounds map to implicits of function types) and there is no feasible workaround.
92
- // One tempting workaround would be to add a global def
93
- //
94
- // implicit def convertIfFuntion1[A, B](x: A)(implicit ev: A => B): B = ev(a)
95
- //
96
- // But that would throw out the baby with the bathwater. Now, every subtype of
97
- // function gives again rise to an implicit conversion. So it's better to just accept
98
- // function types in their dual roles.
99
- //
100
- // The reason for the treatment of <:< and conforms is similar. We could
101
- // avoid the clause by having a standard conversion like this in Predef:
89
+ // as implicit conversions. We could achieve that by having standard conversions like
90
+ // this in Predef:
102
91
//
103
92
// implicit def convertIfConforms[A, B](x: A)(implicit ev: A <:< B): B = ev(a)
93
+ // implicit def convertIfConverter[A, B](x: A)(implicit ev: ImplicitConverter[A, B]): B = ev(a)
104
94
//
105
- // But that would slow down implicit search a lot, because this conversion is
106
- // eligible for all pairs of types, and therefore is tried a lot. So we
107
- // emulate the existence of a such a conversion directly in the search.
95
+ // (Once `<:<` inherits from `ImplicitConverter` we only need the 2nd one.)
96
+ // But clauses like this currently slow down implicit search a lot, because
97
+ // they are eligible for all pairs of types, and therefore are tried too often.
98
+ // We emulate instead these conversions directly in the search.
108
99
// The reason for leaving out `Predef_conforms` is that we know it adds
109
100
// nothing since it only relates subtype with supertype.
110
101
//
111
102
// We keep the old behavior under -language:Scala2.
112
- val isFunction =
113
- if (ctx.scala2Mode) tpw.derivesFrom(defn.FunctionClass (1 ))
114
- else tpw.isRef(defn.FunctionClass (1 ))
103
+ val isFunctionInS2 = ctx.scala2Mode && tpw.derivesFrom(defn.FunctionClass (1 ))
104
+ val isImplicitConverter = tpw.derivesFrom(defn.Predef_ImplicitConverter )
115
105
val isConforms =
116
106
tpw.derivesFrom(defn.Predef_Conforms ) && ref.symbol != defn.Predef_conforms
117
- ! (isFunction || isConforms)
107
+ ! (isFunctionInS2 || isImplicitConverter || isConforms)
118
108
}
119
109
120
110
def discardForValueType (tpw : Type ): Boolean = tpw match {
0 commit comments