Skip to content

Commit 1d4bfa2

Browse files
authored
Merge pull request #3534 from swiftwasm/release/5.5
[pull] swiftwasm-release/5.5 from release/5.5
2 parents 8d966d3 + 5e0d32b commit 1d4bfa2

File tree

12 files changed

+137
-14
lines changed

12 files changed

+137
-14
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ enum class IRGenEmbedMode : unsigned {
8181
EmbedBitcode
8282
};
8383

84+
enum class SwiftAsyncFramePointerKind : unsigned {
85+
Auto, // Choose Swift async extended frame info based on deployment target.
86+
Always, // Unconditionally emit Swift async extended frame info.
87+
Never, // Don't emit Swift async extended frame info.
88+
};
89+
8490
using clang::PointerAuthSchema;
8591

8692
struct PointerAuthOptions : clang::PointerAuthOptions {
@@ -285,6 +291,8 @@ class IRGenOptions {
285291

286292
IRGenLLVMLTOKind LLVMLTOKind : 2;
287293

294+
SwiftAsyncFramePointerKind SwiftAsyncFramePointer : 2;
295+
288296
/// Add names to LLVM values.
289297
unsigned HasValueNamesSetting : 1;
290298
unsigned ValueNames : 1;
@@ -394,7 +402,9 @@ class IRGenOptions {
394402
EmitStackPromotionChecks(false), FunctionSections(false),
395403
DisableAutolinkStdlib(false),
396404
PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
397-
LLVMLTOKind(IRGenLLVMLTOKind::None), HasValueNamesSetting(false),
405+
LLVMLTOKind(IRGenLLVMLTOKind::None),
406+
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Always),
407+
HasValueNamesSetting(false),
398408
ValueNames(false), EnableReflectionMetadata(true),
399409
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
400410
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),

include/swift/Option/FrontendOptions.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,15 @@ def type_info_dump_filter_EQ : Joined<["-"], "type-info-dump-filter=">,
765765
Flags<[FrontendOption]>,
766766
HelpText<"One of 'all', 'resilient' or 'fragile'">;
767767

768+
768769
def emit_ldadd_cfile_path
769770
: Separate<["-"], "emit-ldadd-cfile-path">, MetaVarName<"<path>">,
770771
HelpText<"Generate .c file defining symbols to add back">;
771772

773+
def swift_async_frame_pointer_EQ : Joined<["-"], "swift-async-frame-pointer=">,
774+
Flags<[FrontendOption]>,
775+
HelpText<"One of 'auto', 'always' or 'never'">;
776+
772777
def previous_module_installname_map_file
773778
: Separate<["-"], "previous-module-installname-map-file">, MetaVarName<"<path>">,
774779
HelpText<"Path to a Json file indicating module name to installname map for @_originallyDefinedIn">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,26 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
17761776
}
17771777
}
17781778

1779+
// Default to disabling swift async extended frame info on anything but
1780+
// darwin. Other platforms are unlikely to have support for extended frame
1781+
// pointer information.
1782+
if (!Triple.isOSDarwin()) {
1783+
Opts.SwiftAsyncFramePointer = SwiftAsyncFramePointerKind::Never;
1784+
}
1785+
if (const Arg *A = Args.getLastArg(OPT_swift_async_frame_pointer_EQ)) {
1786+
StringRef mode(A->getValue());
1787+
if (mode == "auto")
1788+
Opts.SwiftAsyncFramePointer = SwiftAsyncFramePointerKind::Auto;
1789+
else if (mode == "always")
1790+
Opts.SwiftAsyncFramePointer = SwiftAsyncFramePointerKind::Always;
1791+
else if (mode == "never")
1792+
Opts.SwiftAsyncFramePointer = SwiftAsyncFramePointerKind::Never;
1793+
else {
1794+
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
1795+
A->getAsString(Args), A->getValue());
1796+
}
1797+
}
1798+
17791799
return false;
17801800
}
17811801

lib/IRGen/IRGen.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ swift::getIRTargetOptions(const IRGenOptions &Opts, ASTContext &Ctx) {
178178
TargetOpts.ThreadModel = llvm::ThreadModel::Single;
179179
}
180180

181+
switch (Opts.SwiftAsyncFramePointer) {
182+
case SwiftAsyncFramePointerKind::Never:
183+
TargetOpts.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
184+
break;
185+
case SwiftAsyncFramePointerKind::Auto:
186+
TargetOpts.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::DeploymentBased;
187+
break;
188+
case SwiftAsyncFramePointerKind::Always:
189+
TargetOpts.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
190+
break;
191+
}
192+
181193
clang::TargetOptions &ClangOpts = Clang->getTargetInfo().getTargetOpts();
182194
return std::make_tuple(TargetOpts, ClangOpts.CPU, ClangOpts.Features, ClangOpts.Triple);
183195
}

