Skip to content

Commit 8a5a820

Browse files
Merge pull request #4398 from swiftwasm/katei/merge-main-2022-04-01
Merge main 2022-04-01
2 parents fbc9c01 + e1e2ffc commit 8a5a820

File tree

574 files changed

+15607
-4188
lines changed

Some content is hidden

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

574 files changed

+15607
-4188
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* [SE-0345][]:
9+
10+
It is now possible to unwrap optional variables with a shorthand syntax that
11+
shadows the existing declaration. For example, the following:
12+
13+
```swift
14+
let foo: String? = "hello world"
15+
16+
if let foo {
17+
print(foo) // prints "hello world"
18+
}
19+
```
20+
21+
is equivalent to:
22+
23+
```swift
24+
let foo: String? = "hello world"
25+
26+
if let foo = foo {
27+
print(foo) // prints "hello world"
28+
}
29+
```
30+
831
* [SE-0340][]:
932

1033
It is now possible to make declarations unavailable from use in asynchronous
@@ -9095,6 +9118,7 @@ Swift 1.0
90959118
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
90969119
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
90979120
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
9121+
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
90989122

90999123
[SR-75]: <https://bugs.swift.org/browse/SR-75>
91009124
[SR-106]: <https://bugs.swift.org/browse/SR-106>

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,15 @@ option(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS
327327
"If non-empty, when embedding the LLVM bitcode binary sections into the relevant binaries, pass in -bitcode_hide_symbols. Does nothing if SWIFT_EMBED_BITCODE_SECTION is set to false."
328328
FALSE)
329329

330+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
331+
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default TRUE)
332+
else()
333+
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default FALSE)
334+
endif()
335+
330336
option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
331337
"Whether to enable CrashReporter integration"
332-
FALSE)
338+
"${SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default}")
333339

334340
set(SWIFT_DARWIN_XCRUN_TOOLCHAIN "XcodeDefault" CACHE STRING
335341
"The name of the toolchain to pass to 'xcrun'")

