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

Commit 92f69d2

Browse files
committed
SI-9302 -Xdisable-assertions raises elide level
Previously, the flag caused any elidable to be elided. This commit simply sets -Xelide-below to ASSERTION + 1. The flag is useful because there's no mnemonic for specifying the magic constant as an option argument. `-Xelide-below ASSERTION` means asserts are enabled.
1 parent 8200009 commit 92f69d2

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ trait ScalaSettings extends AbsScalaSettings
101101
val Xhelp = BooleanSetting ("-X", "Print a synopsis of advanced options.")
102102
val checkInit = BooleanSetting ("-Xcheckinit", "Wrap field accessors to throw an exception on uninitialized access.")
103103
val developer = BooleanSetting ("-Xdev", "Indicates user is a developer - issue warnings about anything which seems amiss")
104-
val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.")
104+
val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions or assumptions.") andThen (flag =>
105+
if (flag) elidebelow.value = elidable.ASSERTION + 1)
105106
val elidebelow = IntSetting ("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument",
106107
elidable.MINIMUM, None, elidable.byName get _)
107108
val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes.")

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,7 @@ abstract class UnCurry extends InfoTransform
437437
def isLiftedLambdaBody(target: Tree) = target.symbol.isLocalToBlock && target.symbol.isArtifact && target.symbol.name.containsName(nme.ANON_FUN_NAME)
438438

439439
val result = (
440-
// TODO - settings.noassertions.value temporarily retained to avoid
441-
// breakage until a reasonable interface is settled upon.
442-
if ((sym ne null) && (sym.elisionLevel.exists (_ < settings.elidebelow.value || settings.noassertions)))
440+
if ((sym ne null) && sym.elisionLevel.exists(_ < settings.elidebelow.value))
443441
replaceElidableTree(tree)
444442
else translateSynchronized(tree) match {
445443
case dd @ DefDef(mods, name, tparams, _, tpt, rhs) =>

src/library/scala/Predef.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import scala.io.StdIn
3535
* === Assertions ===
3636
*
3737
* A set of `assert` functions are provided for use as a way to document
38-
* and dynamically check invariants in code. `assert` statements can be elided
39-
* at compile time by providing the command line argument `-Xdisable-assertions` to
40-
* the `scalac` command.
38+
* and dynamically check invariants in code. Invocations of `assert` can be elided
39+
* at compile time by providing the command line option `-Xdisable-assertions`,
40+
* which raises `-Xelide-below` above `elidable.ASSERTION`, to the `scalac` command.
4141
*
4242
* Variants of `assert` intended for use with static analysis tools are also
4343
* provided: `assume`, `require` and `ensuring`. `require` and `ensuring` are
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xdisable-assertions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
object Elided {
3+
import annotation._, elidable._
4+
@elidable(INFO) def info(): Boolean = true
5+
@elidable(10000) def f(): Boolean = true
6+
def g(): Boolean = { assert(false); true }
7+
}
8+
9+
object Test extends App {
10+
import Elided._
11+
if (info()) println("Bad info.")
12+
if (!f()) println("Elided f.")
13+
if (!g()) println("Elided g?") // assert should be off
14+
}

0 commit comments

Comments
 (0)