Skip to content

Commit 29b1628

Browse files
authored
Merge branch 'main' into shahmishal/bump-yams-argument-parser-tag
2 parents f5bb69c + 682f3a7 commit 29b1628

File tree

269 files changed

+5405
-2447
lines changed

Some content is hidden

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

269 files changed

+5405
-2447
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ set(SWIFT_BENCH_MODULES
179179
single-source/StringMatch
180180
single-source/StringRemoveDupes
181181
single-source/StringReplaceSubrange
182+
single-source/StringSplitting
182183
single-source/StringSwitch
183184
single-source/StringTests
184185
single-source/StringWalk
Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
//===--- StringSplitting.swift --------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
public let StringSplitting = [
16+
BenchmarkInfo(
17+
name: "LineSink.bytes.alpha",
18+
runFunction: run_LinkSink_bytes_alpha,
19+
tags: [.validation, .String],
20+
setUpFunction: setup),
21+
BenchmarkInfo(
22+
name: "LineSink.bytes.complex",
23+
runFunction: run_LinkSink_bytes_complex,
24+
tags: [.validation, .String],
25+
setUpFunction: setup),
26+
BenchmarkInfo(
27+
name: "LineSink.scalars.alpha",
28+
runFunction: run_LinkSink_scalars_alpha,
29+
tags: [.validation, .String],
30+
setUpFunction: setup),
31+
BenchmarkInfo(
32+
name: "LineSink.scalars.complex",
33+
runFunction: run_LinkSink_scalars_complex,
34+
tags: [.validation, .String],
35+
setUpFunction: setup),
36+
BenchmarkInfo(
37+
name: "LineSink.characters.alpha",
38+
runFunction: run_LinkSink_characters_alpha,
39+
tags: [.validation, .String],
40+
setUpFunction: setup),
41+
BenchmarkInfo(
42+
name: "LineSink.characters.complex",
43+
runFunction: run_LinkSink_characters_complex,
44+
tags: [.validation, .String],
45+
setUpFunction: setup),
46+
]
47+
48+
49+
// Line-sink benchmarks: Implement `lines`-like functionality
50+
enum View {
51+
case character
52+
case scalar
53+
case utf8
54+
}
55+
56+
@inline(__always) // Constant fold the switch away, inline closures
57+
fileprivate func lineSink(_ workload: String, view: View, sink: (String) -> ()) {
58+
switch view {
59+
case .character:
60+
var iter = workload.makeIterator()
61+
_linesByCharacters(source: { iter.next() }, sink: sink)
62+
case .scalar:
63+
var iter = workload.unicodeScalars.makeIterator()
64+
_linesByScalars(source: { iter.next() }, sink: sink)
65+
case .utf8:
66+
var iter = workload.utf8.makeIterator()
67+
_linesByBytes(source: { iter.next() }, sink: sink)
68+
}
69+
}
70+
71+
72+
// Inline always to try to ignore any closure stuff
73+
@inline(__always)
74+
fileprivate func _linesByCharacters(
75+
source characterSource: () throws -> Character?,
76+
sink lineSink: (String) -> ()
77+
) rethrows {
78+
var buffer = ""
79+
func yield() {
80+
lineSink(buffer)
81+
buffer.removeAll(keepingCapacity: true)
82+
}
83+
while let c = try characterSource() {
84+
if c.isNewline {
85+
yield()
86+
} else {
87+
buffer.append(c)
88+
}
89+
}
90+
91+
// Don't emit an empty newline when there is no more content (e.g. end of file)
92+
if !buffer.isEmpty {
93+
yield()
94+
}
95+
}
96+
97+
// Inline always to try to ignore any closure stuff
98+
@inline(__always)
99+
fileprivate func _linesByScalars(
100+
source scalarSource: () throws -> Unicode.Scalar?,
101+
sink lineSink: (String) -> ()
102+
) rethrows {
103+
guard #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) else {
104+
fatalError("unavailable")
105+
}
106+
107+
var buffer: Array<UInt8> = []
108+
func yield() {
109+
lineSink(String(decoding: buffer, as: UTF8.self))
110+
buffer.removeAll(keepingCapacity: true)
111+
}
112+
113+
let _CR = Unicode.Scalar(0x0D)!
114+
let _LF = Unicode.Scalar(0x0A)!
115+
116+
while let first = try scalarSource() {
117+
switch first.value {
118+
case _CR.value:
119+
yield()
120+
guard let second = try scalarSource() else { return }
121+
if second != _LF { buffer.append(contentsOf: second.utf8) }
122+
case 0x000A..<0x000D /* LF ..< CR */: yield()
123+
case 0x0085 /* NEXT LINE (NEL) */: yield()
124+
case 0x2028 /* LINE SEPARATOR */: yield()
125+
case 0x2029 /* PARAGRAPH SEPARATOR */: yield()
126+
default: buffer.append(contentsOf: first.utf8)
127+
}
128+
}
129+
130+
// Don't emit an empty newline when there is no more content (e.g. end of file)
131+
if !buffer.isEmpty {
132+
yield()
133+
}
134+
}
135+
136+
137+
@inline(__always)
138+
fileprivate func _linesByBytes(
139+
source byteSource: () throws -> UInt8?,
140+
sink lineSink: (String) -> ()
141+
) rethrows {
142+
143+
let _CR: UInt8 = 0x0D
144+
let _LF: UInt8 = 0x0A
145+
146+
var buffer: Array<UInt8> = []
147+
func yield() {
148+
lineSink(String(decoding: buffer, as: UTF8.self))
149+
buffer.removeAll(keepingCapacity: true)
150+
}
151+
152+
/*
153+
0D 0A: CR-LF
154+
0A | 0B | 0C | 0D: LF, VT, FF, CR
155+
E2 80 A8: U+2028 (LINE SEPARATOR)
156+
E2 80 A9: U+2029 (PARAGRAPH SEPARATOR)
157+
*/
158+
while let first = try byteSource() {
159+
switch first {
160+
case _CR:
161+
yield()
162+
// Swallow up any subsequent LF
163+
guard let next = try byteSource() else { return }
164+
if next != _LF { buffer.append(next) }
165+
case 0x0A..<0x0D: yield()
166+
167+
case 0xE2:
168+
// Try to read: 80 [A8 | A9].
169+
// If we can't, then we put the byte in the buffer for error correction
170+
guard let next = try byteSource() else {
171+
buffer.append(first)
172+
yield()
173+
return
174+
}
175+
guard next == 0x80 else {
176+
buffer.append(first)
177+
buffer.append(next)
178+
continue
179+
}
180+
guard let fin = try byteSource() else {
181+
buffer.append(first)
182+
buffer.append(next)
183+
yield()
184+
return
185+
}
186+
guard fin == 0xA8 || fin == 0xA9 else {
187+
buffer.append(first)
188+
buffer.append(next)
189+
buffer.append(fin)
190+
continue
191+
}
192+
yield()
193+
default:
194+
buffer.append(first)
195+
}
196+
}
197+
// Don't emit an empty newline when there is no more content (e.g. end of file)
198+
if !buffer.isEmpty {
199+
yield()
200+
}
201+
}
202+
203+
// 1-byte sequences
204+
private let ascii = "Swift is a multi-paradigm, compiled programming language created for iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products. Swift is intended to be more resilient to erroneous code (\"safer\") than Objective-C and also more concise. It is built with the LLVM compiler framework included in Xcode 6 and later and uses the Objective-C runtime, which allows C, Objective-C, C++ and Swift code to run within a single program."
205+
206+
// 2-byte sequences
207+
private let russian = "Ру́сский язы́к один из восточнославянских языков, национальный язык русского народа."
208+
// 3-byte sequences
209+
private let japanese = "日本語(にほんご、にっぽんご)は、主に日本国内や日本人同士の間で使われている言語である。"
210+
// 4-byte sequences
211+
// Most commonly emoji, which are usually mixed with other text.
212+
private let emoji = "Panda 🐼, Dog 🐶, Cat 🐱, Mouse 🐭."
213+
214+
private let longComplexNewlines: String = {
215+
var longStr = ascii + russian + japanese + emoji + "\n"
216+
var str = longStr
217+
str += longStr.split(separator: " ").joined(separator: "\n")
218+
str += longStr.split(separator: " ").joined(separator: "\r\n")
219+
str += longStr.split(separator: " ").joined(separator: "\r")
220+
str += longStr.split(separator: " ").joined(separator: "\u{0B}")
221+
str += longStr.split(separator: " ").joined(separator: "\u{0C}")
222+
str += longStr.split(separator: " ").joined(separator: "\u{2028}")
223+
str += longStr.split(separator: " ").joined(separator: "\u{2029}")
224+
str += "\n\n"
225+
return str
226+
}()
227+
228+
public func run_LinkSink_bytes_alpha(_ N: Int) {
229+
let str = alphaInteriorNewlines
230+
for _ in 0..<(N*50) {
231+
lineSink(str, view: .utf8, sink: blackHole)
232+
}
233+
}
234+
public func run_LinkSink_bytes_complex(_ N: Int) {
235+
let str = longComplexNewlines
236+
for _ in 0..<N {
237+
lineSink(str, view: .utf8, sink: blackHole)
238+
}
239+
}
240+
public func run_LinkSink_scalars_alpha(_ N: Int) {
241+
let str = alphaInteriorNewlines
242+
for _ in 0..<(N*50) {
243+
lineSink(str, view: .scalar, sink: blackHole)
244+
}
245+
}
246+
public func run_LinkSink_scalars_complex(_ N: Int) {
247+
let str = longComplexNewlines
248+
for _ in 0..<N {
249+
lineSink(str, view: .utf8, sink: blackHole)
250+
}
251+
}
252+
public func run_LinkSink_characters_alpha(_ N: Int) {
253+
let str = alphaInteriorNewlines
254+
for _ in 0..<(N*50) {
255+
lineSink(str, view: .character, sink: blackHole)
256+
}
257+
}
258+
public func run_LinkSink_characters_complex(_ N: Int) {
259+
let str = longComplexNewlines
260+
for _ in 0..<N {
261+
lineSink(str, view: .character, sink: blackHole)
262+
}
263+
}
264+
265+
fileprivate func setup() {
266+
var utf8Alpha: Array<String> = []
267+
lineSink(alphaInteriorNewlines, view: .utf8) { utf8Alpha.append($0) }
268+
269+
var scalarAlpha: Array<String> = []
270+
lineSink(alphaInteriorNewlines, view: .scalar) { scalarAlpha.append($0) }
271+
272+
var characterAlpha: Array<String> = []
273+
lineSink(alphaInteriorNewlines, view: .character) { characterAlpha.append($0) }
274+
275+
CheckResults(utf8Alpha == scalarAlpha)
276+
CheckResults(utf8Alpha == characterAlpha)
277+
278+
var utf8Complex: Array<String> = []
279+
lineSink(longComplexNewlines, view: .utf8) { utf8Complex.append($0) }
280+
281+
var scalarComplex: Array<String> = []
282+
lineSink(longComplexNewlines, view: .scalar) { scalarComplex.append($0) }
283+
284+
var characterComplex: Array<String> = []
285+
lineSink(longComplexNewlines, view: .character) { characterComplex.append($0) }
286+
287+
CheckResults(utf8Complex == scalarComplex)
288+
CheckResults(utf8Complex == characterComplex)
289+
290+
print("preconditions checked")
291+
}
292+
293+
294+
private let alphaInteriorNewlines: String =
295+
"""
296+
abc\(Unicode.Scalar(0x0A)! // LF
297+
)def\(Unicode.Scalar(0x0B)! // VT
298+
)ghi\(Unicode.Scalar(0x0C)! // FF
299+
)jkl\(Unicode.Scalar(0x0D)! // CR
300+
)mno\(Unicode.Scalar(0x0D)!)\(Unicode.Scalar(0x0A)! // CR-LF
301+
)pqr\(Unicode.Scalar(0x2028)! // LS
302+
)stu\(Unicode.Scalar(0x2029)! // PS
303+
)vwx
304+
yz
305+
"""
306+
307+

