Skip to content

Commit 91a85cd

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # lib/Driver/WebAssemblyToolChains.cpp
2 parents 6e010c6 + 2696df4 commit 91a85cd

File tree

191 files changed

+5154
-1502
lines changed

Some content is hidden

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

191 files changed

+5154
-1502
lines changed

CHANGELOG.md

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,129 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
1919
Swift 5.6
2020
---------
2121

22+
* Actor isolation checking now understands that `defer` bodies share the isolation of their enclosing function.
23+
24+
```swift
25+
// Works on global actors
26+
@MainActor
27+
func runAnimation(controller: MyViewController) async {
28+
controller.hasActiveAnimation = true
29+
defer { controller.hasActiveAnimation = false }
30+
31+
// do the animation here...
32+
}
33+
34+
// Works on actor instances
35+
actor OperationCounter {
36+
var activeOperationCount = 0
37+
38+
func operate() async {
39+
activeOperationCount += 1
40+
defer { activeOperationCount -= 1 }
41+
42+
// do work here...
43+
}
44+
}
45+
```
46+
47+
* [SE-0335][]:
48+
49+
Swift now allows existential types to be explicitly written with the `any`
50+
keyword, creating a syntactic distinction between existential types and
51+
protocol conformance constraints. For example:
52+
53+
```swift
54+
protocol P {}
55+
56+
func generic<T>(value: T) where T: P {
57+
...
58+
}
59+
60+
func existential(value: any P) {
61+
...
62+
}
63+
```
64+
65+
* [SE-0337][]:
66+
67+
Swift now provides an incremental migration path to data race safety, allowing
68+
APIs to adopt concurrency without breaking their clients that themselves have
69+
not adopted concurrency. An existing declaration can introduce
70+
concurrency-related annotations (such as making its closure parameters
71+
`@Sendable`) and use the `@preconcurrency` attribute to maintain its behavior
72+
for clients who have not themselves adopted concurrency:
73+
74+
```swift
75+
// module A
76+
@preconcurrency func runOnSeparateTask(_ workItem: @Sendable () -> Void)
77+
78+
// module B
79+
import A
80+
81+
class MyCounter {
82+
var value = 0
83+
}
84+
85+
func doesNotUseConcurrency(counter: MyCounter) {
86+
runOnSeparateTask {
87+
counter.value += 1 // no warning, because this code hasn't adopted concurrency
88+
}
89+
}
90+
91+
func usesConcurrency(counter: MyCounter) async {
92+
runOnSeparateTask {
93+
counter.value += 1 // warning: capture of non-Sendable type 'MyCounter'
94+
}
95+
}
96+
```
97+
98+
One can enable warnings about data race safety within a module with the
99+
`-warn-concurrency` compiler option. When using a module that does not yet
100+
provide `Sendable` annotations, one can suppress warnings for types from that
101+
module by marking the import with `@preconcurrency`:
102+
103+
```swift
104+
/// module C
105+
public struct Point {
106+
public var x, y: Double
107+
}
108+
109+
// module D
110+
@preconcurrency import C
111+
112+
func centerView(at location: Point) {
113+
Task {
114+
await mainView.center(at: location) // no warning about non-Sendable 'Point' because the @preconcurrency import suppresses it
115+
}
116+
}
117+
```
118+
119+
* [SE-0302][]:
120+
121+
Swift will now produce warnings to indicate potential data races when
122+
non-`Sendable` types are passed across actor or task boundaries. For
123+
example:
124+
125+
```swift
126+
class MyCounter {
127+
var value = 0
128+
}
129+
130+
func f() -> MyCounter {
131+
let counter = MyCounter()
132+
Task {
133+
counter.value += 1 // warning: capture of non-Sendable type 'MyCounter'
134+
}
135+
return counter
136+
}
137+
```
138+
139+
* [SE-0331][]:
140+
141+
The conformance of the unsafe pointer types (e.g., `UnsafePointer`,
142+
`UnsafeMutableBufferPointer`) to the `Sendable` protocols has been removed,
143+
because pointers cannot safely be transferred across task or actor boundaries.
144+
22145
* References to `Self` or so-called "`Self` requirements" in the type signatures
23146
of protocol members are now correctly detected in the parent of a nested type.
24147
As a result, protocol members that fall under this overlooked case are no longer
@@ -39,7 +162,7 @@ Swift 5.6
39162
// protocol type (use a generic constraint instead).
40163
_ = p.method
41164
}
42-
```
165+
```
43166

44167
* [SE-0324][]:
45168

