Skip to content

Commit de73f1a

Browse files
authored
Merge pull request #3724 from swiftwasm/release/5.5
[pull] swiftwasm-release/5.5 from release/5.5
2 parents b733cbf + 55992ad commit de73f1a

File tree

13 files changed

+113
-95
lines changed

13 files changed

+113
-95
lines changed

include/swift/Frontend/BackDeploymentLibs.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
BACK_DEPLOYMENT_LIB((5, 0), all, "swiftCompatibility50")
2828
BACK_DEPLOYMENT_LIB((5, 1), all, "swiftCompatibility51")
2929
BACK_DEPLOYMENT_LIB((5, 0), executable, "swiftCompatibilityDynamicReplacements")
30-
BACK_DEPLOYMENT_LIB((5, 5), all, "swiftCompatibilityConcurrency")
30+
BACK_DEPLOYMENT_LIB((5, 4), all, "swiftCompatibilityConcurrency")
3131

3232
#undef BACK_DEPLOYMENT_LIB

lib/Basic/Platform.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -395,32 +395,46 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
395395
}
396396
}
397397
} else if (Major == 11) {
398-
return floorFor64(llvm::VersionTuple(5, 3));
398+
if (Minor <= 3)
399+
return floorFor64(llvm::VersionTuple(5, 3));
400+
401+
return floorFor64(llvm::VersionTuple(5, 4));
402+
} else if (Major == 12) {
403+
return floorFor64(llvm::VersionTuple(5, 5));
399404
}
400405
} else if (Triple.isiOS()) { // includes tvOS
401406
Triple.getiOSVersion(Major, Minor, Micro);
402407

403-
auto floorFor64e = [&Triple](llvm::VersionTuple v) {
408+
auto floorForArchitecture = [&Triple, Major](llvm::VersionTuple v) {
409+
// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
410+
// with Swift 5.3
411+
if (Triple.isAArch64() && Major <= 14 &&
412+
(Triple.isSimulatorEnvironment() ||
413+
Triple.isMacCatalystEnvironment()))
414+
return MAX(v, llvm::VersionTuple(5, 3));
415+
404416
if (Triple.getArchName() != "arm64e") return v;
417+
405418
// iOS got first arm64e support in 12.0, which has a Swift runtime version
406419
// older than 5.0, so let's floor at VersionTuple(5, 0) instead.
407420
return MAX(v, llvm::VersionTuple(5, 0));
408421
};
409422

410-
// arm64 simulators and macCatalyst are introduced in iOS 14.0/tvOS 14.0
411-
// with Swift 5.3
412-
if (Triple.isAArch64() && Major <= 14 &&
413-
(Triple.isSimulatorEnvironment() || Triple.isMacCatalystEnvironment()))
414-
return floorFor64e(llvm::VersionTuple(5, 3));
415-
416423
if (Major <= 12) {
417-
return floorFor64e(llvm::VersionTuple(5, 0));
424+
return floorForArchitecture(llvm::VersionTuple(5, 0));
418425
} else if (Major <= 13) {
419426
if (Minor <= 3) {
420-
return floorFor64e(llvm::VersionTuple(5, 1));
427+
return floorForArchitecture(llvm::VersionTuple(5, 1));
421428
} else {
422-
return floorFor64e(llvm::VersionTuple(5, 2));
429+
return floorForArchitecture(llvm::VersionTuple(5, 2));
423430
}
431+
} else if (Major <= 14) {
432+
if (Minor <= 4)
433+
return floorForArchitecture(llvm::VersionTuple(5, 3));
434+
435+
return floorForArchitecture(llvm::VersionTuple(5, 4));
436+
} else if (Major <= 15) {
437+
return floorForArchitecture(llvm::VersionTuple(5, 5));
424438
}
425439
} else if (Triple.isWatchOS()) {
426440
auto floorFor64bits = [&Triple](llvm::VersionTuple v) {
@@ -438,6 +452,13 @@ swift::getSwiftRuntimeCompatibilityVersionForTarget(
438452
} else {
439453
return floorFor64bits(llvm::VersionTuple(5, 2));
440454
}
455+
} else if (Major <= 7) {
456+
if (Minor <= 4)
457+
return floorFor64bits(llvm::VersionTuple(5, 3));
458+
459+
return floorFor64bits(llvm::VersionTuple(5, 4));
460+
} else if (Major <= 8) {
461+
return floorFor64bits(llvm::VersionTuple(5, 5));
441462
}
442463
}
443464

lib/SILGen/SILGenBuilder.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,16 @@ void SILGenBuilder::emitDestructureValueOperation(
854854
}
855855
}
856856

