Skip to content

Commit 38dbbf0

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 7e6b441 + 0bd975a commit 38dbbf0

22 files changed

+242
-162
lines changed

Runtimes/Overlay/Cxx/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11

2+
include(CheckSymbolExists)
3+
check_symbol_exists(_LIBCPP_VERSION "version" HAVE_LIBCPP_VERSION)
4+
check_symbol_exists(__GLIBCXX__ "version" HAVE___GLIBCXX__)
5+
26
if(NOT APPLE)
37
add_subdirectory(cxxshim)
48
endif()
5-
if(LINUX)
9+
if(HAVE___GLIBCXX__)
610
add_subdirectory(libstdcxx)
711
endif()
812
add_subdirectory(std)

Runtimes/Overlay/Cxx/std/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ target_compile_options(swiftCxxStdlib PRIVATE
2222
target_compile_options(swiftCxxStdlib PRIVATE
2323
"$<$<PLATFORM_ID:Android>:SHELL:-Xcc --sysroot -Xcc ${CMAKE_ANDROID_NDK_TOOLCHAIN_UNIFIED}/sysroot>")
2424
target_link_libraries(swiftCxxStdlib PRIVATE
25-
$<$<PLATFORM_ID:Linux>:libstdcxx>
25+
$<$<BOOL:${HAVE___GLIBCXX__}>:libstdcxx>
2626
$<$<NOT:$<PLATFORM_ID:Darwin>>:cxxshim>
2727
swiftCxx
2828
swiftCore

include/swift/ABI/MetadataValues.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ class TargetExtendedFunctionTypeFlags {
12931293

12941294
// Values for the enumerated isolation kinds
12951295
IsolatedAny = 0x00000002U,
1296-
NonIsolatedCaller = 0x00000004U,
1296+
NonIsolatedNonsending = 0x00000004U,
12971297

12981298
// Values if we have a sending result.
12991299
HasSendingResult = 0x00000010U,
@@ -1328,7 +1328,7 @@ class TargetExtendedFunctionTypeFlags {
13281328
const TargetExtendedFunctionTypeFlags<int_type>
13291329
withNonIsolatedCaller() const {
13301330
return TargetExtendedFunctionTypeFlags<int_type>((Data & ~IsolationMask) |
1331-
NonIsolatedCaller);
1331+
NonIsolatedNonsending);
13321332
}
13331333

13341334
const TargetExtendedFunctionTypeFlags<int_type>
@@ -1352,7 +1352,7 @@ class TargetExtendedFunctionTypeFlags {
13521352
}
13531353

13541354
bool isNonIsolatedCaller() const {
1355-
return (Data & IsolationMask) == NonIsolatedCaller;
1355+
return (Data & IsolationMask) == NonIsolatedNonsending;
13561356
}
13571357

13581358
bool hasSendingResult() const {

include/swift/AST/ExtInfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ class FunctionTypeIsolation {
6767
/// Inherits isolation from the caller. This is only applicable
6868
/// to asynchronous function types.
6969
///
70-
/// NOTE: The difference in between NonIsolatedCaller and
71-
/// NonIsolated is that NonIsolatedCaller is a strictly
70+
/// NOTE: The difference in between NonIsolatedNonsending and
71+
/// NonIsolated is that NonIsolatedNonsending is a strictly
7272
/// weaker form of nonisolation. While both in their bodies cannot
73-
/// access isolated state directly, NonIsolatedCaller functions
73+
/// access isolated state directly, NonIsolatedNonsending functions
7474
/// /are/ allowed to access state isolated to their caller via
7575
/// function arguments since we know that the callee will stay
7676
/// in the caller's isolation domain. In contrast, NonIsolated
7777
/// is strongly nonisolated and is not allowed to access /any/
7878
/// isolated state (even via function parameters) since it is
7979
/// considered safe to run on /any/ actor.
80-
NonIsolatedCaller,
80+
NonIsolatedNonsending,
8181
};
8282

8383
static constexpr size_t NumBits = 3; // future-proof this slightly
@@ -103,7 +103,7 @@ class FunctionTypeIsolation {
103103
return { Kind::Erased };
104104
}
105105
static FunctionTypeIsolation forNonIsolatedCaller() {
106-
return { Kind::NonIsolatedCaller };
106+
return { Kind::NonIsolatedNonsending };
107107
}
108108

109109
Kind getKind() const { return value.getInt(); }
@@ -124,7 +124,7 @@ class FunctionTypeIsolation {
124124
return getKind() == Kind::Erased;
125125
}
126126
bool isNonIsolatedCaller() const {
127-
return getKind() == Kind::NonIsolatedCaller;
127+
return getKind() == Kind::NonIsolatedNonsending;
128128
}
129129

130130
/// Two function type isolations are equal if they have the same kind and

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6510,7 +6510,7 @@ namespace {
65106510
case FunctionTypeIsolation::Kind::Erased:
65116511
printFlag("@isolated(any)");
65126512
break;
6513-
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
6513+
case FunctionTypeIsolation::Kind::NonIsolatedNonsending:
65146514
printFlag("nonisolated(nonsending)");
65156515
break;
65166516
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3389,7 +3389,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
33893389
appendOperator("YA");
33903390
break;
33913391

3392-
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
3392+
case FunctionTypeIsolation::Kind::NonIsolatedNonsending:
33933393
appendOperator("YC");
33943394
break;
33953395
}

lib/AST/ASTPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6499,7 +6499,7 @@ class TypePrinter : public TypeVisitor<TypePrinter, void, NonRecursivePrintOptio
64996499
Printer << "@isolated(any) ";
65006500
break;
65016501

6502-
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
6502+
case FunctionTypeIsolation::Kind::NonIsolatedNonsending:
65036503
Printer << "nonisolated(nonsending) ";
65046504
break;
65056505
}

lib/IRGen/LoadableByAddress.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3927,6 +3927,13 @@ void AddressAssignment::finish(DominanceInfo *dominance,
39273927
StackNesting::fixNesting(&currFn);
39283928
}
39293929

3930+
static bool isSoleUserOf(LoadInst *load, SILInstruction *next) {
3931+
if (!load->hasOneUse())
3932+
return false;
3933+
if(load->getSingleUse()->getUser() != next)
3934+
return false;
3935+
return true;
3936+
}
39303937
namespace {
39313938
class AssignAddressToDef : SILInstructionVisitor<AssignAddressToDef> {
39323939
friend SILVisitorBase<AssignAddressToDef>;
@@ -4036,6 +4043,14 @@ class AssignAddressToDef : SILInstructionVisitor<AssignAddressToDef> {
40364043
}
40374044

40384045
void visitLoadInst(LoadInst *load) {
4046+
// Forward the address of the load if its sole user immediately follows the
4047+
// load instructions.
4048+
if (isSoleUserOf(load, &*++load->getIterator())) {
4049+
assignment.markForDeletion(load);
4050+
assignment.mapValueToAddress(origValue, load->getOperand());
4051+
return;
4052+
}
4053+
40394054
auto builder = assignment.getBuilder(load->getIterator());
40404055
auto addr = assignment.createAllocStack(load->getType());
40414056

@@ -4464,22 +4479,35 @@ class RewriteUser : SILInstructionVisitor<RewriteUser> {
44644479

44654480
void visitSwitchEnumInst(SwitchEnumInst *sw) {
44664481
auto opdAddr = assignment.getAddressForValue(sw->getOperand());
4467-
{
4482+
// UncheckedTakeEnumDataAddr is destructive. If we have a used switch target
4483+
// block argument we need to provide for a destructible location for the
4484+
// UncheckedTakeEnumDataAddr.
4485+
SILValue destructibleAddress;
4486+
auto initDestructibleAddress = [&] () -> void{
4487+
if (destructibleAddress)
4488+
return;
44684489
auto addr = assignment.createAllocStack(sw->getOperand()->getType());
44694490
// UncheckedTakeEnumDataAddr is destructive.
44704491
// So we need to copy to keep the original address location valid.
44714492
auto builder = assignment.getBuilder(sw->getIterator());
44724493
builder.createCopyAddr(sw->getLoc(), opdAddr, addr, IsTake,
44734494
IsInitialization);
4474-
opdAddr = addr;
4475-
}
4495+
destructibleAddress = addr;
4496+
};
44764497

44774498
auto loc = sw->getLoc();
44784499

44794500
auto rewriteCase = [&](EnumElementDecl *caseDecl, SILBasicBlock *caseBB) {
44804501
// Nothing to do for unused case payloads.
4481-
if (caseBB->getArguments().size() == 0)
4502+
if (caseBB->getArguments().size() == 0 ||
4503+
caseBB->getArguments()[0]->use_empty()) {
4504+
if (caseBB->getArguments().size()) {
4505+
assignment.markBlockArgumentForDeletion(caseBB);
4506+
}
44824507
return;
4508+
}
4509+
4510+
initDestructibleAddress();
44834511

44844512
assert(caseBB->getArguments().size() == 1);
44854513
SILArgument *caseArg = caseBB->getArgument(0);
@@ -4488,8 +4516,10 @@ class RewriteUser : SILInstructionVisitor<RewriteUser> {
44884516

44894517
SILBuilder caseBuilder = assignment.getBuilder(caseBB->begin());
44904518
auto *caseAddr =
4491-
caseBuilder.createUncheckedTakeEnumDataAddr(loc, opdAddr, caseDecl,
4492-
caseArg->getType().getAddressType());
4519+
caseBuilder.createUncheckedTakeEnumDataAddr(loc, destructibleAddress,
4520+
caseDecl,
4521+
caseArg->getType().getAddressType());
4522+
44934523
if (assignment.isLargeLoadableType(caseArg->getType())) {
44944524
assignment.mapValueToAddress(caseArg, caseAddr);
44954525
assignment.markBlockArgumentForDeletion(caseBB);

lib/SILGen/SILGenConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ SILGenFunction::emitFunctionTypeIsolation(SILLocation loc,
571571

572572
// Emit nonisolated by simply emitting Optional.none in the result type.
573573
case FunctionTypeIsolation::Kind::NonIsolated:
574-
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
574+
case FunctionTypeIsolation::Kind::NonIsolatedNonsending:
575575
return emitNonIsolatedIsolation(loc);
576576

577577
// Emit global actor isolation by loading .shared from the global actor,

lib/SILGen/SILGenPoly.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,10 +5485,10 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
54855485
// isolated parameter preventing us from having to memcpy over the array.
54865486
if (outputSubstType->isAsync()) {
54875487
if (outputSubstType->getIsolation().getKind() ==
5488-
FunctionTypeIsolation::Kind::NonIsolatedCaller)
5488+
FunctionTypeIsolation::Kind::NonIsolatedNonsending)
54895489
options |= ThunkGenFlag::ThunkHasImplicitIsolatedParam;
54905490
if (inputSubstType->getIsolation().getKind() ==
5491-
FunctionTypeIsolation::Kind::NonIsolatedCaller)
5491+
FunctionTypeIsolation::Kind::NonIsolatedNonsending)
54925492
options |= ThunkGenFlag::CalleeHasImplicitIsolatedParam;
54935493
}
54945494

@@ -5552,7 +5552,7 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
55525552
// For a function for caller isolation, we'll have to figure out what the
55535553
// output function's formal isolation is. This is quite doable, but we don't
55545554
// have to do it yet.
5555-
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
5555+
case FunctionTypeIsolation::Kind::NonIsolatedNonsending:
55565556
llvm_unreachable("synchronous function has caller isolation?");
55575557

55585558
// For a function with parameter isolation, we'll have to dig the
@@ -5654,7 +5654,7 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
56545654
outputIsolation.getGlobalActorType()->getCanonicalType();
56555655
return SGF.emitGlobalActorIsolation(loc, globalActor).getValue();
56565656
}
5657-
case FunctionTypeIsolation::Kind::NonIsolatedCaller: {
5657+
case FunctionTypeIsolation::Kind::NonIsolatedNonsending: {
56585658
return implicitIsolationParam.getValue();
56595659
}
56605660
case FunctionTypeIsolation::Kind::Parameter:

0 commit comments

Comments
 (0)