Skip to content

Commit 8fb0d5f

Browse files
Virtualize swiftconstvalues output
Virtualize swiftconstvalues output so it can be cached inside CAS.
1 parent 9f51c06 commit 8fb0d5f

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

include/swift/ConstExtract/ConstExtract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ gatherConstValuesForModule(const std::unordered_set<std::string> &Protocols,
5555
/// Serialize a collection of \c ConstValueInfos to JSON at the
5656
/// provided output stream.
5757
bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
58-
llvm::raw_fd_ostream &OS);
58+
llvm::raw_ostream &OS);
5959
} // namespace swift
6060

6161
#endif

lib/ConstExtract/ConstExtract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ void writeAttrInformation(llvm::json::OStream &JSON,
804804
}
805805

806806
bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
807-
llvm::raw_fd_ostream &OS) {
807+
llvm::raw_ostream &OS) {
808808
llvm::json::OStream JSON(OS, 2);
809809
JSON.array([&] {
810810
for (const auto &TypeInfo : ConstValueInfos) {

lib/FrontendTool/FrontendTool.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,12 @@ static bool emitConstValuesForWholeModuleIfNeeded(
726726
return true;
727727
auto ConstValues = gatherConstValuesForModule(Protocols,
728728
Instance.getMainModule());
729-
std::error_code EC;
730-
llvm::raw_fd_ostream OS(ConstValuesFilePath, EC, llvm::sys::fs::OF_None);
731-
writeAsJSONToFile(ConstValues, OS);
732-
return false;
729+
730+
return withOutputPath(Instance.getDiags(), Instance.getOutputBackend(),
731+
ConstValuesFilePath, [&](llvm::raw_ostream &OS) {
732+
writeAsJSONToFile(ConstValues, OS);
733+
return false;
734+
});
733735
}
734736

735737
static void emitConstValuesForAllPrimaryInputsIfNeeded(
@@ -755,9 +757,11 @@ static void emitConstValuesForAllPrimaryInputsIfNeeded(
755757
continue;
756758

757759
auto ConstValues = gatherConstValuesForPrimary(Protocols, SF);
758-
std::error_code EC;
759-
llvm::raw_fd_ostream OS(ConstValuesFilePath, EC, llvm::sys::fs::OF_None);
760-
writeAsJSONToFile(ConstValues, OS);
760+
withOutputPath(Instance.getDiags(), Instance.getOutputBackend(),
761+
ConstValuesFilePath, [&](llvm::raw_ostream &OS) {
762+
writeAsJSONToFile(ConstValues, OS);
763+
return false;
764+
});
761765
}
762766
}
763767

@@ -772,9 +776,12 @@ static bool writeModuleSemanticInfoIfNeeded(CompilerInstance &Instance) {
772776
auto ModuleSemanticPath = frontendOpts.InputsAndOutputs
773777
.getPrimarySpecificPathsForAtMostOnePrimary().SupplementaryOutputs
774778
.ModuleSemanticInfoOutputPath;
775-
llvm::raw_fd_ostream OS(ModuleSemanticPath, EC, llvm::sys::fs::OF_None);
776-
OS << "{}\n";
777-
return false;
779+
780+
return withOutputPath(Instance.getDiags(), Instance.getOutputBackend(),
781+
ModuleSemanticPath, [&](llvm::raw_ostream &OS) {
782+
OS << "{}\n";
783+
return false;
784+
});
778785
}
779786

780787
static bool writeTBDIfNeeded(CompilerInstance &Instance) {

test/Frontend/output_determinism_check.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -module-name test -emit-module -o %t/test.swiftmodule -primary-file %s -emit-module-doc-path %t/test.docc -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=MODULE_OUTPUT --check-prefix=DOCC_OUTPUT
2+
// RUN: echo '[]' > %t/protocol.json
3+
// RUN: %target-swift-frontend -module-name test -emit-module -o %t/test.swiftmodule -primary-file %s -emit-module-doc-path %t/test.docc -const-gather-protocols-file %t/protocol.json -emit-const-values-path %t/test.swiftconstvalues -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=MODULE_OUTPUT --check-prefix=DOCC_OUTPUT --check-prefix=CONSTVALUE_OUTPUT
34
// RUN: %target-swift-frontend -module-name test -emit-sib -o %t/test.sib -primary-file %s -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=SIB_OUTPUT
45

56
/// object files are "not" deterministic because the second run going to match the mod hash and skip code generation.
@@ -25,6 +26,7 @@
2526
// RUN: %target-swift-frontend -emit-pcm -module-name UserClangModule -o %t/test.pcm %S/Inputs/dependencies/module.modulemap -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=PCM_OUTPUT
2627

2728
// DOCC_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.docc'
29+
// CONSTVALUE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftconstvalues'
2830
// MODULE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftmodule'
2931
// SIB_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.sib'
3032
// DEPS_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.d'

0 commit comments

Comments
 (0)