benchmark/utils/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ import StringInterpolation
177177
import StringMatch
178178
import StringRemoveDupes
179179
import StringReplaceSubrange
180+
import StringSplitting
180181
import StringSwitch
181182
import StringTests
182183
import StringWalk
@@ -376,6 +377,11 @@ registerBenchmark(StringMatch)
376377
registerBenchmark(StringNormalization)
377378
registerBenchmark(StringRemoveDupes)
378379
registerBenchmark(StringReplaceSubrange)
380+
381+
if #available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *) {
382+
registerBenchmark(StringSplitting)
383+
}
384+
379385
registerBenchmark(StringSwitch)
380386
registerBenchmark(StringTests)
381387
registerBenchmark(StringWalk)

docs/SIL.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,20 @@ We require that ``%1`` and ``%0`` have the same type ignoring SILValueCategory.
36203620

36213621
This instruction is only valid in functions in Ownership SSA form.
36223622

3623+
end_lifetime
3624+
````````````
3625+
3626+
::
3627+
3628+
sil-instruction ::= 'end_lifetime' sil-operand
3629+
3630+
This instruction signifies the end of it's operand's lifetime to the ownership
3631+
verifier. It is inserted by the compiler in instances where it could be illegal
3632+
to insert a destroy operation. Ex: if the sil-operand had an undef value.
3633+
3634+
This instruction is valid only in OSSA and is lowered to a no-op when lowering
3635+
to non-OSSA.
3636+
36233637
assign
36243638
``````
36253639
::
@@ -5197,7 +5211,7 @@ destroy_value
51975211

