Skip to content

Commit 866f1c1

Browse files
authored
Merge branch 'main' into swift-lexical-lookup-validation
2 parents 0371783 + 6221b29 commit 866f1c1

File tree

1,388 files changed

+17220
-15141
lines changed

Some content is hidden

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

1,388 files changed

+17220
-15141
lines changed

Runtimes/Core/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ target_compile_options(swiftCore PRIVATE
273273
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>"
274274
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>"
275275
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature AllowUnsafeAttribute>"
276-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>"
277276
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature MemberImportVisibility>"
278277
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature TypedThrows>"
279278
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Macros>"

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/LifetimeDependenceDiagnostics.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
4545
// Indirect results are not checked here. Type checking ensures
4646
// that they have a lifetime dependence.
4747
if let lifetimeDep = LifetimeDependence(argument, context) {
48-
analyze(dependence: lifetimeDep, context)
48+
_ = analyze(dependence: lifetimeDep, context)
4949
}
5050
}
5151
for instruction in function.instructions {
5252
if let markDep = instruction as? MarkDependenceInst, markDep.isUnresolved {
5353
if let lifetimeDep = LifetimeDependence(markDep, context) {
54-
analyze(dependence: lifetimeDep, context)
54+
if analyze(dependence: lifetimeDep, context) {
55+
// Note: This promotes the mark_dependence flag but does not invalidate SIL; preserving analyses is good,
56+
// but the change won't appear in -sil-print-function. Ideally, we could notify context of a flag change
57+
// without invalidating analyses.
58+
lifetimeDep.resolve(context)
59+
}
60+
} else {
61+
// For now, if the mark_dependence wasn't recognized as a lifetime dependence, conservatively settle it as
62+
// escaping. In the future, we should not need this because, for escapable types, mark_dependence [unresolved]
63+
// will all be settled during an early LifetimeNormalization pass.
64+
markDep.settleToEscaping()
5565
}
5666
continue
5767
}
@@ -61,7 +71,7 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
6171
apply.resultOrYields.forEach {
6272
if let lifetimeDep = LifetimeDependence(unsafeApplyResult: $0,
6373
context) {
64-
analyze(dependence: lifetimeDep, context)
74+
_ = analyze(dependence: lifetimeDep, context)
6575
}
6676
}
6777
continue
@@ -74,8 +84,9 @@ let lifetimeDependenceDiagnosticsPass = FunctionPass(
7484
/// 1. Compute the LifetimeDependence scope.
7585
///
7686
/// 2. Walk down all dependent values checking that they are within range.
77-
private func analyze(dependence: LifetimeDependence,
78-
_ context: FunctionPassContext) {
87+
///
88+
/// Return true on success.
89+
private func analyze(dependence: LifetimeDependence, _ context: FunctionPassContext) -> Bool {
7990
log("Dependence scope:\n\(dependence)")
8091

8192
// Compute this dependence scope.
@@ -91,10 +102,7 @@ private func analyze(dependence: LifetimeDependence,
91102
var walker = DiagnoseDependenceWalker(diagnostics, context)
92103
defer { walker.deinitialize() }
93104
_ = walker.walkDown(root: dependence.dependentValue)
94-
95-
if !error {
96-
dependence.resolve(context)
97-
}
105+
return !error
98106
}
99107

100108
/// Analyze and diagnose a single LifetimeDependence.

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public struct Builder {
2929
private let notificationHandler: BridgedChangeNotificationHandler
3030
private let notifyNewInstruction: (Instruction) -> ()
3131

32+
/// Return 'nil' when inserting at the start of a function or in a global initializer.
33+
public var insertionBlock: BasicBlock? {
34+
switch insertAt {
35+
case let .before(inst):
36+
return inst.parentBlock
37+
case let .atEndOf(block):
38+
return block
39+
case .atStartOf, .staticInitializer:
40+
return nil
41+
}
42+
}
43+
3244
public var bridged: BridgedBuilder {
3345
switch insertAt {
3446
case .before(let inst):
@@ -482,6 +494,18 @@ public struct Builder {
482494
return notifyNew(endAccess.getAs(EndAccessInst.self))
483495
}
484496

497+
@discardableResult
498+
public func createEndApply(beginApply: BeginApplyInst) -> EndApplyInst {
499+
let endApply = bridged.createEndApply(beginApply.token.bridged)
500+
return notifyNew(endApply.getAs(EndApplyInst.self))
501+
}
502+
503+
@discardableResult
504+
public func createAbortApply(beginApply: BeginApplyInst) -> AbortApplyInst {
505+
let endApply = bridged.createAbortApply(beginApply.token.bridged)
506+
return notifyNew(endApply.getAs(AbortApplyInst.self))
507+
}
508+
485509
public func createConvertFunction(originalFunction: Value, resultType: Type, withoutActuallyEscaping: Bool) -> ConvertFunctionInst {
486510
let convertFunction = bridged.createConvertFunction(originalFunction.bridged, resultType.bridged, withoutActuallyEscaping)
487511
return notifyNew(convertFunction.getAs(ConvertFunctionInst.self))

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,10 @@ class MarkDependenceInst : SingleValueInstruction {
976976
public func resolveToNonEscaping() {
977977
bridged.MarkDependenceInst_resolveToNonEscaping()
978978
}
979+
980+
public func settleToEscaping() {
981+
bridged.MarkDependenceInst_settleToEscaping()
982+
}
979983
}
980984

981985
final public class RefToBridgeObjectInst : SingleValueInstruction {
@@ -1219,6 +1223,8 @@ final public class AllocExistentialBoxInst : SingleValueInstruction, Allocation
12191223
/// `end_borrow`).
12201224
public protocol ScopedInstruction {
12211225
var endOperands: LazyFilterSequence<UseList> { get }
1226+
1227+
var endInstructions: EndInstructions { get }
12221228
}
12231229

12241230
extension Instruction {
@@ -1330,7 +1336,7 @@ final public class BeginApplyInst : MultipleValueInstruction, FullApplySite {
13301336
}
13311337
}
13321338

1333-
final public class EndApplyInst : Instruction, UnaryInstruction {
1339+
final public class EndApplyInst : SingleValueInstruction, UnaryInstruction {
13341340
public var token: MultipleValueInstructionResult { operand.value as! MultipleValueInstructionResult }
13351341
public var beginApply: BeginApplyInst { token.parentInstruction as! BeginApplyInst }
13361342
}
@@ -1342,7 +1348,7 @@ final public class AbortApplyInst : Instruction, UnaryInstruction {
13421348

13431349
extension BeginApplyInst : ScopedInstruction {
13441350
public var endOperands: LazyFilterSequence<UseList> {
1345-
return token.uses.lazy.filter { _ in true }
1351+
return token.uses.lazy.filter { $0.isScopeEndingUse }
13461352
}
13471353
}
13481354

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,19 @@ extension Operand {
192192
}
193193
}
194194

195+
extension Operand {
196+
/// A scope ending use is a consuming use for normal borrow scopes, but it also applies to intructions that end the
197+
/// scope of an address (end_access) or a token (end_apply, abort_apply),
198+
public var isScopeEndingUse: Bool {
199+
switch instruction {
200+
case is EndBorrowInst, is EndAccessInst, is EndApplyInst, is AbortApplyInst:
201+
return true
202+
default:
203+
return false
204+
}
205+
}
206+
}
207+
195208
extension OptionalBridgedOperand {
196209
init(bridged: BridgedOperand?) {
197210
self = OptionalBridgedOperand(op: bridged?.op)

SwiftCompilerSources/Sources/SIL/Utilities/AccessUtils.swift

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,33 @@ public enum AccessBase : CustomStringConvertible, Hashable {
103103
}
104104
case let sb as StoreBorrowInst:
105105
self = .storeBorrow(sb)
106+
case let p2a as PointerToAddressInst:
107+
if let global = p2a.resultOfGlobalAddressorCall {
108+
self = .global(global)
109+
} else {
110+
self = .pointer(p2a)
111+
}
106112
default:
107113
self = .unidentified
108114
}
109115
}
110116

117+
/// Return 'nil' for global varabiables and unidentified addresses.
118+
public var address: Value? {
119+
switch self {
120+
case .global, .unidentified: return nil
121+
case .box(let pbi): return pbi
122+
case .stack(let asi): return asi
123+
case .class(let rea): return rea
124+
case .tail(let rta): return rta
125+
case .argument(let arg): return arg
126+
case .yield(let result): return result
127+
case .storeBorrow(let sb): return sb
128+
case .pointer(let p): return p
129+
case .index(let ia): return ia
130+
}
131+
}
132+
111133
public var description: String {
112134
switch self {
113135
case .unidentified: return "?"
@@ -480,9 +502,40 @@ public enum EnclosingScope {
480502
case base(AccessBase)
481503
}
482504

505+
private struct EnclosingAccessWalker : AddressUseDefWalker {
506+
var enclosingScope: EnclosingScope?
507+
508+
mutating func walk(startAt address: Value, initialPath: UnusedWalkingPath = UnusedWalkingPath()) {
509+
if walkUp(address: address, path: UnusedWalkingPath()) == .abortWalk {
510+
assert(enclosingScope == nil, "shouldn't have set an enclosing scope in an aborted walk")
511+
}
512+
}
513+
514+
mutating func rootDef(address: Value, path: UnusedWalkingPath) -> WalkResult {
515+
assert(enclosingScope == nil, "rootDef should only called once")
516+
// Try identifying the address a pointer originates from
517+
if let p2ai = address as? PointerToAddressInst, let originatingAddr = p2ai.originatingAddress {
518+
return walkUp(address: originatingAddr, path: path)
519+
}
520+
enclosingScope = .base(AccessBase(baseAddress: address))
521+
return .continueWalk
522+
}
523+
524+
mutating func walkUp(address: Value, path: UnusedWalkingPath) -> WalkResult {
525+
if let ba = address as? BeginAccessInst {
526+
enclosingScope = .scope(ba)
527+
return .continueWalk
528+
}
529+
return walkUpDefault(address: address, path: path)
530+
}
531+
}
532+
483533
private struct AccessPathWalker : AddressUseDefWalker {
484534
var result = AccessPath.unidentified()
485-
var foundBeginAccess: BeginAccessInst?
535+
536+
// List of nested BeginAccessInst: inside-out order.
537+
var foundBeginAccesses = SingleInlineArray<BeginAccessInst>()
538+
486539
let enforceConstantProjectionPath: Bool
487540

488541
init(enforceConstantProjectionPath: Bool = false) {
@@ -528,18 +581,9 @@ private struct AccessPathWalker : AddressUseDefWalker {
528581
mutating func rootDef(address: Value, path: Path) -> WalkResult {
529582
assert(result.base == .unidentified, "rootDef should only called once")
530583
// Try identifying the address a pointer originates from
531-
if let p2ai = address as? PointerToAddressInst {
532-
if let originatingAddr = p2ai.originatingAddress {
533-
return walkUp(address: originatingAddr, path: path)
534-
} else if let global = p2ai.resultOfGlobalAddressorCall {
535-
self.result = AccessPath(base: .global(global), projectionPath: path.projectionPath)
536-
return .continueWalk
537-
} else {
538-
self.result = AccessPath(base: .pointer(p2ai), projectionPath: path.projectionPath)
539-
return .continueWalk
540-
}
584+
if let p2ai = address as? PointerToAddressInst, let originatingAddr = p2ai.originatingAddress {
585+
return walkUp(address: originatingAddr, path: path)
541586
}
542-
543587
let base = AccessBase(baseAddress: address)
544588
self.result = AccessPath(base: base, projectionPath: path.projectionPath)
545589
return .continueWalk
@@ -557,8 +601,8 @@ private struct AccessPathWalker : AddressUseDefWalker {
557601
// An `index_addr` instruction cannot be derived from an address
558602
// projection. Bail out
559603
return .abortWalk
560-
} else if let ba = address as? BeginAccessInst, foundBeginAccess == nil {
561-
foundBeginAccess = ba
604+
} else if let ba = address as? BeginAccessInst {
605+
foundBeginAccesses.push(ba)
562606
}
563607
return walkUpDefault(address: address, path: path.with(indexAddr: false))
564608
}
@@ -611,17 +655,20 @@ extension Value {
611655
public var accessPathWithScope: (AccessPath, scope: BeginAccessInst?) {
612656
var walker = AccessPathWalker()
613657
walker.walk(startAt: self)
614-
return (walker.result, walker.foundBeginAccess)
658+
return (walker.result, walker.foundBeginAccesses.first)
615659
}
616660

617661
/// Computes the enclosing access scope of this address value.
618662
public var enclosingAccessScope: EnclosingScope {
663+
var walker = EnclosingAccessWalker()
664+
walker.walk(startAt: self)
665+
return walker.enclosingScope ?? .base(.unidentified)
666+
}
667+
668+
public var accessBaseWithScopes: (AccessBase, SingleInlineArray<BeginAccessInst>) {
619669
var walker = AccessPathWalker()
620670
walker.walk(startAt: self)
621-
if let ba = walker.foundBeginAccess {
622-
return .scope(ba)
623-
}
624-
return .base(walker.result.base)
671+
return (walker.result.base, walker.foundBeginAccesses)
625672
}
626673

627674
/// The root definition of a reference, obtained by skipping ownership forwarding and ownership transition.

cmake/modules/DarwinSDKs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(SUPPORTED_IOS_SIMULATOR_ARCHS "x86_64;arm64")
33
set(SUPPORTED_TVOS_ARCHS "arm64")
44
set(SUPPORTED_TVOS_SIMULATOR_ARCHS "x86_64;arm64")
55
set(SUPPORTED_WATCHOS_ARCHS "armv7k;arm64_32")
6-
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "i386;x86_64;arm64")
6+
set(SUPPORTED_WATCHOS_SIMULATOR_ARCHS "x86_64;arm64")
77
set(SUPPORTED_OSX_ARCHS "x86_64;arm64")
88
set(SUPPORTED_XROS_ARCHS "arm64;arm64e")
99
set(SUPPORTED_XROS_SIMULATOR_ARCHS "arm64")

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ function(remove_sdk_unsupported_archs name os sdk_path deployment_version archit
9191
# 32-bit watchOS is not listed explicitly in SDK settings.
9292
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
9393
list(APPEND architectures ${arch})
94-
elseif(arch STREQUAL "i386" AND os STREQUAL "watchsimulator")
95-
# 32-bit watchOS simulator is not listed explicitly in SDK settings.
96-
message(STATUS "Assuming ${name} SDK at ${sdk_path} supports architecture ${arch}")
97-
list(APPEND architectures ${arch})
9894
else()
9995
message(STATUS "${name} SDK at ${sdk_path} does not support architecture ${arch}")
10096
endif()

docs/Generics/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,14 @@ The following chapters need some editing:
6363

6464
- Part II:
6565
- Substitution Maps
66-
- Part III:
67-
- Conformance Paths
68-
- Part V:
66+
- Part IV:
6967
- Completion
7068

7169
The following chapters are not yet written:
7270

73-
- Part IV:
71+
- Part III:
7472
- Opaque Return Types
7573
- Existential Types
76-
- Part V:
74+
- Part IV:
7775
- The Property Map
7876
- Rule Minimization

0 commit comments

Comments
 (0)