mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Simplify assertion machinery in the standard library.
This change includes a number of simplifications that allow us to eliminate the type checker hack that specifically tries AssertString. Doing so provides a 25% speedup in the test/stdlib/ArrayNew.swift test (which is type-checker bound). The specific simplifications here: - User-level assert/precondition/preconditionalFailure/assertionFailer/fatalError always take an autoclosure producing a String, eliminating the need for the StaticString/AssertString dance. - Standard-library internal _precondition/_sanityCheck/etc. always take a StaticString. When we want to improve the diagnostics in the standard library, we can provide a separate overload or differently-named function. - Remove AssertString, AssertStringType, StaticStringType, which are no longer used or needed - Remove the AssertString hack from the compiler - Remove the "BooleanType" overloads of these functions, because their usefuless left when we stopped making optional types conform to BooleanType (sorry, should have been a separate patch). Swift SVN r22139
This commit is contained in:
@@ -14,15 +14,6 @@ import StdlibUnittest
|
||||
// Utilities.
|
||||
//===---
|
||||
|
||||
struct Truthiness : BooleanType {
|
||||
init(_ value: Bool) { self.value = value }
|
||||
var boolValue: Bool { return value }
|
||||
|
||||
var value: Bool
|
||||
}
|
||||
var falsie = Truthiness(false)
|
||||
var truthie = Truthiness(true)
|
||||
|
||||
func isDebugOrRelease() -> Bool {
|
||||
return !_isFastAssertConfiguration()
|
||||
}
|
||||
@@ -80,31 +71,6 @@ Assert.test("assert/StringInterpolation")
|
||||
assert(x == 42, "this \(should) fail")
|
||||
}
|
||||
|
||||
Assert.test("assert/BooleanType")
|
||||
.xfail(.Custom(
|
||||
{ !_isDebugAssertConfiguration() },
|
||||
reason: "assertions are disabled in Release and Unchecked mode"))
|
||||
.crashOutputMatches("this should fail")
|
||||
.code {
|
||||
assert(truthie, "should not fail")
|
||||
|
||||
expectCrashLater()
|
||||
assert(falsie, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("assert/BooleanType/StringInterpolation")
|
||||
.xfail(.Custom(
|
||||
{ !_isDebugAssertConfiguration() },
|
||||
reason: "assertions are disabled in Release and Unchecked mode"))
|
||||
.crashOutputMatches("this should fail")
|
||||
.code {
|
||||
var should = "should"
|
||||
assert(truthie, "\(should) not fail")
|
||||
|
||||
expectCrashLater()
|
||||
assert(falsie, "this \(should) fail")
|
||||
}
|
||||
|
||||
Assert.test("assertionFailure")
|
||||
.skip(.Custom(
|
||||
{ !_isDebugAssertConfiguration() },
|
||||
@@ -151,29 +117,6 @@ Assert.test("precondition/StringInterpolation")
|
||||
precondition(x == 42, "this \(should) fail")
|
||||
}
|
||||
|
||||
Assert.test("precondition/BooleanType")
|
||||
.xfail(.Custom(
|
||||
{ _isFastAssertConfiguration() },
|
||||
reason: "preconditions are disabled in Unchecked mode"))
|
||||
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
|
||||
.code {
|
||||
precondition(truthie, "should not fail")
|
||||
expectCrashLater()
|
||||
precondition(falsie, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("precondition/BooleanType/StringInterpolation")
|
||||
.xfail(.Custom(
|
||||
{ _isFastAssertConfiguration() },
|
||||
reason: "preconditions are disabled in Unchecked mode"))
|
||||
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
|
||||
.code {
|
||||
var should = "should"
|
||||
precondition(truthie, "\(should) not fail")
|
||||
expectCrashLater()
|
||||
precondition(falsie, "this \(should) fail")
|
||||
}
|
||||
|
||||
Assert.test("preconditionFailure")
|
||||
.skip(.Custom(
|
||||
{ _isFastAssertConfiguration() },
|
||||
@@ -222,17 +165,6 @@ Assert.test("_precondition")
|
||||
_precondition(x == 42, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("_precondition/BooleanType")
|
||||
.xfail(.Custom(
|
||||
{ _isFastAssertConfiguration() },
|
||||
reason: "preconditions are disabled in Unchecked mode"))
|
||||
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
|
||||
.code {
|
||||
_precondition(truthie, "should not fail")
|
||||
expectCrashLater()
|
||||
_precondition(falsie, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("_preconditionFailure")
|
||||
.skip(.Custom(
|
||||
{ _isFastAssertConfiguration() },
|
||||
@@ -255,17 +187,6 @@ Assert.test("_debugPrecondition")
|
||||
_debugPrecondition(x == 42, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("_debugPrecondition/BooleanType")
|
||||
.xfail(.Custom(
|
||||
{ !_isDebugAssertConfiguration() },
|
||||
reason: "debug preconditions are disabled in Release and Unchecked mode"))
|
||||
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
|
||||
.code {
|
||||
_debugPrecondition(truthie, "should not fail")
|
||||
expectCrashLater()
|
||||
_debugPrecondition(falsie, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("_debugPreconditionFailure")
|
||||
.skip(.Custom(
|
||||
{ !_isDebugAssertConfiguration() },
|
||||
@@ -288,17 +209,6 @@ Assert.test("_sanityCheck")
|
||||
_sanityCheck(x == 42, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("_sanityCheck/BooleanType")
|
||||
.xfail(.Custom(
|
||||
{ !_isStdlibInternalChecksEnabled() },
|
||||
reason: "sanity checks are disabled in this build of stdlib"))
|
||||
.crashOutputMatches("this should fail")
|
||||
.code {
|
||||
_sanityCheck(truthie, "should not fail")
|
||||
expectCrashLater()
|
||||
_sanityCheck(falsie, "this should fail")
|
||||
}
|
||||
|
||||
Assert.test("_sanityCheckFailure")
|
||||
.skip(.Custom(
|
||||
{ !_isStdlibInternalChecksEnabled() },
|
||||
|
||||
Reference in New Issue
Block a user