Skip to content

Commit 4713770

Browse files
[CAS] Virtualize TBD output
Virtualize TBD file output so we can check the output determinisim and also be cached.
1 parent 8fb0d5f commit 4713770

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ static bool writeTBDIfNeeded(CompilerInstance &Instance) {
806806

807807
const std::string &TBDPath = Invocation.getTBDPathForWholeModule();
808808

809-
return writeTBD(Instance.getMainModule(), TBDPath, tbdOpts);
809+
return writeTBD(Instance.getMainModule(), TBDPath,
810+
Instance.getOutputBackend(), tbdOpts);
810811
}
811812

812813
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,

lib/FrontendTool/TBD.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "swift/AST/Decl.h"
1616
#include "swift/AST/DiagnosticEngine.h"
1717
#include "swift/AST/DiagnosticsFrontend.h"
18+
#include "swift/AST/FileSystem.h"
1819
#include "swift/AST/FileUnit.h"
1920
#include "swift/AST/Module.h"
2021
#include "swift/AST/TBDGenRequests.h"
@@ -29,6 +30,7 @@
2930
#include "llvm/IR/Mangler.h"
3031
#include "llvm/IR/ValueSymbolTable.h"
3132
#include "llvm/Support/FileSystem.h"
33+
#include "llvm/Support/VirtualOutputBackend.h"
3234
#include <vector>
3335

3436
using namespace swift;
@@ -42,18 +44,13 @@ static std::vector<StringRef> sortSymbols(llvm::StringSet<> &symbols) {
4244
}
4345

4446
bool swift::writeTBD(ModuleDecl *M, StringRef OutputFilename,
47+
llvm::vfs::OutputBackend &Backend,
4548
const TBDGenOptions &Opts) {
46-
std::error_code EC;
47-
llvm::raw_fd_ostream OS(OutputFilename, EC, llvm::sys::fs::OF_None);
48-
if (EC) {
49-
M->getASTContext().Diags.diagnose(SourceLoc(), diag::error_opening_output,
50-
OutputFilename, EC.message());
51-
return true;
52-
}
53-
54-
writeTBDFile(M, OS, Opts);
55-
56-
return false;
49+
return withOutputPath(M->getDiags(), Backend, OutputFilename,
50+
[&](raw_ostream &OS) -> bool {
51+
writeTBDFile(M, OS, Opts);
52+
return false;
53+
});
5754
}
5855

5956
static bool validateSymbols(DiagnosticEngine &diags,

lib/FrontendTool/TBD.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
namespace llvm {
1919
class StringRef;
2020
class Module;
21+
namespace vfs {
22+
class OutputBackend;
23+
}
2124
}
2225
namespace swift {
2326
class ModuleDecl;
@@ -26,7 +29,7 @@ class FrontendOptions;
2629
struct TBDGenOptions;
2730

2831
bool writeTBD(ModuleDecl *M, StringRef OutputFilename,
29-
const TBDGenOptions &Opts);
32+
llvm::vfs::OutputBackend &Backend, const TBDGenOptions &Opts);
3033
bool validateTBD(ModuleDecl *M,
3134
const llvm::Module &IRModule,
3235
const TBDGenOptions &opts,

test/Frontend/output_determinism_check.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// 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
3+
// RUN: %target-swift-frontend -module-name test -emit-module -o %t/test.swiftmodule %s -emit-module-doc-path %t/test.docc -const-gather-protocols-file %t/protocol.json -emit-const-values-path %t/test.swiftconstvalues -emit-tbd-path %t/test.tbd -tbd-current-version 1 -tbd-compatibility-version 1 -tbd-install_name @rpath/test.dylib -enable-deterministic-check 2>&1 | %FileCheck %s --check-prefix=MODULE_OUTPUT --check-prefix=DOCC_OUTPUT --check-prefix=CONSTVALUE_OUTPUT --check-prefix=TBD_OUTPUT
44
// 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
55

66
/// object files are "not" deterministic because the second run going to match the mod hash and skip code generation.
@@ -28,6 +28,7 @@
2828
// DOCC_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.docc'
2929
// CONSTVALUE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftconstvalues'
3030
// MODULE_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.swiftmodule'
31+
// TBD_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.tbd'
3132
// SIB_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.sib'
3233
// DEPS_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.d'
3334
// OBJECT_OUTPUT: remark: produced matching output file '{{.*}}{{/|\\}}test.o'

0 commit comments

Comments
 (0)