Skip to content

Commit d3edb5b

Browse files
committed
[Incremental] Plumb -verify-incremental-dependencies Through The Frontend and Driver
When enabled at the driver level, the frontends will inherit the flag. For each frontend that recieves this option, all primaries will have their reference dependencies validated.
1 parent 101dd2d commit d3edb5b

File tree

8 files changed

+45
-1
lines changed

8 files changed

+45
-1
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ WARNING(warn_ignore_embed_bitcode_marker, none,
159159
WARNING(verify_debug_info_requires_debug_option,none,
160160
"ignoring '-verify-debug-info'; no debug info is being generated", ())
161161

162+
ERROR(verify_incremental_dependencies_needs_incremental,none,
163+
"'-verify-incremental-dependencies' requires '-incremental'", ())
164+
162165
ERROR(error_profile_missing,none,
163166
"no profdata file exists at '%0'", (StringRef))
164167

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include "swift/Basic/LLVM.h"
2222

2323
namespace swift {
24+
class FileUnit;
2425
class SourceManager;
26+
class SourceFile;
2527

2628
/// Set up the specified source manager so that diagnostics are captured
2729
/// instead of being printed.
@@ -34,6 +36,9 @@ namespace swift {
3436
/// This returns true if there are any mismatches found.
3537
bool verifyDiagnostics(SourceManager &SM, ArrayRef<unsigned> BufferIDs,
3638
bool autoApplyFixes, bool ignoreUnknown);
39+
40+
bool verifyDependencies(SourceManager &SM, ArrayRef<FileUnit *> SFs);
41+
bool verifyDependencies(SourceManager &SM, ArrayRef<SourceFile *> SFs);
3742
}
3843

3944
#endif

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ class FrontendOptions {
263263
/// Should we lock .swiftinterface while generating .swiftmodule from it?
264264
bool DisableInterfaceFileLock = false;
265265

266+
/// Should we enable the dependency verifier for all primary files known to this frontend?
267+
bool VerifyDependencies = false;
268+
266269
/// The different modes for validating TBD against the LLVM IR.
267270
enum class TBDValidationMode {
268271
Default, ///< Do the default validation for the current platform.

include/swift/Option/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ Flag<["-"], "driver-verify-fine-grained-dependency-graph-after-every-import">,
184184
InternalDebugOpt,
185185
HelpText<"Debug DriverGraph by verifying it after every import">;
186186

187+
def verify_incremental_dependencies :
188+
Flag<["-"], "verify-incremental-dependencies">,
189+
Flags<[FrontendOption, HelpHidden]>,
190+
HelpText<"Enable the dependency verifier for each frontend job">;
191+
187192
def driver_emit_fine_grained_dependency_dot_file_after_every_import :
188193
Flag<["-"], "driver-emit-fine-grained-dependency-dot-file-after-every-import">,
189194
InternalDebugOpt,

lib/Driver/Driver.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ static void validateDebugInfoArgs(DiagnosticEngine &diags,
179179
diags.diagnose(SourceLoc(), diag::error_invalid_debug_prefix_map, A);
180180
}
181181

182+
static void validateVerifyIncrementalArgs(DiagnosticEngine &diags,
183+
const ArgList &args) {
184+
// No option? No problem!
185+
if (!args.hasArg(options::OPT_verify_incremental_dependencies)) {
186+
return;
187+
}
188+
189+
// Make sure we see -incremental but not -wmo, no matter in what order they're
190+
// in - the build systems can pass them both and just hope the last one wins.
191+
if (args.hasArg(options::OPT_incremental) &&
192+
!args.hasArg(options::OPT_whole_module_optimization)) {
193+
return;
194+
}
195+
196+
diags.diagnose(SourceLoc(),
197+
diag::verify_incremental_dependencies_needs_incremental);
198+
}
199+
182200
static void validateCompilationConditionArgs(DiagnosticEngine &diags,
183201
const ArgList &args) {
184202
for (const Arg *A : args.filtered(options::OPT_D)) {
@@ -239,6 +257,7 @@ static void validateArgs(DiagnosticEngine &diags, const ArgList &args,
239257
validateCompilationConditionArgs(diags, args);
240258
validateSearchPathArgs(diags, args);
241259
validateAutolinkingArgs(diags, args, T);
260+
validateVerifyIncrementalArgs(diags, args);
242261
}
243262

244263
std::unique_ptr<ToolChain>

lib/Driver/ToolChains.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
254254
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);
255255
inputArgs.AddLastArg(arguments,
256256
options::OPT_enable_experimental_concise_pound_file);
257-
257+
inputArgs.AddLastArg(arguments,
258+
options::OPT_verify_incremental_dependencies);
259+
258260
// Pass on any build config options
259261
inputArgs.AddAllArgs(arguments, options::OPT_D);
260262

lib/Frontend/ArgsToFrontendOptionsConverter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ bool ArgsToFrontendOptionsConverter::convert(
176176

177177
Opts.EnableSourceImport |= Args.hasArg(OPT_enable_source_import);
178178
Opts.ImportUnderlyingModule |= Args.hasArg(OPT_import_underlying_module);
179+
Opts.VerifyDependencies |= Args.hasArg(OPT_verify_incremental_dependencies);
179180

180181
computeImportObjCHeaderOptions();
181182
computeImplicitImportModuleNames();

lib/FrontendTool/FrontendTool.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,12 @@ computeDeallocatableResources(const CompilerInvocation &Invocation,
14801480
return DeallocatableResources::SILModule;
14811481
}
14821482

1483+
// Verifying incremental dependencies relies on access to the Swift Module's
1484+
// source files. We can still free the SIL module, though.
1485+
if (Invocation.getFrontendOptions().VerifyDependencies) {
1486+
return DeallocatableResources::SILModule;
1487+
}
1488+
14831489
// If there are multiple primary inputs it is too soon to free
14841490
// the ASTContext, etc.. OTOH, if this compilation generates code for > 1
14851491
// primary input, then freeing it after processing the last primary is

0 commit comments

Comments
 (0)