Skip to content

Commit c177a16

Browse files
authored
Merge pull request #39249 from xymus/emit-module-separately-5.5
[5.5][Driver] Support for emit-module-separately
2 parents 5fc5b11 + 40dc406 commit c177a16

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

include/swift/Option/Options.td

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,13 @@ def experimental_cxx_stdlib :
581581

582582
def experimental_emit_module_separately:
583583
Flag<["-"], "experimental-emit-module-separately">,
584-
Flags<[FrontendOption, NoInteractiveOption, HelpHidden]>,
585-
HelpText<"Schedule a swift module emission job instead of a merge-modules job (new Driver only)">;
584+
Flags<[NoInteractiveOption, HelpHidden]>,
585+
HelpText<"Emit module files as a distinct job (new Driver only)">;
586+
587+
def no_emit_module_separately:
588+
Flag<["-"], "no-emit-module-separately">,
589+
Flags<[NoInteractiveOption, HelpHidden]>,
590+
HelpText<"Force using merge-module as the incremental build mode (new Driver only)">;
586591

587592
// Diagnostic control options
588593
def suppress_warnings : Flag<["-"], "suppress-warnings">,

lib/AST/Module.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,11 @@ void SourceLookupCache::populateMemberCache(const ModuleDecl &Mod) {
276276
"populate-module-class-member-cache");
277277

278278
for (const FileUnit *file : Mod.getFiles()) {
279-
auto &SF = *cast<SourceFile>(file);
280-
addToMemberCache(SF.getTopLevelDecls());
279+
assert(isa<SourceFile>(file) ||
280+
isa<SynthesizedFileUnit>(file));
281+
SmallVector<Decl *, 8> decls;
282+
file->getTopLevelDecls(decls);
283+
addToMemberCache(decls);
281284
}
282285

283286
MemberCachePopulated = true;

lib/Frontend/Frontend.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,10 +1145,10 @@ CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
11451145
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
11461146
}
11471147

1148+
auto typeOpts = getASTContext().TypeCheckerOpts;
11481149
if (forPrimary || isWholeModuleCompilation()) {
11491150
// Disable delayed body parsing for primaries and in WMO, unless
11501151
// forcefully skipping function bodies
1151-
auto typeOpts = getASTContext().TypeCheckerOpts;
11521152
if (typeOpts.SkipFunctionBodies == FunctionBodySkipping::None)
11531153
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
11541154
} else {
@@ -1157,9 +1157,10 @@ CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
11571157
opts |= SourceFile::ParsingFlags::SuppressWarnings;
11581158
}
11591159

1160-
// Enable interface hash computation for primaries, but not in WMO, as it's
1161-
// only currently needed for incremental mode.
1162-
if (forPrimary) {
1160+
// Enable interface hash computation for primaries or emit-module-separately,
1161+
// but not in WMO, as it's only currently needed for incremental mode.
1162+
if (forPrimary ||
1163+
typeOpts.SkipFunctionBodies == FunctionBodySkipping::NonInlinableWithoutTypes) {
11631164
opts |= SourceFile::ParsingFlags::EnableInterfaceHash;
11641165
}
11651166
return opts;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,9 +1549,19 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
15491549
SerializationOptions serializationOpts =
15501550
Invocation.computeSerializationOptions(outs, Instance.getMainModule());
15511551

1552+
// Infer if this is an emit-module job part of an incremental build,
1553+
// vs a partial emit-module job (with primary files) or other kinds.
1554+
// We may want to rely on a flag instead to differentiate them.
1555+
const bool isEmitModuleSeparately =
1556+
Action == FrontendOptions::ActionType::EmitModuleOnly &&
1557+
MSF.is<ModuleDecl *>() &&
1558+
Instance.getInvocation()
1559+
.getTypeCheckerOptions()
1560+
.SkipFunctionBodies == FunctionBodySkipping::NonInlinableWithoutTypes;
15521561
const bool canEmitIncrementalInfoIntoModule =
15531562
!serializationOpts.DisableCrossModuleIncrementalInfo &&
1554-
(Action == FrontendOptions::ActionType::MergeModules);
1563+
(Action == FrontendOptions::ActionType::MergeModules ||
1564+
isEmitModuleSeparately);
15551565
if (canEmitIncrementalInfoIntoModule) {
15561566
const auto alsoEmitDotFile =
15571567
Instance.getInvocation()

test/Driver/Dependencies/one-way-merge-module-fine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: cp -r %S/Inputs/one-way-fine/* %t
55
// RUN: touch -t 201401240005 %t/*
66

7-
// RUN: cd %t && %swiftc_driver -driver-use-frontend-path "%{python.unquoted};%S/Inputs/update-dependencies.py;%swift-dependency-tool" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -emit-module-path %t/master.swiftmodule -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
7+
// RUN: cd %t && %swiftc_driver -driver-use-frontend-path "%{python.unquoted};%S/Inputs/update-dependencies.py;%swift-dependency-tool" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -emit-module-path %t/master.swiftmodule -module-name main -j1 -v -no-emit-module-separately 2>&1 | %FileCheck -check-prefix=CHECK-FIRST %s
88

99
// CHECK-FIRST-NOT: warning
1010
// CHECK-FIRST: Handled main.swift
@@ -14,7 +14,7 @@
1414
// swift-driver checks existence of all outputs
1515
// RUN: touch -t 201401240006 %t/{main,other,master}.swift{module,doc,sourceinfo}
1616

17-
// RUN: cd %t && %swiftc_driver -driver-use-frontend-path "%{python.unquoted};%S/Inputs/update-dependencies.py;%swift-dependency-tool" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -emit-module-path %t/master.swiftmodule -module-name main -j1 -v 2>&1 | %FileCheck -check-prefix=CHECK-SECOND %s
17+
// RUN: cd %t && %swiftc_driver -driver-use-frontend-path "%{python.unquoted};%S/Inputs/update-dependencies.py;%swift-dependency-tool" -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -emit-module-path %t/master.swiftmodule -module-name main -j1 -v -no-emit-module-separately 2>&1 | %FileCheck -check-prefix=CHECK-SECOND %s
1818

1919
// CHECK-SECOND-NOT: warning
2020
// CHECK-SECOND-NOT: Handled

test/InterfaceHash/added_function.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
55
// RUN: not cmp %t/a.hash %t/b.hash
66

7+
/// We should generate an interface hash for emit-module-separately jobs even
8+
/// with no primaries.
9+
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift -experimental-skip-non-inlinable-function-bodies-without-types 2> %t/b-emit-module.hash
10+
// RUN: cmp %t/b.hash %t/b-emit-module.hash
11+
712
// BEGIN a.swift
813
func f() {}
914

0 commit comments

Comments
 (0)