Skip to content

Commit ef149d5

Browse files
authored
Merge pull request swiftlang#30135 from CodaFi/verily-i-depend-on-thee
[Incremental] Introducing: DependencyVerifier
2 parents db10388 + f85ec38 commit ef149d5

File tree

19 files changed

+993
-1
lines changed

19 files changed

+993
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
#include "swift/Basic/LLVM.h"
2222

2323
namespace swift {
24+
class DependencyTracker;
25+
class FileUnit;
2426
class SourceManager;
27+
class SourceFile;
2528

2629
/// Set up the specified source manager so that diagnostics are captured
2730
/// instead of being printed.
@@ -34,6 +37,11 @@ namespace swift {
3437
/// This returns true if there are any mismatches found.
3538
bool verifyDiagnostics(SourceManager &SM, ArrayRef<unsigned> BufferIDs,
3639
bool autoApplyFixes, bool ignoreUnknown);
40+
41+
bool verifyDependencies(SourceManager &SM, const DependencyTracker &DT,
42+
ArrayRef<FileUnit *> SFs);
43+
bool verifyDependencies(SourceManager &SM, const DependencyTracker &DT,
44+
ArrayRef<SourceFile *> SFs);
3745
}
3846

3947
#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 EnableIncrementalDependencyVerifier = 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
@@ -180,6 +180,24 @@ static void validateDebugInfoArgs(DiagnosticEngine &diags,
180180
diags.diagnose(SourceLoc(), diag::error_invalid_debug_prefix_map, A);
181181
}
182182

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

245264
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.EnableIncrementalDependencyVerifier |= Args.hasArg(OPT_verify_incremental_dependencies);
179180

180181
computeImportObjCHeaderOptions();
181182
computeImplicitImportModuleNames();

lib/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ add_swift_host_library(swiftFrontend STATIC
33
ArgsToFrontendOptionsConverter.cpp
44
ArgsToFrontendOutputsConverter.cpp
55
CompilerInvocation.cpp
6+
DependencyVerifier.cpp
67
DiagnosticVerifier.cpp
78
Frontend.cpp
89
FrontendInputsAndOutputs.cpp

0 commit comments

Comments
 (0)