Skip to content

Commit 2ff8eed

Browse files
committed
---
yaml --- r: 345062 b: refs/heads/master c: 6c91760 h: refs/heads/master
1 parent bb7710c commit 2ff8eed

20 files changed

+145
-152
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ad3238f943eae0911038131386b1d5671c7f4bda
2+
refs/heads/master: 6c917606f0ebfb601173555bbab0b3bb65472df1
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Evaluator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ class Evaluator {
238238
/// diagnostics through the given diagnostics engine.
239239
Evaluator(DiagnosticEngine &diags, CycleDiagnosticKind shouldDiagnoseCycles);
240240

241+
/// Emit GraphViz output visualizing the request graph.
242+
void emitRequestEvaluatorGraphViz(llvm::StringRef graphVizPath);
243+
241244
/// Set the unified stats reporter through which evaluated-request
242245
/// statistics will be recorded.
243246
void setStatsReporter(UnifiedStatsReporter *stats) { this->stats = stats; }

trunk/include/swift/AST/TypeCheckRequests.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,31 @@ class RequirementRequest :
297297
void cacheResult(Requirement value) const;
298298
};
299299

300+
/// Generate the USR for the given declaration.
301+
class USRGenerationRequest :
302+
public SimpleRequest<USRGenerationRequest,
303+
CacheKind::Cached,
304+
std::string,
305+
const ValueDecl*>
306+
{
307+
public:
308+
using SimpleRequest::SimpleRequest;
309+
310+
private:
311+
friend class SimpleRequest;
312+
313+
// Evaluation.
314+
llvm::Expected<std::string> evaluate(Evaluator &eval, const ValueDecl* d) const;
315+
316+
public:
317+
// Cycle handling
318+
void diagnoseCycle(DiagnosticEngine &diags) const;
319+
void noteCycleStep(DiagnosticEngine &diags) const;
320+
321+
// Caching
322+
bool isCached() const { return true; }
323+
};
324+
300325
/// The zone number for the type checker.
301326
#define SWIFT_TYPE_CHECKER_REQUESTS_TYPEID_ZONE 10
302327

trunk/include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ SWIFT_TYPEID(OverriddenDeclsRequest)
2121
SWIFT_TYPEID(IsObjCRequest)
2222
SWIFT_TYPEID(IsDynamicRequest)
2323
SWIFT_TYPEID(RequirementRequest)
24+
SWIFT_TYPEID(USRGenerationRequest)

trunk/include/swift/Basic/CTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ SWIFT_TYPEID_NAMED(double, Double)
3232
SWIFT_TYPEID_NAMED(bool, Bool)
3333
SWIFT_TYPEID_NAMED(decltype(nullptr), NullPtr)
3434
SWIFT_TYPEID_NAMED(void, Void)
35+
SWIFT_TYPEID_NAMED(std::string, String)
3536

3637
// C++ standard library types.
3738
SWIFT_TYPEID_TEMPLATE1_NAMED(std::vector, Vector, typename T, T)