51985212
::
51995213

5200-
sil-instruction ::= 'destroy_value' sil-operand
5214+
sil-instruction ::= 'destroy_value' '[poison]'? sil-operand
52015215

52025216
destroy_value %0 : $A
52035217

include/swift-c/SyntaxParser/SwiftSyntaxParser.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ typedef struct {
103103
uint16_t leading_trivia_count;
104104
uint16_t trailing_trivia_count;
105105
swiftparse_token_kind_t kind;
106+
/// Represents the range for the node, including trivia.
107+
swiftparse_range_t range;
106108
} swiftparse_token_data_t;
107109

108110
typedef struct {
@@ -115,9 +117,6 @@ typedef struct {
115117
swiftparse_token_data_t token_data;
116118
swiftparse_layout_data_t layout_data;
117119
};
118-
/// Represents the range for the node. For a token node the range includes
119-
/// the trivia associated with it.
120-
swiftparse_range_t range;
121120
/// The syntax kind. A value of '0' means this is a token node.
122121
swiftparse_syntax_kind_t kind;
123122
bool present;
@@ -218,8 +217,10 @@ swiftparse_parser_set_node_lookup(swiftparse_parser_t,
218217
/// via the return value of \c swiftparse_parse_string.
219218
///
220219
/// \param source a null-terminated UTF8 string buffer.
220+
/// \param len The length of the source string. This allows \p source to contain
221+
/// intermediate null characters.
221222
SWIFTPARSE_PUBLIC swiftparse_client_node_t
222-
swiftparse_parse_string(swiftparse_parser_t, const char *source);
223+
swiftparse_parse_string(swiftparse_parser_t, const char *source, size_t len);
223224

224225
/// Returns a constant string pointer for verification purposes.
225226
///

0 commit comments

Comments
 (0)