Skip to content

Commit e513a7a

Browse files
authored
Merge branch 'apple:main' into my-branch
2 parents 00b0491 + 20021cf commit e513a7a

File tree

697 files changed

+17521
-6091
lines changed

Some content is hidden

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

697 files changed

+17521
-6091
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
> **Note**\
44
> This is in reverse chronological order, so newer entries are added to the top.
55
6-
## Swift 5.11
6+
## Swift 6.0
77
* [SE-0422][]:
88
Non-built-in expression macros can now be used as default arguments that
99
expand at each call site. For example, a custom `#CurrentFile` macro used as

CMakeLists.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ option(SWIFT_STDLIB_ENABLE_UNICODE_DATA
238238
NOTE: Disabling this will cause many String methods to crash."
239239
TRUE)
240240

241+
option(SWIFT_BUILD_CLANG_OVERLAYS
242+
"Build Swift overlays for the clang builtin modules"
243+
TRUE)
244+
241245
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
242246
"Build dynamic variants of the Swift SDK overlay"
243247
TRUE)
@@ -1381,14 +1385,6 @@ endif()
13811385
add_subdirectory(include)
13821386

13831387
if(SWIFT_INCLUDE_TOOLS)
1384-
# TODO Remove this once release/5.9 is done and we can finish migrating Swift
1385-
# off of `llvm::None`/`llvm::Optional`, and `llvm::makeArrayRef`.
1386-
# This is to silence the avalanche of deprecation warnings from LLVM headers
1387-
# until we can actually do something about them. This is nasty, but it's
1388-
# better than losing context due to the sheer number in-actionable deprecation
1389-
# warnings or the massive number of merge-conflicts we would get otherwise.
1390-
add_definitions(-DSWIFT_TARGET)
1391-
13921388
add_subdirectory(lib)
13931389

13941390
add_subdirectory(SwiftCompilerSources)

SwiftCompilerSources/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ For example, to add a new instruction class:
129129
* if needed, add bridging functions to access the instruction's data fields.
130130

131131

132-
No yet implemented instruction classes are mapped to a "placeholder" instruction, e.g `UnimplementedInstruction`. This ensures that optimizations can process any kind of SIL, even if some instructions don't have a representation in Swift yet.
133-
134132
## The Optimizer
135133

