Skip to content

Commit 3d3507b

Browse files
author
David Ungar
committed
Remove unparsed ranges and use diffs to schedule dependents earlier.
1 parent 3cba230 commit 3d3507b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+514
-1627
lines changed

include/swift/AST/IncrementalRanges.h

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <vector>
2727

2828
namespace swift {
29-
class PersistentParserState;
3029
class SourceManager;
3130
class DiagnosticEngine;
3231
class SourceFile;
@@ -170,15 +169,12 @@ struct SwiftRangesFileContents {
170169
/// For each non-primary, the unparsed ranges in it.
171170
/// At present these represent the bodies of types defined in the nonprimary
172171
/// that are not used in the primary.
173-
RangesByFilename unparsedRangesByNonPrimary;
174172
Ranges noninlinableFunctionBodies;
175173

176-
SwiftRangesFileContents() : SwiftRangesFileContents({}, {}) {}
174+
SwiftRangesFileContents() = default;
177175

178-
SwiftRangesFileContents(RangesByFilename &&unparsedRangesByNonPrimary,
179-
Ranges &&noninlinableFunctionBodies)
180-
: unparsedRangesByNonPrimary(std::move(unparsedRangesByNonPrimary)),
181-
noninlinableFunctionBodies(std::move(noninlinableFunctionBodies)) {}
176+
SwiftRangesFileContents(Ranges &&noninlinableFunctionBodies)
177+
: noninlinableFunctionBodies(std::move(noninlinableFunctionBodies)) {}
182178

183179
/// Return None for error.
184180
static Optional<SwiftRangesFileContents>
@@ -198,8 +194,6 @@ struct llvm::yaml::MappingTraits<
198194
static void
199195
mapping(llvm::yaml::IO &io,
200196
swift::incremental_ranges::SwiftRangesFileContents &srfc) {
201-
io.mapRequired("unparsedRangesByNonPrimary",
202-
srfc.unparsedRangesByNonPrimary);
203197
io.mapRequired("noninlinableFunctionBodies",
204198
srfc.noninlinableFunctionBodies);
205199
}
@@ -218,16 +212,14 @@ namespace incremental_ranges {
218212
class SwiftRangesEmitter {
219213
const StringRef outputPath;
220214
SourceFile *const primaryFile;
221-
const PersistentParserState &persistentState;
222215
const SourceManager &sourceMgr;
223216
DiagnosticEngine &diags;
224217

225218
public:
226219
SwiftRangesEmitter(StringRef outputPath, SourceFile *primaryFile,
227-
const PersistentParserState &persistentState,
228220
const SourceManager &sourceMgr, DiagnosticEngine &diags)
229-
: outputPath(outputPath), primaryFile(primaryFile),
230-
persistentState(persistentState), sourceMgr(sourceMgr), diags(diags) {}
221+
: outputPath(outputPath), primaryFile(primaryFile), sourceMgr(sourceMgr),
222+
diags(diags) {}
231223

232224
/// True for error
233225
bool emit() const;
@@ -236,13 +228,9 @@ class SwiftRangesEmitter {
236228
void emitRanges(llvm::raw_ostream &out) const;
237229

238230
private:
239-
RangesByFilename collectSerializedUnparsedRangesByNonPrimary() const;
240-
241231
Ranges collectSortedSerializedNoninlinableFunctionBodies() const;
242232
std::vector<CharSourceRange> collectNoninlinableFunctionBodies() const;
243233

244-
std::map<std::string, std::vector<CharSourceRange>>
245-
collectUnparsedRanges() const;
246234
std::vector<CharSourceRange>
247235
sortRanges(std::vector<CharSourceRange> ranges) const;
248236

include/swift/Driver/Compilation.h

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class Compilation {
8282
const bool EnableIncrementalBuildWhenConstructed;
8383
const bool &EnableIncrementalBuild;
8484
const bool EnableSourceRangeDependencies;
85-
const bool &UseSourceRangeDependencies;
8685

8786
/// If not empty, the path to use to log the comparision.
8887
const StringRef CompareIncrementalSchemesPath;
@@ -95,38 +94,28 @@ class Compilation {
9594
private:
9695
DiagnosticEngine &Diags;
9796

98-
CommandSet DependencyCompileJobs;
99-
CommandSet SourceRangeCompileJobs;
100-
CommandSet SourceRangeLackingSuppJobs;
97+
CommandSet JobsWithoutRanges;
98+
CommandSet JobsWithRanges;
10199

102-
unsigned DependencyCompileStages = 0;
103-
unsigned SourceRangeCompileStages = 0;
100+
unsigned CompileStagesWithoutRanges = 0;
101+
unsigned CompileStagesWithRanges = 0;
104102

105103
public:
106104
IncrementalSchemeComparator(const bool &EnableIncrementalBuild,
107105
bool EnableSourceRangeDependencies,
108-
const bool &UseSourceRangeDependencies,
109106
const StringRef CompareIncrementalSchemesPath,
110107
unsigned SwiftInputCount,
111108
DiagnosticEngine &Diags)
112109
: EnableIncrementalBuildWhenConstructed(EnableIncrementalBuild),
113110
EnableIncrementalBuild(EnableIncrementalBuild),
114111
EnableSourceRangeDependencies(EnableSourceRangeDependencies),
115-
UseSourceRangeDependencies(UseSourceRangeDependencies),
116112
CompareIncrementalSchemesPath(CompareIncrementalSchemesPath),
117113
SwiftInputCount(SwiftInputCount), Diags(Diags) {}
118114

119115
/// Record scheduled jobs in support of the
120116
/// -compare-incremental-schemes[-path] options
121-
///
122-
/// \param depJobs A vector-like collection of jobs that the dependency
123-
/// scheme would run \param rangeJobs A vector-like collection of jobs that
124-
/// the range scheme would run because of changes \param lackingSuppJobs A
125-
/// vector-like collection of jobs that the range scheme would run because
126-
/// there are no incremental supplementary outputs such as swiftdeps,
127-
/// swiftranges, compiledsource
128-
void update(const CommandSet &depJobs, const CommandSet &rangeJobs,
129-
const CommandSet &lackingSuppJobs);
117+
void update(const CommandSet &withoutRangeJobs,
118+
const CommandSet &withRangeJobs);
130119

131120
/// Write the information for the -compare-incremental-schemes[-path]
132121
/// options
@@ -285,9 +274,6 @@ class Compilation {
285274
/// Experiment with source-range-based dependencies
286275
const bool EnableSourceRangeDependencies;
287276

288-
/// May not actually use them if e.g. there is a new input
289-
bool UseSourceRangeDependencies;
290-
291277
public:
292278
/// Will contain a comparator if an argument demands it.
293279
Optional<IncrementalSchemeComparator> IncrementalComparator;
@@ -408,14 +394,6 @@ class Compilation {
408394
return EnableSourceRangeDependencies;
409395
}
410396

411-
bool getUseSourceRangeDependencies() const {
412-
return UseSourceRangeDependencies;
413-
}
414-
415-
void setUseSourceRangeDependencies(bool use) {
416-
UseSourceRangeDependencies = use;
417-
}
418-
419397
bool getBatchModeEnabled() const {
420398
return EnableBatchMode;
421399
}
@@ -515,14 +493,6 @@ class Compilation {
515493
/// How many .swift input files?
516494
unsigned countSwiftInputs() const;
517495

518-
void updateIncrementalComparison(const CommandSet &depJobs,
519-
const CommandSet &rangeJobs,
520-
const CommandSet &lackingSuppJobs) {
521-
if (IncrementalComparator.hasValue())
522-
IncrementalComparator.getValue().update(depJobs, rangeJobs,
523-
lackingSuppJobs);
524-
}
525-
526496
private:
527497
/// Perform all jobs.
528498
///

include/swift/Driver/DependencyGraph.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ class DependencyGraphImpl {
165165
void markExternal(SmallVectorImpl<const void *> &visited,
166166
StringRef externalDependency);
167167

168-
public: // for ranges
169-
size_t countTopLevelProvides(const void *) const;
170-
168+
public:
171169
void forEachUnmarkedJobDirectlyDependentOnExternalSwiftdeps(
172170
StringRef externalDependency, function_ref<void(const void *)> fn);
173171

include/swift/Driver/DriverIncrementalRanges.h

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,34 @@ namespace incremental_ranges {
3636
/// A per-primary collection of information about its source ranges.
3737

3838
class SourceRangeBasedInfo {
39-
SwiftRangesFileContents swiftRangesFileContents;
39+
const std::string primaryInputPath;
40+
const SwiftRangesFileContents swiftRangesFileContents;
4041
/// All changed ranges in the primary as computed by the diff in the driver
4142
/// Both relative to the previously-compiled and the current source.
42-
SourceComparator::LRRanges changedRanges;
43+
const SourceComparator::LRRanges changedRanges;
4344
/// All of the non-local changes in the previously-compiled code: those
4445
/// residing outside function bodies.
4546
/// (We only have and only need function-body ranges for the
4647
/// previously-compiled source.)
47-
Ranges nonlocalChangedRanges;
48+
const Ranges nonlocalChangedRanges;
4849

4950
//==============================================================================
5051
// MARK: construction
5152
//==============================================================================
5253

5354
public:
54-
/// return hadError and info
55-
static llvm::StringMap<SourceRangeBasedInfo>
56-
loadAllInfo(const driver::Compilation &);
55+
static Optional<SourceRangeBasedInfo>
56+
loadInfoForOneJob(const driver::Job *cmd,
57+
const bool showIncrementalBuildDecisions,
58+
DiagnosticEngine &diags);
5759

5860
SourceRangeBasedInfo(SourceRangeBasedInfo &&);
5961

6062
private:
61-
SourceRangeBasedInfo(SwiftRangesFileContents &&,
63+
SourceRangeBasedInfo(StringRef primaryInputPath, SwiftRangesFileContents &&,
6264
SourceComparator::LRRanges &&changedRanges,
6365
Ranges &&nonlocalChangedRanges);
6466

65-
static Optional<SourceRangeBasedInfo> wholeFileChanged();
66-
6767
/// Using supplied paths, interrogate the supplementary outputs and update the
6868
/// two references. Return None if a file was missing or corrupted.
6969
static Optional<SourceRangeBasedInfo>
@@ -93,37 +93,29 @@ class SourceRangeBasedInfo {
9393
//==============================================================================
9494
// MARK: scheduling jobs
9595
//==============================================================================
96-
9796
public:
98-
static bool shouldScheduleCompileJob(
99-
const llvm::StringMap<SourceRangeBasedInfo> &allInfos,
100-
const driver::Job *, function_ref<void(bool, Twine)>);
97+
bool
98+
didInputChangeAtAll(DiagnosticEngine &,
99+
function_ref<void(bool, StringRef)> noteBuilding) const;
100+
bool didInputChangeNonlocally(
101+
DiagnosticEngine &,
102+
function_ref<void(bool, StringRef)> noteInitiallyCascading) const;
101103

102104
private:
103105
static Optional<bool> isFileNewerThan(StringRef lhs, StringRef rhs,
104106
DiagnosticEngine&);
105107

106-
private:
107-
/// Return hadError
108-
109-
bool didPrimaryParseAnyNonlocalNonprimaryChanges(
110-
StringRef primary, const llvm::StringMap<SourceRangeBasedInfo> &,
111-
function_ref<void(bool, Twine)>) const;
112-
113-
bool wasEveryNonprimaryNonlocalChangeUnparsed(
114-
StringRef primary, const llvm::StringMap<SourceRangeBasedInfo> &,
115-
function_ref<void(bool, Twine)>) const;
116108

117109
//==============================================================================
118110
// MARK: printing
119111
//==============================================================================
120112

121113
public:
122-
static void dumpAllInfo(const llvm::StringMap<SourceRangeBasedInfo> &,
123-
bool dumpCompiledSourceDiffs, bool dumpSwiftRanges);
114+
void dump(bool dumpCompiledSourceDiffs = true,
115+
bool dumpSwiftRanges = true) const;
124116

125117
private:
126-
void dumpChangedRanges(StringRef primary) const;
118+
void dumpChangedRanges() const;
127119
};
128120

129121
} // namespace incremental_ranges

include/swift/Driver/ExperimentalDependencyDriverGraph.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ class ModuleDepGraph {
267267
assert(verify() && "ModuleDepGraph should be fine when created");
268268
}
269269

270+
/// Unlike the standard \c DependencyGraph, returns \c
271+
/// DependencyGraphImpl::LoadResult::AffectsDownstream when loading a new
272+
/// file, i.e. when determining the initial set. Caller compensates.
270273
DependencyGraphImpl::LoadResult loadFromPath(const driver::Job *, StringRef,
271274
DiagnosticEngine &);
272275

@@ -286,10 +289,6 @@ class ModuleDepGraph {
286289
forEachMatchingNode(const DependencyKey &key,
287290
function_ref<void(const ModuleDepGraphNode *)>) const;
288291

289-
public:
290-
// Interface to source-range incremental system
291-
size_t countTopLevelProvides(const driver::Job *);
292-
293292
public:
294293
// This section contains the interface to the status quo code in the driver.
295294

include/swift/Parse/PersistentParserState.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ class PersistentParserState {
128128
MarkedPos = ParserPosition();
129129
return Pos;
130130
}
131-
132-
void forEachDelayedSourceRange(const SourceFile *primaryFile,
133-
function_ref<void(SourceRange)>) const;
134131
};
135132

136133
} // end namespace swift

lib/AST/IncrementalRanges.cpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/AST/SourceFile.h"
2626
#include "swift/Basic/SourceManager.h"
2727
#include "swift/Parse/Lexer.h"
28-
#include "swift/Parse/PersistentParserState.h"
2928
#include "llvm/Support/YAMLParser.h"
3029

3130
using namespace swift;
@@ -194,26 +193,11 @@ bool SwiftRangesEmitter::emit() const {
194193

195194
void SwiftRangesEmitter::emitRanges(llvm::raw_ostream &out) const {
196195
SwiftRangesFileContents wholeFileContents(
197-
collectSerializedUnparsedRangesByNonPrimary(),
198196
collectSortedSerializedNoninlinableFunctionBodies());
199197
llvm::yaml::Output yamlWriter(out);
200198
yamlWriter << wholeFileContents;
201199
}
202200

203-
RangesByFilename
204-
SwiftRangesEmitter::collectSerializedUnparsedRangesByNonPrimary() const {
205-
auto rangesByNonprimary = collectUnparsedRanges();
206-
std::map<std::string, std::vector<SerializableSourceRange>>
207-
serializedRangesByNonprimary;
208-
// The driver counts on getting coalescedSortedRanges because it
209-
// does binary chop searches
210-
for (auto &nonPriAndRanges : rangesByNonprimary)
211-
serializedRangesByNonprimary.insert(
212-
{nonPriAndRanges.first, serializeRanges(coalesceSortedRanges(sortRanges(
213-
std::move(nonPriAndRanges.second))))});
214-
return serializedRangesByNonprimary;
215-
}
216-
217201
Ranges
218202
SwiftRangesEmitter::collectSortedSerializedNoninlinableFunctionBodies() const {
219203
return serializeRanges(
@@ -249,20 +233,6 @@ SwiftRangesEmitter::collectNoninlinableFunctionBodies() const {
249233
return collector.ranges;
250234
}
251235

252-
std::map<std::string, std::vector<CharSourceRange>>
253-
SwiftRangesEmitter::collectUnparsedRanges() const {
254-
std::map<std::string, std::vector<CharSourceRange>> rangesByNonprimaryFile;
255-
persistentState.forEachDelayedSourceRange(
256-
primaryFile, [&](const SourceRange sr) {
257-
const auto filename = sourceMgr.getIdentifierForBuffer(
258-
sourceMgr.findBufferContainingLoc(sr.Start));
259-
const auto csr =
260-
Lexer::getCharSourceRangeFromSourceRange(sourceMgr, sr);
261-
rangesByNonprimaryFile[filename].push_back(csr);
262-
});
263-
return rangesByNonprimaryFile;
264-
}
265-
266236
std::vector<CharSourceRange>
267237
SwiftRangesEmitter::sortRanges(std::vector<CharSourceRange> ranges) const {
268238
std::sort(ranges.begin(), ranges.end(),
@@ -331,9 +301,9 @@ bool CompiledSourceEmitter::emit() {
331301
// MARK: SwiftRangesFileContents
332302
//==============================================================================
333303

334-
void SwiftRangesFileContents::dump(const StringRef primaryFilename) const {
335-
llvm::errs() << "\n*** Swift range file contents for '" << primaryFilename
336-
<< "': ***\n";
304+
void SwiftRangesFileContents::dump(const StringRef primaryInputFilename) const {
305+
llvm::errs() << "\n*** Swift range file contents for '"
306+
<< primaryInputFilename << "': ***\n";
337307
llvm::yaml::Output dumper(llvm::errs());
338308
dumper << *const_cast<SwiftRangesFileContents *>(this);
339309
}

0 commit comments

Comments
 (0)