Skip to content

Commit 756d440

Browse files
authored
Merge pull request #66196 from gottesmm/release-5.9-more-stuff-2
[5.9] More batched changes
2 parents 7203d52 + 20a9b1b commit 756d440

35 files changed

+3373
-84
lines changed

include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,10 @@ ERROR(sil_movechecking_value_used_after_consume, none,
758758
"'%0' used after consume", (StringRef))
759759
ERROR(sil_movechecking_guaranteed_value_consumed, none,
760760
"'%0' is borrowed and cannot be consumed", (StringRef))
761-
762-
// FIXME: this diagnostic shouldn't ever be emitted now. rdar://109742587 (closures may still try to consume captures, e.g., borrowed parameters)
763-
ERROR(sil_movechecking_guaranteed_value_captured_by_closure, none,
764-
"'%0' is borrowed and cannot be consumed by closure capture", (StringRef))
765-
761+
ERROR(sil_movechecking_borrowed_parameter_captured_by_closure, none,
762+
"'%0' cannot be captured by an escaping closure since it is a borrowed "
763+
"parameter",
764+
(StringRef))
766765
ERROR(sil_movechecking_capture_consumed, none,
767766
"noncopyable '%0' cannot be consumed when captured by a closure", (StringRef))
768767
ERROR(sil_movechecking_inout_not_reinitialized_before_end_of_function, none,

include/swift/SIL/SILFunctionConventions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ class SILFunctionConventions {
371371
return getNumIndirectSILResults();
372372
}
373373

374+
/// Returns the index of self.
375+
unsigned getSILArgIndexOfSelf() const {
376+
return getSILArgIndexOfFirstParam() + getNumParameters() - 1;
377+
}
378+
374379
/// Get the index into formal indirect results corresponding to the given SIL
375380
/// indirect result argument index.
376381
unsigned getIndirectFormalResultIndexForSILArg(unsigned argIdx) const {

include/swift/SIL/SILMoveOnlyDeinit.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ class SILMoveOnlyDeinit final : public SILAllocated<SILMoveOnlyDeinit> {
6363

6464
SILFunction *getImplementation() const { return funcImpl; }
6565

66-
bool isSerialized() const { return serialized; }
66+
IsSerialized_t isSerialized() const {
67+
return serialized ? IsSerialized : IsNotSerialized;
68+
}
69+
void setSerialized(IsSerialized_t inputSerialized) {
70+
serialized = inputSerialized ? 1 : 0;
71+
}
6772

6873
void print(llvm::raw_ostream &os, bool verbose) const;
6974
void dump() const;

include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,9 @@ class CanonicalizeOSSALifetime final {
319319
liveness->initializeDef(getCurrentDef());
320320
}
321321

322-
void invalidateLiveness() {
322+
void clear() {
323323
consumingBlocks.clear();
324324
debugValues.clear();
325-
liveness->invalidate();
326325
discoveredBlocks.clear();
327326
}
328327

lib/IRGen/GenType.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,19 +2887,26 @@ static bool tryEmitDeinitCall(IRGenFunction &IGF,
28872887
llvm::function_ref<void ()> indirectCleanup) {
28882888
auto ty = T.getASTType();
28892889
auto nominal = ty->getAnyNominal();
2890+
28902891
// We are only concerned with move-only type deinits here.
28912892
if (!nominal || !nominal->getValueTypeDestructor()) {
28922893
return false;
28932894
}
2894-
2895-
auto deinit = IGF.getSILModule().lookUpMoveOnlyDeinit(nominal);
2896-
assert(deinit && "type has a deinit declared in AST but SIL deinit record is not present!");
2897-
2895+
2896+
auto deinitTable = IGF.getSILModule().lookUpMoveOnlyDeinit(nominal);
2897+
2898+
// If we do not have a deinit table, call the value witness instead.
2899+
if (!deinitTable) {
2900+
irgen::emitDestroyCall(IGF, T, indirect());
2901+
indirectCleanup();
2902+
return true;
2903+
}
2904+
28982905
// The deinit should take a single value parameter of the nominal type, either
28992906
// by @owned or indirect @in convention.
2900-
auto deinitFn = IGF.IGM.getAddrOfSILFunction(deinit->getImplementation(),
2907+
auto deinitFn = IGF.IGM.getAddrOfSILFunction(deinitTable->getImplementation(),
29012908
NotForDefinition);
2902-
auto deinitTy = deinit->getImplementation()->getLoweredFunctionType();
2909+
auto deinitTy = deinitTable->getImplementation()->getLoweredFunctionType();
29032910
auto deinitFP = FunctionPointer::forDirect(IGF.IGM, deinitFn,
29042911
nullptr, deinitTy);
29052912
assert(deinitTy->getNumParameters() == 1

lib/SILGen/ArgumentSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class ArgumentSource {
280280

281281
ArgumentSource copyForDiagnostics() const;
282282

283-
void dump() const;
283+
LLVM_DUMP_METHOD void dump() const;
284284
void dump(raw_ostream &os, unsigned indent = 0) const;
285285

286286
private:

lib/SILGen/SILGen.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,11 +1079,6 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
10791079
preEmitFunction(constant, f, loc);
10801080
PrettyStackTraceSILFunction X("silgen emitDeallocatingDestructor", f);
10811081
SILGenFunction(*this, *f, dd).emitDeallocatingDestructor(dd);
1082-
1083-
// If we have a move only type, create the table for this type.
1084-
if (nom->isMoveOnly())
1085-
SILMoveOnlyDeinit::create(f->getModule(), nom, IsNotSerialized, f);
1086-
10871082
postEmitFunction(constant, f);
10881083
return;
10891084
}

lib/SILGen/SILGen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
459459
SILFunction *jvp, SILFunction *vjp,
460460
const DeclAttribute *diffAttr);
461461

462+
/// Emit a deinit table for a noncopyable type.
463+
void emitNonCopyableTypeDeinitTable(NominalTypeDecl *decl);
464+
462465
/// Known functions for bridging.
463466
SILDeclRef getStringToNSStringFn();
464467
SILDeclRef getNSStringToStringFn();

lib/SILGen/SILGenApply.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3029,7 +3029,8 @@ static StorageRefResult findStorageReferenceExprForBorrow(Expr *e) {
30293029
return result.withTransitiveRoot(te);
30303030

30313031
} else if (auto ioe = dyn_cast<InOutExpr>(e)) {
3032-
return ioe;
3032+
if (auto result = findStorageReferenceExprForBorrow(ioe->getSubExpr()))
3033+
return result.withTransitiveRoot(ioe);
30333034
}
30343035

30353036
return StorageRefResult();
@@ -3049,6 +3050,24 @@ Expr *ArgumentSource::findStorageReferenceExprForMoveOnly(
30493050
sawLoad = true;
30503051
}
30513052

3053+
// If we have a subscript, strip it off and make sure that our base is
3054+
// something that we can process. If we do and we succeed below, we return the
3055+
// subscript instead.
3056+
SubscriptExpr *subscriptExpr = nullptr;
3057+
if ((subscriptExpr = dyn_cast<SubscriptExpr>(argExpr))) {
3058+
auto *decl = cast<SubscriptDecl>(subscriptExpr->getDecl().getDecl());
3059+
if (decl->getReadImpl() != ReadImplKind::Read) {
3060+
subscriptExpr = nullptr;
3061+
} else {
3062+
argExpr = subscriptExpr->getBase();
3063+
}
3064+
3065+
// If there's a load on the base of the subscript expr, look past it.
3066+
if (auto *li = dyn_cast<LoadExpr>(argExpr)) {
3067+
argExpr = li->getSubExpr();
3068+
}
3069+
}
3070+
30523071
// If we're consuming instead, then the load _must_ have been there.
30533072
if (kind == StorageReferenceOperationKind::Consume && !sawLoad)
30543073
return nullptr;
@@ -3097,6 +3116,12 @@ Expr *ArgumentSource::findStorageReferenceExprForMoveOnly(
30973116
// has a move only base.
30983117
(void)std::move(*this).asKnownExpr();
30993118

3119+
// If we saw a subscript expr and the base of the subscript expr passed our
3120+
// tests above, we can emit the call to the subscript directly as a borrowed
3121+
// lvalue. Return the subscript expr here so that we emit it appropriately.
3122+
if (subscriptExpr)
3123+
return subscriptExpr;
3124+
31003125
return result.getTransitiveRoot();
31013126
}
31023127

lib/SILGen/SILGenDecl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,13 +1958,19 @@ InitializationPtr SILGenFunction::emitLocalVariableWithCleanup(
19581958
std::unique_ptr<TemporaryInitialization>
19591959
SILGenFunction::emitTemporary(SILLocation loc, const TypeLowering &tempTL) {
19601960
SILValue addr = emitTemporaryAllocation(loc, tempTL.getLoweredType());
1961+
if (addr->getType().isMoveOnly())
1962+
addr = B.createMarkMustCheckInst(
1963+
loc, addr, MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
19611964
return useBufferAsTemporary(addr, tempTL);
19621965
}
19631966

19641967
std::unique_ptr<TemporaryInitialization>
19651968
SILGenFunction::emitFormalAccessTemporary(SILLocation loc,
19661969
const TypeLowering &tempTL) {
19671970
SILValue addr = emitTemporaryAllocation(loc, tempTL.getLoweredType());
1971+
if (addr->getType().isMoveOnly())
1972+
addr = B.createMarkMustCheckInst(
1973+
loc, addr, MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
19681974
CleanupHandle cleanup =
19691975
enterDormantFormalAccessTemporaryCleanup(addr, loc, tempTL);
19701976
return std::unique_ptr<TemporaryInitialization>(

0 commit comments

Comments
 (0)