lib/SILGen/SILGenDecl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,16 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
6969
// In the address case, we forward the underlying value and store it
7070
// into memory and then create a +1 cleanup. since we assume here
7171
// that we have a +1 value since we are forwarding into memory.
72+
//
73+
// In order to ensure that we properly clean up along any failure paths, we
74+
// need to mark value as being persistently active. We then unforward it once
75+
// we are done.
7276
assert(value.isPlusOne(SGF) && "Can not store a +0 value into memory?!");
73-
value = ManagedValue::forUnmanaged(value.forward(SGF));
74-
return copyOrInitValueIntoHelper(
77+
CleanupStateRestorationScope valueScope(SGF.Cleanups);
78+
if (value.hasCleanup())
79+
valueScope.pushCleanupState(value.getCleanup(),
80+
CleanupState::PersistentlyActive);
81+
copyOrInitValueIntoHelper(
7582
SGF, loc, value, isInit, SubInitializations,
7683
[&](ManagedValue aggregate, unsigned i,
7784
SILType fieldType) -> ManagedValue {
@@ -83,6 +90,8 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
8390

8491
return SGF.emitManagedRValueWithCleanup(elt.getValue());
8592
});
93+
std::move(valueScope).pop();
94+
value.forward(SGF);
8695
}
8796

8897
void TupleInitialization::finishUninitialized(SILGenFunction &SGF) {

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ if(SWIFT_HOST_VARIANT STREQUAL "android")
3838
-latomic)
3939
endif()
4040

41+
set(SWIFT_RUNTIME_CONCURRENCY_C_FLAGS)
42+
set(SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS)
43+
44+
if(NOT swift_concurrency_async_fp_mode)
45+
set(swift_concurrency_async_fp_mode "always")
46+
endif()
47+
48+
# Don't emit extended frame info on platforms other than darwin, system
49+
# backtracer and system debugger are unlikely to support it.
50+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
51+
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS
52+
"-fswift-async-fp=${swift_concurrency_async_fp_mode}")
53+
list(APPEND SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS
54+
"-Xfrontend"
55+
"-swift-async-frame-pointer=${swift_concurrency_async_fp_mode}")
56+
else()
57+
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS "-fswift-async-fp=never")
58+
endif()
59+
4160
add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
4261
../CompatibilityOverride/CompatibilityOverride.cpp
4362
Actor.cpp
@@ -99,13 +118,14 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
99118
LINK_LIBRARIES ${swift_concurrency_link_libraries}
100119

101120
C_COMPILE_FLAGS
102-
-Dswift_Concurrency_EXPORTS
121+
-Dswift_Concurrency_EXPORTS ${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS}
103122
SWIFT_COMPILE_FLAGS
104123
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
105124
-parse-stdlib
106125
-Xfrontend -enable-experimental-concurrency
107126
-Xfrontend -define-availability
108127
-Xfrontend \"SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0\"
128+
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
109129
LINK_FLAGS "${SWIFT_RUNTIME_CONCURRENCY_SWIFT_LINK_FLAGS}"
110130
INSTALL_IN_COMPONENT stdlib
111131
)

