Skip to content

Commit 794a3d7

Browse files
author
David Ungar
authored
Merge pull request #16669 from davidungar/refdep-refactor
NFC, [Incremental Compilation] Refactor ReferenceDependencies
2 parents 83f68da + a14a873 commit 794a3d7

File tree

8 files changed

+707
-400
lines changed

8 files changed

+707
-400
lines changed

docs/DependencyAnalysis.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ External Dependencies
9191
=====================
9292

9393
External dependencies, including imported Swift module files and Clang headers,
94-
are tracked using a special ``depends-external`` set. The Swift driver
94+
are tracked using a special ``depends-external`` set. These dependencies refer
95+
to files that are external to the module. The Swift driver
9596
interprets this set specially and decides whether or not the cross-module
9697
dependencies have changed.
9798

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ class SourceFile final : public FileUnit {
977977
ReferencedNameTracker *getReferencedNameTracker() {
978978
return ReferencedNames ? ReferencedNames.getPointer() : nullptr;
979979
}
980+
const ReferencedNameTracker *getReferencedNameTracker() const {
981+
return ReferencedNames ? ReferencedNames.getPointer() : nullptr;
982+
}
983+
980984
void createReferencedNameTracker();
981985

982986
/// \brief The buffer ID for the file that was imported, or None if there

include/swift/Driver/DependencyGraph.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,16 @@ class DependencyGraphImpl {
123123
/// The set of marked nodes.
124124
llvm::SmallPtrSet<const void *, 16> Marked;
125125

126-
/// A list of all "external" dependencies that cannot be resolved just from
127-
/// this dependency graph.
126+
/// A list of all external dependencies that cannot be resolved from just this
127+
/// dependency graph. Each member of the set is the name of a file which is
128+
/// not in the module. These files' contents may (or may not) have affected
129+
/// the module's compilation. This list may even include the paths of
130+
/// non-existent files whose absence is significant.
131+
///
132+
/// Furthermore, this set might not exhaustive. It only includes dependencies
133+
/// that will be checked by the driver's incremental mode.
134+
/// For example, it might excludes headers in the SDK if the cost
135+
/// of `stat`ing them were to outweigh the likelihood that they would change.
128136
llvm::StringSet<> ExternalDependencies;
129137

130138
/// The interface hash for each node. This determines if the interface of
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===--- ReferenceDependencyKeys.h - Keys for swiftdeps files ---*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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_REFERENCEDEPENDENCYKEYS_H
14+
#define SWIFT_FRONTENDTOOL_REFERENCEDEPENDENCYKEYS_H
15+
16+
#include "swift/Basic/LLVM.h"
17+
#include "llvm/ADT/StringRef.h"
18+
19+
namespace swift {
20+
/// Define these string constants for reference dependencies (a.k.a. swiftdeps)
21+
/// in one place to ensure consistency.
22+
namespace reference_dependency_keys {
23+
static constexpr StringLiteral providesTopLevel("provides-top-level");
24+
static constexpr StringLiteral providesNominal("provides-nominal");
25+
static constexpr StringLiteral providesMember("provides-member");
26+
static constexpr StringLiteral providesDynamicLookup("provides-dynamic-lookup");
27+
28+
static constexpr StringLiteral dependsTopLevel("depends-top-level");
29+
static constexpr StringLiteral dependsMember("depends-member");
30+
static constexpr StringLiteral dependsNominal("depends-nominal");
31+
static constexpr StringLiteral dependsDynamicLookup("depends-dynamic-lookup");
32+
static constexpr StringLiteral dependsExternal("depends-external");
33+
34+
static constexpr StringLiteral interfaceHash("interface-hash");
35+
} // end namespace reference_dependency_keys
36+
} // end namespace swift
37+
38+
#endif

lib/Driver/DependencyGraph.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "swift/Basic/Statistic.h"
1414
#include "swift/Driver/DependencyGraph.h"
1515
#include "swift/Demangling/Demangle.h"
16+
#include "swift/Frontend/ReferenceDependencyKeys.h"
1617
#include "llvm/ADT/SmallString.h"
1718
#include "llvm/ADT/SmallVector.h"
1819
#include "llvm/ADT/StringSwitch.h"
@@ -99,7 +100,9 @@ parseDependencyFile(llvm::MemoryBuffer &buffer,
99100
return LoadResult::HadError;
100101
StringRef keyString = key->getValue(scratch);
101102

102-
if (keyString == "interface-hash") {
103+
using namespace reference_dependency_keys;
104+
105+
if (keyString == interfaceHash) {
103106
auto *value = dyn_cast<yaml::ScalarNode>(i->getValue());
104107
if (!value)
105108
return LoadResult::HadError;
@@ -115,31 +118,31 @@ parseDependencyFile(llvm::MemoryBuffer &buffer,
115118
using KindPair = std::pair<DependencyKind, DependencyDirection>;
116119

117120
KindPair dirAndKind = llvm::StringSwitch<KindPair>(key->getValue(scratch))
118-
.Case("depends-top-level",
121+
.Case(dependsTopLevel,
119122
std::make_pair(DependencyKind::TopLevelName,
120123
DependencyDirection::Depends))
121-
.Case("depends-nominal",
124+
.Case(dependsNominal,
122125
std::make_pair(DependencyKind::NominalType,
123126
DependencyDirection::Depends))
124-
.Case("depends-member",
127+
.Case(dependsMember,
125128
std::make_pair(DependencyKind::NominalTypeMember,
126129
DependencyDirection::Depends))
127-
.Case("depends-dynamic-lookup",
130+
.Case(dependsDynamicLookup,
128131
std::make_pair(DependencyKind::DynamicLookupName,
129132
DependencyDirection::Depends))
130-
.Case("depends-external",
133+
.Case(dependsExternal,
131134
std::make_pair(DependencyKind::ExternalFile,
132135
DependencyDirection::Depends))
133-
.Case("provides-top-level",
136+
.Case(providesTopLevel,
134137
std::make_pair(DependencyKind::TopLevelName,
135138
DependencyDirection::Provides))
136-
.Case("provides-nominal",
139+
.Case(providesNominal,
137140
std::make_pair(DependencyKind::NominalType,
138141
DependencyDirection::Provides))
139-
.Case("provides-member",
142+
.Case(providesMember,
140143
std::make_pair(DependencyKind::NominalTypeMember,
141144
DependencyDirection::Provides))
142-
.Case("provides-dynamic-lookup",
145+
.Case(providesDynamicLookup,
143146
std::make_pair(DependencyKind::DynamicLookupName,
144147
DependencyDirection::Provides))
145148
.Default(std::make_pair(DependencyKind(),

0 commit comments

Comments
 (0)