Skip to content

Commit 6aa918f

Browse files
authored
Merge branch 'release/6.0' into pick-wip-ktoso-changelog
2 parents 0ab71e1 + 91c753a commit 6aa918f

File tree

10 files changed

+139
-19
lines changed

10 files changed

+139
-19
lines changed

CHANGELOG.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,48 @@ And the module structure to support such applications looks like this:
5959
checking, and now even an actor which is "on a queue which is targeting
6060
another specific queue" can be properly detected using these APIs.
6161

62+
* Closures can now appear in pack expansion expressions, which allows you to
63+
construct a parameter pack of closures where each closure captures the
64+
corresponding element of some other parameter pack. For example:
65+
66+
```swift
67+
struct Manager<each T> {
68+
let fn: (repeat () -> (each T))
69+
70+
init(_ t: repeat each T) {
71+
fn = (repeat { each t })
72+
}
73+
}
74+
```
75+
76+
* [SE-0431][]:
77+
You can now require a function value to carry its actor isolation
78+
dynamically in a way that can be directly read by clients:
79+
80+
```swift
81+
func apply<R>(count: Int,
82+
operation: @isolated(any) async () -> R) async -> [R]
83+
where R: Sendable {
84+
// implementation
85+
}
86+
```
87+
88+
The isolation can read with the `.isolation` property, which has type
89+
`(any Actor)?`:
90+
91+
```swift
92+
let iso = operation.isolation
93+
```
94+
95+
This capability has been adopted by the task-creation APIs in the
96+
standard library. As a result, creating a task with an actor-isolated
97+
function will now synchronously enqueue the task on the actor, which
98+
can be used for transitive event-ordering guarantees if the actor
99+
guarantees that jobs will be run in the order they are enqueued, as
100+
`@MainActor` does. If the function is not explicitly isolated, Swift
101+
still retains the right to optimize enqueues for functions that actually
102+
start by doing work with different isolation from their formal isolation.
103+
62104
* [SE-0423][]:
63105
You can now use `@preconcurrency` attribute to replace static actor isolation
64106
checking with dynamic checks for witnesses of synchronous nonisolated protocol
@@ -99,6 +141,21 @@ And the module structure to support such applications looks like this:
99141
The dynamic actor isolation checks can be disabled using the flag
100142
`-disable-dynamic-actor-isolation`.
101143

144+
* [SE-0420][]:
145+
`async` functions can now explicitly inherit the isolation of their caller
146+
by declaring an `isolated` parameter with the default value of `#isolation`:
147+
148+
```swift
149+
func poll(isolation: isolated (any Actor)? = #isolation) async -> [Item] {
150+
// implementation
151+
}
152+
```
153+
154+
When the caller is actor-isolated, this allows it to pass isolated state
155+
to the function, which would otherwise have concurrency problems. The
156+
function may also be able to eliminate unwanted scheduling changes, such
157+
as when it can quickly return in a fast path without needing to suspend.
158+
102159
* [SE-0418][]:
103160

