diff options
author | Paul Phillips <paulp@improving.org> | 2010-03-23 17:26:23 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-03-23 17:26:23 +0000 |
commit | c452268c133dde1d7555473f992545b08d69194f (patch) | |
tree | 65df1ae672ce2f177a72c44e84a10a64c0993e56 | |
parent | 26a2abff274fb7facfadcf5e9b66d805a1b670b1 (diff) | |
download | scala-c452268c133dde1d7555473f992545b08d69194f.tar.gz scala-c452268c133dde1d7555473f992545b08d69194f.tar.bz2 scala-c452268c133dde1d7555473f992545b08d69194f.zip |
Added some documentation to the methods in Pred...
Added some documentation to the methods in Predef which utilize
@elidable. No review.
4 files changed, 52 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala index a68963f6d8..830370a3e7 100644 --- a/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/AdvancedScalaSettings.scala @@ -15,7 +15,7 @@ trait AdvancedScalaSettings { val assempath: StringSetting val checkinit: BooleanSetting val disableassertions: BooleanSetting - val elidelevel: IntSetting + val elidebelow: IntSetting val experimental: BooleanSetting val future: BooleanSetting val generatephasegraph: StringSetting diff --git a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala index 4bc8e47bb4..0ee0f6f422 100644 --- a/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/ScalaSettings.scala @@ -55,7 +55,7 @@ trait ScalaSettings extends AbsScalaSettings with StandardScalaSettings { val sourcedir = StringSetting ("-Xsourcedir", "directory", "When -target:msil, the source folder structure is mirrored in output directory.", ".").dependsOn(target, "msil") val checkInit = BooleanSetting ("-Xcheckinit", "Add runtime checks on field accessors. Uninitialized accesses result in an exception being thrown.") val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions and assumptions") - val elideLevel = IntSetting ("-Xelide-below", "Generate calls to @elidable-marked methods only if method priority is greater than argument.", + val elidebelow = IntSetting ("-Xelide-below", "Generate calls to @elidable-marked methods only if method priority is greater than argument.", elidable.ASSERTION, None, elidable.byName.get(_)) val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions") val noForwarders = BooleanSetting ("-Xno-forwarders", "Do not generate static forwarders in mirror classes") diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index c22eae60c5..c59450432f 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -582,7 +582,7 @@ abstract class UnCurry extends InfoTransform with TypingTransformers { // XXX settings.noassertions.value temporarily retained to avoid // breakage until a reasonable interface is settled upon. def elideFunctionCall(sym: Symbol) = - sym != null && sym.elisionLevel.exists(x => x < settings.elideLevel.value || settings.noassertions.value) + sym != null && sym.elisionLevel.exists(x => x < settings.elidebelow.value || settings.noassertions.value) if (elideFunctionCall(fn.symbol)) { Literal(()).setPos(tree.pos).setType(UnitClass.tpe) diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index d022b3e4a5..20d70edadf 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -14,6 +14,8 @@ package scala import collection.immutable.StringOps import collection.mutable.ArrayOps import collection.generic.CanBuildFrom +import annotation.elidable +import annotation.elidable.ASSERTION /** The <code>Predef</code> object provides definitions that are * accessible in all Scala compilation units without explicit @@ -64,38 +66,82 @@ object Predef extends LowPriorityImplicits { throw new Throwable() } - import annotation.elidable - import annotation.elidable.ASSERTION - + /** Tests an expression, throwing an AssertionError if false. + * Calls to this method will not be generated if -Xelide-below + * is at least ASSERTION. + * + * @see elidable + * @param p the expression to test + */ @elidable(ASSERTION) def assert(assertion: Boolean) { if (!assertion) throw new java.lang.AssertionError("assertion failed") } + /** Tests an expression, throwing an AssertionError if false. + * Calls to this method will not be generated if -Xelide-below + * is at least ASSERTION. + * + * @see elidable + * @param p the expression to test + * @param msg a String to include in the failure message + */ @elidable(ASSERTION) def assert(assertion: Boolean, message: => Any) { if (!assertion) throw new java.lang.AssertionError("assertion failed: "+ message) } + /** Tests an expression, throwing an AssertionError if false. + * This method differs from assert only in the intent expressed: + * assert contains a predicate which needs to be proven, while + * assume contains an axiom for a static checker. Calls to this method + * will not be generated if -Xelide-below is at least ASSERTION. + * + * @see elidable + * @param p the expression to test + */ @elidable(ASSERTION) def assume(assumption: Boolean) { if (!assumption) throw new java.lang.AssertionError("assumption failed") } + /** Tests an expression, throwing an AssertionError if false. + * This method differs from assert only in the intent expressed: + * assert contains a predicate which needs to be proven, while + * assume contains an axiom for a static checker. Calls to this method + * will not be generated if -Xelide-below is at least ASSERTION. + * + * @see elidable + * @param p the expression to test + * @param msg a String to include in the failure message + */ @elidable(ASSERTION) def assume(assumption: Boolean, message: => Any) { if (!assumption) throw new java.lang.AssertionError("assumption failed: "+ message) } + /** Tests an expression, throwing an IllegalArgumentException if false. + * This method is similar to assert, but blames the caller of the method + * for violating the condition. + * + * @param p the expression to test + */ def require(requirement: Boolean) { if (!requirement) throw new IllegalArgumentException("requirement failed") } + /** Tests an expression, throwing an IllegalArgumentException if false. + * This method is similar to assert, but blames the caller of the method + * for violating the condition. + * + * @param p the expression to test + * @param msg a String to include in the failure message + */ def require(requirement: Boolean, message: => Any) { if (!requirement) throw new IllegalArgumentException("requirement failed: "+ message) |