Skip to content

Commit 9be198f

Browse files
Address review feedback
1 parent f70d2bb commit 9be198f

28 files changed

+132
-163
lines changed

include/swift/AST/ASTContext.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class ASTContext final {
285285
DiagnosticEngine &Diags;
286286

287287
/// OutputBackend for writing outputs.
288-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> Backend;
288+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend;
289289

290290
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
291291
/// all operations working on this ASTContext should be aborted at the next
@@ -1525,13 +1525,13 @@ class ASTContext final {
15251525
/// Get the output backend. The output backend needs to be initialized via
15261526
/// constructor or `setOutputBackend`.
15271527
llvm::vfs::OutputBackend &getOutputBackend() const {
1528-
assert(Backend && "OutputBackend is not setup");
1529-
return *Backend;
1528+
assert(OutputBackend && "OutputBackend is not setup");
1529+
return *OutputBackend;
15301530
}
15311531
/// Set output backend for virtualized outputs.
15321532
void setOutputBackend(
1533-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend) {
1534-
Backend = std::move(OutputBackend);
1533+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend) {
1534+
OutputBackend = std::move(OutBackend);
15351535
}
15361536

15371537
private:

include/swift/AST/DiagnosticsCommon.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ ERROR(not_implemented,none,
2929
ERROR(error_opening_output,none,
3030
"error opening '%0' for output: %1", (StringRef, StringRef))
3131

32+
ERROR(error_closing_output,none,
33+
"error closing '%0' for output: %1", (StringRef, StringRef))
34+
3235
ERROR(cannot_find_group_info_file,none,
3336
"cannot find group info file at path: '%0'", (StringRef))
3437

include/swift/AST/FileSystem.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace swift {
2626
/// \returns true if there were any errors, either from the filesystem
2727
/// operations or from \p action returning true.
2828
inline bool
29-
withOutputFile(DiagnosticEngine &diags, llvm::vfs::OutputBackend &Backend,
29+
withOutputPath(DiagnosticEngine &diags, llvm::vfs::OutputBackend &Backend,
3030
StringRef outputPath,
3131
llvm::function_ref<bool(llvm::raw_pwrite_stream &)> action) {
3232
assert(!outputPath.empty());
@@ -37,15 +37,19 @@ withOutputFile(DiagnosticEngine &diags, llvm::vfs::OutputBackend &Backend,
3737
if (!outputFile) {
3838
diags.diagnose(SourceLoc(), diag::error_opening_output, outputPath,
3939
toString(outputFile.takeError()));
40-
return false;
40+
return true;
4141
}
4242

4343
bool failed = action(*outputFile);
4444
// If there is an error, discard output. Otherwise keep the output file.
4545
if (auto error = failed ? outputFile->discard() : outputFile->keep()) {
46-
diags.diagnose(SourceLoc(), diag::error_opening_output, outputPath,
47-
toString(std::move(error)));
48-
return false;
46+
// Don't diagnose discard error.
47+
if (failed)
48+
consumeError(std::move(error));
49+
else
50+
diags.diagnose(SourceLoc(), diag::error_closing_output, outputPath,
51+
toString(std::move(error)));
52+
return true;
4953
}
5054
return failed;
5155
}

include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class IRGenOptions {
318318
/// Print the LLVM inline tree at the end of the LLVM pass pipeline.
319319
unsigned PrintInlineTree : 1;
320320

321-
/// Always recompile the output even the module hash might match.
321+
/// Always recompile the output even if the module hash might match.
322322
unsigned AlwaysCompile : 1;
323323

324324
/// Whether we should embed the bitcode file.

include/swift/ClangImporter/ClangImporter.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ class ClangImporter final : public ClangModuleLoader {
395395
/// replica.
396396
///
397397
/// \sa clang::GeneratePCHAction
398-
bool
399-
emitBridgingPCH(llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> backend,
400-
StringRef headerPath, StringRef outputPCHPath);
398+
bool emitBridgingPCH(StringRef headerPath, StringRef outputPCHPath);
401399

402400
/// Returns true if a clang CompilerInstance can successfully read in a PCH,
403401
/// assuming it exists, with the current options. This can be used to find out
@@ -408,21 +406,16 @@ class ClangImporter final : public ClangModuleLoader {
408406
/// module map into the replica and emits a PCM file for one of the modules it
409407
/// declares. Delegates to clang for everything except construction of the
410408
/// replica.
411-
bool emitPrecompiledModule(
412-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> backend,
413-
StringRef moduleMapPath, StringRef moduleName, StringRef outputPath);
409+
bool emitPrecompiledModule(StringRef moduleMapPath, StringRef moduleName,
410+
StringRef outputPath);
414411

415412
/// Makes a temporary replica of the ClangImporter's CompilerInstance and
416413
/// dumps information about a PCM file (assumed to be generated by -emit-pcm
417414
/// or in the Swift module cache). Delegates to clang for everything except
418415
/// construction of the replica.
419-
bool dumpPrecompiledModule(
420-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> backend,
421-
StringRef modulePath, StringRef outputPath);
416+
bool dumpPrecompiledModule(StringRef modulePath, StringRef outputPath);
422417

423-
bool
424-
runPreprocessor(llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> backend,
425-
StringRef inputPath, StringRef outputPath);
418+
bool runPreprocessor(StringRef inputPath, StringRef outputPath);
426419
const clang::Module *getClangOwningModule(ClangNode Node) const;
427420
bool hasTypedef(const clang::Decl *typeDecl) const;
428421

@@ -510,8 +503,7 @@ class ClangImporter final : public ClangModuleLoader {
510503

511504
Optional<std::string>
512505
getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
513-
StringRef SwiftPCHHash,
514-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> Backend);
506+
StringRef SwiftPCHHash);
515507
Optional<std::string>
516508
/// \param isExplicit true if the PCH filename was passed directly
517509
/// with -import-objc-header option.

include/swift/Frontend/Frontend.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class CompilerInstance {
461461
std::unique_ptr<UnifiedStatsReporter> Stats;
462462

463463
/// Virtual OutputBackend.
464-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> TheOutputBackend = nullptr;
464+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend = nullptr;
465465

466466
/// The verification output backend.
467467
using HashBackendTy = llvm::vfs::HashingOutputBackend<llvm::BLAKE3>;
@@ -518,11 +518,11 @@ class CompilerInstance {
518518
}
519519

520520
llvm::vfs::OutputBackend &getOutputBackend() const {
521-
return *TheOutputBackend;
521+
return *OutputBackend;
522522
}
523523
void
524524
setOutputBackend(llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> Backend) {
525-
TheOutputBackend = std::move(Backend);
525+
OutputBackend = std::move(Backend);
526526
}
527527
using HashingBackendPtrTy = llvm::IntrusiveRefCntPtr<HashBackendTy>;
528528
HashingBackendPtrTy getHashingBackend() { return HashBackend; }

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,9 @@ def enable_emit_generic_class_ro_t_list :
11761176
HelpText<"Enable emission of a section with references to class_ro_t of "
11771177
"generic class patterns">;
11781178

1179-
def enable_swift_deterministic_check :
1180-
Flag<["-"], "enable-swift-deterministic-check">,
1181-
HelpText<"Check swift compiler output determinisim by run it twice">;
1179+
def enable_deterministic_check :
1180+
Flag<["-"], "enable-deterministic-check">,
1181+
HelpText<"Check compiler output determinisim by running it twice">;
11821182
def always_compile_output_files :
11831183
Flag<["-"], "always-compile-output-files">,
11841184
HelpText<"Always compile output files even it might not change the results">;

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,12 @@ ASTContext::ASTContext(
661661
ClangImporterOptions &ClangImporterOpts,
662662
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
663663
SourceManager &SourceMgr, DiagnosticEngine &Diags,
664-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend,
664+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend,
665665
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback)
666666
: LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts),
667667
SearchPathOpts(SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
668668
SymbolGraphOpts(SymbolGraphOpts), SourceMgr(SourceMgr), Diags(Diags),
669-
Backend(std::move(OutputBackend)), evaluator(Diags, langOpts),
669+
OutputBackend(std::move(OutBackend)), evaluator(Diags, langOpts),
670670
TheBuiltinModule(createBuiltinModule(*this)),
671671
StdlibModuleName(getIdentifier(STDLIB_NAME)),
672672
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
@@ -714,8 +714,8 @@ ASTContext::ASTContext(
714714

715715
createModuleToExecutablePluginMap();
716716
// Provide a default OnDiskOutputBackend if user didn't supply one.
717-
if (!Backend)
718-
Backend = llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>();
717+
if (!OutputBackend)
718+
OutputBackend = llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>();
719719
}
720720

721721
ASTContext::~ASTContext() {

lib/AST/FineGrainedDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ void SourceFileDepGraph::emitDotFile(llvm::vfs::OutputBackend &outputBackend,
377377
StringRef outputPath,
378378
DiagnosticEngine &diags) {
379379
std::string dotFileName = outputPath.str() + ".dot";
380-
withOutputFile(
380+
withOutputPath(
381381
diags, outputBackend, dotFileName, [&](llvm::raw_pwrite_stream &out) {
382382
DotFileEmitter<SourceFileDepGraph>(out, *this, false, false).emit();
383383
return false;

lib/AST/FineGrainedDependencyFormat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ bool swift::fine_grained_dependencies::writeFineGrainedDependencyGraphToPath(
502502
DiagnosticEngine &diags, llvm::vfs::OutputBackend &backend, StringRef path,
503503
const SourceFileDepGraph &g) {
504504
PrettyStackTraceStringAction stackTrace("saving fine-grained dependency graph", path);
505-
return withOutputFile(diags, backend, path, [&](llvm::raw_ostream &out) {
505+
return withOutputPath(diags, backend, path, [&](llvm::raw_ostream &out) {
506506
SmallVector<char, 0> Buffer;
507507
llvm::BitstreamWriter Writer{Buffer};
508508
writeFineGrainedDependencyGraph(Writer, g, Purpose::ForSwiftDeps);

0 commit comments

Comments
 (0)