Skip to content

Commit c769e49

Browse files
authored
Revert "ModuleInterface: lock .swiftinterface while generating module cache"
1 parent a2be4fe commit c769e49

File tree

5 files changed

+7
-97
lines changed

5 files changed

+7
-97
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ ERROR(unknown_forced_module_loading_mode,none,
343343
"unknown value for SWIFT_FORCE_MODULE_LOADING variable: '%0'",
344344
(StringRef))
345345

346-
REMARK(interface_file_lock_failure,none,
347-
"could not acquire lock file for module interface '%0'", (StringRef))
348-
349-
REMARK(interface_file_lock_timed_out,none,
350-
"timed out waiting to acquire lock file for module interface '%0'", (StringRef))
351-
352346
#ifndef DIAG_NO_UNDEF
353347
# if defined(DIAG)
354348
# undef DIAG

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "llvm/Support/Errc.h"
3737
#include "llvm/Support/Regex.h"
3838
#include "llvm/Support/StringSaver.h"
39-
#include "llvm/Support/LockFileManager.h"
4039

4140
using namespace swift;
4241
using FileDependency = SerializationOptions::FileDependency;
@@ -241,7 +240,7 @@ bool ModuleInterfaceBuilder::collectDepsForSerialization(
241240
return false;
242241
}
243242

244-
bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
243+
bool ModuleInterfaceBuilder::buildSwiftModule(
245244
StringRef OutPath, bool ShouldSerializeDeps,
246245
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer) {
247246
bool SubError = false;
@@ -385,70 +384,3 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
385384
});
386385
return !RunSuccess || SubError;
387386
}
388-
389-
bool ModuleInterfaceBuilder::buildSwiftModule(StringRef OutPath,
390-
bool ShouldSerializeDeps,
391-
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
392-
llvm::function_ref<void()> RemarkRebuild) {
393-
394-
while (1) {
395-
// Attempt to lock the interface file. Only one process is allowed to build
396-
// module from the interface so we don't consume too much memory when multiple
397-
// processes are doing the same.
398-
// FIXME: We should surface the module building step to the build system so
399-
// we don't need to synchronize here.
400-
llvm::LockFileManager Locked(interfacePath);
401-
switch (Locked) {
402-
case llvm::LockFileManager::LFS_Error:{
403-
// ModuleInterfaceBuilder takes care of correctness and locks are only
404-
// necessary for performance. Fallback to building the module in case of any lock
405-
// related errors.
406-
if (RemarkRebuild) {
407-
diags.diagnose(SourceLoc(), diag::interface_file_lock_failure,
408-
interfacePath);
409-
}
410-
// Clear out any potential leftover.
411-
Locked.unsafeRemoveLockFile();
412-
LLVM_FALLTHROUGH;
413-
}
414-
case llvm::LockFileManager::LFS_Owned: {
415-
if (RemarkRebuild) {
416-
RemarkRebuild();
417-
}
418-
return buildSwiftModuleInternal(OutPath, ShouldSerializeDeps, ModuleBuffer);
419-
}
420-
case llvm::LockFileManager::LFS_Shared: {
421-
// Someone else is responsible for building the module. Wait for them to
422-
// finish.
423-
switch (Locked.waitForUnlock()) {
424-
case llvm::LockFileManager::Res_Success: {
425-
// This process may have a different module output path. If the other
426-
// process doesn't build the interface to this output path, we should try
427-
// building ourselves.
428-
auto bufferOrError = llvm::MemoryBuffer::getFile(OutPath);
429-
if (!bufferOrError)
430-
continue;
431-
*ModuleBuffer = std::move(bufferOrError.get());
432-
return false;
433-
}
434-
case llvm::LockFileManager::Res_OwnerDied: {
435-
continue; // try again to get the lock.
436-
}
437-
case llvm::LockFileManager::Res_Timeout: {
438-
// Since ModuleInterfaceBuilder takes care of correctness, we try waiting for
439-
// another process to complete the build so swift does not do it done
440-
// twice. If case of timeout, build it ourselves.
441-
if (RemarkRebuild) {
442-
diags.diagnose(SourceLoc(), diag::interface_file_lock_timed_out,
443-
interfacePath);
444-
}
445-
// Clear the lock file so that future invocations can make progress.
446-
Locked.unsafeRemoveLockFile();
447-
continue;
448-
}
449-
}
450-
break;
451-
}
452-
}
453-
}
454-
}

lib/Frontend/ModuleInterfaceBuilder.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ class ModuleInterfaceBuilder {
6767
version::Version &Vers, llvm::StringSaver &SubArgSaver,
6868
SmallVectorImpl<const char *> &SubArgs);
6969

70-
bool buildSwiftModuleInternal(StringRef OutPath, bool ShouldSerializeDeps,
71-
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer);
7270
public:
7371
ModuleInterfaceBuilder(SourceManager &sourceMgr, DiagnosticEngine &diags,
7472
const SearchPathOptions &searchPathOpts,
@@ -104,8 +102,7 @@ class ModuleInterfaceBuilder {
104102
}
105103

106104
bool buildSwiftModule(StringRef OutPath, bool ShouldSerializeDeps,
107-
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer,
108-
llvm::function_ref<void()> RemarkRebuild = nullptr);
105+
std::unique_ptr<llvm::MemoryBuffer> *ModuleBuffer);
109106
};
110107

111108
} // end namespace swift

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -950,11 +950,13 @@ class ModuleInterfaceLoaderImpl {
950950
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
951951

952952
// We didn't discover a module corresponding to this interface.
953+
953954
// Diagnose that we didn't find a loadable module, if we were asked to.
954-
auto remarkRebuild = [&]() {
955+
if (remarkOnRebuildFromInterface) {
955956
rebuildInfo.diagnose(ctx, diagnosticLoc, moduleName,
956957
interfacePath);
957-
};
958+
}
959+
958960
// If we found an out-of-date .swiftmodule, we still want to add it as
959961
// a dependency of the .swiftinterface. That way if it's updated, but
960962
// the .swiftinterface remains the same, we invalidate the cache and
@@ -964,9 +966,7 @@ class ModuleInterfaceLoaderImpl {
964966
builder.addExtraDependency(modulePath);
965967

966968
if (builder.buildSwiftModule(cachedOutputPath, /*shouldSerializeDeps*/true,
967-
&moduleBuffer,
968-
remarkOnRebuildFromInterface ? remarkRebuild:
969-
llvm::function_ref<void()>()))
969+
&moduleBuffer))
970970
return std::make_error_code(std::errc::invalid_argument);
971971

972972
assert(moduleBuffer &&

test/Driver/lock_interface.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)