857+
void SILGenBuilder::emitDestructureValueOperation(
858+
SILLocation loc, ManagedValue value,
859+
SmallVectorImpl<ManagedValue> &destructuredValues) {
860+
CleanupCloner cloner(*this, value);
861+
emitDestructureValueOperation(
862+
loc, value.forward(SGF), [&](unsigned index, SILValue subValue) {
863+
destructuredValues.push_back(cloner.clone(subValue));
864+
});
865+
}
866+
857867
ManagedValue SILGenBuilder::createProjectBox(SILLocation loc, ManagedValue mv,
858868
unsigned index) {
859869
auto *pbi = createProjectBox(loc, mv.getValue(), index);

lib/SILGen/SILGenBuilder.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ class SILGenBuilder : public SILBuilder {
372372
void emitDestructureValueOperation(
373373
SILLocation loc, ManagedValue value,
374374
function_ref<void(unsigned, ManagedValue)> func);
375+
void emitDestructureValueOperation(
376+
SILLocation loc, ManagedValue value,
377+
SmallVectorImpl<ManagedValue> &destructuredValues);
375378

376379
using SILBuilder::createProjectBox;
377380
ManagedValue createProjectBox(SILLocation loc, ManagedValue mv,

lib/SILGen/SILGenDecl.cpp

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -39,59 +39,42 @@ using namespace Lowering;
3939
void Initialization::_anchor() {}
4040
void SILDebuggerClient::anchor() {}
4141

42-
static void copyOrInitValueIntoHelper(
43-
SILGenFunction &SGF, SILLocation loc, ManagedValue value, bool isInit,
44-
ArrayRef<InitializationPtr> subInitializations,
45-
llvm::function_ref<ManagedValue(ManagedValue, unsigned, SILType)> func) {
46-
auto sourceType = value.getType().castTo<TupleType>();
47-
auto sourceSILType = value.getType();
48-
for (unsigned i = 0, e = sourceType->getNumElements(); i != e; ++i) {
49-
SILType fieldTy = sourceSILType.getTupleElementType(i);
50-
ManagedValue elt = func(value, i, fieldTy);
51-
subInitializations[i]->copyOrInitValueInto(SGF, loc, elt, isInit);
52-
subInitializations[i]->finishInitialization(SGF);
53-
}
54-
}
55-
5642
void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
5743
SILLocation loc,
5844
ManagedValue value, bool isInit) {
45+
// Process all values before initialization all at once to ensure all cleanups
46+
// are setup on all tuple elements before a potential early exit.
47+
SmallVector<ManagedValue, 8> destructuredValues;
48+
5949
// In the object case, emit a destructure operation and return.
6050
if (value.getType().isObject()) {
61-
return SGF.B.emitDestructureValueOperation(
62-
loc, value, [&](unsigned i, ManagedValue subValue) {
63-
auto &subInit = SubInitializations[i];
64-
subInit->copyOrInitValueInto(SGF, loc, subValue, isInit);
65-
subInit->finishInitialization(SGF);
66-
});
51+
SGF.B.emitDestructureValueOperation(loc, value, destructuredValues);
52+
} else {
53+
// In the address case, we forward the underlying value and store it
54+
// into memory and then create a +1 cleanup. since we assume here
55+
// that we have a +1 value since we are forwarding into memory.
56+
assert(value.isPlusOne(SGF) && "Can not store a +0 value into memory?!");
57+
CleanupCloner cloner(SGF, value);
58+
SILValue v = value.forward(SGF);
59+
60+
auto sourceType = value.getType().castTo<TupleType>();
61+
auto sourceSILType = value.getType();
62+
for (unsigned i : range(sourceType->getNumElements())) {
63+
SILType fieldTy = sourceSILType.getTupleElementType(i);
64+
SILValue elt = SGF.B.createTupleElementAddr(loc, v, i, fieldTy);
65+
if (!fieldTy.isAddressOnly(SGF.F)) {
66+
elt = SGF.B.emitLoadValueOperation(loc, elt,
67+
LoadOwnershipQualifier::Take);
68+
}
69+
destructuredValues.push_back(cloner.clone(elt));
70+
}
6771
}
6872

69-
// In the address case, we forward the underlying value and store it
70-
// into memory and then create a +1 cleanup. since we assume here
71-
// 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.
76-
assert(value.isPlusOne(SGF) && "Can not store a +0 value into memory?!");
77-
CleanupStateRestorationScope valueScope(SGF.Cleanups);
78-
if (value.hasCleanup())
79-
valueScope.pushCleanupState(value.getCleanup(),
80-
CleanupState::PersistentlyActive);
81-
copyOrInitValueIntoHelper(
82-
SGF, loc, value, isInit, SubInitializations,
83-
[&](ManagedValue aggregate, unsigned i,
84-
SILType fieldType) -> ManagedValue {
85-
ManagedValue elt =
86-
SGF.B.createTupleElementAddr(loc, value, i, fieldType);
87-
if (!fieldType.isAddressOnly(SGF.F)) {
88-
return SGF.B.createLoadTake(loc, elt);
89-
}
90-
91-
return SGF.emitManagedRValueWithCleanup(elt.getValue());
92-
});
93-
std::move(valueScope).pop();
94-
value.forward(SGF);
73+
for (unsigned i : indices(destructuredValues)) {
74+
SubInitializations[i]->copyOrInitValueInto(SGF, loc, destructuredValues[i],
75+
isInit);
76+
SubInitializations[i]->finishInitialization(SGF);
77+
}
9578
}
9679

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

stdlib/public/BackDeployConcurrency/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ add_compile_definitions(SWIFT_CONCURRENCY_BACK_DEPLOYMENT)
4444
set(swift_concurrency_install_component back-deployment)
4545
set(swift_concurrency_options
4646
BACK_DEPLOYMENT_LIBRARY 5.5
47-
DARWIN_INSTALL_NAME_DIR "@rpath")
47+
DARWIN_INSTALL_NAME_DIR "@rpath"
48+
LINK_FLAGS -lobjc)
4849
set(swift_concurrency_extra_sources
4950
"../BackDeployConcurrency/Exclusivity.cpp"
5051
"../BackDeployConcurrency/Metadata.cpp"

stdlib/public/BackDeployConcurrency/Exclusivity.cpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,16 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616
#include <cinttypes>
17-
18-
#include "swift/Basic/Lazy.h"
1917
#include "swift/Runtime/Exclusivity.h"
20-
#include "swift/Runtime/ThreadLocalStorage.h"
21-
#include "../runtime/ExclusivityPrivate.h"
22-
#include "../runtime/SwiftTLSContext.h"
2318

2419
using namespace swift;
25-
using namespace swift::runtime;
2620

27-
SwiftTLSContext &SwiftTLSContext::get() {
28-
SwiftTLSContext *ctx = static_cast<SwiftTLSContext *>(
29-
SWIFT_THREAD_GETSPECIFIC(SWIFT_RUNTIME_TLS_KEY));
30-
if (ctx)
31-
return *ctx;
21+
void swift::swift_task_enterThreadLocalContextBackDeploy(char *state) { }
3222

33-
static OnceToken_t setupToken;
34-
SWIFT_ONCE_F(
35-
setupToken,
36-
[](void *) {
37-
pthread_key_init_np(SWIFT_RUNTIME_TLS_KEY, [](void *pointer) {
38-
delete static_cast<SwiftTLSContext *>(pointer);
39-
});
40-
},
41-
nullptr);
23+
void swift::swift_task_exitThreadLocalContextBackDeploy(char *state) { }
4224

43-
ctx = new SwiftTLSContext();
44-
SWIFT_THREAD_SETSPECIFIC(SWIFT_RUNTIME_TLS_KEY, ctx);
45-
return *ctx;
25+
// Forcibly disable exclusivity checking, because the back-deployed concurrency
26+
// library cannot communicate with older Swift runtimes effectively.
27+
__attribute__((constructor)) static void disableExclusivityChecking() {
28+
_swift_disableExclusivityChecking = true;
4629
}
47-
48-
// Bring in the concurrency-specific exclusivity code.
49-
#include "../runtime/ConcurrencyExclusivity.inc"

test/Concurrency/Backdeploy/mangling.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
// REQUIRES: executable_test
1818
// REQUIRES: concurrency_runtime
1919

20-
// REQUIRES: rdar84218063
21-
2220
actor MyActor { }
2321

2422
protocol MyProtocol {
@@ -80,8 +78,8 @@ assert(assocIsolated(MyStruct.self) == ActorIsolatedFn.self)
8078
// NEW-NOT: call swiftcc %swift.metadata_response @"$syyScMYccMa"
8179
// NEW: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$syyScMYccMD")
8280

83-
// OLD: call swiftcc %swift.metadata_response @"$sSS4main7MyActorCYicMa"(i64 0) #3
81+
// OLD: call swiftcc %swift.metadata_response @"$sSS4main7MyActorCYicMa"(i64 0)
8482
// OLD-NOT: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$sSS4main7MyActorCYicMD")
8583

86-
// NEW-NOT: call swiftcc %swift.metadata_response @"$sSS4main7MyActorCYicMa"(i64 0) #3
84+
// NEW-NOT: call swiftcc %swift.metadata_response @"$sSS4main7MyActorCYicMa"(i64 0)
8785
// NEW: call %swift.type* @__swift_instantiateConcreteTypeFromMangledName({ i32, i32 }* @"$sSS4main7MyActorCYicMD")

test/Concurrency/Runtime/exclusivity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
// REQUIRES: concurrency_runtime
77
// UNSUPPORTED: back_deployment_runtime
8-
98
// UNSUPPORTED: OS=windows-msvc
9+
// UNSUPPORTED: use_os_stdlib
1010
// UNSUPPORTED: OS=wasi
1111

1212
// This test makes sure that:

test/Concurrency/Runtime/exclusivity_custom_executors.swift

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

14+
// UNSUPPORTED: use_os_stdlib
15+
1416
// This test makes sure that we properly save/restore access when we
1517
// synchronously launch a task from a serial executor. The access from the task
1618
// should be merged into the already created access set while it runs and then

0 commit comments

Comments
 (0)