Skip to content

Commit 1f4dfce

Browse files
author
David Ungar
committed
Add -enable-experimental-dependencies and push it through.
1 parent 4710c43 commit 1f4dfce

File tree

13 files changed

+80
-23
lines changed

13 files changed

+80
-23
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,10 @@ class alignas(1 << DeclAlignInBits) Decl {
958958
assert(Mem);
959959
return Mem;
960960
}
961+
962+
/// Scaffolding to permit experimentation with finer-grained dependencies and
963+
/// faster rebuilds.
964+
bool getEnableExperimentalDependencies() const;
961965
};
962966

963967
/// \brief Use RAII to track Decl validation progress and non-reentrancy.

include/swift/AST/DeclContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
524524
LLVM_READONLY
525525
ASTContext &getASTContext() const;
526526

527+
/// Scaffolding to permit experimentation with finer-grained dependencies and
528+
/// faster rebuilds.
529+
bool getEnableExperimentalDependencies() const;
530+
527531
/// Retrieve the set of protocols whose conformances will be
528532
/// associated with this declaration context.
529533
///

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ namespace swift {
288288
/// Whether to verify the parsed syntax tree and emit related diagnostics.
289289
bool VerifySyntaxTree = false;
290290

291+
/// Scaffolding to permit experimentation with finer-grained dependencies
292+
/// and faster rebuilds.
293+
bool EnableExperimentalDependencies = false;
294+
291295
/// Sets the target we are building for and updates platform conditions
292296
/// to match.
293297
///

include/swift/Driver/Compilation.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ class Compilation {
206206
/// limit filelists will be used.
207207
size_t FilelistThreshold;
208208

209+
/// Scaffolding to permit experimentation with finer-grained dependencies and
210+
/// faster rebuilds.
211+
const bool EnableExperimentalDependencies;
212+
209213
template <typename T>
210214
static T *unwrap(const std::unique_ptr<T> &p) {
211215
return p.get();
@@ -234,7 +238,8 @@ class Compilation {
234238
Optional<unsigned> BatchSizeLimit = None,
235239
bool SaveTemps = false,
236240
bool ShowDriverTimeCompilation = false,
237-
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr);
241+
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr,
242+
bool EnableExperimentalDependencies = false);
238243
~Compilation();
239244

240245
ToolChain const &getToolChain() const {
@@ -289,6 +294,10 @@ class Compilation {
289294
EnableIncrementalBuild = false;
290295
}
291296

297+
bool getEnableExperimentalDependencies() const {
298+
return EnableExperimentalDependencies;
299+
}
300+
292301
bool getBatchModeEnabled() const {
293302
return EnableBatchMode;
294303
}

include/swift/Driver/DependencyGraph.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,13 @@ class DependencyGraphImpl {
141141
/// \sa SourceFile::getInterfaceHash
142142
llvm::DenseMap<const void *, std::string> InterfaceHashes;
143143

144-
LoadResult loadFromBuffer(const void *node, llvm::MemoryBuffer &buffer);
144+
LoadResult loadFromBuffer(const void *node, llvm::MemoryBuffer &buffer,
145+
const bool EnableExperimentalDependencies);
145146

146147
protected:
147148
LoadResult loadFromString(const void *node, StringRef data);
148-
LoadResult loadFromPath(const void *node, StringRef path);
149+
LoadResult loadFromPath(const void *node, StringRef path,
150+
const bool EnableExperimentalDependencies);
149151

150152
void addIndependentNode(const void *node) {
151153
bool newlyInserted = Provides.insert({node, {}}).second;
@@ -228,9 +230,10 @@ class DependencyGraph : public DependencyGraphImpl {
228230
/// ("depends") are not cleared; new dependencies are considered additive.
229231
///
230232
/// If \p node has already been marked, only its outgoing edges are updated.
231-
LoadResult loadFromPath(T node, StringRef path) {
232-
return DependencyGraphImpl::loadFromPath(Traits::getAsVoidPointer(node),
233-
path);
233+
LoadResult loadFromPath(T node, StringRef path,
234+
const bool EnableExperimentalDependencies) {
235+
return DependencyGraphImpl::loadFromPath(
236+
Traits::getAsVoidPointer(node), path, EnableExperimentalDependencies);
234237
}
235238

236239
/// Load "depends" and "provides" data for \p node from a plain string.

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ def driver_always_rebuild_dependents :
129129
Flag<["-"], "driver-always-rebuild-dependents">, InternalDebugOpt,
130130
HelpText<"Always rebuild dependents of files that have been modified">;
131131

132+
def enable_experimental_dependencies :
133+
Flag<["-"], "enable-experimental-dependencies">, Flags<[FrontendOption, HelpHidden]>,
134+
HelpText<"When interface changes, be more selective">;
135+
132136
def driver_mode : Joined<["--"], "driver-mode=">, Flags<[HelpHidden]>,
133137
HelpText<"Set the driver mode to either 'swift' or 'swiftc'">;
134138

lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6220,6 +6220,10 @@ void Decl::setClangNode(ClangNode Node) {
62206220
*(ptr - 1) = Node.getOpaqueValue();
62216221
}
62226222

6223+
bool Decl::getEnableExperimentalDependencies() const {
6224+
return getASTContext().LangOpts.EnableExperimentalDependencies;
6225+
}
6226+
62236227
// See swift/Basic/Statistic.h for declaration: this enables tracing Decls, is
62246228
// defined here to avoid too much layering violation / circular linkage
62256229
// dependency.

lib/AST/DeclContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ unsigned DeclContext::printContext(raw_ostream &OS, unsigned indent) const {
624624
return Depth + 1;
625625
}
626626

627+
bool DeclContext::getEnableExperimentalDependencies() const {
628+
return getASTContext().LangOpts.EnableExperimentalDependencies;
629+
}
630+
627631
const Decl *
628632
IterableDeclContext::getDecl() const {
629633
switch (getIterableContextKind()) {

lib/Driver/Compilation.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ Compilation::Compilation(DiagnosticEngine &Diags,
117117
Optional<unsigned> BatchSizeLimit,
118118
bool SaveTemps,
119119
bool ShowDriverTimeCompilation,
120-
std::unique_ptr<UnifiedStatsReporter> StatsReporter)
120+
std::unique_ptr<UnifiedStatsReporter> StatsReporter,
121+
bool EnableExperimentalDependencies)
121122
: Diags(Diags), TheToolChain(TC),
122123
TheOutputInfo(OI),
123124
Level(Level),
@@ -138,7 +139,9 @@ Compilation::Compilation(DiagnosticEngine &Diags,
138139
SaveTemps(SaveTemps),
139140
ShowDriverTimeCompilation(ShowDriverTimeCompilation),
140141
Stats(std::move(StatsReporter)),
141-
FilelistThreshold(FilelistThreshold) {
142+
FilelistThreshold(FilelistThreshold),
143+
EnableExperimentalDependencies(EnableExperimentalDependencies) {
144+
142145
};
143146

144147
static bool writeFilelistIfNecessary(const Job *job, const ArgList &args,
@@ -405,7 +408,9 @@ namespace driver {
405408
if (ReturnCode == EXIT_SUCCESS || ReturnCode == EXIT_FAILURE) {
406409
bool wasCascading = DepGraph.isMarked(FinishedCmd);
407410

408-
switch (DepGraph.loadFromPath(FinishedCmd, DependenciesFile)) {
411+
switch (
412+
DepGraph.loadFromPath(FinishedCmd, DependenciesFile,
413+
Comp.getEnableExperimentalDependencies())) {
409414
case DependencyGraphImpl::LoadResult::HadError:
410415
if (ReturnCode == EXIT_SUCCESS) {
411416
dependencyLoadFailed(DependenciesFile);
@@ -696,7 +701,9 @@ namespace driver {
696701
if (Cmd->getCondition() == Job::Condition::NewlyAdded) {
697702
DepGraph.addIndependentNode(Cmd);
698703
} else {
699-
switch (DepGraph.loadFromPath(Cmd, DependenciesFile)) {
704+
switch (DepGraph.loadFromPath(
705+
Cmd, DependenciesFile,
706+
Comp.getEnableExperimentalDependencies())) {
700707
case DependencyGraphImpl::LoadResult::HadError:
701708
dependencyLoadFailed(DependenciesFile, /*Warn=*/false);
702709
break;

lib/Driver/DependencyGraph.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ using DependencyKind = DependencyGraphImpl::DependencyKind;
5252
using DependencyCallbackTy = LoadResult(StringRef, DependencyKind, bool);
5353
using InterfaceHashCallbackTy = LoadResult(StringRef);
5454

55-
static LoadResult
56-
parseDependencyFile(llvm::MemoryBuffer &buffer,
57-
llvm::function_ref<DependencyCallbackTy> providesCallback,
58-
llvm::function_ref<DependencyCallbackTy> dependsCallback,
59-
llvm::function_ref<InterfaceHashCallbackTy> interfaceHashCallback) {
55+
static LoadResult parseDependencyFile(
56+
llvm::MemoryBuffer &buffer,
57+
llvm::function_ref<DependencyCallbackTy> providesCallback,
58+
llvm::function_ref<DependencyCallbackTy> dependsCallback,
59+
llvm::function_ref<InterfaceHashCallbackTy> interfaceHashCallback,
60+
const bool EnableExperimentalDependencies) {
6061
namespace yaml = llvm::yaml;
6162

6263
// FIXME: Switch to a format other than YAML.
@@ -211,21 +212,25 @@ parseDependencyFile(llvm::MemoryBuffer &buffer,
211212
return result;
212213
}
213214

214-
LoadResult DependencyGraphImpl::loadFromPath(const void *node, StringRef path) {
215+
LoadResult
216+
DependencyGraphImpl::loadFromPath(const void *node, StringRef path,
217+
const bool EnableExperimentalDependencies) {
215218
auto buffer = llvm::MemoryBuffer::getFile(path);
216219
if (!buffer)
217220
return LoadResult::HadError;
218-
return loadFromBuffer(node, *buffer.get());
221+
return loadFromBuffer(node, *buffer.get(), EnableExperimentalDependencies);
219222
}
220223

221224
LoadResult
222225
DependencyGraphImpl::loadFromString(const void *node, StringRef data) {
223226
auto buffer = llvm::MemoryBuffer::getMemBuffer(data);
224-
return loadFromBuffer(node, *buffer);
227+
return loadFromBuffer(node, *buffer, false);
225228
}
226229

227-
LoadResult DependencyGraphImpl::loadFromBuffer(const void *node,
228-
llvm::MemoryBuffer &buffer) {
230+
LoadResult
231+
DependencyGraphImpl::loadFromBuffer(const void *node,
232+
llvm::MemoryBuffer &buffer,
233+
const bool EnableExperimentalDependencies) {
229234
auto &provides = Provides[node];
230235

231236
auto dependsCallback = [this, node](StringRef name, DependencyKind kind,
@@ -291,7 +296,8 @@ LoadResult DependencyGraphImpl::loadFromBuffer(const void *node,
291296
};
292297

293298
return parseDependencyFile(buffer, providesCallback, dependsCallback,
294-
interfaceHashCallback);
299+
interfaceHashCallback,
300+
EnableExperimentalDependencies);
295301
}
296302

297303
void DependencyGraphImpl::markExternal(SmallVectorImpl<const void *> &visited,

lib/Driver/Driver.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,9 @@ Driver::buildCompilation(const ToolChain &TC,
920920
ArgList->hasArg(options::OPT_driver_time_compilation);
921921
std::unique_ptr<UnifiedStatsReporter> StatsReporter =
922922
createStatsReporter(ArgList.get(), Inputs, OI, DefaultTargetTriple);
923-
923+
const bool EnableExperimentalDependencies =
924+
ArgList->hasArg(options::OPT_enable_experimental_dependencies);
925+
924926
C = llvm::make_unique<Compilation>(
925927
Diags, TC, OI, Level,
926928
std::move(ArgList),
@@ -939,7 +941,8 @@ Driver::buildCompilation(const ToolChain &TC,
939941
DriverBatchSizeLimit,
940942
SaveTemps,
941943
ShowDriverTimeCompilation,
942-
std::move(StatsReporter));
944+
std::move(StatsReporter),
945+
EnableExperimentalDependencies);
943946
}
944947

945948
// Construct the graph of Actions.

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
218218
inputArgs.AddLastArg(arguments, options::OPT_O_Group);
219219
inputArgs.AddLastArg(arguments, options::OPT_RemoveRuntimeAsserts);
220220
inputArgs.AddLastArg(arguments, options::OPT_AssumeSingleThreaded);
221+
inputArgs.AddLastArg(arguments,
222+
options::OPT_enable_experimental_dependencies);
221223

222224
// Pass on any build config options
223225
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
273273
Opts.BuildSyntaxTree = true;
274274
Opts.VerifySyntaxTree = true;
275275
}
276+
277+
if (Args.hasArg(OPT_enable_experimental_dependencies))
278+
Opts.EnableExperimentalDependencies = true;
276279

277280
Opts.DebuggerSupport |= Args.hasArg(OPT_debugger_support);
278281
if (Opts.DebuggerSupport)

0 commit comments

Comments
 (0)