Skip to content

Commit 09b5325

Browse files
authored
Merge pull request #3747 from swiftwasm/main
[pull] swiftwasm from main
2 parents 14dfa83 + 710c6b8 commit 09b5325

23 files changed

+687
-224
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,13 @@ elseif(LIBSWIFT_BUILD_MODE STREQUAL "BOOTSTRAPPING" OR LIBSWIFT_BUILD_MODE STREQ
610610
set(SWIFT_EXEC_FOR_LIBSWIFT "${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/swiftc")
611611
endif()
612612

613+
if(LIBSWIFT_BUILD_MODE STREQUAL "HOSTTOOLS" OR LIBSWIFT_BUILD_MODE STREQUAL "BOOTSTRAPPING-WITH-HOSTLIBS")
614+
if(SWIFT_ENABLE_ARRAY_COW_CHECKS)
615+
message(STATUS "array COW checks disabled when building libswift with host libraries")
616+
set(SWIFT_ENABLE_ARRAY_COW_CHECKS FALSE)
617+
endif()
618+
endif()
619+
613620
# This setting causes all CMakeLists.txt to automatically have
614621
# ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CURRENT_SOURCE_DIR} as an
615622
# include_directories path. This is done for developer

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ function(add_swift_host_tool executable)
912912
913913
# At build time link against the built swift libraries from the
914914
# previous bootstrapping stage.
915-
get_bootstrapping_swift_lib_dir(bs_lib_dir "${bootstrapping}")
915+
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
916916
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
917917
918918
# At runtime link against the built swift libraries from the current
@@ -981,7 +981,7 @@ function(add_swift_host_tool executable)
981981
elseif(LIBSWIFT_BUILD_MODE STREQUAL "BOOTSTRAPPING")
982982
# At build time link against the built swift libraries from the
983983
# previous bootstrapping stage.
984-
get_bootstrapping_swift_lib_dir(bs_lib_dir "${bootstrapping}")
984+
get_bootstrapping_swift_lib_dir(bs_lib_dir "${ASHT_BOOTSTRAPPING}")
985985
target_link_directories(${executable} PRIVATE ${bs_lib_dir})
986986
987987
# At runtime link against the built swift libraries from the current

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,8 +1600,8 @@ ERROR(originally_definedin_topleve_decl,none,
16001600
ERROR(originally_definedin_need_available,none,
16011601
"need @available attribute for @%0", (StringRef))
16021602

1603-
ERROR(originally_definedin_must_after_available_version,none,
1604-
"moved version from @%0 must after introduced OS version", (StringRef))
1603+
ERROR(originally_definedin_must_not_before_available_version,none,
1604+
"symbols are moved to the current module before they were available in the OSs", (StringRef))
16051605

16061606
// Alignment attribute
16071607
ERROR(alignment_not_power_of_two,none,

lib/SILGen/SILGenDistributed.cpp

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ static void emitDistributedActorStore_transport(
128128
SILArgument *transportArg) {
129129
auto &B = SGF.B;
130130

131-
auto &SGM = SGF.SGM;
132-
SILGenFunctionBuilder builder(SGM);
133-
134131
auto *dc = func->getDeclContext();
135132
auto classDecl = dc->getSelfClassDecl();
136133

@@ -148,42 +145,36 @@ static void emitDistributedActorStore_transport(
148145
loc, actorSelf, var,
149146
SGF.getLoweredType(var->getInterfaceType()));
150147

151-
// ==== Store the transport
152-
B.createCopyAddr(loc,
153-
/*src*/transportArg,
154-
/*dest*/fieldAddr,
155-
IsNotTake, IsInitialization);
156-
}
157-
158-
// TODO(distributed): remove this store impl and reuse Store_transport
159-
static void
160-
emitDistributedActor_init_transportStore(
161-
SILGenFunction &SGF,
162-
ManagedValue borrowedSelfArg, VarDecl *selfDecl,
163-
ConstructorDecl *ctor,
164-
Pattern *pattern, VarDecl *var) {
165-
auto &C = selfDecl->getASTContext();
166-
auto &B = SGF.B;
167-
auto &F = SGF.F;
168-
auto &SGM = SGF.SGM;
169-
SILGenFunctionBuilder builder(SGM);
170-
171-
auto loc = SILLocation(ctor);
172-
loc.markAutoGenerated();
173-
174-
// ==== Prepare assignment: get the self.transport address
175-
SILValue transportArgValue = getActorTransportArgument(C, F, ctor);
176-
177-
// ----
178-
179-
auto transportFieldAddr = B.createRefElementAddr(
180-
loc, borrowedSelfArg.getValue(), var,
181-
SGF.getLoweredType(var->getInterfaceType()));
148+
// If the argument is not existential, it will be a concrete type
149+
// that can be erased to that existential.
150+
SILValue transportValue = transportArg;
151+
if (!transportArg->getType().isExistentialType()) {
152+
auto &existentialTL = SGF.getTypeLowering(var->getInterfaceType());
153+
auto concreteFormalType = transportArg->getType().getASTType();
154+
155+
auto archetype = OpenedArchetypeType::getAny(var->getInterfaceType());
156+
AbstractionPattern abstractionPattern(archetype);
157+
auto &concreteTL = SGF.getTypeLowering(abstractionPattern,
158+
concreteFormalType);
159+
160+
auto module = dc->getParentModule();
161+
auto actorTransportProto = C.getProtocol(KnownProtocolKind::ActorTransport);
162+
ProtocolConformanceRef conformances[] = {
163+
module->lookupConformance(concreteFormalType, actorTransportProto) };
164+
ManagedValue mv = SGF.emitExistentialErasure(loc, concreteFormalType,
165+
concreteTL, existentialTL,
166+
C.AllocateCopy(conformances),
167+
SGFContext(),
168+
[&](SGFContext C) -> ManagedValue {
169+
return ManagedValue::forBorrowedRValue(transportArg);
170+
});
171+
transportValue = mv.getValue();
172+
}
182173

183174
// ==== Store the transport
184175
B.createCopyAddr(loc,
185-
/*src*/transportArgValue,
186-
/*dest*/transportFieldAddr,
176+
/*src*/transportValue,
177+
/*dest*/fieldAddr,
187178
IsNotTake, IsInitialization);
188179
}
189180

@@ -254,14 +245,17 @@ static void emitDistributedActorStore_init_assignIdentity(
254245
assert(distributedActorProto);
255246
assert(transportProto);
256247

257-
// --- Open the transport existential
258-
OpenedArchetypeType *Opened;
248+
// --- Open the transport existential, if needed.
249+
SILValue transportValue = transportArgValue;
259250
auto transportASTType = transportArgValue->getType().getASTType();
260-
auto openedTransportType =
261-
transportASTType->openAnyExistentialType(Opened)->getCanonicalType();
262-
auto openedTransportSILType = F.getLoweredType(openedTransportType);
263-
auto transportArchetypeValue = B.createOpenExistentialAddr(
264-
loc, transportArgValue, openedTransportSILType, OpenedExistentialAccess::Immutable);
251+
if (transportASTType->isAnyExistentialType()) {
252+
OpenedArchetypeType *Opened;
253+
transportASTType =
254+
transportASTType->openAnyExistentialType(Opened)->getCanonicalType();
255+
transportValue = B.createOpenExistentialAddr(
256+
loc, transportValue, F.getLoweredType(transportASTType),
257+
OpenedExistentialAccess::Immutable);
258+
}
265259

266260
// --- prepare `Self.self` metatype
267261
auto *selfTyDecl = ctor->getParent()->getSelfNominalTypeDecl();
@@ -298,7 +292,7 @@ static void emitDistributedActorStore_init_assignIdentity(
298292

299293
auto assignWitnessMethod = B.createWitnessMethod(
300294
loc,
301-
/*lookupTy*/openedTransportType,
295+
/*lookupTy*/transportASTType,
302296
/*Conformance*/transportConfRef,
303297
/*member*/assignIdentityRef,
304298
/*methodTy*/assignIdentitySILTy);
@@ -308,7 +302,7 @@ static void emitDistributedActorStore_init_assignIdentity(
308302

309303
SubstitutionMap subs =
310304
SubstitutionMap::get(genericSig,
311-
{openedTransportType, selfTy},
305+
{transportASTType, selfTy},
312306
{transportConfRef, distributedActorConfRef});
313307

314308
// --- create a temporary storage for the result of the call
@@ -319,7 +313,7 @@ static void emitDistributedActorStore_init_assignIdentity(
319313
// ---- actually call transport.assignIdentity(Self.self)
320314
B.createApply(
321315
loc, assignWitnessMethod, subs,
322-
{ temp, selfMetatypeValue, transportArchetypeValue});
316+
{ temp, selfMetatypeValue, transportValue});
323317

324318
// ==== Assign the identity to stored property
325319
// TODO(distributed): reuse emitDistributedActorStore_id here, pass the SILValue
@@ -374,9 +368,9 @@ void SILGenFunction::initializeDistributedActorImplicitStorageInit(
374368
if (var->getName() == C.Id_actorTransport &&
375369
var->getInterfaceType()->isEqual(transportTy)) {
376370
transportMember = var;
377-
// TODO(distributed): reuse emitDistributedActorStore_transport
378-
emitDistributedActor_init_transportStore(
379-
*this, borrowedSelfArg, selfVarDecl, ctor, pattern, var);
371+
emitDistributedActorStore_transport(
372+
C, *this, borrowedSelfArg.getValue(), ctor,
373+
getActorTransportArgument(C, F, ctor));
380374
} else if (var->getName() == C.Id_id &&
381375
(var->getInterfaceType()->isEqual(identityProtoTy) ||
382376
var->getInterfaceType()->isEqual(anyIdentityTy))) { // TODO(distributed): stick one way to store, but today we can't yet store the existential
@@ -417,13 +411,16 @@ void SILGenFunction::emitDistributedActorReady(
417411
assert(transportProto);
418412

419413
// --- Open the transport existential
420-
OpenedArchetypeType *Opened;
421-
auto transportASTType = transportArgValue->getType().getASTType();
422-
auto openedTransportType =
423-
transportASTType->openAnyExistentialType(Opened)->getCanonicalType();
424-
auto openedTransportSILType = F.getLoweredType(openedTransportType);
425-
auto transportArchetypeValue = B.createOpenExistentialAddr(
426-
loc, transportArgValue, openedTransportSILType, OpenedExistentialAccess::Immutable);
414+
SILValue transportValue = transportArgValue;
415+
auto transportASTType = transportValue->getType().getASTType();
416+
if (transportASTType->isAnyExistentialType()) {
417+
OpenedArchetypeType *Opened;
418+
transportASTType =
419+
transportASTType->openAnyExistentialType(Opened)->getCanonicalType();
420+
transportValue = B.createOpenExistentialAddr(
421+
loc, transportValue, F.getLoweredType(transportASTType),
422+
OpenedExistentialAccess::Immutable);
423+
}
427424

428425
// === Make the transport.actorReady call
429426
// --- prepare the witness_method
@@ -453,7 +450,7 @@ void SILGenFunction::emitDistributedActorReady(
453450

454451
auto readyWitnessMethod = B.createWitnessMethod(
455452
loc,
456-
/*lookupTy*/openedTransportType,
453+
/*lookupTy*/transportASTType,
457454
/*Conformance*/transportConfRef,
458455
/*member*/actorReadyRef,
459456
/*methodTy*/actorReadySILTy);
@@ -463,13 +460,13 @@ void SILGenFunction::emitDistributedActorReady(
463460

464461
SubstitutionMap subs =
465462
SubstitutionMap::get(genericSig,
466-
{openedTransportType, selfTy},
463+
{transportASTType, selfTy},
467464
{transportConfRef, distributedActorConfRef});
468465

469466
// ---- actually call transport.actorReady(self)
470467
B.createApply(
471468
loc, readyWitnessMethod, subs,
472-
{ selfArgValue, transportArchetypeValue});
469+
{ selfArgValue, transportValue});
473470
}
474471

475472
/******************************************************************************/

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,19 @@ bool DCE::removeDead() {
601601
// may also have been dead and a destroy_value of its baseValue may
602602
// have been inserted before the pred's terminator. Make sure to
603603
// adjust the insertPt before any destroy_value.
604+
//
605+
// FIXME: This code currently can reorder destroys, e.g., when the
606+
// block already contains a destroy_value just before the
607+
// terminator. Fix this by making note of the added
608+
// destroy_value insts and only moving the insertion point
609+
// before those that are newly added.
604610
for (SILInstruction &predInst : llvm::reverse(*pred)) {
605611
if (&predInst == predTerm)
606612
continue;
607613
if (!isa<DestroyValueInst>(&predInst)) {
608-
insertPt = &*std::next(predInst.getIterator());
609614
break;
610615
}
616+
insertPt = &predInst;
611617
}
612618
}
613619

lib/SILOptimizer/Utils/OwnershipOptUtils.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ static bool canFixUpOwnershipForRAUW(SILValue oldValue, SILValue newValue,
350350
if (oldValue.getOwnershipKind() != OwnershipKind::Guaranteed)
351351
return true;
352352

353+
SILValue newRoot = findOwnershipReferenceAggregate(newValue);
354+
if (newRoot && isa<SILFunctionArgument>(newRoot)
355+
&& newRoot->getOwnershipKind() == OwnershipKind::Guaranteed) {
356+
return true;
357+
}
353358
// Check that the old lifetime can be extended and record the necessary
354359
// book-keeping in the OwnershipFixupContext.
355360
context.clear();
@@ -870,9 +875,10 @@ SILValue
870875
OwnershipLifetimeExtender::borrowOverValue(SILValue newValue,
871876
SILValue guaranteedValue) {
872877
// Avoid borrowing guaranteed function arguments.
873-
if (isa<SILFunctionArgument>(newValue)
874-
&& newValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
875-
return newValue;
878+
if (newValue.getOwnershipKind() == OwnershipKind::Guaranteed) {
879+
SILValue newRoot = findOwnershipReferenceAggregate(newValue);
880+
if (newRoot && isa<SILFunctionArgument>(newRoot))
881+
return newValue;
876882
}
877883
auto borrowedValue = BorrowedValue(guaranteedValue);
878884
if (borrowedValue && borrowedValue.isLocalScope()) {

lib/Sema/CSRanking.cpp

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,8 +1368,14 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
13681368

13691369
// Find a potential best.
13701370
SmallVector<bool, 16> losers(viable.size(), false);
1371+
Score bestScore = viable.front().getFixedScore();
13711372
unsigned bestIdx = 0;
13721373
for (unsigned i = 1, n = viable.size(); i != n; ++i) {
1374+
auto currScore = viable[i].getFixedScore();
1375+
1376+
if (currScore < bestScore)
1377+
bestScore = currScore;
1378+
13731379
switch (compareSolutions(*this, viable, diff, i, bestIdx)) {
13741380
case SolutionCompareResult::Identical:
13751381
// FIXME: Might want to warn about this in debug builds, so we can
@@ -1424,52 +1430,14 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
14241430
return bestIdx;
14251431
}
14261432

1427-
// If there is not a single "better" than others
1428-
// solution, which probably means that solutions
1429-
// were incomparable, let's just keep the original
1430-
// list instead of removing everything, even if we
1431-
// are asked to "minimize" the result.
1432-
if (losers.size() == viable.size())
1433+
if (!minimize)
14331434
return None;
14341435

1435-
// The comparison was ambiguous. Identify any solutions that are worse than
1436-
// any other solution.
1437-
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
1438-
// If the first solution has already lost once, don't bother looking
1439-
// further.
1440-
if (losers[i])
1441-
continue;
1442-
1443-
for (unsigned j = i + 1; j != n; ++j) {
1444-
// If the second solution has already lost once, don't bother looking
1445-
// further.
1446-
if (losers[j])
1447-
continue;
1448-
1449-
switch (compareSolutions(*this, viable, diff, i, j)) {
1450-
case SolutionCompareResult::Identical:
1451-
// FIXME: Dub one of these the loser arbitrarily?
1452-
break;
1453-
1454-
case SolutionCompareResult::Better:
1455-
losers[j] = true;
1456-
break;
1457-
1458-
case SolutionCompareResult::Worse:
1459-
losers[i] = true;
1460-
break;
1461-
1462-
case SolutionCompareResult::Incomparable:
1463-
break;
1464-
}
1465-
}
1466-
}
1467-
14681436
// Remove any solution that is worse than some other solution.
14691437
unsigned outIndex = 0;
14701438
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
14711439
// Skip over the losing solutions.
1472-
if (losers[i])
1440+
if (viable[i].getFixedScore() > bestScore)
14731441
continue;
14741442

14751443
// If we have skipped any solutions, move this solution into the next
@@ -1479,6 +1447,7 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
14791447

14801448
++outIndex;
14811449
}
1450+
14821451
viable.erase(viable.begin() + outIndex, viable.end());
14831452
NumDiscardedSolutions += viable.size() - outIndex;
14841453

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,9 +3291,9 @@ void AttributeChecker::checkOriginalDefinedInAttrs(Decl *D,
32913291
AttrName);
32923292
return;
32933293
}
3294-
if (IntroVer.getValue() >= Attr->MovedVersion) {
3294+
if (IntroVer.getValue() > Attr->MovedVersion) {
32953295
diagnose(AtLoc,
3296-
diag::originally_definedin_must_after_available_version,
3296+
diag::originally_definedin_must_not_before_available_version,
32973297
AttrName);
32983298
return;
32993299
}

0 commit comments

Comments
 (0)