Skip to content

Swift MCCAS object files are 0 bytes on cache miss #9164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

rastogishubham
Copy link

When clang caching and MCCAS are enabled, on a cache miss, the object file is not written to in MachOCASWriter, instead the replay code is rerun and the object file is serialized and written out. However, in swift, the replay code isn't run on a cache miss at all, and it expects the object writer to write to the object file.

This patch makes it so that on a cache miss, the MachOCASWriter always writes to the raw_ostream buffer for the object file and doesn't serialize the object file in the replay code.

rdar://134425492 ([MCCAS] Fix bug with swift caching where object files are 0 bytes in size)

@rastogishubham
Copy link
Author

@swift-ci please test

@rastogishubham
Copy link
Author

@swift-ci please test llvm

@rastogishubham
Copy link
Author

rastogishubham commented Aug 23, 2024

@cachemeifyoucan I added a test for the -fcasid-output option.

The code is now

if (JustComputedResult && !WriteOutputAsCASID)

In file-based caching, if -fcasid-output is not used and if there is a cache miss, JustComputedResult will be true and WriteOutputAsCASID will be false, so the code will just exit this function and not replay anything.

In file-based caching, if -fcasid-output is not used and if there is a cache hit, JustComputedResult will be false and WriteOutputAsCASID will be false, so the code will replay the object file.

In MCCAS, if -fcasid-output is not used and if there is a cache miss, JustComputedResult will be true and WriteOutputAsCASID will be false, so the code will just exit this function and not replay anything.

In MCCAS, if -fcasid-output is not used and if there is a cache hit, JustComputedResult will be false and WriteOutputAsCASID will be false, so the code will replay the object file.

if -fcasid-output is used, then WriteOutputAsCASID is true, so we always go into the replay code whether we used MCCAS or file based caching, whether there is a cache hit or miss. However, the raw_ostream is filtered out.

CompileJobCache.cpp:449

IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OnDiskOutputs =
      llvm::makeIntrusiveRefCnt<llvm::vfs::OnDiskOutputBackend>();
  if (WriteOutputAsCASID) {
    OnDiskOutputs = llvm::vfs::makeFilteringOutputBackend(
        OnDiskOutputs,
        [this](StringRef ResolvedPath, std::optional<llvm::vfs::OutputConfig>) {
          return ResolvedPath != this->OutputFile;
        });
  }

So we always write the casid to the object file stream when -fcasid-output is used.

Now this patch also ensures that whether swift caching or clang caching is used with MCCAS. The MachOCASWriter always writes to the raw_ostream it gets, which also solves the bug with 0 byte object files in swift MCCAS.

@rastogishubham
Copy link
Author

@swift-ci please test

When clang caching and MCCAS are enabled, on a cache miss, the object
file is not written to in MachOCASWriter, instead the replay code is
rerun and the object file is serialized and written out. However, in
swift, the replay code isn't run on a cache miss at all, and it expects
the object writer to write to the object file.

This patch makes it so that on a cache miss, the MachOCASWriter always
writes to the raw_ostream buffer for the object file and doesn't
serialize the object file in the replay code.
@rastogishubham
Copy link
Author

@swift-ci please test

@rastogishubham
Copy link
Author

@swift-ci please test macOS

@rastogishubham rastogishubham merged commit c461ea7 into swiftlang:stable/20230725 Aug 28, 2024
3 checks passed
@rastogishubham rastogishubham deleted the FixReplay branch August 28, 2024 01:45
rastogishubham added a commit that referenced this pull request Aug 28, 2024
rastogishubham added a commit that referenced this pull request Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants