mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Make the static enforcement of accesses in noescape closures stored-property
sensitive. This will relax the existing enforcement so that the following is
not diagnosed:
struct MyStruct {
var x = X()
var y = Y()
mutating
func foo() {
x.mutatesAndTakesClosure() {
_ = y.read() // no-warning
}
}
}
To do this, update the access summary analysis to summarize accesses to
subpaths of a capture.
rdar://problem/32987932
53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
//===--- AccessSummaryDumper.cpp - Dump access summaries for functions -----===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#define DEBUG_TYPE "sil-access-summary-dumper"
|
|
#include "swift/SIL/SILArgument.h"
|
|
#include "swift/SIL/SILFunction.h"
|
|
#include "swift/SIL/SILInstruction.h"
|
|
#include "swift/SIL/SILValue.h"
|
|
#include "swift/SILOptimizer/Analysis/AccessSummaryAnalysis.h"
|
|
#include "swift/SILOptimizer/PassManager/Passes.h"
|
|
#include "swift/SILOptimizer/PassManager/Transforms.h"
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
using namespace swift;
|
|
|
|
namespace {
|
|
|
|
/// Dumps summaries of kinds of accesses a function performs on its
|
|
/// @inout_aliasiable arguments.
|
|
class AccessSummaryDumper : public SILModuleTransform {
|
|
|
|
void run() override {
|
|
auto *analysis = PM->getAnalysis<AccessSummaryAnalysis>();
|
|
|
|
for (auto &fn : *getModule()) {
|
|
llvm::outs() << "@" << fn.getName() << "\n";
|
|
if (fn.empty()) {
|
|
llvm::outs() << "<unknown>\n";
|
|
continue;
|
|
}
|
|
const AccessSummaryAnalysis::FunctionSummary &summary =
|
|
analysis->getOrCreateSummary(&fn);
|
|
summary.print(llvm::outs(), &fn);
|
|
llvm::outs() << "\n";
|
|
}
|
|
}
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
SILTransform *swift::createAccessSummaryDumper() {
|
|
return new AccessSummaryDumper();
|
|
}
|