Skip to content

Commit

Permalink
Make ∀ rewrites opt-in.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasMikula committed Jul 6, 2017
1 parent 3d8192b commit f918491
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ scalacOptions in Test ++= {

scalacOptions in Test += "-Yrangepos"

scalacOptions in Test += "-P:kind-projector:forall=true"

libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v")

Expand Down
22 changes: 20 additions & 2 deletions src/main/scala/KindProjector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,27 @@ class KindProjector(val global: Global) extends Plugin {
val name = "kind-projector"
val description = "Expand type lambda syntax"
val components = new KindRewriter(this, global) :: Nil

var enableForall = false

override def processOptions(options: List[String], error: String => Unit): Unit = {

// enable ∀ rewrites if "forall=true" is present
val (forallOpts, rest) = options partition { _.split("=")(0) == "forall" }
enableForall = forallOpts.lastOption match {
case Some(opt) =>
opt.split("=").tail match {
case Array("true") => true
case _ => false
}
case None => false
}

if(rest.nonEmpty) error(s"Unrecognized ${name} options: ${rest.mkString}")
}
}

class KindRewriter(plugin: Plugin, val global: Global)
class KindRewriter(plugin: KindProjector, val global: Global)
extends PluginComponent with Transform with TypingTransformers with TreeDSL {

import global._
Expand Down Expand Up @@ -191,7 +209,7 @@ class KindRewriter(plugin: Plugin, val global: Global)
atPos(tree.pos.makeTransparent)(
q"new $arrowType { def $methodName[$TParam]($name: $f[$TParam]): $g[$TParam] = $body }"
)
case PolyVal(targetType, methodName, tArgs, body) =>
case PolyVal(targetType, methodName, tArgs, body) if plugin.enableForall =>
atPos(tree.pos.makeTransparent)(tArgs match {
case Nil =>
val tParam = newTypeName(freshName("A"))
Expand Down

0 comments on commit f918491

Please sign in to comment.