Skip to content

Commit 8300906

Browse files
committed
- Rework computation of "direct" closure capture formation to be based on whether
the DeclRefExpr's access semantics is "direct to storage" instead of basing it on the weird special case we were using before. - Change AST dumper to print the "direct" flag. NFC. Swift SVN r25749
1 parent b05268b commit 8300906

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

Diff for: lib/AST/CaptureInfo.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ void CaptureInfo::dump() const {
4646

4747
void CaptureInfo::print(raw_ostream &OS) const {
4848
OS << "captures=(";
49-
OS << getCaptures()[0].getDecl()->getName();
50-
for (auto capture : getCaptures().slice(1)) {
51-
OS << ", " << capture.getDecl()->getName();
49+
bool isFirst = true;
50+
51+
for (auto capture : getCaptures()) {
52+
if (isFirst)
53+
isFirst = false;
54+
else
55+
OS << ", ";
56+
OS << capture.getDecl()->getName();
57+
58+
if (capture.isDirect())
59+
OS << "<direct>";
5260
}
5361
OS << ')';
5462
}

Diff for: lib/SIL/TypeLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ getDeclCaptureKind(CapturedValue capture, AnyFunctionRef TheClosure) {
154154
auto decl = capture.getDecl();
155155
if (VarDecl *var = dyn_cast<VarDecl>(decl)) {
156156
// If captured directly, the variable is captured by box or pointer.
157-
if (capture.isDirect()) {
157+
if (capture.isDirect() && var->getStorageKind() != VarDecl::Stored) {
158158
assert(var->hasStorage());
159159
return TheClosure.isKnownNoEscape() ?
160160
CaptureKind::NoEscape : CaptureKind::Box;

Diff for: lib/Sema/TypeCheckExpr.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,10 @@ namespace {
708708

709709
unsigned Flags = 0;
710710

711-
// Determine whether this is a direct capture. This is a direct capture
712-
// if we're looking at an accessor capturing its underlying decl.
713-
if (const FuncDecl *FuncContext = dyn_cast<FuncDecl>(CurDC))
714-
if (auto *ASD = FuncContext->getAccessorStorageDecl())
715-
if (ASD == D)
716-
Flags |= CapturedValue::IsDirect;
711+
// If this is a direct reference to underlying storage, then this is a
712+
// capture of the storage address - not a capture of the getter/setter.
713+
if (DRE->getAccessSemantics() == AccessSemantics::DirectToStorage)
714+
Flags |= CapturedValue::IsDirect;
717715

718716
addCapture(CapturedValue(D, Flags), DRE->getStartLoc());
719717
return { false, DRE };

0 commit comments

Comments
 (0)