Skip to content

Commit 40b1a0b

Browse files
author
Max Moiseev
committed
[stdlib] all sorts of require renamed back to precondition
1 parent b1ef18f commit 40b1a0b

File tree

77 files changed

+360
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+360
-378
lines changed

benchmark/single-source/PopFrontGeneric.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ func _arrayReplace<B: _ArrayBufferProtocol, C: Collection
2323
>(
2424
inout target: B, _ subRange: Range<Int>, _ newValues: C
2525
) {
26-
_require(
26+
_precondition(
2727
subRange.startIndex >= 0,
2828
"Array replace: subRange start is negative")
2929

30-
_require(
30+
_precondition(
3131
subRange.endIndex <= target.endIndex,
3232
"Array replace: subRange extends past the end")
3333

@@ -40,7 +40,7 @@ func _arrayReplace<B: _ArrayBufferProtocol, C: Collection
4040
target.replace(subRange: subRange, with: insertCount, elementsOf: newValues)
4141
}
4242
else {
43-
_requirementFailure("Should not get here?")
43+
_preconditionFailure("Should not get here?")
4444
}
4545
}
4646

stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

+3-3
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ public func runAllTests() {
866866
public class TestSuite {
867867
public init(_ name: String) {
868868
self.name = name
869-
_require(
869+
_precondition(
870870
_testNameToIndex[name] == nil,
871871
"test suite with the same name already exists")
872872
_allTestSuites.append(self)
@@ -890,12 +890,12 @@ public class TestSuite {
890890
}
891891

892892
public func setUp(code: () -> Void) {
893-
_require(_testSetUpCode == nil, "set-up code already set")
893+
_precondition(_testSetUpCode == nil, "set-up code already set")
894894
_testSetUpCode = code
895895
}
896896

897897
public func tearDown(code: () -> Void) {
898-
_require(_testTearDownCode == nil, "tear-down code already set")
898+
_precondition(_testTearDownCode == nil, "tear-down code already set")
899899
_testTearDownCode = code
900900
}
901901

stdlib/private/StdlibUnittestFoundationExtras/StdlibUnittestFoundationExtras.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ public func withOverriddenNSLocaleCurrentLocale<Result>(
2828
) -> Result {
2929
let oldMethod = class_getClassMethod(
3030
NSLocale.self, #selector(NSLocale.current))
31-
require(oldMethod != nil, "could not find +[NSLocale currentLocale]")
31+
precondition(oldMethod != nil, "could not find +[NSLocale currentLocale]")
3232

3333
let newMethod = class_getClassMethod(
3434
NSLocale.self, #selector(NSLocale._swiftUnittest_currentLocale))
35-
require(newMethod != nil, "could not find +[NSLocale _swiftUnittest_currentLocale]")
35+
precondition(newMethod != nil, "could not find +[NSLocale _swiftUnittest_currentLocale]")
3636

37-
require(_temporaryNSLocaleCurrentLocale == nil,
37+
precondition(_temporaryNSLocaleCurrentLocale == nil,
3838
"nested calls to withOverriddenNSLocaleCurrentLocale are not supported")
3939

4040
_temporaryNSLocaleCurrentLocale = temporaryLocale
@@ -50,7 +50,7 @@ public func withOverriddenNSLocaleCurrentLocale<Result>(
5050
temporaryLocaleIdentifier: String,
5151
@noescape _ body: () -> Result
5252
) -> Result {
53-
require(
53+
precondition(
5454
NSLocale.availableLocaleIdentifiers().contains(temporaryLocaleIdentifier),
5555
"requested locale \(temporaryLocaleIdentifier) is not available")
5656

stdlib/private/SwiftPrivateDarwinExtras/Subprocess.swift

+18-18
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func posixPipe() -> (readFD: CInt, writeFD: CInt) {
5454
(fds) in
5555
let ptr = fds.baseAddress
5656
if pipe(ptr) != 0 {
57-
requirementFailure("pipe() failed")
57+
preconditionFailure("pipe() failed")
5858
}
5959
}
6060
return (fds[0], fds[1])
@@ -66,46 +66,46 @@ public func spawnChild(args: [String])
6666
-> (pid: pid_t, stdinFD: CInt, stdoutFD: CInt, stderrFD: CInt) {
6767
var fileActions: posix_spawn_file_actions_t = nil
6868
if swift_posix_spawn_file_actions_init(&fileActions) != 0 {
69-
requirementFailure("swift_posix_spawn_file_actions_init() failed")
69+
preconditionFailure("swift_posix_spawn_file_actions_init() failed")
7070
}
7171

7272
let childStdin = posixPipe()
7373
// Close the write end of the pipe on the child side.
7474
if swift_posix_spawn_file_actions_addclose(
7575
&fileActions, childStdin.writeFD) != 0 {
76-
requirementFailure("swift_posix_spawn_file_actions_addclose() failed")
76+
preconditionFailure("swift_posix_spawn_file_actions_addclose() failed")
7777
}
7878

7979
// Remap child's stdin.
8080
if swift_posix_spawn_file_actions_adddup2(
8181
&fileActions, childStdin.readFD, STDIN_FILENO) != 0 {
82-
requirementFailure("swift_posix_spawn_file_actions_adddup2() failed")
82+
preconditionFailure("swift_posix_spawn_file_actions_adddup2() failed")
8383
}
8484

8585
let childStdout = posixPipe()
8686
// Close the read end of the pipe on the child side.
8787
if swift_posix_spawn_file_actions_addclose(
8888
&fileActions, childStdout.readFD) != 0 {
89-
requirementFailure("swift_posix_spawn_file_actions_addclose() failed")
89+
preconditionFailure("swift_posix_spawn_file_actions_addclose() failed")
9090
}
9191

9292
// Remap child's stdout.
9393
if swift_posix_spawn_file_actions_adddup2(
9494
&fileActions, childStdout.writeFD, STDOUT_FILENO) != 0 {
95-
requirementFailure("swift_posix_spawn_file_actions_adddup2() failed")
95+
preconditionFailure("swift_posix_spawn_file_actions_adddup2() failed")
9696
}
9797

9898
let childStderr = posixPipe()
9999
// Close the read end of the pipe on the child side.
100100
if swift_posix_spawn_file_actions_addclose(
101101
&fileActions, childStderr.readFD) != 0 {
102-
requirementFailure("swift_posix_spawn_file_actions_addclose() failed")
102+
preconditionFailure("swift_posix_spawn_file_actions_addclose() failed")
103103
}
104104

105105
// Remap child's stderr.
106106
if swift_posix_spawn_file_actions_adddup2(
107107
&fileActions, childStderr.writeFD, STDERR_FILENO) != 0 {
108-
requirementFailure("swift_posix_spawn_file_actions_adddup2() failed")
108+
preconditionFailure("swift_posix_spawn_file_actions_adddup2() failed")
109109
}
110110

111111
var pid: pid_t = -1
@@ -115,26 +115,26 @@ public func spawnChild(args: [String])
115115
}
116116
if spawnResult != 0 {
117117
print(String(cString: strerror(spawnResult)))
118-
requirementFailure("swift_posix_spawn() failed")
118+
preconditionFailure("swift_posix_spawn() failed")
119119
}
120120

121121
if swift_posix_spawn_file_actions_destroy(&fileActions) != 0 {
122-
requirementFailure("swift_posix_spawn_file_actions_destroy() failed")
122+
preconditionFailure("swift_posix_spawn_file_actions_destroy() failed")
123123
}
124124

125125
// Close the read end of the pipe on the parent side.
126126
if close(childStdin.readFD) != 0 {
127-
requirementFailure("close() failed")
127+
preconditionFailure("close() failed")
128128
}
129129

130130
// Close the write end of the pipe on the parent side.
131131
if close(childStdout.writeFD) != 0 {
132-
requirementFailure("close() failed")
132+
preconditionFailure("close() failed")
133133
}
134134

135135
// Close the write end of the pipe on the parent side.
136136
if close(childStderr.writeFD) != 0 {
137-
requirementFailure("close() failed")
137+
preconditionFailure("close() failed")
138138
}
139139

140140
return (pid, childStdin.writeFD, childStdout.readFD, childStderr.readFD)
@@ -156,7 +156,7 @@ internal func _readAll(fd: CInt) -> String {
156156
if readResult == 0 {
157157
break
158158
}
159-
requirementFailure("read() failed")
159+
preconditionFailure("read() failed")
160160
}
161161
return String._fromCodeUnitSequenceWithRepair(
162162
UTF8.self, input: buffer[0..<usedBytes]).0
@@ -193,15 +193,15 @@ public enum ProcessTerminationStatus : CustomStringConvertible {
193193
public func posixWaitpid(pid: pid_t) -> ProcessTerminationStatus {
194194
var status: CInt = 0
195195
if waitpid(pid, &status, 0) < 0 {
196-
requirementFailure("waitpid() failed")
196+
preconditionFailure("waitpid() failed")
197197
}
198198
if (WIFEXITED(status)) {
199199
return .Exit(Int(WEXITSTATUS(status)))
200200
}
201201
if (WIFSIGNALED(status)) {
202202
return .Signal(Int(WTERMSIG(status)))
203203
}
204-
requirementFailure("did not understand what happened to child process")
204+
preconditionFailure("did not understand what happened to child process")
205205
}
206206

207207
public func runChild(args: [String])
@@ -215,10 +215,10 @@ public func runChild(args: [String])
215215
let stderr = _readAll(stderrFD)
216216

217217
if close(stdoutFD) != 0 {
218-
requirementFailure("close() failed")
218+
preconditionFailure("close() failed")
219219
}
220220
if close(stderrFD) != 0 {
221-
requirementFailure("close() failed")
221+
preconditionFailure("close() failed")
222222
}
223223
let status = posixWaitpid(pid)
224224
return (stdout, stderr, status)

stdlib/public/SDK/CoreAudio/CoreAudio.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension AudioBufferList {
4848
/// - Returns: the size in bytes of an `AudioBufferList` that can hold up to
4949
/// `maximumBuffers` `AudioBuffer`s.
5050
public static func sizeInBytes(maximumBuffers maximumBuffers: Int) -> Int {
51-
_require(maximumBuffers >= 1,
51+
_precondition(maximumBuffers >= 1,
5252
"AudioBufferList should contain at least one AudioBuffer")
5353
return sizeof(AudioBufferList) +
5454
(maximumBuffers - 1) * strideof(AudioBuffer)
@@ -65,7 +65,7 @@ extension AudioBufferList {
6565
-> UnsafeMutableAudioBufferListPointer {
6666
let byteSize = sizeInBytes(maximumBuffers: maximumBuffers)
6767
let ablMemory = calloc(byteSize, 1)
68-
_require(ablMemory != nil,
68+
_precondition(ablMemory != nil,
6969
"failed to allocate memory for an AudioBufferList")
7070

7171
let abl = UnsafeMutableAudioBufferListPointer(
@@ -134,12 +134,12 @@ extension UnsafeMutableAudioBufferListPointer : MutableCollection {
134134
/// Access an indexed `AudioBuffer` (`mBuffers[i]`).
135135
public subscript(index: Int) -> AudioBuffer {
136136
get {
137-
_require(index >= 0 && index < self.count,
137+
_precondition(index >= 0 && index < self.count,
138138
"subscript index out of range")
139139
return (_audioBuffersPointer + index).pointee
140140
}
141141
nonmutating set(newValue) {
142-
_require(index >= 0 && index < self.count,
142+
_precondition(index >= 0 && index < self.count,
143143
"subscript index out of range")
144144
(_audioBuffersPointer + index).pointee = newValue
145145
}

stdlib/public/SDK/Foundation/ExtraStringAPIs.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
extension String.UTF16View.Index : RandomAccessIndex {
1717
/// Construct from an integer offset.
1818
public init(_ offset: Int) {
19-
_require(offset >= 0, "Negative UTF16 index offset not allowed")
19+
_precondition(offset >= 0, "Negative UTF16 index offset not allowed")
2020
self.init(_offset: offset)
2121
// self._offset = offset
2222
}

stdlib/public/SDK/Foundation/Foundation.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ extension Array : _ObjectiveCBridgeable {
482482
source: NSArray,
483483
inout result: Array?
484484
) {
485-
_require(
485+
_precondition(
486486
Swift._isBridgedToObjectiveC(Element.self),
487487
"array element type is not bridged to Objective-C")
488488

stdlib/public/SDK/Foundation/NSStringAPI.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ extension String {
947947
/// format string as a template into which the remaining argument
948948
/// values are substituted according to given locale information.
949949
public init(format: String, locale: NSLocale?, arguments: [CVarArg]) {
950-
_require(
950+
_precondition(
951951
_countFormatSpecifiers(format) <= arguments.count,
952952
"Too many format specifiers (%<letter>) provided for the argument list"
953953
)

stdlib/public/SDK/GLKit/GLKit.swift.gyb

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def defineSubscript(Type, limit):
4343
public subscript(i: Int) -> Float {{
4444
@inline(__always)
4545
get {{
46-
_require(i >= 0, "Negative {0} index out of range")
47-
_require(i < {1}, "{0} index out of range")
46+
_precondition(i >= 0, "Negative {0} index out of range")
47+
_precondition(i < {1}, "{0} index out of range")
4848
4949
// We can't derive an UnsafePointer from a let binding. Lame.
5050
var clone = self

stdlib/public/SDK/XCTest/XCTest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ public func XCTAssertEqualWithAccuracy<T : FloatingPoint>(@autoclosure expressio
670670

671671
default:
672672
// unknown type, fail with prejudice
673-
_requirementFailure("unsupported floating-point type passed to XCTAssertEqualWithAccuracy")
673+
_preconditionFailure("unsupported floating-point type passed to XCTAssertEqualWithAccuracy")
674674
}
675675

676676
if !equalWithAccuracy {
@@ -741,7 +741,7 @@ public func XCTAssertNotEqualWithAccuracy<T : FloatingPoint>(@autoclosure expres
741741

742742
default:
743743
// unknown type, fail with prejudice
744-
_requirementFailure("unsupported floating-point type passed to XCTAssertNotEqualWithAccuracy")
744+
_preconditionFailure("unsupported floating-point type passed to XCTAssertNotEqualWithAccuracy")
745745
}
746746

747747
if !notEqualWithAccuracy {

stdlib/public/SDK/simd/simd.swift.gyb

+9-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public struct ${vectype} :
100100
///
101101
/// - Precondition: `array` must have exactly ${cardinal[size]} elements.
102102
public init(_ array: [${type}]) {
103-
_require(array.count == ${size},
103+
_precondition(array.count == ${size},
104104
"${vectype} requires a ${cardinal[size]}-element array")
105105
self.init(${', '.join(map(lambda i:
106106
'array[' + str(i) + ']',
@@ -116,16 +116,16 @@ public struct ${vectype} :
116116
public subscript(index: Int) -> ${type} {
117117
@_transparent
118118
get {
119-
_require(index >= 0, "vector index out of range")
120-
_require(index < ${size}, "vector index out of range")
119+
_precondition(index >= 0, "vector index out of range")
120+
_precondition(index < ${size}, "vector index out of range")
121121
let elt = Builtin.${extractelement}(_vector,
122122
Int32(index)._value)
123123
return ${type}(_bits: elt)
124124
}
125125
@_transparent
126126
set(value) {
127-
_require(index >= 0, "vector index out of range")
128-
_require(index < ${size}, "vector index out of range")
127+
_precondition(index >= 0, "vector index out of range")
128+
_precondition(index < ${size}, "vector index out of range")
129129
_vector = Builtin.${insertelement}(_vector,
130130
value._value,
131131
Int32(index)._value)
@@ -720,15 +720,15 @@ public struct ${mattype} : CustomDebugStringConvertible {
720720
721721
/// Initialize matrix to have specified `columns`.
722722
public init(_ columns: [${coltype}]) {
723-
_require(columns.count == ${cols}, "Requires array of ${cols} vectors")
723+
_precondition(columns.count == ${cols}, "Requires array of ${cols} vectors")
724724
% for i in range(cols):
725725
self._columns.${i} = columns[${i}]
726726
% end
727727
}
728728
729729
/// Initialize matrix to have specified `rows`.
730730
public init(rows: [${rowtype}]) {
731-
_require(rows.count == ${rows}, "Requires array of ${rows} vectors")
731+
_precondition(rows.count == ${rows}, "Requires array of ${rows} vectors")
732732
% for i in range(cols):
733733
self._columns.${i} = [${', '.join(map(lambda j:
734734
'rows[' + str(j) + '].' + component[i],
@@ -762,15 +762,15 @@ public struct ${mattype} : CustomDebugStringConvertible {
762762
% for i in range(cols):
763763
case ${i}: return _columns.${i}
764764
% end
765-
default: _requirementFailure("Column index out of range")
765+
default: _preconditionFailure("Column index out of range")
766766
}
767767
}
768768
set (value) {
769769
switch(column) {
770770
% for i in range(cols):
771771
case ${i}: _columns.${i} = value
772772
% end
773-
default: _requirementFailure("Column index out of range")
773+
default: _preconditionFailure("Column index out of range")
774774
}
775775
}
776776
}

0 commit comments

Comments
 (0)