stdlib/public/Concurrency/TaskGroup.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ static TaskGroup *asAbstract(TaskGroupImpl *group) {
456456
// Initializes into the preallocated _group an actual TaskGroupImpl.
457457
SWIFT_CC(swift)
458458
static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T) {
459+
SWIFT_TASK_DEBUG_LOG("creating task group = %p", group);
460+
459461
TaskGroupImpl *impl = new (group) TaskGroupImpl(T);
460462
auto record = impl->getTaskRecord();
461463
assert(impl == record && "the group IS the task record");
@@ -474,8 +476,7 @@ static void swift_taskGroup_initializeImpl(TaskGroup *group, const Metadata *T)
474476
SWIFT_CC(swift)
475477
static void swift_taskGroup_attachChildImpl(TaskGroup *group,
476478
AsyncTask *child) {
477-
SWIFT_TASK_DEBUG_LOG("attach child task = %p to group = %p\n",
478-
child, group);
479+
SWIFT_TASK_DEBUG_LOG("attach child task = %p to group = %p", child, group);
479480

480481
// The counterpart of this (detachChild) is performed by the group itself,
481482
// when it offers the completed (child) task's value to a waiting task -
@@ -492,11 +493,17 @@ static void swift_taskGroup_destroyImpl(TaskGroup *group) {
492493
}
493494

494495
void TaskGroupImpl::destroy() {
496+
SWIFT_TASK_DEBUG_LOG("destroying task group = %p", this);
497+
495498
// First, remove the group from the task and deallocate the record
496499
swift_task_removeStatusRecord(getTaskRecord());
497500

498-
// By the time we call destroy, all tasks inside the group must have been
499-
// awaited on already; We handle this on the swift side.
501+
// No need to drain our queue here, as by the time we call destroy,
502+
// all tasks inside the group must have been awaited on already.
503+
// This is done in Swift's withTaskGroup function explicitly.
504+
505+
// destroy the group's storage
506+
this->~TaskGroupImpl();
500507
}
501508

502509
// =============================================================================
@@ -568,7 +575,7 @@ void TaskGroupImpl::offer(AsyncTask *completedTask, AsyncContext *context) {
568575
bool hadErrorResult = false;
569576
auto errorObject = asyncContextPrefix->errorResult;
570577
if (errorObject) {
571-
// instead we need to enqueue this result:
578+
// instead, we need to enqueue this result:
572579
hadErrorResult = true;
573580
}
574581

test/Concurrency/Runtime/exclusivity_custom_executors.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// UNSUPPORTED: OS=windows-msvc
1212
// UNSUPPORTED: OS=wasi
1313

14-
// rdar://82973061
15-
// XFAIL: linux
16-
1714
// This test makes sure that we properly save/restore access when we
1815
// synchronously launch a task from a serial executor. The access from the task
1916
// should be merged into the already created access set while it runs and then
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -target x86_64-apple-macosx11 %s -S | %FileCheck -check-prefix=ALWAYS %s
2+
// RUN: %target-swift-frontend -disable-availability-checking -target x86_64-apple-macosx12 %s -S | %FileCheck -check-prefix=ALWAYS %s
3+
// RUN: %target-swift-frontend -disable-availability-checking -swift-async-frame-pointer=auto -target x86_64-apple-macosx11 %s -S | %FileCheck -check-prefix=AUTO %s
4+
// RUN: %target-swift-frontend -disable-availability-checking -swift-async-frame-pointer=auto -target x86_64-apple-macosx12 %s -S | %FileCheck -check-prefix=ALWAYS %s
5+
// RUN: %target-swift-frontend -disable-availability-checking -swift-async-frame-pointer=never -target x86_64-apple-macosx11 %s -S | %FileCheck -check-prefix=NEVER %s
6+
// RUN: %target-swift-frontend -disable-availability-checking -swift-async-frame-pointer=never -target x86_64-apple-macosx12 %s -S | %FileCheck -check-prefix=NEVER %s
7+
// RUN: %target-swift-frontend -disable-availability-checking -swift-async-frame-pointer=always -target x86_64-apple-macosx11 %s -S | %FileCheck -check-prefix=ALWAYS %s
8+
// RUN: %target-swift-frontend -disable-availability-checking -swift-async-frame-pointer=always -target x86_64-apple-macosx12 %s -S | %FileCheck -check-prefix=ALWAYS %s
9+
10+
// REQUIRES: OS=macosx
11+
12+
public func someAsyncFunction() async {
13+
}
14+
15+
// AUTO: s31swift_async_extended_frame_info17someAsyncFunctionyyYaF:
16+
// AUTO: _swift_async_extendedFramePointerFlags
17+
18+
// ALWAYS: s31swift_async_extended_frame_info17someAsyncFunctionyyYaF:
19+
// ALWAYS: btsq $60
20+
21+
// NEVER: s31swift_async_extended_frame_info17someAsyncFunctionyyYaF:
22+
// NEVER-NOT: _swift_async_extendedFramePointerFlags
23+
// NEVER-NOT: btsq $60

test/SILGen/enum.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,23 @@ func sr7799_1(bar: SR7799??) {
219219
default: print("default")
220220
}
221221
}
222+
223+
// Make sure that we handle enum, tuple initialization composed
224+
// correctly. Previously, we leaked down a failure path due to us misusing
225+
// scopes.
226+
enum rdar81817725 {
227+
case localAddress
228+
case setOption(Int, Any)
229+
230+
static func takeAny(_:Any) -> Bool { return true }
231+
232+
static func testSwitchCleanup(syscall: rdar81817725, expectedLevel: Int,
233+
valueMatcher: (Any) -> Bool)
234+
throws -> Bool {
235+
if case .setOption(expectedLevel, let value) = syscall {
236+
return rdar81817725.takeAny(value)
237+
} else {
238+
return false
239+
}
240+
}
241+
}

0 commit comments

Comments
 (0)