Skip to content

Stage in Frontend/Driver Feature Flags for Cross-Module Incremental Builds #34070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion include/swift/Driver/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ class Compilation {
/// Experiment with source-range-based dependencies
const bool EnableSourceRangeDependencies;

/// (experimental) Enable cross-module incremental build scheduling.
const bool EnableCrossModuleIncrementalBuild;

public:
/// Will contain a comparator if an argument demands it.
Optional<IncrementalSchemeComparator> IncrementalComparator;
Expand Down Expand Up @@ -323,7 +326,8 @@ class Compilation {
bool FineGrainedDependenciesIncludeIntrafileOnes = false,
bool EnableSourceRangeDependencies = false,
bool CompareIncrementalSchemes = false,
StringRef CompareIncrementalSchemesPath = "");
StringRef CompareIncrementalSchemesPath = "",
bool EnableCrossModuleIncrementalBuild = false);
// clang-format on
~Compilation();

Expand Down Expand Up @@ -429,6 +433,10 @@ class Compilation {
return ShowDriverTimeCompilation;
}

bool getEnableCrossModuleIncrementalBuild() const {
return EnableCrossModuleIncrementalBuild;
}

size_t getFilelistThreshold() const {
return FilelistThreshold;
}
Expand Down
8 changes: 8 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ class FrontendOptions {
/// of the main Swift module's source files.
bool ImportPrescan = false;

/// When performing an incremental build, ensure that cross-module incremental
/// build metadata is available in any swift modules emitted by this frontend
/// job.
///
/// This flag is currently only propagated from the driver to
/// any merge-modules jobs.
bool EnableExperimentalCrossModuleIncrementalBuild = false;

/// The different modes for validating TBD against the LLVM IR.
enum class TBDValidationMode {
Default, ///< Do the default validation for the current platform.
Expand Down
5 changes: 5 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,11 @@ def experimental_cxx_stdlib :
Separate<["-"], "experimental-cxx-stdlib">,
HelpText<"C++ standard library to use; forwarded to Clang's -stdlib flag">;

def enable_experimental_cross_module_incremental_build :
Flag<["-"], "enable-experimental-cross-module-incremental-build">,
HelpText<"(experimental) Enable cross-module incremental build metadata and "
"driver scheduling">;


// Diagnostic control options
def suppress_warnings : Flag<["-"], "suppress-warnings">,
Expand Down
1 change: 1 addition & 0 deletions include/swift/Serialization/SerializationOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ namespace swift {
bool SerializeAllSIL = false;
bool SerializeOptionsForDebugging = false;
bool IsSIB = false;
bool ExperimentalCrossModuleIncrementalInfo = false;
};

} // end namespace swift
Expand Down
6 changes: 4 additions & 2 deletions lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ Compilation::Compilation(DiagnosticEngine &Diags,
bool FineGrainedDependenciesIncludeIntrafileOnes,
bool EnableSourceRangeDependencies,
bool CompareIncrementalSchemes,
StringRef CompareIncrementalSchemesPath)
StringRef CompareIncrementalSchemesPath,
bool EnableCrossModuleIncrementalBuild)
: Diags(Diags), TheToolChain(TC),
TheOutputInfo(OI),
Level(Level),
Expand Down Expand Up @@ -155,7 +156,8 @@ Compilation::Compilation(DiagnosticEngine &Diags,
EmitFineGrainedDependencyDotFileAfterEveryImport),
FineGrainedDependenciesIncludeIntrafileOnes(
FineGrainedDependenciesIncludeIntrafileOnes),
EnableSourceRangeDependencies(EnableSourceRangeDependencies)
EnableSourceRangeDependencies(EnableSourceRangeDependencies),
EnableCrossModuleIncrementalBuild(EnableCrossModuleIncrementalBuild)
{
if (CompareIncrementalSchemes)
IncrementalComparator.emplace(
Expand Down
5 changes: 4 additions & 1 deletion lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,8 @@ Driver::buildCompilation(const ToolChain &TC,
OPT_driver_emit_fine_grained_dependency_dot_file_after_every_import);
const bool FineGrainedDependenciesIncludeIntrafileOnes =
ArgList->hasArg(options::OPT_fine_grained_dependency_include_intrafile);
const bool EnableCrossModuleDependencies = ArgList->hasArg(
options::OPT_enable_experimental_cross_module_incremental_build);

// clang-format off
C = std::make_unique<Compilation>(
Expand Down Expand Up @@ -1054,7 +1056,8 @@ Driver::buildCompilation(const ToolChain &TC,
FineGrainedDependenciesIncludeIntrafileOnes,
EnableSourceRangeDependencies,
CompareIncrementalSchemes,
CompareIncrementalSchemesPath);
CompareIncrementalSchemesPath,
EnableCrossModuleDependencies);
// clang-format on
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ ToolChain::constructInvocation(const MergeModuleJobAction &job,

context.Args.AddLastArg(Arguments, options::OPT_import_objc_header);

context.Args.AddLastArg(
Arguments,
options::OPT_enable_experimental_cross_module_incremental_build);

Arguments.push_back("-module-name");
Arguments.push_back(context.Args.MakeArgString(context.OI.ModuleName));

Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/ArgsToFrontendOptionsConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ bool ArgsToFrontendOptionsConverter::convert(

Opts.ImportPrescan |= Args.hasArg(OPT_import_prescan);

Opts.EnableExperimentalCrossModuleIncrementalBuild |=
Args.hasArg(OPT_enable_experimental_cross_module_incremental_build);

// Always track system dependencies when scanning dependencies.
if (const Arg *ModeArg = Args.getLastArg(OPT_modes_Group)) {
if (ModeArg->getOption().matches(OPT_scan_dependencies)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ SerializationOptions CompilerInvocation::computeSerializationOptions(
opts.SerializeOptionsForDebugging.getValueOr(
!isModuleExternallyConsumed(module));

serializationOpts.ExperimentalCrossModuleIncrementalInfo =
opts.EnableExperimentalCrossModuleIncrementalBuild;

return serializationOpts;
}

Expand Down
6 changes: 6 additions & 0 deletions test/Driver/cross_module.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %empty-directory(%t/sub)
// RUN: echo "{\"\": {\"swift-dependencies\": \"cross_module.swiftdeps\"}}" > %t/ofm.json
// RUN: %swiftc_driver -incremental -emit-module -module-name cross_module -output-file-map=%/t/ofm.json -driver-print-jobs -target x86_64-apple-macosx10.9 %s -enable-experimental-cross-module-incremental-build 2>^1 | %FileCheck -check-prefix ENABLE %s

// ENABLE: {{bin(/|\\\\)swift(-frontend|c)?(\.exe)?"?}} -frontend -merge-modules
// ENABLE-SAME: -enable-experimental-cross-module-incremental-build