136134
Similar to SIL, the optimizer also uses a small bridging layer (`OptimizerBridging.h`).

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LetPropertyLowering.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,17 @@ private func constructLetInitRegion(
156156
initRegion.insert(inst)
157157

158158
case let beginAccess as BeginAccessInst
159-
where beginAccess.accessKind == .Deinit &&
159+
where beginAccess.accessKind == .deinit &&
160160
beginAccess.address.isLetFieldAddress(of: markUninitialized):
161161
// Include let-field partial de-initializations in the region.
162162
initRegion.insert(inst)
163163

164164
case let beginBorrow as BeginBorrowInst
165-
where beginBorrow.borrowedValue.referenceRoot == markUninitialized:
165+
where beginBorrow.borrowedValue.isReferenceDerived(from: markUninitialized):
166166
borrows.append(beginBorrow)
167167

168168
case let storeBorrow as StoreBorrowInst
169-
where storeBorrow.source.referenceRoot == markUninitialized:
169+
where storeBorrow.source.isReferenceDerived(from: markUninitialized):
170170
borrows.append(storeBorrow)
171171

172172
default:
@@ -202,10 +202,28 @@ private extension RefElementAddrInst {
202202
}
203203

204204
private extension Value {
205+
func isReferenceDerived(from root: Value) -> Bool {
206+
var parent: Value = self
207+
while true {
208+
if parent == root {
209+
return true
210+
}
211+
if let operand = parent.forwardingInstruction?.singleForwardedOperand {
212+
parent = operand.value
213+
continue
214+
}
215+
if let transition = parent.definingInstruction as? OwnershipTransitionInstruction {
216+
parent = transition.operand.value
217+
continue
218+
}
219+
return false
220+
}
221+
}
222+
205223
func isLetFieldAddress(of markUninitialized: MarkUninitializedInst) -> Bool {
206224
if case .class(let rea) = self.accessBase,
207225
rea.fieldIsLet,
208-
rea.instance.referenceRoot == markUninitialized
226+
rea.instance.isReferenceDerived(from: markUninitialized)
209227
{
210228
return true
211229
}

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyDestructure.swift

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

1313
import SIL
1414

15-
extension DestructureTupleInst : OnoneSimplifyable {
15+
extension DestructureTupleInst : OnoneSimplifyable, SILCombineSimplifyable {
1616
func simplify(_ context: SimplifyContext) {
1717

1818
// Eliminate the redundant instruction pair
@@ -28,7 +28,7 @@ extension DestructureTupleInst : OnoneSimplifyable {
2828
}
2929
}
3030

31-
extension DestructureStructInst : OnoneSimplifyable {
31+
extension DestructureStructInst : OnoneSimplifyable, SILCombineSimplifyable {
3232
func simplify(_ context: SimplifyContext) {
3333

3434
switch self.struct {

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ private struct StackProtectionOptimization {
355355
/// Moves the value of a `beginAccess` to a temporary stack location, if possible.
356356
private func moveToTemporary(scope beginAccess: BeginAccessInst, mustFixStackNesting: inout Bool,
357357
_ context: FunctionPassContext) {
358-
if beginAccess.accessKind != .Modify {
358+
if beginAccess.accessKind != .modify {
359359
// We can only move from a `modify` access.
360360
// Also, read-only accesses shouldn't be subject to buffer overflows (because
361361
// no one should ever write to such a storage).

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import OptimizerBridging
1717
public func initializeSwiftModules() {
1818
registerSILClasses()
1919
registerSwiftAnalyses()
20+
registerUtilities()
2021
registerSwiftPasses()
2122
registerOptimizerTests()
2223
}
@@ -102,6 +103,8 @@ private func registerSwiftPasses() {
102103
registerForSILCombine(LoadInst.self, { run(LoadInst.self, $0) })
103104
registerForSILCombine(CopyValueInst.self, { run(CopyValueInst.self, $0) })
104105
registerForSILCombine(DestroyValueInst.self, { run(DestroyValueInst.self, $0) })
106+
registerForSILCombine(DestructureStructInst.self, { run(DestructureStructInst.self, $0) })
107+
registerForSILCombine(DestructureTupleInst.self, { run(DestructureTupleInst.self, $0) })
105108

106109
// Test passes
107110
registerPass(functionUsesDumper, { functionUsesDumper.run($0) })
@@ -120,3 +123,7 @@ private func registerSwiftAnalyses() {
120123
AliasAnalysis.register()
121124
CalleeAnalysis.register()
122125
}
126+
127+
private func registerUtilities() {
128+
registerVerifier()
129+
}

SwiftCompilerSources/Sources/Optimizer/Utilities/AddressUtils.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ extension AccessBase {
192192
/// with the initialized address. This does not guarantee that all
193193
/// uses of that address are dominated by the store or even that the
194194
/// store is a direct use of `address`.
195-
func findSingleInitializer(_ context: some Context)
196-
-> (initialAddress: Value, initializingStore: Instruction)? {
195+
func findSingleInitializer(_ context: some Context) -> (initialAddress: Value, initializingStore: Instruction)? {
197196
let baseAddr: Value
198197
switch self {
199198
case let .stack(allocStack):
@@ -206,15 +205,7 @@ extension AccessBase {
206205
default:
207206
return nil
208207
}
209-
var walker = AddressInitializationWalker(context: context)
210-
if walker.walkDownUses(ofAddress: baseAddr, path: SmallProjectionPath())
211-
== .abortWalk {
212-
return nil
213-
}
214-
guard let initializingStore = walker.initializingStore else {
215-
return nil
216-
}
217-
return (initialAddress: baseAddr, initializingStore: initializingStore)
208+
return AddressInitializationWalker.findSingleInitializer(ofAddress: baseAddr, context: context)
218209
}
219210
}
220211

@@ -223,6 +214,9 @@ extension AccessBase {
223214
// Implements AddressUseVisitor to guarantee that we can't miss any
224215
// stores. This separates escapingAddressUse from leafAddressUse.
225216
//
217+
// Main entry point:
218+
// static func findSingleInitializer(ofAddress: Value, context: some Context)
219+
//
226220
// TODO: Make AddressDefUseWalker always conform to AddressUseVisitor once we're
227221
// ready to debug changes to escape analysis etc...
228222
//
@@ -249,6 +243,19 @@ struct AddressInitializationWalker: AddressDefUseWalker, AddressUseVisitor {
249243
var isProjected = false
250244
var initializingStore: Instruction?
251245

246+
static func findSingleInitializer(ofAddress baseAddr: Value, context: some Context)
247+
-> (initialAddress: Value, initializingStore: Instruction)? {
248+
249+
var walker = AddressInitializationWalker(context: context)
250+
if walker.walkDownUses(ofAddress: baseAddr, path: SmallProjectionPath()) == .abortWalk {
251+
return nil
252+
}
253+
guard let initializingStore = walker.initializingStore else {
254+
return nil
255+
}
256+
return (initialAddress: baseAddr, initializingStore: initializingStore)
257+
}
258+
252259
private mutating func setInitializer(instruction: Instruction) -> WalkResult {
253260
// An initializer must be unique and store the full value.
254261
if initializingStore != nil || isProjected {

SwiftCompilerSources/Sources/Optimizer/Utilities/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ swift_compiler_sources(Optimizer
2020
SSAUpdater.swift
2121
StaticInitCloner.swift
2222
Test.swift
23+
Verifier.swift
2324
)

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,8 @@ extension LifetimeDependenceUseDefWalker {
706706
mutating func walkUpDefault(dependent value: Value, owner: Value?)
707707
-> WalkResult {
708708
switch value.definingInstruction {
709-
case let copyInst as CopyValueInst:
710-
return walkUp(newLifetime: copyInst.fromValue)
711-
case let moveInst as MoveValueInst:
712-
return walkUp(value: moveInst.fromValue, owner)
713-
case let borrow as BeginBorrowInst:
714-
return walkUp(newLifetime: borrow.borrowedValue)
709+
case let transition as OwnershipTransitionInstruction:
710+
return walkUp(newLifetime: transition.operand.value)
715711
case let load as LoadInstruction:
716712
return walkUp(address: load.address)
717713
case let markDep as MarkDependenceInst:
@@ -862,11 +858,8 @@ extension LifetimeDependenceDefUseWalker {
862858
return leafUse(of: operand)
863859
}
864860
switch operand.instruction {
865-
case let copy as CopyingInstruction:
866-
return walkDownUses(of: copy, using: operand)
867-
868-
case let move as MoveValueInst:
869-
return walkDownUses(of: move, using: operand)
861+
case let transition as OwnershipTransitionInstruction:
862+
return walkDownUses(of: transition.ownershipResult, using: operand)
870863

871864
case let mdi as MarkDependenceInst where mdi.isUnresolved:
872865
// Override mark_dependence [unresolved] to handle them just

0 commit comments

Comments
 (0)