@@ -66,6 +189,19 @@ Swift 5.6
66189
}
67190
```
68191

192+
* [SE-0322][]:
193+
194+
The standard library now provides a new operation
195+
`withUnsafeTemporaryAllocation` which provides an efficient temporarily
196+
allocation within a limited scope, which will be optimized to use stack
197+
allocation when possible.
198+
199+
* [SE-0320][]:
200+
201+
Dictionaries with keys of any type conforming to the new protocol
202+
`CodingKeyRepresentable` can now be encoded and decoded. Formerly, encoding
203+
and decoding was limited to keys of type `String` or `Int`.
204+
69205
* [SE-0315][]:
70206

71207
Type expressions and annotations can now include "type placeholders" which
@@ -8766,15 +8902,21 @@ Swift 1.0
87668902
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
87678903
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
87688904
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
8905+
[SE-0302]: <https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md>
87698906
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
87708907
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
87718908
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
87728909
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
87738910
[SE-0315]: <https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md>
87748911
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
8912+
[SE-0320]: <https://github.com/apple/swift-evolution/blob/main/proposals/0320-codingkeyrepresentable.md>
8913+
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
87758914
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
87768915
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
87778916
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
8917+
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
8918+
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
8919+
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
87788920

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

SwiftCompilerSources/Sources/Optimizer/InstructionPasses/SimplifyStrongRetainRelease.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ private func isNotReferenceCounted(value: Value, context: PassContext) -> Bool {
7676
return isNotReferenceCounted(value: uci.operand, context: context)
7777
case let urc as UncheckedRefCastInst:
7878
return isNotReferenceCounted(value: urc.operand, context: context)
79-
case is GlobalValueInst:
79+
case let gvi as GlobalValueInst:
8080
// Since Swift 5.1, statically allocated objects have "immortal" reference
8181
// counts. Therefore we can safely eliminate unbalaced retains and
8282
// releases, because they are no-ops on immortal objects.
8383
// Note that the `simplifyGlobalValuePass` pass is deleting balanced
8484
// retains/releases, which doesn't require a Swift 5.1 minimum deployment
8585
// targert.
86-
return context.isSwift51RuntimeAvailable
86+
return gvi.function.isSwift51RuntimeAvailable
8787
case let rptr as RawPointerToRefInst:
8888
// Like `global_value` but for the empty collection singletons from the
8989
// stdlib, e.g. the empty Array singleton.
90-
if context.isSwift51RuntimeAvailable {
90+
if rptr.function.isSwift51RuntimeAvailable {
9191
// The pattern generated for empty collection singletons is:
9292
// %0 = global_addr @_swiftEmptyArrayStorage
9393
// %1 = address_to_pointer %0

SwiftCompilerSources/Sources/Optimizer/PassManager/PassUtils.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ struct PassContext {
2222

2323
let _bridged: BridgedPassContext
2424

25-
var isSwift51RuntimeAvailable: Bool {
26-
PassContext_isSwift51RuntimeAvailable(_bridged) != 0
27-
}
28-
2925
var aliasAnalysis: AliasAnalysis {
3026
let bridgedAA = PassContext_getAliasAnalysis(_bridged)
3127
return AliasAnalysis(bridged: bridgedAA)

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ final public class Function : CustomStringConvertible, HasName {
5252
public var argumentTypes: ArgumentTypeArray { ArgumentTypeArray(function: self) }
5353
public var resultType: Type { SILFunction_getSILResultType(bridged).type }
5454

55+
/// True, if the function runs with a swift 5.1 runtime.
56+
/// Note that this is function specific, because inlinable functions are de-serialized
57+
/// in a client module, which might be compiled with a different deployment target.
58+
public var isSwift51RuntimeAvailable: Bool {
59+
SILFunction_isSwift51RuntimeAvailable(bridged) != 0
60+
}
61+
5562
// Only to be called by PassContext
5663
public func _modifyEffects(_ body: (inout FunctionEffects) -> ()) {
5764
body(&effects)

docs/ExternalResources.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ https://medium.com/kinandcartacreated/contributing-to-swift-part-2-efebcf7b6c93
135135

136136
## Code generation, runtime and ABI
137137

138+
- [Bringing Swift to Windows][] by Saleem Abdulrasool (talk, Nov 2019): This talk
139+
covers the story of bringing Swift to Windows from the ground up through an unusual
140+
route: cross-compilation on Linux. It covers interesting challenges in porting
141+
the Swift compiler, standard library, and core libraries that were overcome in the
142+
process of bringing Swift to a platform that challenges the Unix design assumptions.
138143
- [The Swift Runtime][] by Jordan Rose (blog post series, Aug-Oct 2020):
139144
This blog post series describes the runtime layout for different structures,
140145
runtime handling for metadata, as well as basic runtime functionality such
@@ -187,6 +192,7 @@ https://medium.com/kinandcartacreated/contributing-to-swift-part-2-efebcf7b6c93
187192
value witness tables, type metadata, abstraction patterns, reabstraction,
188193
reabstraction thunks and protocol witness tables.
189194

195+
[Bringing Swift to Windows]: https://www.youtube.com/watch?v=Zjlxa1NIfJc
190196
[Mac OS 9]: https://belkadan.com/blog/2020/04/Swift-on-Mac-OS-9/
191197
[The Swift Runtime]: https://belkadan.com/blog/tags/swift-runtime/
192198
[Part 1: Heap Objects]: https://belkadan.com/blog/2020/08/Swift-Runtime-Heap-Objects/

include/swift/ABI/ObjectFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class SwiftObjectFileFormat {
2828
public:
2929
virtual ~SwiftObjectFileFormat() {}
3030
virtual llvm::StringRef getSectionName(ReflectionSectionKind section) = 0;
31+
virtual llvm::Optional<llvm::StringRef> getSegmentName() {
32+
return {};
33+
}
3134
};
3235

3336
/// Responsible for providing the Mach-O reflection section identifiers.
@@ -50,6 +53,9 @@ class SwiftObjectFileFormatMachO : public SwiftObjectFileFormat {
5053
}
5154
llvm_unreachable("Section type not found.");
5255
}
56+
llvm::Optional<llvm::StringRef> getSegmentName() override {
57+
return {"__TEXT"};
58+
}
5359
};
5460

5561
/// Responsible for providing the ELF reflection section identifiers.

include/swift/AST/ASTContext.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,50 @@ class ASTContext final {
659659
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
660660
FuncDecl *getIsOSVersionAtLeastDecl() const;
661661

662+
/// Retrieve the declaration of DistributedActorSystem.remoteCall(Void)(...).
663+
///
664+
/// \param actorOrSystem distributed actor or actor system to get the
665+
/// remoteCall function for. Since the method we're looking for is an ad-hoc
666+
/// requirement, a specific type MUST be passed here as it is not possible
667+
/// to obtain the decl from just the `DistributedActorSystem` protocol type.
668+
/// \param isVoidReturn true if the call will be returning `Void`.
669+
AbstractFunctionDecl *getRemoteCallOnDistributedActorSystem(
670+
NominalTypeDecl *actorOrSystem,
671+
bool isVoidReturn) const;
672+
673+
/// Retrieve the declaration of DistributedActorSystem.make().
674+
///
675+
/// \param actorOrSystem distributed actor or actor system to get the
676+
/// remoteCall function for. Since the method we're looking for is an ad-hoc
677+
/// requirement, a specific type MUST be passed here as it is not possible
678+
/// to obtain the decl from just the `DistributedActorSystem` protocol type.
679+
FuncDecl *getMakeInvocationEncoderOnDistributedActorSystem(
680+
NominalTypeDecl *actorOrSystem) const;
681+
682+
// Retrieve the declaration of DistributedInvocationEncoder.recordArgument(_:).
683+
//
684+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
685+
// function decl shall be extracted. This is useful to avoid witness calls
686+
// through the protocol which is looked up when nominal is null.
687+
FuncDecl *getRecordArgumentOnDistributedInvocationEncoder(
688+
NominalTypeDecl *nominal) const;
689+
690+
// Retrieve the declaration of DistributedInvocationEncoder.recordErrorType(_:).
691+
FuncDecl *getRecordErrorTypeOnDistributedInvocationEncoder(
692+
NominalTypeDecl *nominal) const;
693+
694+
// Retrieve the declaration of DistributedInvocationEncoder.recordReturnType(_:).
695+
FuncDecl *getRecordReturnTypeOnDistributedInvocationEncoder(
696+
NominalTypeDecl *nominal) const;
697+
698+
// Retrieve the declaration of DistributedInvocationEncoder.doneRecording().
699+
//
700+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
701+
// function decl shall be extracted. This is useful to avoid witness calls
702+
// through the protocol which is looked up when nominal is null.
703+
FuncDecl *getDoneRecordingOnDistributedInvocationEncoder(
704+
NominalTypeDecl *nominal) const;
705+
662706
/// Look for the declaration with the given name within the
663707
/// passed in module.
664708
void lookupInModule(ModuleDecl *M, StringRef name,

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ASTMangler : public Mangler {
7070
/// Whether the mangling predates concurrency, and therefore shouldn't
7171
/// include concurrency features such as global actors or @Sendable
7272
/// function types.
73-
bool PredatesConcurrency = false;
73+
bool Preconcurrency = false;
7474

7575
public:
7676
using SymbolicReferent = llvm::PointerUnion<const NominalTypeDecl *,

include/swift/AST/Attr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,9 @@ SIMPLE_DECL_ATTR(_noAllocation, NoAllocation,
691691
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
692692
124)
693693

694-
SIMPLE_DECL_ATTR(_predatesConcurrency, PredatesConcurrency,
694+
SIMPLE_DECL_ATTR(preconcurrency, Preconcurrency,
695695
OnFunc | OnConstructor | OnProtocol | OnGenericType | OnVar | OnSubscript |
696-
OnEnumElement | OnImport | UserInaccessible |
696+
OnEnumElement | OnImport |
697697
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
698698
125)
699699

0 commit comments

Comments
 (0)