Skip to content

Commit adaa063

Browse files
authored
Merge branch 'release/5.6' into QuietMisdreavus/5.6/display-decl-recur
2 parents 97b46c4 + 189f815 commit adaa063

File tree

101 files changed

+1106
-450
lines changed

Some content is hidden

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

101 files changed

+1106
-450
lines changed

CHANGELOG.md

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,129 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
66
Swift 5.6
77
---------
88

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

31154
* [SE-0324][]:
32155

@@ -53,6 +176,13 @@ Swift 5.6
53176
}
54177
```
55178

179+
* [SE-0322][]:
180+
181+
The standard library now provides a new operation
182+
`withUnsafeTemporaryAllocation` which provides an efficient temporarily
183+
allocation within a limited scope, which will be optimized to use stack
184+
allocation when possible.
185+
56186
* [SE-0315][]:
57187

58188
Type expressions and annotations can now include "type placeholders" which
@@ -8753,14 +8883,19 @@ Swift 1.0
87538883
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
87548884
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
87558885
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
8886+
[SE-0302]: <https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md>
87568887
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
87578888
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
87588889
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
87598890
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
87608891
[SE-0315]: <https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md>
87618892
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
8893+
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
87628894
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
87638895
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
8896+
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
8897+
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
8898+
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
87648899

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

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ Types
619619
type-list ::= empty-list
620620

621621
// FIXME: Consider replacing 'h' with a two-char code
622-
list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'Yi'? 'd'? // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, actor 'isolated', and variadic specifier
622+
list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'Yi'? 'd'? 'Yt'? // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, actor 'isolated', variadic specifier, and compile-time constant
623623

624624
METATYPE-REPR ::= 't' // Thin metatype representation
625625
METATYPE-REPR ::= 'T' // Thick metatype representation

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
@@ -688,9 +688,9 @@ SIMPLE_DECL_ATTR(_noAllocation, NoAllocation,
688688
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
689689
124)
690690

691-
SIMPLE_DECL_ATTR(_predatesConcurrency, PredatesConcurrency,
691+
SIMPLE_DECL_ATTR(preconcurrency, Preconcurrency,
692692
OnFunc | OnConstructor | OnProtocol | OnGenericType | OnVar | OnSubscript |
693-
OnEnumElement | OnImport | UserInaccessible |
693+
OnEnumElement | OnImport |
694694
ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
695695
125)
696696

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
896896
void setHoisted(bool hoisted = true) { Bits.Decl.Hoisted = hoisted; }
897897

898898
/// Whether this declaration predates the introduction of concurrency.
899-
bool predatesConcurrency() const;
899+
bool preconcurrency() const;
900900

901901
public:
902902
bool escapedFromIfConfig() const {

include/swift/AST/DeclContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ namespace swift {
7373
class PrefixOperatorDecl;
7474
class ProtocolConformance;
7575
class ValueDecl;
76+
class VarDecl;
7677
class Initializer;
7778
class ClassDecl;
7879
class SerializedAbstractClosureExpr;
@@ -355,6 +356,11 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
355356
LLVM_READONLY
356357
ProtocolDecl *getExtendedProtocolDecl() const;
357358

359+
/// If this DeclContext is the initializer expression of a global or instance
360+
/// property, return the VarDecl, otherwise return null.
361+
LLVM_READONLY
362+
VarDecl *getNonLocalVarDecl() const;
363+
358364
/// Retrieve the generic parameter 'Self' from a protocol or
359365
/// protocol extension.
360366
///

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ ERROR(sil_inst_autodiff_invalid_witness_generic_signature,PointsToFirstBadToken,
17321732
(StringRef, StringRef))
17331733

17341734
WARNING(warn_attr_unsafe_removed,none,
1735-
"'%0' attribute has been removed in favor of @_predatesConcurrency",
1735+
"'%0' attribute has been removed in favor of @preconcurrency",
17361736
(StringRef))
17371737

17381738
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,11 +1953,11 @@ NOTE(add_nominal_sendable_conformance,none,
19531953
"consider making %0 %1 conform to the 'Sendable' protocol",
19541954
(DescriptiveDeclKind, DeclName))
19551955
REMARK(add_predates_concurrency_import,none,
1956-
"add '@_predatesConcurrency' to %select{suppress|treat}0 "
1956+
"add '@preconcurrency' to %select{suppress|treat}0 "
19571957
"'Sendable'-related %select{warnings|errors}0 from module %1"
19581958
"%select{| as warnings}0", (bool, Identifier))
19591959
REMARK(remove_predates_concurrency_import,none,
1960-
"'@_predatesConcurrency' attribute on module %0 is unused", (Identifier))
1960+
"'@preconcurrency' attribute on module %0 is unused", (Identifier))
19611961
WARNING(public_decl_needs_sendable,none,
19621962
"public %0 %1 does not specify whether it is 'Sendable' or not",
19631963
(DescriptiveDeclKind, DeclName))
@@ -4475,6 +4475,10 @@ ERROR(global_actor_from_nonactor_context,none,
44754475
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
44764476
" from %select{this|a non-isolated}3%select{| synchronous}5 context",
44774477
(DescriptiveDeclKind, DeclName, Type, bool, unsigned, bool))
4478+
ERROR(global_actor_from_initializing_expr,none,
4479+
"expression requiring global actor %0 cannot appear in "
4480+
"default-value expression of %1 %2",
4481+
(Type, DescriptiveDeclKind, DeclName))
44784482
ERROR(actor_isolated_call,none,
44794483
"call to %0 function in a synchronous %1 context",
44804484
(ActorIsolation, ActorIsolation))

include/swift/AST/Import.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enum class ImportFlags {
8282

8383
/// The module is imported assuming that the module itself predates
8484
/// concurrency.
85-
PredatesConcurrency = 0x20,
85+
Preconcurrency = 0x20,
8686

8787
/// Used for DenseMap.
8888
Reserved = 0x80
@@ -550,17 +550,17 @@ struct AttributedImport {
550550
/// Names of explicitly imported SPI groups.
551551
ArrayRef<Identifier> spiGroups;
552552

553-
/// When the import declaration has a `@_predatesConcurrency` annotation, this
553+
/// When the import declaration has a `@preconcurrency` annotation, this
554554
/// is the source range covering the annotation.
555-
SourceRange predatesConcurrencyRange;
555+
SourceRange preconcurrencyRange;
556556

557557
AttributedImport(ModuleInfo module, SourceLoc importLoc = SourceLoc(),
558558
ImportOptions options = ImportOptions(),
559559
StringRef filename = {}, ArrayRef<Identifier> spiGroups = {},
560-
SourceRange predatesConcurrencyRange = {})
560+
SourceRange preconcurrencyRange = {})
561561
: module(module), importLoc(importLoc), options(options),
562562
sourceFileArg(filename), spiGroups(spiGroups),
563-
predatesConcurrencyRange(predatesConcurrencyRange) {
563+
preconcurrencyRange(preconcurrencyRange) {
564564
assert(!(options.contains(ImportFlags::Exported) &&
565565
options.contains(ImportFlags::ImplementationOnly)) ||
566566
options.contains(ImportFlags::Reserved));
@@ -570,7 +570,7 @@ struct AttributedImport {
570570
AttributedImport(ModuleInfo module, AttributedImport<OtherModuleInfo> other)
571571
: AttributedImport(module, other.importLoc, other.options,
572572
other.sourceFileArg, other.spiGroups,
573-
other.predatesConcurrencyRange) { }
573+
other.preconcurrencyRange) { }
574574

575575
friend bool operator==(const AttributedImport<ModuleInfo> &lhs,
576576
const AttributedImport<ModuleInfo> &rhs) {

include/swift/AST/SourceFile.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class SourceFile final : public FileUnit {
8484
/// This is \c None until it is filled in by the import resolution phase.
8585
Optional<ArrayRef<AttributedImport<ImportedModule>>> Imports;
8686

87-
/// Which imports have made use of @_predatesConcurrency.
87+
/// Which imports have made use of @preconcurrency.
8888
llvm::SmallDenseSet<AttributedImport<ImportedModule>>
89-
PredatesConcurrencyImportsUsed;
89+
PreconcurrencyImportsUsed;
9090

9191
/// A unique identifier representing this file; used to mark private decls
9292
/// within the file to keep them from conflicting with other files in the
@@ -301,12 +301,12 @@ class SourceFile final : public FileUnit {
301301
/// resolution.
302302
void setImports(ArrayRef<AttributedImport<ImportedModule>> imports);
303303

304-
/// Whether the given import has used @_predatesConcurrency.
305-
bool hasImportUsedPredatesConcurrency(
304+
/// Whether the given import has used @preconcurrency.
305+
bool hasImportUsedPreconcurrency(
306306
AttributedImport<ImportedModule> import) const;
307307

308-
/// Note that the given import has used @_predatesConcurrency/
309-
void setImportUsedPredatesConcurrency(
308+
/// Note that the given import has used @preconcurrency/
309+
void setImportUsedPreconcurrency(
310310
AttributedImport<ImportedModule> import);
311311

312312
enum ImportQueryKind {

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5666,14 +5666,14 @@ class OpenedArchetypeType final : public ArchetypeType,
56665666
/// \param knownID When non-empty, the known ID of the archetype. When empty,
56675667
/// a fresh archetype with a unique ID will be opened.
56685668
static CanTypeWrapper<OpenedArchetypeType>
5669-
get(Type existential,
5669+
get(CanType existential,
56705670
Optional<UUID> knownID = None);
56715671

56725672
/// Create a new archetype that represents the opened type
56735673
/// of an existential value.
56745674
///
56755675
/// \param existential The existential type or existential metatype to open.
5676-
static CanType getAny(Type existential);
5676+
static CanType getAny(CanType existential);
56775677

56785678
/// Retrieve the ID number of this opened existential.
56795679
UUID getOpenedExistentialID() const { return ID; }

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,8 @@ NODE(IndexSubset)
325325
NODE(AsyncAwaitResumePartialFunction)
326326
NODE(AsyncSuspendResumePartialFunction)
327327

328+
// Added in Swift 5.6
329+
NODE(CompileTimeConst)
330+
328331
#undef CONTEXT_NODE
329332
#undef NODE

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ void findTransitiveReborrowBaseValuePairs(
12031203
/// Given a begin of a borrow scope, visit all end_borrow users of the borrow or
12041204
/// its reborrows.
12051205
void visitTransitiveEndBorrows(
1206-
BorrowedValue beginBorrow,
1206+
SILValue value,
12071207
function_ref<void(EndBorrowInst *)> visitEndBorrow);
12081208

12091209
/// Whether the specified lexical begin_borrow instruction is nested.

0 commit comments

Comments
 (0)