Skip to content

Commit 7f4ffa4

Browse files
Merge pull request #4597 from swiftwasm/release/5.7
[pull] swiftwasm-release/5.7 from release/5.7
2 parents 0d8b14b + 412f0e0 commit 7f4ffa4

File tree

81 files changed

+2065
-1723
lines changed

Some content is hidden

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

81 files changed

+2065
-1723
lines changed

CHANGELOG.md

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

66
## Swift 5.7
77

8+
* [SE-0338][]:
9+
10+
Non-isolated async functions now always execute on the global concurrent pool,
11+
so calling a non-isolated async function from actor-isolated code will leave
12+
the actor. For example:
13+
14+
```swift
15+
class C { }
16+
17+
func f(_: C) async { /* always executes on the global concurrent pool */ }
18+
19+
actor A {
20+
func g(c: C) async {
21+
/* always executes on the actor */
22+
print("on the actor")
23+
24+
await f(c)
25+
}
26+
}
27+
```
28+
29+
Prior to this change, the call from `f` to `g` might have started execution of
30+
`g` on the actor, which could lead to actors being busy longer than strictly
31+
necessary. Now, the non-isolated async function will always hop to the global
32+
cooperative pool, not run on the actor. This can result in a behavior change
33+
for programs that assumed that a non-isolated async function called from a
34+
`@MainActor` context will be executed on the main actor, although such
35+
programs were already technically incorrect.
36+
37+
Additionally, when leaving an actor to execution on the global cooperative
38+
pool, `Sendable` checking will be performed, so the compiler will emit a
39+
diagnostic in the call to `f` if `c` is not of `Sendable` type.
40+
41+
* [SE-0353][]:
42+
43+
Protocols with primary associated types can now be used in existential types,
44+
enabling same-type constraints on those associated types.
45+
46+
```
47+
let strings: any Collection<String> = [ "Hello" ]
48+
```
49+
50+
Note that language features requiring runtime support like dynamic casts
51+
(`is`, `as?`, `as!`), as well as generic usages of parameterized existentials
52+
in generic types (e.g. `Array<any Collection<Int>>`) involve additional
53+
availability checks to use. Back-deploying usages in generic position can be
54+
worked around with a generic type-erasing wrapper struct, which is now much
55+
simpler to implement:
56+
57+
```swift
58+
struct AnyCollection<T> {
59+
var wrapped: any Collection<T>
60+
}
61+
62+
let arrayOfCollections: [AnyCollection<T>] = [ /**/ ]
63+
```
64+
65+
* [SE-0329][]:
66+
New types representing time and clocks were introduced. This includes a protocol `Clock` defining clocks which allow for defining a concept of now and a way to wake up after a given instant. Additionally a new protocol `InstantProtocol` for defining instants in time was added. Furthermore a new protocol `DurationProtocol` was added to define an elapsed duration between two given `InstantProtocol` types. Most commonly the `Clock` types for general use are the `SuspendingClock` and `ContinuousClock` which represent the most fundamental clocks for the system. The `SuspendingClock` type does not progress while the machine is suspended whereas the `ContinuousClock` progresses no matter the state of the machine.
67+
68+
* [SE-0309][]:
69+
70+
Protocols with associated types and `Self` requirements can now be used as the
71+
types of values with the `any` keyword.
72+
73+
Protocol methods that return associated types can be called on an `any` type;
74+
the result is type-erased to the associated type's upper bound, which is another
75+
`any` type having the same constraints as the associated type. For example:
76+
77+
```swift
78+
func delayedHello() async throws {
79+
try await Task.sleep(until: .now + .milliseconds(123), clock: .continuous)
80+
print("hello delayed world")
81+
}
82+
```
83+
84+
`Clock` also has methods to measure the elapsed duration of the execution of work. In the case of the `SuspendingClock` and `ContinuousClock` this measures with high resolution and is suitable for benchmarks.
85+
86+
```swift
87+
let clock = ContinuousClock()
88+
let elapsed = clock.measure {
89+
someLongRunningWork()
90+
}
91+
```
92+
893
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
994

