Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 916320e

Browse files
committed
Faster resolution of inductive implicits.
1 parent 3a2062d commit 916320e

File tree

53 files changed

+3102
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3102
-27
lines changed

bincompat-forward.whitelist.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ filter {
102102
{
103103
matchName="scala.util.Properties.coloredOutputEnabled"
104104
problemName=DirectMissingMethodProblem
105+
},
106+
{
107+
matchName="scala.annotation.inductive"
108+
problemName=MissingClassProblem
109+
},
110+
{
111+
matchName="scala.reflect.runtime.Settings.YinductionHeuristics"
112+
problemName=MissingMethodProblem
105113
}
106114
]
107115
}

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait ScalaSettings extends AbsScalaSettings
3030
protected def defaultClasspath = sys.env.getOrElse("CLASSPATH", ".")
3131

3232
/** Enabled under -Xexperimental. */
33-
protected def experimentalSettings = List[BooleanSetting](YpartialUnification)
33+
protected def experimentalSettings = List[BooleanSetting](YpartialUnification, YinductionHeuristics)
3434

3535
/** Enabled under -Xfuture. */
3636
protected def futureSettings = List[BooleanSetting]()
@@ -221,6 +221,7 @@ trait ScalaSettings extends AbsScalaSettings
221221
val YdisableFlatCpCaching = BooleanSetting ("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.")
222222
val YpartialUnification = BooleanSetting ("-Ypartial-unification", "Enable partial unification in type constructor inference")
223223
val Yvirtpatmat = BooleanSetting ("-Yvirtpatmat", "Enable pattern matcher virtualization")
224+
val YinductionHeuristics = BooleanSetting ("-Yinduction-heuristics", "Enable induction heuristics in implicit resolution")
224225

225226
val exposeEmptyPackage = BooleanSetting ("-Yexpose-empty-package", "Internal only: expose the empty package.").internalOnly()
226227
val Ydelambdafy = ChoiceSetting ("-Ydelambdafy", "strategy", "Strategy used for translating lambdas into JVM code.", List("inline", "method"), "method")

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,25 @@ trait ContextErrors {
8282
// (pt at the point of divergence gives less information to the user)
8383
// Note: it is safe to delay error message generation in this case
8484
// because we don't modify implicits' infos.
85+
sealed abstract class ImplicitTypeError extends TreeTypeError
86+
8587
case class DivergentImplicitTypeError(underlyingTree: Tree, pt0: Type, sym: Symbol)
86-
extends TreeTypeError {
88+
extends ImplicitTypeError {
8789
def errMsg: String = errMsgForPt(pt0)
8890
def withPt(pt: Type): AbsTypeError = this.copy(pt0 = pt)
8991
private def errMsgForPt(pt: Type) =
9092
s"diverging implicit expansion for type ${pt}\nstarting with ${sym.fullLocationString}"
9193
}
9294

95+
case class NoninductiveImplicitTypeError(underlyingTree: Tree, pt: Type)
96+
extends ImplicitTypeError {
97+
def errMsg: String = s"Noninductive implicit expansion for type ${pt}"
98+
}
99+
100+
case class IncompleteInductionImplicitTypeError(underlyingTree: Tree, pt: Type, aux: Type)
101+
extends ImplicitTypeError {
102+
def errMsg: String = s"Inductive implicit expansion for type ${pt} failed due to missing auxiliary implicit ${aux}"
103+
}
93104

94105
case class PosAndMsgTypeError(errPos: Position, errMsg: String)
95106
extends AbsTypeError
@@ -1306,6 +1317,12 @@ trait ContextErrors {
13061317

13071318
def DivergingImplicitExpansionError(tree: Tree, pt: Type, sym: Symbol)(implicit context0: Context) =
13081319
issueTypeError(DivergentImplicitTypeError(tree, pt, sym))
1320+
1321+
def NoninductiveImplicitExpansionError(tree: Tree, pt: Type)(implicit context0: Context) =
1322+
issueTypeError(NoninductiveImplicitTypeError(tree, pt))
1323+
1324+
def IncompleteInductionImplicitExpansionError(tree: Tree, pt: Type, aux: Type)(implicit context0: Context) =
1325+
issueTypeError(IncompleteInductionImplicitTypeError(tree, pt, aux))
13091326
}
13101327

13111328
object NamesDefaultsErrorsGen {

src/compiler/scala/tools/nsc/typechecker/Contexts.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,15 +1309,23 @@ trait Contexts { self: Analyzer =>
13091309
// have to pass in context because multiple contexts may share the same ReportBuffer
13101310
def reportFirstDivergentError(fun: Tree, param: Symbol, paramTp: Type)(implicit context: Context): Unit =
13111311
errors.collectFirst {
1312-
case dte: DivergentImplicitTypeError => dte
1312+
case ite: ImplicitTypeError => ite
13131313
} match {
1314-
case Some(divergent) =>
1314+
case Some(divergent: DivergentImplicitTypeError) =>
13151315
// DivergentImplicit error has higher priority than "no implicit found"
13161316
// no need to issue the problem again if we are still in silent mode
13171317
if (context.reportErrors) {
13181318
context.issue(divergent.withPt(paramTp))
13191319
errorBuffer.retain {
1320-
case dte: DivergentImplicitTypeError => false
1320+
case ite: ImplicitTypeError => false
1321+
case _ => true
1322+
}
1323+
}
1324+
case Some(ite) =>
1325+
if (context.reportErrors) {
1326+
context.issue(ite)
1327+
errorBuffer.retain {
1328+
case ite: ImplicitTypeError => false
13211329
case _ => true
13221330
}
13231331
}
@@ -1333,7 +1341,7 @@ trait Contexts { self: Analyzer =>
13331341

13341342
def propagateImplicitTypeErrorsTo(target: ContextReporter) = {
13351343
errors foreach {
1336-
case err@(_: DivergentImplicitTypeError | _: AmbiguousImplicitTypeError) =>
1344+
case err@(_: ImplicitTypeError | _: AmbiguousImplicitTypeError) =>
13371345
target.errorBuffer += err
13381346
case _ =>
13391347
}

0 commit comments

Comments
 (0)