trunk/include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ namespace swift {
176176
CycleDiagnosticKind EvaluatorCycleDiagnostics =
177177
CycleDiagnosticKind::NoDiagnose;
178178

179+
/// \brief The path to which we should emit GraphViz output for the complete
180+
/// request-evaluator graph.
181+
std::string RequestEvaluatorGraphVizPath;
182+
179183
/// \brief The upper bound, in bytes, of temporary data that can be
180184
/// allocated by the constraint solver.
181185
unsigned SolverMemoryThreshold = 512 * 1024 * 1024;

trunk/include/swift/Basic/SimpleDisplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace swift {
4949
HAS_TRIVIAL_DISPLAY(float);
5050
HAS_TRIVIAL_DISPLAY(double);
5151
HAS_TRIVIAL_DISPLAY(bool);
52+
HAS_TRIVIAL_DISPLAY(std::string);
5253

5354
#undef HAS_TRIVIAL_DISPLAY
5455

trunk/include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ class FrontendOptions {
7272
/// The path to which we should store indexing data, if any.
7373
std::string IndexStorePath;
7474

75-
/// The path to which we should emit GraphViz output for the complete
76-
/// request-evaluator graph.
77-
std::string RequestEvaluatorGraphVizPath;
78-
7975
/// Emit index data for imported serialized swift system modules.
8076
bool IndexSystemModules = false;
8177

trunk/lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ ASTContext::ASTContext(LangOptions &langOpts, SearchPathOptions &SearchPathOpts,
518518
}
519519

520520
ASTContext::~ASTContext() {
521+
// Emit evaluator dependency graph if requested.
522+
auto graphPath = LangOpts.RequestEvaluatorGraphVizPath;
523+
if (!graphPath.empty()) {
524+
evaluator.emitRequestEvaluatorGraphViz(graphPath);
525+
}
521526
getImpl().~Implementation();
522527
}
523528

trunk/lib/AST/Evaluator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/Basic/Range.h"
1919
#include "llvm/ADT/StringExtras.h"
2020
#include "llvm/Support/Debug.h"
21+
#include "llvm/Support/FileSystem.h"
2122

2223
using namespace swift;
2324

@@ -62,6 +63,12 @@ Evaluator::Evaluator(DiagnosticEngine &diags,
6263
CycleDiagnosticKind shouldDiagnoseCycles)
6364
: diags(diags), shouldDiagnoseCycles(shouldDiagnoseCycles) { }
6465

66+
void Evaluator::emitRequestEvaluatorGraphViz(llvm::StringRef graphVizPath) {
67+
std::error_code error;
68+
llvm::raw_fd_ostream out(graphVizPath, error, llvm::sys::fs::F_Text);
69+
printDependenciesGraphviz(out);
70+
}
71+
6572
bool Evaluator::checkDependency(const AnyRequest &request) {
6673
// If there is an active request, record it's dependency on this request.
6774
if (!activeRequests.empty())

trunk/lib/AST/TypeCheckRequests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,19 @@ void RequirementRequest::cacheResult(Requirement value) const {
412412
break;
413413
}
414414
}
415+
416+
//----------------------------------------------------------------------------//
417+
// USR computation.
418+
//----------------------------------------------------------------------------//
419+
420+
void USRGenerationRequest::diagnoseCycle(DiagnosticEngine &diags) const {
421+
const auto &storage = getStorage();
422+
auto &d = std::get<0>(storage);
423+
diags.diagnose(d, diag::circular_reference);
424+
}
425+
426+
void USRGenerationRequest::noteCycleStep(DiagnosticEngine &diags) const {
427+
const auto &storage = getStorage();
428+
auto &d = std::get<0>(storage);
429+
diags.diagnose(d, diag::circular_reference);
430+
}

trunk/lib/AST/USRGeneration.cpp

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "swift/AST/USRGeneration.h"
1616
#include "swift/AST/ASTMangler.h"
1717
#include "swift/AST/SwiftNameTranslation.h"
18+
#include "swift/AST/TypeCheckRequests.h"
1819
#include "llvm/ADT/SmallString.h"
1920
#include "llvm/ADT/StringRef.h"
2021
#include "llvm/Support/raw_ostream.h"
@@ -163,13 +164,14 @@ static bool shouldUseObjCUSR(const Decl *D) {
163164
return false;
164165
}
165166

166-
bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
167+
llvm::Expected<std::string>
168+
swift::USRGenerationRequest::evaluate(Evaluator &evaluator, const ValueDecl* D) const {
167169
if (!D->hasName() && !isa<ParamDecl>(D) && !isa<AccessorDecl>(D))
168-
return true; // Ignore.
170+
return std::string(); // Ignore.
169171
if (D->getModuleContext()->isBuiltinModule())
170-
return true; // Ignore.
172+
return std::string(); // Ignore.
171173
if (isa<ModuleDecl>(D))
172-
return true; // Ignore.
174+
return std::string(); // Ignore.
173175

174176
auto interpretAsClangNode = [](const ValueDecl *D)->ClangNode {
175177
ClangNode ClangN = D->getClangNode();
@@ -200,13 +202,17 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
200202
return ClangN;
201203
};
202204

205+
llvm::SmallString<128> Buffer;
206+
llvm::raw_svector_ostream OS(Buffer);
207+
203208
if (ClangNode ClangN = interpretAsClangNode(D)) {
204-
llvm::SmallString<128> Buf;
205209
if (auto ClangD = ClangN.getAsDecl()) {
206-
bool Ignore = clang::index::generateUSRForDecl(ClangD, Buf);
207-
if (!Ignore)
208-
OS << Buf.str();
209-
return Ignore;
210+
bool Ignore = clang::index::generateUSRForDecl(ClangD, Buffer);
211+
if (!Ignore) {
212+
return Buffer.str();
213+
} else {
214+
return std::string();
215+
}
210216
}
211217

212218
auto &Importer = *D->getASTContext().getClangModuleLoader();
@@ -215,30 +221,41 @@ bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
215221
bool Ignore = clang::index::generateUSRForMacro(
216222
D->getBaseName().getIdentifier().str(),
217223
ClangMacroInfo->getDefinitionLoc(),
218-
Importer.getClangASTContext().getSourceManager(), Buf);
224+
Importer.getClangASTContext().getSourceManager(), Buffer);
219225
if (!Ignore)
220-
OS << Buf.str();
221-
return Ignore;
226+
return Buffer.str();
227+
else
228+
return std::string();
222229
}
223230

224231
if (shouldUseObjCUSR(D)) {
225-
return printObjCUSR(D, OS);
232+
if (printObjCUSR(D, OS)) {
233+
return std::string();
234+
} else {
235+
return OS.str();
236+
}
226237
}
227238

228239
if (!D->hasInterfaceType())
229-
return true;
240+
return std::string();
230241

231242
// Invalid code.
232243
if (D->getInterfaceType().findIf([](Type t) -> bool {
233244
return t->is<ModuleType>();
234245
}))
235-
return true;
246+
return std::string();
236247

237248
Mangle::ASTMangler NewMangler;
238-
std::string Mangled = NewMangler.mangleDeclAsUSR(D, getUSRSpacePrefix());
239-
240-
OS << Mangled;
249+
return NewMangler.mangleDeclAsUSR(D, getUSRSpacePrefix());
250+
}
241251

252+
bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
253+
auto result = evaluateOrDefault(D->getASTContext().evaluator,
254+
USRGenerationRequest { D },
255+
std::string());
256+
if (result.empty())
257+
return true;
258+
OS << result;
242259
return false;
243260
}
244261

trunk/lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ bool ArgsToFrontendOptionsConverter::convert(
6060
if (const Arg *A = Args.getLastArg(OPT_index_store_path)) {
6161
Opts.IndexStorePath = A->getValue();
6262
}
63-
if (const Arg *A = Args.getLastArg(OPT_output_request_graphviz)) {
64-
Opts.RequestEvaluatorGraphVizPath = A->getValue();
65-
}
6663

6764
Opts.IndexSystemModules |= Args.hasArg(OPT_index_system_modules);
6865

trunk/lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
259259
Opts.EvaluatorCycleDiagnostics = CycleDiagnosticKind::DebugDiagnose;
260260
}
261261

262+
if (const Arg *A = Args.getLastArg(OPT_output_request_graphviz)) {
263+
Opts.RequestEvaluatorGraphVizPath = A->getValue();
264+
}
265+
262266
if (const Arg *A = Args.getLastArg(OPT_solver_memory_threshold)) {
263267
unsigned threshold;
264268
if (StringRef(A->getValue()).getAsInteger(10, threshold)) {

trunk/lib/FrontendTool/FrontendTool.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -868,13 +868,6 @@ emitIndexData(CompilerInvocation &Invocation, CompilerInstance &Instance) {
868868
return hadEmitIndexDataError;
869869
}
870870

871-
/// Emits the request-evaluator graph to the given file in GraphViz format.
872-
void emitRequestEvaluatorGraphViz(ASTContext &ctx, StringRef graphVizPath) {
873-
std::error_code error;
874-
llvm::raw_fd_ostream out(graphVizPath, error, llvm::sys::fs::F_Text);
875-
ctx.evaluator.printDependenciesGraphviz(out);
876-
}
877-
878871
static bool performCompileStepsPostSILGen(
879872
CompilerInstance &Instance, CompilerInvocation &Invocation,
880873
std::unique_ptr<SILModule> SM, bool astGuaranteedToCorrespondToSIL,
@@ -917,17 +910,6 @@ static bool performCompile(CompilerInstance &Instance,
917910
Instance.performSema();
918911
}
919912

920-
SWIFT_DEFER {
921-
// Emit request-evaluator graph via GraphViz, if requested.
922-
if (!Invocation.getFrontendOptions().RequestEvaluatorGraphVizPath.empty() &&
923-
Instance.hasASTContext()) {
924-
ASTContext &ctx = Instance.getASTContext();
925-
emitRequestEvaluatorGraphViz(
926-
ctx,
927-
Invocation.getFrontendOptions().RequestEvaluatorGraphVizPath);
928-
}
929-
};
930-
931913
ASTContext &Context = Instance.getASTContext();
932914
if (Action == FrontendOptions::ActionType::Parse)
933915
return Context.hadError();

0 commit comments

Comments
 (0)