SwiftCompilerSources/Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
.library(
1212
name: "Swift",
1313
type: .static,
14-
targets: ["SIL", "Optimizer", "ExperimentalRegex"]),
14+
targets: ["SIL", "Optimizer", "_RegexParser"]),
1515
],
1616
dependencies: [
1717
],
@@ -26,15 +26,15 @@ let package = Package(
2626
"-cross-module-optimization"
2727
])]),
2828
.target(
29-
name: "ExperimentalRegex",
29+
name: "_RegexParser",
3030
dependencies: [],
3131
swiftSettings: [SwiftSetting.unsafeFlags([
3232
"-I", "../include/swift",
3333
"-cross-module-optimization"
3434
])]),
3535
.target(
3636
name: "Optimizer",
37-
dependencies: ["SIL", "ExperimentalRegex"],
37+
dependencies: ["SIL", "_RegexParser"],
3838
swiftSettings: [SwiftSetting.unsafeFlags([
3939
"-I", "../include/swift",
4040
"-cross-module-optimization"

SwiftCompilerSources/Sources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
add_subdirectory(Basic)
1212
add_subdirectory(AST)
1313
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
14-
add_subdirectory(ExperimentalRegex)
14+
add_subdirectory(_RegexParser)
1515
endif()
1616
add_subdirectory(SIL)
1717
add_subdirectory(Optimizer)

SwiftCompilerSources/Sources/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
set(dependencies)
1010
list(APPEND dependencies Basic SIL)
1111
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
12-
list(APPEND dependencies ExperimentalRegex)
12+
list(APPEND dependencies _RegexParser)
1313
endif()
1414

1515
add_swift_compiler_module(Optimizer DEPENDS ${dependencies})

SwiftCompilerSources/Sources/Optimizer/DataStructures/BasicBlockRange.swift

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,62 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
5151
/// The dominating begin block.
5252
let begin: BasicBlock
5353

54-
/// The exclusive range, i.e. not containing the end blocks.
55-
private(set) var range: Stack<BasicBlock>
54+
/// The inclusive range, i.e. the exclusive range plus the end blocks.
55+
private(set) var inclusiveRange: Stack<BasicBlock>
5656

57+
/// The exclusive range, i.e. not containing the end blocks.
58+
var range: LazyFilterSequence<Stack<BasicBlock>> {
59+
inclusiveRange.lazy.filter { contains($0) }
60+
}
61+
5762
/// All inserted blocks.
5863
private(set) var inserted: Stack<BasicBlock>
5964

60-
private var insertedSet: BasicBlockSet
65+
private var wasInserted: BasicBlockSet
66+
private var inExclusiveRange: BasicBlockSet
6167
private var worklist: BasicBlockWorklist
6268

6369
init(begin: BasicBlock, _ context: PassContext) {
6470
self.begin = begin
65-
self.range = Stack(context)
71+
self.inclusiveRange = Stack(context)
6672
self.inserted = Stack(context)
67-
self.insertedSet = BasicBlockSet(context)
73+
self.wasInserted = BasicBlockSet(context)
74+
self.inExclusiveRange = BasicBlockSet(context)
6875
self.worklist = BasicBlockWorklist(context)
76+
worklist.pushIfNotVisited(begin)
6977
}
7078

7179
/// Insert a potential end block.
7280
mutating func insert(_ block: BasicBlock) {
73-
if !insertedSet.contains(block) {
74-
insertedSet.insert(block)
81+
if !wasInserted.contains(block) {
82+
wasInserted.insert(block)
7583
inserted.append(block)
7684
}
77-
if block != begin {
78-
worklist.pushIfNotVisited(contentsOf: block.predecessors)
79-
80-
while let b = worklist.pop() {
81-
range.append(b)
82-
if b != begin {
83-
worklist.pushIfNotVisited(contentsOf: b.predecessors)
85+
worklist.pushIfNotVisited(block)
86+
while let b = worklist.pop() {
87+
inclusiveRange.append(b)
88+
if b != begin {
89+
for pred in b.predecessors {
90+
worklist.pushIfNotVisited(pred)
91+
inExclusiveRange.insert(pred)
8492
}
8593
}
8694
}
8795
}
8896

97+
/// Insert a sequence of potential end blocks.
98+
mutating func insert<S: Sequence>(contentsOf other: S) where S.Element == BasicBlock {
99+
for block in other {
100+
insert(block)
101+
}
102+
}
103+
89104
/// Returns true if the exclusive range contains `block`.
90-
func contains(_ block: BasicBlock) -> Bool { worklist.hasBeenPushed(block) }
105+
func contains(_ block: BasicBlock) -> Bool { inExclusiveRange.contains(block) }
91106

92107
/// Returns true if the inclusive range contains `block`.
93108
func inclusiveRangeContains (_ block: BasicBlock) -> Bool {
94-
contains(block) || insertedSet.contains(block)
109+
worklist.hasBeenPushed(block)
95110
}
96111

97112
/// Returns true if the range is valid and that's iff the begin block dominates all blocks of the range.
@@ -104,14 +119,14 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
104119

105120
/// Returns the end blocks.
106121
var ends: LazyFilterSequence<Stack<BasicBlock>> {
107-
inserted.lazy.filter { !worklist.hasBeenPushed($0) }
122+
inserted.lazy.filter { !contains($0) }
108123
}
109124

110125
/// Returns the exit blocks.
111126
var exits: LazySequence<FlattenSequence<
112-
LazyMapSequence<Stack<BasicBlock>,
127+
LazyMapSequence<LazyFilterSequence<Stack<BasicBlock>>,
113128
LazyFilterSequence<SuccessorArray>>>> {
114-
range.lazy.flatMap {
129+
range.flatMap {
115130
$0.successors.lazy.filter {
116131
!inclusiveRangeContains($0) || $0 == begin
117132
}
@@ -124,22 +139,25 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
124139
}
125140

126141
var description: String {
127-
"""
128-
begin: \(begin.name)
129-
range: \(range)
130-
ends: \(ends)
131-
exits: \(exits)
132-
interiors: \(interiors)
133-
"""
142+
return (isValid ? "" : "<invalid>\n") +
143+
"""
144+
begin: \(begin.name)
145+
range: \(range)
146+
inclrange: \(inclusiveRange)
147+
ends: \(ends)
148+
exits: \(exits)
149+
interiors: \(interiors)
150+
"""
134151
}
135152

136153
var customMirror: Mirror { Mirror(self, children: []) }
137154

138155
/// TODO: once we have move-only types, make this a real deinit.
139156
mutating func deinitialize() {
140157
worklist.deinitialize()
158+
inExclusiveRange.deinitialize()
159+
wasInserted.deinitialize()
141160
inserted.deinitialize()
142-
insertedSet.deinitialize()
143-
range.deinitialize()
161+
inclusiveRange.deinitialize()
144162
}
145163
}

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import SIL
1414

15-
/// A range of basic blocks.
15+
/// A range of instructions.
1616
///
1717
/// The `InstructionRange` defines a range from a dominating "begin" instruction to one or more "end" instructions.
1818
/// The range is "exclusive", which means that the "end" instructions are not part of the range.
@@ -60,6 +60,13 @@ struct InstructionRange : CustomStringConvertible, CustomReflectable {
6060
blockRange.insert(inst.block)
6161
}
6262

63+
/// Insert a sequence of potential end instructions.
64+
mutating func insert<S: Sequence>(contentsOf other: S) where S.Element == Instruction {
65+
for inst in other {
66+
insert(inst)
67+
}
68+
}
69+
6370
/// Returns true if the exclusive range contains `inst`.
6471
func contains(_ inst: Instruction) -> Bool {
6572
let block = inst.block
@@ -99,7 +106,7 @@ struct InstructionRange : CustomStringConvertible, CustomReflectable {
99106

100107
/// Returns the exit instructions.
101108
var exits: LazyMapSequence<LazySequence<FlattenSequence<
102-
LazyMapSequence<Stack<BasicBlock>,
109+
LazyMapSequence<LazyFilterSequence<Stack<BasicBlock>>,
103110
LazyFilterSequence<SuccessorArray>>>>,
104111
Instruction> {
105112
blockRange.exits.lazy.map { $0.instructions.first! }
@@ -116,21 +123,20 @@ struct InstructionRange : CustomStringConvertible, CustomReflectable {
116123
let isInterior = include
117124
include = true
118125
return isInterior
119-
120126
}
121127
return false
122128
}
123129
}
124130
}
125131

126132
var description: String {
127-
"""
128-
begin: \(begin)
129-
range: \(blockRange.range)
130-
ends: \(ends.map { $0.description }.joined(separator: "\n "))
131-
exits: \(exits.map { $0.description }.joined(separator: "\n "))
132-
interiors:\(interiors.map { $0.description }.joined(separator: "\n "))
133-
"""
133+
return (isValid ? "" : "<invalid>\n") +
134+
"""
135+
begin: \(begin)
136+
ends: \(ends.map { $0.description }.joined(separator: "\n "))
137+
exits: \(exits.map { $0.description }.joined(separator: "\n "))
138+
interiors:\(interiors.map { $0.description }.joined(separator: "\n "))
139+
"""
134140
}
135141

136142
var customMirror: Mirror { Mirror(self, children: []) }

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ swift_compiler_sources(Optimizer
1010
AssumeSingleThreaded.swift
1111
SILPrinter.swift
1212
MergeCondFails.swift
13+
RangeDumper.swift
1314
ReleaseDevirtualizer.swift
1415
RunUnitTests.swift
1516
)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//===--- RangeDumper.swift - Dumps escape information ----------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 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 SIL
14+
15+
let rangeDumper = FunctionPass(name: "dump-ranges", {
16+
(function: Function, context: PassContext) in
17+
18+
var begin: Instruction?
19+
var ends = Stack<Instruction>(context)
20+
defer { ends.deinitialize() }
21+
var interiors = Stack<Instruction>(context)
22+
defer { interiors.deinitialize() }
23+
var ins = Stack<Instruction>(context)
24+
defer { ins.deinitialize() }
25+
var outs = Stack<Instruction>(context)
26+
defer { outs.deinitialize() }
27+
28+
for block in function.blocks {
29+
for inst in block.instructions {
30+
if let sli = inst as? StringLiteralInst {
31+
switch sli.string {
32+
case "begin":
33+
precondition(begin == nil, "more than one begin instruction")
34+
begin = sli
35+
case "end":
36+
ends.append(sli)
37+
case "interior":
38+
interiors.append(sli)
39+
case "inside":
40+
ins.append(sli)
41+
case "outside":
42+
outs.append(sli)
43+
default:
44+
break
45+
}
46+
}
47+
}
48+
}
49+
50+
guard let begin = begin else { return }
51+
52+
var instRange = InstructionRange(begin: begin, context)
53+
defer { instRange.deinitialize() }
54+
55+
instRange.insert(contentsOf: ends)
56+
instRange.insert(contentsOf: interiors)
57+
58+
print("Instruction range in \(function.name):")
59+
print(instRange)
60+
print("Block range in \(function.name):")
61+
print(instRange.blockRange)
62+
print("End function \(function.name)\n")
63+
64+
verify(instRange.blockRange, context)
65+
66+
for i in ins {
67+
precondition(instRange.contains(i))
68+
precondition(instRange.inclusiveRangeContains(i))
69+
}
70+
for e in ends {
71+
precondition(!instRange.contains(e))
72+
precondition(instRange.inclusiveRangeContains(e))
73+
}
74+
for o in outs {
75+
precondition(!instRange.contains(o))
76+
precondition(!instRange.inclusiveRangeContains(o))
77+
}
78+
})
79+
80+
private func verify(_ blockRange: BasicBlockRange, _ context: PassContext) {
81+
var inRange = BasicBlockSet(context)
82+
defer { inRange.deinitialize() }
83+
for b in blockRange.range {
84+
inRange.insert(b)
85+
}
86+
87+
var inInclusiveRange = BasicBlockSet(context)
88+
defer { inInclusiveRange.deinitialize() }
89+
for b in blockRange.inclusiveRange {
90+
inInclusiveRange.insert(b)
91+
}
92+
93+
for b in blockRange.begin.function.blocks {
94+
precondition(blockRange.contains(b) == inRange.contains(b))
95+
precondition(blockRange.inclusiveRangeContains(b) == inInclusiveRange.contains(b))
96+
}
97+
}
98+

0 commit comments

Comments
 (0)