@@ -563,53 +563,6 @@ void format_object_base::home() {
563
563
// ===----------------------------------------------------------------------===//
564
564
// raw_fd_ostream
565
565
// ===----------------------------------------------------------------------===//
566
- static void emitExtraOpenFileFailDiagnostic (const Twine &Name,
567
- const Twine &Error,
568
- int Retries) {
569
- SmallVector<char , 64 > Buffer;
570
- raw_svector_ostream OS (Buffer);
571
- OS << " Open File failed on file: " << Name << " \n " ;
572
- OS << " Error: " << Error << " \n " ;
573
- OS << " Attempted again: " << Retries << " times\n " ;
574
- StringRef MessageStr = OS.str ();
575
- ::write (2 , MessageStr.data(), MessageStr.size());
576
- }
577
-
578
- static std::error_code openFileForWriteWithRetry (const Twine &Name, int &ResultFD,
579
- sys::fs::CreationDisposition Disp,
580
- llvm::sys::fs::OpenFlags Flags,
581
- bool WithRead) {
582
- // This is a workaround for a Swift compiler issue wherein the compiler
583
- // occassionally fails when destructing a file descriptor with no meaningful
584
- // diagnostic.
585
- // Re-try opening descriptor, in case it helps.
586
- // Emit additional diagnostics to ease with root-causing this issue.
587
- // Reversal tracked in: rdar://74359658
588
- std::error_code EC;
589
- if (WithRead)
590
- EC = sys::fs::openFileForReadWrite (Name, ResultFD, Disp, Flags);
591
- else
592
- EC = sys::fs::openFileForWrite (Name, ResultFD, Disp, Flags);
593
-
594
- if (EC) {
595
- const unsigned MAX_COUNT = 10 ;
596
- unsigned I = 0 ;
597
- for (I = 0 ; I != MAX_COUNT; ++I) {
598
- std::error_code RetryEC;
599
- if (WithRead)
600
- RetryEC = sys::fs::openFileForReadWrite (Name, ResultFD, Disp, Flags);
601
- else
602
- RetryEC = sys::fs::openFileForWrite (Name, ResultFD, Disp, Flags);
603
- if (!RetryEC) {
604
- EC = RetryEC;
605
- break ;
606
- }
607
- }
608
- emitExtraOpenFileFailDiagnostic (Name, EC.message (), I);
609
- }
610
-
611
- return EC;
612
- }
613
566
614
567
static int getFD (StringRef Filename, std::error_code &EC,
615
568
sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access,
@@ -630,9 +583,9 @@ static int getFD(StringRef Filename, std::error_code &EC,
630
583
631
584
int FD;
632
585
if (Access & sys::fs::FA_Read)
633
- EC = openFileForWriteWithRetry (Filename, FD, Disp, Flags, true );
586
+ EC = sys::fs::openFileForReadWrite (Filename, FD, Disp, Flags);
634
587
else
635
- EC = openFileForWriteWithRetry (Filename, FD, Disp, Flags, false );
588
+ EC = sys::fs::openFileForWrite (Filename, FD, Disp, Flags);
636
589
if (EC)
637
590
return -1 ;
638
591
@@ -710,39 +663,8 @@ raw_fd_ostream::~raw_fd_ostream() {
710
663
if (FD >= 0 ) {
711
664
flush ();
712
665
if (ShouldClose) {
713
- if (auto EC = sys::Process::SafelyCloseFileDescriptor (FD)) {
714
- // This is a workaround for a Swift compiler issue wherein the compiler
715
- // occassionally crashes in this destructor with no meaningful error
716
- // diagnostic.
717
- // Re-try closing the file descriptor, in case it helps.
718
- // Emit additional diagnostics to ease with root-causing this issue.
719
- // Reversal tracked in: rdar://74359658
720
- const unsigned MAX_RETRY_COUNT = 10 ;
721
- bool AllAttemptsFailed = true ;
722
- unsigned I;
723
- for (I = 0 ; I != MAX_RETRY_COUNT; ++I) {
724
- if (bool (sys::Process::SafelyCloseFileDescriptor (FD)) == false ) {
725
- AllAttemptsFailed = false ;
726
- break ;
727
- }
728
- }
729
- {
730
- // Blast the error out to stderr. We don't try hard to make sure
731
- // this succeeds and we can't use errs() here because it may be
732
- // part of the problem.
733
- SmallVector<char , 64 > Buffer;
734
- raw_svector_ostream OS (Buffer);
735
- OS << " File Descriptor close failed on FD: " << FD << " \n " ;
736
- OS << " Error: " << EC.message () << " \n " ;
737
- OS << " Attempted to retry: " << I << " times.\n " ;
738
- OS << " A re-try attempt succeeded: "
739
- << (AllAttemptsFailed ? " false" : " true" ) << " \n " ;
740
- StringRef MessageStr = OS.str ();
741
- ::write (2 , MessageStr.data(), MessageStr.size());
742
- }
743
- if (AllAttemptsFailed)
744
- error_detected (EC);
745
- }
666
+ if (auto EC = sys::Process::SafelyCloseFileDescriptor (FD))
667
+ error_detected (EC);
746
668
}
747
669
}
748
670
@@ -754,15 +676,6 @@ raw_fd_ostream::~raw_fd_ostream() {
754
676
if (FD == 2 ) return ;
755
677
#endif
756
678
757
- // This is a workaround for a Swift compiler issue wherein the compiler
758
- // occassionally crashes in this destructor with no meaningful error
759
- // diagnostic when destructing a *global* stream.
760
- // In case we encounter an error on destroying a global stream
761
- // to stdout or stderr, for now just exit to avoid a crash in:
762
- // report_fatal_error.
763
- // `Reversal tracked in: rdar://74359658`
764
- if (has_error () && (FD == 2 || FD == 1 )) return ;
765
-
766
679
// If there are any pending errors, report them now. Clients wishing
767
680
// to avoid report_fatal_error calls should check for errors with
768
681
// has_error() and clear the error flag with clear_error() before
0 commit comments