104161
The compiler would now automatically employ `Sendable` on functions
@@ -10458,17 +10515,22 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
1045810515
[SE-0407]: https://github.com/apple/swift-evolution/blob/main/proposals/0407-member-macro-conformances.md
1045910516
[SE-0408]: https://github.com/apple/swift-evolution/blob/main/proposals/0408-pack-iteration.md
1046010517
[SE-0411]: https://github.com/apple/swift-evolution/blob/main/proposals/0411-isolated-default-values.md
10461-
[SE-0417]: https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md
1046210518
[SE-0412]: https://github.com/apple/swift-evolution/blob/main/proposals/0412-strict-concurrency-for-global-variables.md
1046310519
[SE-0413]: https://github.com/apple/swift-evolution/blob/main/proposals/0413-typed-throws.md
10464-
[SE-0422]: https://github.com/apple/swift-evolution/blob/main/proposals/0422-caller-side-default-argument-macro-expression.md
10465-
[SE-0427]: https://github.com/apple/swift-evolution/blob/main/proposals/0427-noncopyable-generics.md
1046610520
[SE-0414]: https://github.com/apple/swift-evolution/blob/main/proposals/0414-region-based-isolation.md
1046710521
[SE-0424]: https://github.com/apple/swift-evolution/blob/main/proposals/0424-custom-isolation-checking-for-serialexecutor.md
1046810522
[SE-0428]: https://github.com/apple/swift-evolution/blob/main/proposals/0428-resolve-distributed-actor-protocols.md
1046910523
[SE-0430]: https://github.com/apple/swift-evolution/blob/main/proposals/0430-transferring-parameters-and-results.md
10524+
[SE-0417]: https://github.com/apple/swift-evolution/blob/main/proposals/0417-task-executor-preference.md
1047010525
[SE-0418]: https://github.com/apple/swift-evolution/blob/main/proposals/0418-inferring-sendable-for-methods.md
10526+
[SE-0420]: https://github.com/apple/swift-evolution/blob/main/proposals/0420-inheritance-of-actor-isolation.md
10527+
[SE-0422]: https://github.com/apple/swift-evolution/blob/main/proposals/0422-caller-side-default-argument-macro-expression.md
1047110528
[SE-0423]: https://github.com/apple/swift-evolution/blob/main/proposals/0423-dynamic-actor-isolation.md
10529+
[SE-0427]: https://github.com/apple/swift-evolution/blob/main/proposals/0427-noncopyable-generics.md
10530+
[SE-0429]: https://github.com/apple/swift-evolution/blob/main/proposals/0429-partial-consumption.md
10531+
[SE-0430]: https://github.com/apple/swift-evolution/blob/main/proposals/0430-transferring-parameters-and-results.md
10532+
[SE-0431]: https://github.com/apple/swift-evolution/blob/main/proposals/0431-isolated-any-functions.md
10533+
[SE-0432]: https://github.com/apple/swift-evolution/blob/main/proposals/0432-noncopyable-switch.md
1047210534
[#64927]: <https://github.com/apple/swift/issues/64927>
1047310535
[#42697]: <https://github.com/apple/swift/issues/42697>
1047410536
[#42728]: <https://github.com/apple/swift/issues/42728>

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ static llvm::Error resolveExplicitModuleInputs(
270270
auto optionalBridgingHeaderDepModuleInfo = cache.findKnownDependency(
271271
{bridgingHeaderDepName, ModuleDependencyKind::Clang});
272272
const auto bridgingHeaderDepModuleDetails =
273-
optionalBridgingHeaderDepModuleInfo.getAsClangModule();
273+
optionalBridgingHeaderDepModuleInfo.getAsClangModule();
274+
commandLine.push_back("-Xcc");
274275
commandLine.push_back(
275276
"-fmodule-map-file=" +
276277
remapPath(bridgingHeaderDepModuleDetails->moduleMapFile));

lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,9 @@ static void emitEntryPointArgumentsCOrObjC(IRGenSILFunction &IGF,
23302330
// First, claim all the indirect results.
23312331
ArrayRef<SILArgument *> args = emitEntryPointIndirectReturn(
23322332
*emission, IGF, entry, funcTy, [&](SILType directResultType) -> bool {
2333-
return FI.getReturnInfo().isIndirect();
2333+
// Indirect at the IR level but direct at the SIL level.
2334+
return FI.getReturnInfo().isIndirect() &&
2335+
!funcTy->hasIndirectFormalResults();
23342336
});
23352337

23362338
unsigned nextArgTyIdx = 0;

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ static void buildFuncToBlockInvokeBody(SILGenFunction &SGF,
392392
if (blockTy->getNumResults() != 0) {
393393
auto result = blockTy->getSingleResult();
394394
if (result.getConvention() == ResultConvention::Indirect) {
395-
indirectResult = entry->createFunctionArgument(blockResultTy);
395+
indirectResult =
396+
entry->createFunctionArgument(blockResultTy.getAddressType());
396397
}
397398
}
398399

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,14 @@ extension UnsafeRawPointer {
510510
/// with the value in the range of memory referenced by this pointer.
511511
@inlinable
512512
@_alwaysEmitIntoClient
513-
@available(swift, deprecated: 6, message:
514-
"Use the BitwiseCopyable-constrained overload"
515-
)
516513
public func loadUnaligned<T>(
517514
fromByteOffset offset: Int = 0,
518515
as type: T.Type
519516
) -> T {
520-
_debugPrecondition(_isPOD(T.self))
517+
_debugPrecondition(
518+
_isPOD(T.self),
519+
"loadUnaligned only supports loading BitwiseCopyable types."
520+
)
521521
return _withUnprotectedUnsafeTemporaryAllocation(of: T.self, capacity: 1) {
522522
let temporary = $0.baseAddress._unsafelyUnwrappedUnchecked
523523
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
@@ -1344,14 +1344,14 @@ extension UnsafeMutableRawPointer {
13441344
/// with the value in the range of memory referenced by this pointer.
13451345
@inlinable
13461346
@_alwaysEmitIntoClient
1347-
@available(swift, deprecated: 6, message:
1348-
"Use the BitwiseCopyable-constrained overload"
1349-
)
13501347
public func loadUnaligned<T>(
13511348
fromByteOffset offset: Int = 0,
13521349
as type: T.Type
13531350
) -> T {
1354-
_debugPrecondition(_isPOD(T.self))
1351+
_debugPrecondition(
1352+
_isPOD(T.self),
1353+
"loadUnaligned only supports loading BitwiseCopyable types."
1354+
)
13551355
return _withUnprotectedUnsafeTemporaryAllocation(of: T.self, capacity: 1) {
13561356
let temporary = $0.baseAddress._unsafelyUnwrappedUnchecked
13571357
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
@@ -1450,13 +1450,13 @@ extension UnsafeMutableRawPointer {
14501450
@_alwaysEmitIntoClient
14511451
// This custom silgen name is chosen to not interfere with the old ABI
14521452
@_silgen_name("_swift_se0349_UnsafeMutableRawPointer_storeBytes")
1453-
@available(swift, deprecated: 6, message:
1454-
"Use the BitwiseCopyable-constrained overload"
1455-
)
14561453
public func storeBytes<T>(
14571454
of value: T, toByteOffset offset: Int = 0, as type: T.Type
14581455
) {
1459-
_debugPrecondition(_isPOD(T.self))
1456+
_debugPrecondition(
1457+
_isPOD(T.self),
1458+
"storeBytes only supports storing the bytes of BitwiseCopyable types."
1459+
)
14601460

14611461
#if $TypedThrows
14621462
withUnsafePointer(to: value) { source in

test/Interop/Cxx/class/Inputs/closure.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ struct ARCStrong {
2020
void cfuncARCStrong(void (*_Nonnull)(ARCStrong));
2121
#endif
2222

23+
void cfuncReturnNonTrivial(NonTrivial (^_Nonnull)()) noexcept;
24+
2325
#endif // __CLOSURE__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swiftxx-frontend -I %S/Inputs -emit-irgen %s | %FileCheck %s
2+
3+
// REQUIRES: OS=macosx
4+
5+
import Closure
6+
7+
// CHECK: define internal swiftcc void @"$s4main34testClosureToBlockReturnNonTrivialyyFSo0gH0VycfU_"(ptr noalias sret(%{{.*}}) %[[V0:.*]])
8+
// CHECK: call {{void|ptr}} @__swift_cxx_ctor_ZN10NonTrivialC1Ev(ptr %[[V0]])
9+
// CHECK: ret void
10+
11+
// CHECK: define linkonce_odr hidden void @"$sSo10NonTrivialVIegr_ABIeyBr_TR"(ptr noalias sret(%{{.*}}) %[[V0:.*]], ptr %[[V1:.*]])
12+
// CHECK: %[[V2:.*]] = getelementptr inbounds { %{{.*}}, %{{.*}} }, ptr %[[V1]], i32 0, i32 1
13+
// CHECK: %[[_FN:.*]] = getelementptr inbounds %{{.*}}, ptr %[[V2]], i32 0, i32 0
14+
// CHECK: %[[V3:.*]] = load ptr, ptr %[[_FN]], align 8
15+
// CHECK: %[[_DATA:.*]] = getelementptr inbounds %{{.*}}, ptr %[[V2]], i32 0, i32 1
16+
// CHECK: %[[V4:.*]] = load ptr, ptr %[[_DATA]], align 8
17+
// CHECK: call ptr @swift_retain(ptr returned %[[V4]])
18+
// CHECK: call swiftcc void %[[V3]](ptr noalias sret(%{{.*}}) %[[V0]], ptr swiftself %[[V4]])
19+
// CHECK: call void @swift_release(ptr %[[V4]])
20+
// CHECK: ret void
21+
22+
public func testClosureToBlockReturnNonTrivial() {
23+
cfuncReturnNonTrivial({() -> NonTrivial in return NonTrivial() })
24+
}

test/Interop/Cxx/class/closure-thunk-macosx.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@ import Closure
2020
public func testClosureToFuncPtr() {
2121
cfuncARCStrong({N in})
2222
}
23+
24+
// CHECK: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSo10NonTrivialVIegr_ABIeyBr_TR : $@convention(c) (@inout_aliasable @block_storage @callee_guaranteed () -> @out NonTrivial) -> @out NonTrivial {
25+
// CHECK: bb0(%[[V0:.*]] : $*NonTrivial, %[[V1:.*]] : $*@block_storage @callee_guaranteed () -> @out NonTrivial):
26+
// CHECK: %[[V2:.*]] = project_block_storage %[[V1]] : $*@block_storage @callee_guaranteed () -> @out NonTrivial
27+
// CHECK: %[[V3:.*]] = load [copy] %[[V2]] : $*@callee_guaranteed () -> @out NonTrivial
28+
// CHECK: %[[V4:.*]] = begin_borrow %[[V3]] : $@callee_guaranteed () -> @out NonTrivial
29+
// CHECK: apply %[[V4]](%[[V0]]) : $@callee_guaranteed () -> @out NonTrivial
30+
// CHECK: end_borrow %[[V4]] : $@callee_guaranteed () -> @out NonTrivial
31+
// CHECK: %[[V8:.*]] = tuple ()
32+
// CHECK: destroy_value %[[V3]] : $@callee_guaranteed () -> @out NonTrivial
33+
// CHECK: return %[[V8]] : $()
34+
35+
public func testClosureToBlockReturnNonTrivial() {
36+
cfuncReturnNonTrivial({() -> NonTrivial in return NonTrivial() })
37+
}

test/ScanDependencies/bridging_header_dep_module_map.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,18 @@
4949
// CHECK-DAG: "clang": "Dart"
5050
// CHECK: ],
5151
// CHECK: "commandLine": [
52-
// CHECK: "-fmodule-map-file={{.*}}{{/|\\}}CHeaders{{/|\\}}module.modulemap"
52+
// CHECK: "-Xcc"
53+
// CHECK-NEXT: "-fno-implicit-modules"
54+
// CHECK: "-Xcc"
55+
// CHECK-NEXT: "-fno-implicit-module-maps"
56+
// CHECK-DAG: "-Xcc",
57+
// CHECK-NEXT: "-fmodule-file=Dart={{.*}}"
58+
// CHECK-DAG: "-Xcc"
59+
// CHECK-NEXT: "-fmodule-map-file={{.*}}{{/|\\}}CHeaders{{/|\\}}module.modulemap"
60+
// CHECK-DAG: "-Xcc",
61+
// CHECK-NEXT: "-fmodule-file=SwiftShims={{.*}}"
62+
// CHECK-DAG: "-Xcc",
63+
// CHECK-NEXT: "-fmodule-file=X={{.*}}"
5364
// CHECK-NOT: "-fmodule-map-file={{.*}}{{/|\\}}TestCHeaders{{/|\\}}module.modulemap"
5465
// CHECK: ]
5566

utils/build-script-impl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,7 @@ function build_and_test_installable_package() {
33753375
COMPATIBILITY_VERSION=2
33763376
COMPATIBILITY_VERSION_DISPLAY_STRING="Xcode 8.0"
33773377
DARWIN_TOOLCHAIN_CREATED_DATE="$(date -u +'%a %b %d %T GMT %Y')"
3378+
TOOLCHAIN_PLUGIN_PATH_DESCRIPTOR='$(TOOLCHAIN_DIR)/usr/lib/swift/host/plugins'
33783379

33793380
SWIFT_USE_DEVELOPMENT_TOOLCHAIN_RUNTIME="YES"
33803381
if [[ "${DARWIN_TOOLCHAIN_REQUIRE_USE_OS_RUNTIME}" -eq "1" ]]; then
@@ -3409,6 +3410,7 @@ function build_and_test_installable_package() {
34093410
call ${PLISTBUDDY_BIN} -c "Add OverrideBuildSettings:SWIFT_LINK_OBJC_RUNTIME string 'YES'" "${DARWIN_TOOLCHAIN_INFO_PLIST}"
34103411
call ${PLISTBUDDY_BIN} -c "Add OverrideBuildSettings:SWIFT_DEVELOPMENT_TOOLCHAIN string 'YES'" "${DARWIN_TOOLCHAIN_INFO_PLIST}"
34113412
call ${PLISTBUDDY_BIN} -c "Add OverrideBuildSettings:SWIFT_USE_DEVELOPMENT_TOOLCHAIN_RUNTIME string '${SWIFT_USE_DEVELOPMENT_TOOLCHAIN_RUNTIME}'" "${DARWIN_TOOLCHAIN_INFO_PLIST}"
3413+
call ${PLISTBUDDY_BIN} -c "Add OverrideBuildSettings:OTHER_SWIFT_FLAGS string '\$(inherited) -plugin-path ${TOOLCHAIN_PLUGIN_PATH_DESCRIPTOR}'" "${DARWIN_TOOLCHAIN_INFO_PLIST}"
34123414

34133415
call chmod a+r "${DARWIN_TOOLCHAIN_INFO_PLIST}"
34143416

0 commit comments

Comments
 (0)