1095
```swift
@@ -9257,12 +9342,14 @@ Swift 1.0
92579342
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
92589343
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
92599344
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
9345+
[SE-0329]: <https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md>
92609346
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
92619347
[SE-0333]: <https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md>
92629348
[SE-0334]: <https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md>
92639349
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
92649350
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
92659351
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
9352+
[SE-0338]: <https://github.com/apple/swift-evolution/blob/main/proposals/0338-clarify-execution-non-actor-async.md>
92669353
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
92679354
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
92689355
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>

include/swift/AST/ActorIsolation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class ActorIsolation {
131131
return getKind() == GlobalActor || getKind() == GlobalActorUnsafe;
132132
}
133133

134+
bool isDistributedActor() const;
135+
134136
Type getGlobalActor() const {
135137
assert(isGlobalActor());
136138
return globalActor;

include/swift/AST/DiagnosticsSema.def

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,14 +4470,11 @@ NOTE(note_add_nonisolated_to_decl,none,
44704470
(DeclName, DescriptiveDeclKind))
44714471
NOTE(note_add_async_and_throws_to_decl,none,
44724472
"mark the protocol requirement %0 '%select{|async|throws|async throws}1' "
4473-
"in order witness it with 'distributed' function declared in distributed actor %2",
4474-
(DeclName, unsigned, DeclName))
4473+
"to allow actor-isolated conformances",
4474+
(DeclName, unsigned))
44754475
NOTE(note_add_distributed_to_decl,none,
4476-
"add 'distributed' to %0 to make this %1 witness the protocol requirement",
4476+
"add 'distributed' to %0 to make this %1 satisfy the protocol requirement",
44774477
(DeclName, DescriptiveDeclKind))
4478-
NOTE(note_distributed_requirement_defined_here,none,
4479-
"distributed instance method requirement %0 declared here",
4480-
(DeclName))
44814478
NOTE(note_add_globalactor_to_function,none,
44824479
"add '@%0' to make %1 %2 part of global actor %3",
44834480
(StringRef, DescriptiveDeclKind, DeclName, Type))
@@ -4558,13 +4555,16 @@ ERROR(override_implicit_unowned_executor,none,
45584555
"cannot override an actor's 'unownedExecutor' property that wasn't "
45594556
"explicitly defined", ())
45604557
ERROR(actor_isolated_non_self_reference,none,
4561-
"actor-isolated %0 %1 can not be "
4558+
"%5 %0 %1 can not be "
45624559
"%select{referenced|mutated|used 'inout'}2 "
4563-
"%select{on a non-isolated actor instance|"
4560+
"%select{from outside the actor|on a different actor instance|"
4561+
"on a non-isolated actor instance|"
45644562
"from a Sendable function|from a Sendable closure|"
45654563
"from an 'async let' initializer|from global actor %4|"
4566-
"from the main actor|from a non-isolated context|from a non-isolated autoclosure}3",
4567-
(DescriptiveDeclKind, DeclName, unsigned, unsigned, Type))
4564+
"from the main actor|from a non-isolated context|"
4565+
"from a non-isolated autoclosure}3",
4566+
(DescriptiveDeclKind, DeclName, unsigned, unsigned, Type,
4567+
ActorIsolation))
45684568
ERROR(distributed_actor_isolated_non_self_reference,none,
45694569
"distributed actor-isolated %0 %1 can not be accessed from a "
45704570
"non-isolated context",
@@ -4579,18 +4579,6 @@ ERROR(actor_isolated_inout_state,none,
45794579
ERROR(actor_isolated_mutating_func,none,
45804580
"cannot call mutating async function %0 on actor-isolated %1 %2",
45814581
(DeclName, DescriptiveDeclKind, DeclName))
4582-
ERROR(global_actor_from_instance_actor_context,none,
4583-
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
4584-
" from actor %3 %select{|in a synchronous context}5",
4585-
(DescriptiveDeclKind, DeclName, Type, DeclName, unsigned, bool))
4586-
ERROR(global_actor_from_other_global_actor_context,none,
4587-
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
4588-
" from different global actor %3 %select{|in a synchronous context}5",
4589-
(DescriptiveDeclKind, DeclName, Type, Type, unsigned, bool))
4590-
ERROR(global_actor_from_nonactor_context,none,
4591-
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
4592-
" from %select{this|a non-isolated}3%select{| synchronous}5 context",
4593-
(DescriptiveDeclKind, DeclName, Type, bool, unsigned, bool))
45944582
ERROR(actor_isolated_call,none,
45954583
"call to %0 function in a synchronous %1 context",
45964584
(ActorIsolation, ActorIsolation))
@@ -4684,19 +4672,9 @@ WARNING(shared_mutable_state_access,none,
46844672
"reference to %0 %1 is not concurrency-safe because it involves "
46854673
"shared mutable state", (DescriptiveDeclKind, DeclName))
46864674
ERROR(actor_isolated_witness,none,
4687-
"actor-isolated %0 %1 cannot be used to satisfy a protocol requirement",
4688-
(DescriptiveDeclKind, DeclName))
4689-
ERROR(distributed_actor_isolated_witness,none,
4690-
"distributed actor-isolated %0 %1 cannot be used to satisfy a protocol requirement",
4691-
(DescriptiveDeclKind, DeclName))
4692-
ERROR(global_actor_isolated_witness,none,
4693-
"%0 %1 isolated to global actor %2 can not satisfy corresponding "
4694-
"requirement from protocol %3",
4695-
(DescriptiveDeclKind, DeclName, Type, Identifier))
4696-
ERROR(global_actor_isolated_requirement_witness_conflict,none,
4697-
"%0 %1 isolated to global actor %2 can not satisfy corresponding "
4698-
"requirement from protocol %3 isolated to global actor %4",
4699-
(DescriptiveDeclKind, DeclName, Type, Identifier, Type))
4675+
"%select{|distributed }0%1 %2 %3 cannot be used to satisfy %4 protocol "
4676+
"requirement",
4677+
(bool, ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
47004678
ERROR(actor_cannot_conform_to_global_actor_protocol,none,
47014679
"actor %0 cannot conform to global actor isolated protocol %1",
47024680
(Type, Type))
@@ -4708,9 +4686,10 @@ ERROR(isolated_parameter_not_actor,none,
47084686

47094687
WARNING(non_sendable_param_type,none,
47104688
"non-sendable type %0 %select{passed in call to %4 %2 %3|"
4689+
"exiting %4 context in call to non-isolated %2 %3|"
47114690
"passed in implicitly asynchronous call to %4 %2 %3|"
4712-
"in parameter of %4 %2 %3 satisfying non-isolated protocol "
4713-
"requirement|"
4691+
"in parameter of %4 %2 %3 satisfying protocol requirement|"
4692+
"in parameter of %4 overriding %2 %3|"
47144693
"in parameter of %4 '@objc' %2 %3}1 cannot cross actor boundary",
47154694
(Type, unsigned, DescriptiveDeclKind, DeclName, ActorIsolation))
47164695
WARNING(non_sendable_call_param_type,none,
@@ -4719,8 +4698,10 @@ WARNING(non_sendable_call_param_type,none,
47194698
(Type, bool, ActorIsolation))
47204699
WARNING(non_sendable_result_type,none,
47214700
"non-sendable type %0 returned by %select{call to %4 %2 %3|"
4701+
"call from %4 context to non-isolated %2 %3|"
47224702
"implicitly asynchronous call to %4 %2 %3|"
4723-
"%4 %2 %3 satisfying non-isolated protocol requirement|"
4703+
"%4 %2 %3 satisfying protocol requirement|"
4704+
"%4 overriding %2 %3|"
47244705
"%4 '@objc' %2 %3}1 cannot cross actor boundary",
47254706
(Type, unsigned, DescriptiveDeclKind, DeclName, ActorIsolation))
47264707
WARNING(non_sendable_call_result_type,none,
@@ -4730,8 +4711,10 @@ WARNING(non_sendable_call_result_type,none,
47304711
WARNING(non_sendable_property_type,none,
47314712
"non-sendable type %0 in %select{"
47324713
"%select{asynchronous access to %5 %1 %2|"
4714+
"asynchronous access from %5 context to non-isolated %1 %2|"
47334715
"implicitly asynchronous access to %5 %1 %2|"
4734-
"conformance of %5 %1 %2 to non-isolated protocol requirement|"
4716+
"conformance of %5 %1 %2 to protocol requirement|"
4717+
"%5 overriding %1 %2|"
47354718
"%5 '@objc' %1 %2}4|captured local %1 %2}3 cannot "
47364719
"cross %select{actor|task}3 boundary",
47374720
(Type, DescriptiveDeclKind, DeclName, bool, unsigned, ActorIsolation))

include/swift/AST/PrintOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ struct PrintOptions {
285285
/// types.
286286
bool PrintExplicitAny = false;
287287

288+
/// Whether to desugar the constraint for an existential type.
289+
bool DesugarExistentialConstraint = false;
290+
288291
/// Whether to skip keywords with a prefix of underscore such as __consuming.
289292
bool SkipUnderscoredKeywords = false;
290293

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,6 @@ namespace swift {
338338
/// in calls to generic functions.
339339
bool EnableOpenedExistentialTypes = false;
340340

341-
/// Enable support for parameterized protocol types in existential
342-
/// position.
343-
bool EnableParameterizedExistentialTypes = false;
344-
345341
/// Enable experimental flow-sensitive concurrent captures.
346342
bool EnableExperimentalFlowSensitiveConcurrentCaptures = false;
347343

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,6 @@ def enable_explicit_existential_types :
543543
Flag<["-"], "enable-explicit-existential-types">,
544544
HelpText<"Enable experimental support for explicit existential types">;
545545

546-
def enable_parameterized_existential_types :
547-
Flag<["-"], "enable-parameterized-existential-types">,
548-
HelpText<"Enable experimental support for parameterized existential types">;
549-
550546
def enable_experimental_opened_existential_types :
551547
Flag<["-"], "enable-experimental-opened-existential-types">,
552548
HelpText<"Enable experimental support for implicitly opened existentials">;

include/swift/Sema/Constraint.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ enum class ConversionRestrictionKind {
264264
ProtocolMetatypeToProtocolClass,
265265
/// Inout-to-pointer conversion.
266266
InoutToPointer,
267+
/// Converting from `inout` to a C pointer has `PointerToCPointer` semantics.
268+
InoutToCPointer,
267269
/// Array-to-pointer conversion.
268270
ArrayToPointer,
269271
/// String-to-pointer conversion.
@@ -303,8 +305,8 @@ enum class ConversionRestrictionKind {
303305
/// via an implicit Double initializer call passing a CGFloat value.
304306
CGFloatToDouble,
305307
/// Implicit conversion between Swift and C pointers:
306-
// - Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
307-
// - Unsafe[Mutable]Pointer<Int{8, 16, ...}> <-> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
308+
/// - Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int>
309+
/// - Unsafe[Mutable]Pointer<Int{8, 16, ...}> <-> Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
308310
PointerToCPointer,
309311
// Convert a pack into a type with an equivalent arity.
310312
// - If the arity of the pack is 1, drops the pack structure <T> => T

include/swift/SymbolGraphGen/SymbolGraphOptions.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,33 @@ namespace symbolgraphgen {
2121

2222
struct SymbolGraphOptions {
2323
/// The directory to output the symbol graph JSON files.
24-
StringRef OutputDir;
24+
StringRef OutputDir = {};
2525

2626
/// The target of the module.
27-
llvm::Triple Target;
27+
llvm::Triple Target = {};
2828
/// Pretty-print the JSON with newlines and indentation.
29-
bool PrettyPrint;
29+
bool PrettyPrint = false;
3030

3131
/// The minimum access level that symbols must have in order to be
3232
/// included in the graph.
33-
AccessLevel MinimumAccessLevel;
33+
AccessLevel MinimumAccessLevel = AccessLevel::Public;
3434

3535
/// Emit members gotten through class inheritance or protocol default
3636
/// implementations with compound, "SYNTHESIZED" USRs.
37-
bool EmitSynthesizedMembers;
37+
bool EmitSynthesizedMembers = false;
3838

3939
/// Whether to print informational messages when rendering
4040
/// a symbol graph.
41-
bool PrintMessages;
41+
bool PrintMessages = false;
4242

4343
/// Whether to skip docs for symbols with compound, "SYNTHESIZED" USRs.
44-
bool SkipInheritedDocs;
44+
bool SkipInheritedDocs = false;
4545

4646
/// Whether to emit symbols with SPI information.
47-
bool IncludeSPISymbols;
47+
bool IncludeSPISymbols = false;
4848

4949
/// Whether to include documentation for clang nodes or not.
50-
bool IncludeClangDocs;
50+
bool IncludeClangDocs = false;
5151
};
5252

5353
} // end namespace symbolgraphgen

lib/AST/ASTMangler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,10 @@ static bool isRetroactiveConformance(const RootProtocolConformance *root) {
16371637
return false; // self-conformances are never retroactive. nor are builtin.
16381638
}
16391639

1640+
// Don't consider marker protocols at all.
1641+
if (conformance->getProtocol()->isMarkerProtocol())
1642+
return false;
1643+
16401644
return conformance->isRetroactive();
16411645
}
16421646

@@ -1682,6 +1686,12 @@ void ASTMangler::appendRetroactiveConformances(SubstitutionMap subMap,
16821686

16831687
unsigned numProtocolRequirements = 0;
16841688
for (auto conformance : subMap.getConformances()) {
1689+
if (conformance.isInvalid())
1690+
continue;
1691+
1692+
if (conformance.getRequirement()->isMarkerProtocol())
1693+
continue;
1694+
16851695
SWIFT_DEFER {
16861696
++numProtocolRequirements;
16871697
};

lib/AST/ASTPrinter.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
146146
result.AlwaysTryPrintParameterLabels = true;
147147
result.PrintSPIs = printSPIs;
148148
result.PrintExplicitAny = true;
149+
result.DesugarExistentialConstraint = true;
149150

150151
// We should print __consuming, __owned, etc for the module interface file.
151152
result.SkipUnderscoredKeywords = false;
@@ -6195,7 +6196,16 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
61956196
if (Options.PrintExplicitAny)
61966197
Printer << "any ";
61976198

6198-
visit(T->getConstraintType());
6199+
// FIXME: The desugared type is used here only to support
6200+
// existential types with protocol typealiases in Swift
6201+
// interfaces. Verifying that the underlying type of a
6202+
// protocol typealias is a constriant type is fundamentally
6203+
// circular, so the desugared type should be written in source.
6204+
if (Options.DesugarExistentialConstraint) {
6205+
visit(T->getConstraintType()->getDesugaredType());
6206+
} else {
6207+
visit(T->getConstraintType());
6208+
}
61996209
}
62006210

62016211
void visitLValueType(LValueType *T) {

0 commit comments

Comments
 (0)