8000 SI-6582 Use Tseitin's algorithm for CNF conversion in pattern matching analysis. by adriaanm · Pull Request #2796 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

SI-6582 Use Tseitin's algorithm for CNF conversion in pattern matching analysis. #2796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

8000 Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
Prev Previous commit
Next Next commit
Add sequence method via reflect.internal.Sequenceable implicit
  • Loading branch information
adriaanm committed Aug 13, 2013
commit c5084023e6ddb518c10c9f6fcea6dd70f6646f3f
4 changes: 4 additions & 0 deletions bincompat-forward.whitelist.conf
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ filter {
{
matchName="scala.reflect.internal.annotations.uncheckedBounds"
problemName=MissingClassProblem
},
{
matchName="scala.reflect.internal.util.package$Sequenceable"
problemName=MissingClassProblem
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import scala.collection.mutable
import scala.reflect.internal.util.Statistics
import scala.reflect.internal.util.Position
import scala.reflect.internal.util.NoPosition
import scala.reflect.internal.util.Sequenceable

/** Optimize and analyze matches based on their TreeMaker-representation.
*
Expand Down Expand Up @@ -240,9 +241,6 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
def defaultBody: Tree
def defaultCase(scrutSym: Symbol = defaultSym, guard: Tree = EmptyTree, body: Tree = defaultBody): CaseDef

private def sequence[T](xs: List[Option[T]]): Option[List[T]] =
if (xs exists (_.isEmpty)) None else Some(xs.flatten)

object GuardAndBodyTreeMakers {
def unapply(tms: List[TreeMaker]): Option[(Tree, Tree)] = {
tms match {
Expand Down Expand Up @@ -451,7 +449,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
}

// succeed if they were all switchable
sequence(switchableAlts) map { switchableAlts =>
switchableAlts.sequence map { switchableAlts =>
def extractConst(t: Tree) = t match {
case Literal(const) => const
case _ => t
Expand All @@ -470,7 +468,7 @@ trait MatchOptimization extends MatchTreeMaking with MatchAnalysis {
}
}

val caseDefsWithGuards = sequence(caseDefs) match {
val caseDefsWithGuards = caseDefs.sequence match {
case None => return Nil
case Some(cds) => cds
}
Expand Down
20 changes: 18 additions & 2 deletions src/reflect/scala/reflect/internal/util/package.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
package scala.reflect
package internal

import scala.collection.generic.GenericTraversableTemplate
import scala.collection.GenTraversableOnce

package object util {
/**
* Adds the `sm` String interpolator to a [[scala.StringContext]].
/** Adds the `sm` String interpolator to a [[scala.StringContext]].
*/
implicit class StringContextStripMarginOps(val stringContext: StringContext) extends StripMarginInterpolator

/** Adds the `sequence` method to a traversable `xss` that has traversables as elements.
* `xss.sequence` returns `None` if `xss` contains an empty traversable,
* or else `Some(xss.flatten)`.
*/
implicit class Sequenceable[CC[X] <: Traversable[X] with GenericTraversableTemplate[X, CC], A](xss: CC[A]) {
def sequence[B](implicit asTraversable: A => GenTraversableOnce[B]): Option[CC[B]] = {
val b = xss.genericBuilder[B]
for (xs <- xss)
if (xs.isEmpty) return None
else b ++= asTraversable(xs).seq
Some(b.result)
}
}
}
0