From 8ac9549b5e19846c649e6b8233bc3489e266b440 Mon Sep 17 00:00:00 2001 From: MikePopoloski Date: Wed, 2 Aug 2023 05:55:33 -0400 Subject: [PATCH] Remove unnecessary assert from SourceManager when finding an existing cache entry for a new file insertion --- source/text/SourceManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/text/SourceManager.cpp b/source/text/SourceManager.cpp index a293a5816..bec28b0bd 100644 --- a/source/text/SourceManager.cpp +++ b/source/text/SourceManager.cpp @@ -484,8 +484,13 @@ SourceBuffer SourceManager::cacheBuffer(fs::path&& path, std::string&& pathStr, auto fd = std::make_unique(directory, std::move(name), std::move(buffer), std::move(path)); + // Note: it's possible that insertion here fails due to another thread + // racing against us to open and insert the same file. We do a lookup + // in the cache before proceeding to read the file but we drop the lock + // during the read. It's not actually a problem, we'll just use the data + // we already loaded (just like we had gotten a hit on the cache in the + // first place). auto [it, inserted] = lookupCache.emplace(pathStr, std::pair{std::move(fd), std::error_code{}}); - SLANG_ASSERT(inserted); FileData* fdPtr = it->second.first.get(); return createBufferEntry(fdPtr, includedFrom, library, lock);