Skip to content

Commit 7b3130b

Browse files
authored
Merge pull request #34694 from CodaFi/frontend-loader
[NFC] Spin Off Dependency Tracing Utilities From FrontendTool
2 parents e89b534 + 19e6bee commit 7b3130b

11 files changed

+984
-921
lines changed

include/swift/AST/FineGrainedDependencies.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ class BiIndexedTwoStageMap {
351351
///
352352
/// \Note The returned graph should not be escaped from the callback.
353353
bool withReferenceDependencies(
354-
llvm::PointerUnion<ModuleDecl *, SourceFile *> MSF,
354+
llvm::PointerUnion<const ModuleDecl *, const SourceFile *> MSF,
355355
const DependencyTracker &depTracker, StringRef outputPath,
356356
bool alsoEmitDotFile, llvm::function_ref<bool(SourceFileDepGraph &&)>);
357357

lib/AST/FrontendSourceFileDepGraphFactory.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,16 @@ std::string DependencyKey::computeNameForProvidedEntity<
193193
//==============================================================================
194194

195195
bool fine_grained_dependencies::withReferenceDependencies(
196-
llvm::PointerUnion<ModuleDecl *, SourceFile *> MSF,
196+
llvm::PointerUnion<const ModuleDecl *, const SourceFile *> MSF,
197197
const DependencyTracker &depTracker, StringRef outputPath,
198198
bool alsoEmitDotFile,
199199
llvm::function_ref<bool(SourceFileDepGraph &&)> cont) {
200-
if (auto *MD = MSF.dyn_cast<ModuleDecl *>()) {
200+
if (auto *MD = MSF.dyn_cast<const ModuleDecl *>()) {
201201
SourceFileDepGraph g =
202202
ModuleDepGraphFactory(MD, alsoEmitDotFile).construct();
203203
return cont(std::move(g));
204204
} else {
205-
auto *SF = MSF.get<SourceFile *>();
205+
auto *SF = MSF.get<const SourceFile *>();
206206
SourceFileDepGraph g = FrontendSourceFileDepGraphFactory(
207207
SF, outputPath, depTracker, alsoEmitDotFile)
208208
.construct();
@@ -215,22 +215,22 @@ bool fine_grained_dependencies::withReferenceDependencies(
215215
//==============================================================================
216216

217217
FrontendSourceFileDepGraphFactory::FrontendSourceFileDepGraphFactory(
218-
SourceFile *SF, StringRef outputPath, const DependencyTracker &depTracker,
219-
const bool alsoEmitDotFile)
218+
const SourceFile *SF, StringRef outputPath,
219+
const DependencyTracker &depTracker, const bool alsoEmitDotFile)
220220
: AbstractSourceFileDepGraphFactory(
221-
SF->getASTContext().hadError(),
222-
outputPath, getInterfaceHash(SF), alsoEmitDotFile,
223-
SF->getASTContext().Diags),
221+
SF->getASTContext().hadError(), outputPath, getInterfaceHash(SF),
222+
alsoEmitDotFile, SF->getASTContext().Diags),
224223
SF(SF), depTracker(depTracker) {}
225224

226225
/// Centralize the invariant that the fingerprint of the whole file is the
227226
/// interface hash
228-
std::string FrontendSourceFileDepGraphFactory::getFingerprint(SourceFile *SF) {
227+
std::string
228+
FrontendSourceFileDepGraphFactory::getFingerprint(const SourceFile *SF) {
229229
return getInterfaceHash(SF);
230230
}
231231

232232
std::string
233-
FrontendSourceFileDepGraphFactory::getInterfaceHash(SourceFile *SF) {
233+
FrontendSourceFileDepGraphFactory::getInterfaceHash(const SourceFile *SF) {
234234
llvm::SmallString<32> interfaceHash;
235235
SF->getInterfaceHash(interfaceHash);
236236
return interfaceHash.str().str();
@@ -415,7 +415,7 @@ void FrontendSourceFileDepGraphFactory::addAllDefinedDecls() {
415415
namespace {
416416
/// Extracts uses out of a SourceFile
417417
class UsedDeclEnumerator {
418-
SourceFile *SF;
418+
const SourceFile *SF;
419419
const DependencyTracker &depTracker;
420420
StringRef swiftDeps;
421421

@@ -427,16 +427,16 @@ class UsedDeclEnumerator {
427427

428428
public:
429429
UsedDeclEnumerator(
430-
SourceFile *SF, const DependencyTracker &depTracker, StringRef swiftDeps,
430+
const SourceFile *SF, const DependencyTracker &depTracker,
431+
StringRef swiftDeps,
431432
function_ref<void(const DependencyKey &, const DependencyKey &)>
432433
createDefUse)
433434
: SF(SF), depTracker(depTracker), swiftDeps(swiftDeps),
434435
sourceFileInterface(DependencyKey::createKeyForWholeSourceFile(
435436
DeclAspect::interface, swiftDeps)),
436437
sourceFileImplementation(DependencyKey::createKeyForWholeSourceFile(
437438
DeclAspect::implementation, swiftDeps)),
438-
createDefUse(createDefUse) {
439-
}
439+
createDefUse(createDefUse) {}
440440

441441
public:
442442
void enumerateAllUses() {
@@ -517,10 +517,11 @@ void FrontendSourceFileDepGraphFactory::addAllUsedDecls() {
517517
// MARK: ModuleDepGraphFactory
518518
//==============================================================================
519519

520-
ModuleDepGraphFactory::ModuleDepGraphFactory(ModuleDecl *Mod, bool emitDot)
521-
: AbstractSourceFileDepGraphFactory(
522-
Mod->getASTContext().hadError(),
523-
Mod->getNameStr(), "0xBADBEEF", emitDot, Mod->getASTContext().Diags),
520+
ModuleDepGraphFactory::ModuleDepGraphFactory(const ModuleDecl *Mod,
521+
bool emitDot)
522+
: AbstractSourceFileDepGraphFactory(Mod->getASTContext().hadError(),
523+
Mod->getNameStr(), "0xBADBEEF", emitDot,
524+
Mod->getASTContext().Diags),
524525
Mod(Mod) {}
525526

526527
void ModuleDepGraphFactory::addAllDefinedDecls() {

lib/AST/FrontendSourceFileDepGraphFactory.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,29 @@ namespace fine_grained_dependencies {
2323

2424
class FrontendSourceFileDepGraphFactory
2525
: public AbstractSourceFileDepGraphFactory {
26-
SourceFile *const SF;
26+
const SourceFile *SF;
2727
const DependencyTracker &depTracker;
2828

2929
public:
30-
FrontendSourceFileDepGraphFactory(SourceFile *SF, StringRef outputPath,
30+
FrontendSourceFileDepGraphFactory(const SourceFile *SF, StringRef outputPath,
3131
const DependencyTracker &depTracker,
3232
bool alsoEmitDotFile);
3333

3434
~FrontendSourceFileDepGraphFactory() override = default;
3535

3636
private:
37-
static std::string getFingerprint(SourceFile *SF);
38-
static std::string getInterfaceHash(SourceFile *SF);
37+
static std::string getFingerprint(const SourceFile *SF);
38+
static std::string getInterfaceHash(const SourceFile *SF);
3939

4040
void addAllDefinedDecls() override;
4141
void addAllUsedDecls() override;
4242
};
4343

4444
class ModuleDepGraphFactory : public AbstractSourceFileDepGraphFactory {
45-
ModuleDecl *const Mod;
45+
const ModuleDecl *Mod;
4646

4747
public:
48-
ModuleDepGraphFactory(ModuleDecl *Mod, bool emitDot);
48+
ModuleDepGraphFactory(const ModuleDecl *Mod, bool emitDot);
4949

5050
~ModuleDepGraphFactory() override = default;
5151

lib/FrontendTool/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ set_swift_llvm_is_available()
22
add_swift_host_library(swiftFrontendTool STATIC
33
FrontendTool.cpp
44
ImportedModules.cpp
5+
LoadedModuleTrace.cpp
6+
MakeStyleDependencies.cpp
57
ScanDependencies.cpp
68
TBD.cpp)
79
add_dependencies(swiftFrontendTool

lib/FrontendTool/Dependencies.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- Dependencies.h -- Unified header for dependnecy tracing utilies --===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_FRONTENDTOOL_DEPENDENCIES_H
14+
#define SWIFT_FRONTENDTOOL_DEPENDENCIES_H
15+
16+
namespace swift {
17+
18+
class ASTContext;
19+
class DependencyTracker;
20+
class DiagnosticEngine;
21+
class FrontendOptions;
22+
class InputFile;
23+
class ModuleDecl;
24+
25+
/// Emit the names of the modules imported by \c mainModule.
26+
bool emitImportedModules(ModuleDecl *mainModule, const FrontendOptions &opts);
27+
bool emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
28+
DependencyTracker *depTracker,
29+
const FrontendOptions &opts,
30+
const InputFile &input);
31+
bool emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
32+
DependencyTracker *depTracker,
33+
const FrontendOptions &opts,
34+
const InputFile &input);
35+
36+
} // end namespace swift
37+
38+
#endif

0 commit comments

Comments
 (0)