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

Commit d76ccf3

Browse files
committed
Merge pull request #1 from puffnfresh/feature/irrefutable-generator-patterns
Add flag to disable withFilter pattern desugaring
2 parents 379af13 + 5161c11 commit d76ccf3

File tree

9 files changed

+32
-3
lines changed

9 files changed

+32
-3
lines changed

bincompat-forward.whitelist.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ filter {
389389
{
390390
matchName="scala.collection.immutable.Stream.scala$collection$immutable$Stream$$loop$2"
391391
problemName=MissingMethodProblem
392+
},
393+
{
394+
matchName="scala.reflect.runtime.Settings.ZirrefutableGeneratorPatterns"
395+
problemName=MissingMethodProblem
392396
}
393397
]
394398
}

src/compiler/scala/tools/nsc/CompilerCommand.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
8282
def usageMsg = createUsageMsg("where possible standard", shouldExplain = false, _.isStandard)
8383
def xusageMsg = createUsageMsg("Possible advanced", shouldExplain = true, _.isAdvanced)
8484
def yusageMsg = createUsageMsg("Possible private", shouldExplain = true, _.isPrivate)
85+
def zusageMsg = createUsageMsg("Possible Typelevel", shouldExplain = true, _.isTypelevel)
8586

8687
/** For info settings, compiler should just print a message and quit. */
8788
def shouldStopWithInfo = settings.isInfo
@@ -95,6 +96,7 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
9596
else if (help) usageMsg + global.pluginOptionsHelp
9697
else if (Xhelp) xusageMsg
9798
else if (Yhelp) yusageMsg
99+
else if (Zhelp) zusageMsg
98100
else if (showPlugins) global.pluginDescriptions
99101
else if (showPhases) global.phaseDescriptions + (
100102
if (debug) "\n" + global.phaseFlagDescriptions else ""

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ trait AbsSettings extends scala.reflect.internal.settings.AbsSettings {
109109
*/
110110
def isAdvanced = name match { case "-Y" => true ; case "-X" => false ; case _ => name startsWith "-X" }
111111
def isPrivate = name match { case "-Y" => false ; case _ => name startsWith "-Y" }
112+
def isTypelevel = name match { case "-Z" => false ; case _ => name startsWith "-Z" }
112113
def isStandard = !isAdvanced && !isPrivate
113114
def isForDebug = name endsWith "-debug" // by convention, i.e. -Ytyper-debug
114115
def isDeprecated = deprecationMessage.isDefined

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait ScalaSettings extends AbsScalaSettings
4242
def optimiseSettings = List[BooleanSetting](inline, inlineHandlers, Xcloselim, Xdce, YconstOptimization)
4343

4444
/** If any of these settings is enabled, the compiler should print a message and exit. */
45-
def infoSettings = List[Setting](version, help, Xhelp, Yhelp, showPlugins, showPhases, genPhaseGraph)
45+
def infoSettings = List[Setting](version, help, Xhelp, Yhelp, Zhelp, showPlugins, showPhases, genPhaseGraph)
4646

4747
/** Any -multichoice:help? Nicer if any option could report that it had help to offer. */
4848
private def multihelp = allSettings exists { case s: MultiChoiceSetting[_] => s.isHelping case _ => false }
@@ -237,6 +237,12 @@ trait ScalaSettings extends AbsScalaSettings
237237

238238
private def removalIn212 = "This flag is scheduled for removal in 2.12. If you have a case where you need this flag then please report a bug."
239239

240+
/**
241+
* -Z Typelevel settings
242+
*/
243+
val Zhelp = BooleanSetting("-Z", "Print a synopsis of Typelevel options.")
244+
val ZirrefutableGeneratorPatterns = BooleanSetting("-Zirrefutable-generator-patterns", "Treat patterns in for comprehensions as irrefutable. Do not add filter or withFilter calls.")
245+
240246
object YstatisticsPhases extends MultiChoiceEnumeration { val parser, typer, patmat, erasure, cleanup, jvm = Value }
241247
val Ystatistics = {
242248
val description = "Print compiler statistics for specific phases"

src/reflect/scala/reflect/internal/TreeGen.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ abstract class TreeGen {
622622
body) setPos splitpos
623623
case None =>
624624
atPos(splitpos) {
625-
mkVisitor(List(CaseDef(pat, EmptyTree, body)), checkExhaustive = false)
625+
mkVisitor(List(CaseDef(pat, EmptyTree, body)), checkExhaustive = settings.ZirrefutableGeneratorPatterns)
626626
}
627627
}
628628
}
@@ -768,7 +768,7 @@ abstract class TreeGen {
768768
}
769769

770770
def mkCheckIfRefutable(pat: Tree, rhs: Tree)(implicit fresh: FreshNameCreator) =
771-
if (treeInfo.isVarPatternDeep(pat)) rhs
771+
if (treeInfo.isVarPatternDeep(pat) || settings.ZirrefutableGeneratorPatterns) rhs
772772
else {
773773
val cases = List(
774774
CaseDef(pat.duplicate, EmptyTree, Literal(Constant(true))),

src/reflect/scala/reflect/internal/settings/MutableSettings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ abstract class MutableSettings extends AbsSettings {
5555
def maxClassfileName: IntSetting
5656

5757
def isScala211: Boolean
58+
59+
def ZirrefutableGeneratorPatterns: BooleanSetting
5860
}
5961

6062
object MutableSettings {

src/reflect/scala/reflect/runtime/Settings.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,6 @@ private[reflect] class Settings extends MutableSettings {
5151
val Yrecursion = new IntSetting(0)
5252
val maxClassfileName = new IntSetting(255)
5353
def isScala211 = true
54+
55+
def ZirrefutableGeneratorPatterns = new BooleanSetting(false)
5456
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Zirrefutable-generator-patterns
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
case class Foo[A](a: A) {
2+
def map[B](f: A => B): Foo[B] = Foo(f(a))
3+
def flatMap[B](f: A => Foo[B]): Foo[B] = Foo(f(a).a)
4+
}
5+
6+
object Test {
7+
for {
8+
(a, b) <- Foo((1, 'd'))
9+
(c, d, e) <- Foo((1, true, "three"))
10+
} yield (a + c, e :+ b, !d)
11+
}

0 commit comments

Comments
 (0)