Files
swift-mirror/lib/AST/CaptureInfo.cpp
Chris Lattner ab43e444d6 Rework processing of @noescape closures a bit to fix rdar://19981118:
- Have Sema, not SILGen decide if a vardecl can be captured by address
  instead of by-box.  This is a non-local property that is best computed
  during capture set formation.  Sema captures this as a bit on the new
  CapturedValue entry.
- Rework some diagnostic emission to centralize a class of noescape 
  diagnostics in capture set calculation.  Previously, funcdecl closures
  produced their diagnostics there, but ClosureExprs produced them in
  MiscDiagnostics (NFC for this part).

This fixes <rdar://problem/19981118> Swift 1.2 beta 2: Closures nested in @noescape closures copy, rather than reference, captured vars.



Swift SVN r25759
2015-03-04 19:30:36 +00:00

66 lines
1.6 KiB
C++

//===--- CaptureInfo.cpp - Data Structure for Capture Lists ---------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/AST/CaptureInfo.h"
#include "swift/AST/Decl.h"
#include "llvm/Support/raw_ostream.h"
using namespace swift;
bool CaptureInfo::hasLocalCaptures() const {
for (auto capture : getCaptures())
if (capture.getDecl()->getDeclContext()->isLocalContext())
return true;
return false;
}
void CaptureInfo::
getLocalCaptures(SmallVectorImpl<CapturedValue> &Result) const {
if (!hasLocalCaptures()) return;
Result.reserve(Captures.size());
// Filter out global variables.
for (auto capture : Captures) {
if (!capture.getDecl()->getDeclContext()->isLocalContext())
continue;
Result.push_back(capture);
}
}
void CaptureInfo::dump() const {
print(llvm::errs());
llvm::errs() << '\n';
}
void CaptureInfo::print(raw_ostream &OS) const {
OS << "captures=(";
bool isFirst = true;
for (auto capture : getCaptures()) {
if (isFirst)
isFirst = false;
else
OS << ", ";
OS << capture.getDecl()->getName();
if (capture.isDirect())
OS << "<direct>";
if (capture.isNoEscape())
OS << "<noescape>";
}
OS << ')';
}