From bd815f02d846a50e16dab67e6512db2a6215c41f Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 21 Jan 2019 16:41:54 -0500 Subject: Feature/file unique identity (#789) * * Fix memory bug around expanding va_args - needed buffer to have space for terminating 0 * Fix problem with FileWriter defaults being globals, as memory they allocate, will only be freed after return from main - work around by making StdWriters RefObject derived, and kept in scope such the writers are destroyed before checks for leaks is found * Added SimplifyPathAndHash mode for CacheFileSystem - will simplify the path and see if simplified path is in cache before reading file (limiting amout of underlying file requests) * * Added calcReplaceChar * Renamed DefaultFileSystem to OSFileSystem * Made OSFileSystem convert windows \ to / on linux * Simplified logic for caching in CacheFileSystem. * Added pragma-once-c to add extra test, but also so there is an 'include' directory in preprocessor tests. * Small fixes in pragma once test. * Simplified cache handling path, so that paths/simplified paths area always added. * Improve naming of methods for different caches. * Removed references to 'canonicalPath' and made 'uniqueIdentity' * * Re-add support for canonicalPath to ISlangFileSystem -> not for uniqueIdentifier but as a way to display 'canonicalPath' * Added peliminary support for being able to display verbose paths in a diagnostic * Added 'clearCache' support * Added verbose path support to SourceManager (now needs a ISlangFileSystemExt to do this) * Added support for '-verbose-path' option to slangc and slang-test. --- source/slang/slang.cpp | 89 ++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 43 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 247098434..359848d65 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -58,7 +58,7 @@ Session::Session() #include "object-meta-end.h" // Make sure our source manager is initialized - builtinSourceManager.initialize(nullptr); + builtinSourceManager.initialize(nullptr, nullptr); // Initialize representations of some very basic types: initializeTypes(); @@ -117,21 +117,21 @@ struct IncludeHandlerImpl : IncludeHandler return SLANG_E_NOT_FOUND; } - // Get the canonical path - ComPtr canonicalPathBlob; - SLANG_RETURN_ON_FAIL(fileSystemExt->getCanoncialPath(combinedPath.begin(), canonicalPathBlob.writeRef())); + // Get the uniqueIdentity + ComPtr uniqueIdentityBlob; + SLANG_RETURN_ON_FAIL(fileSystemExt->getFileUniqueIdentity(combinedPath.begin(), uniqueIdentityBlob.writeRef())); - // If the rel path exists -> the canonical path MUST exists too - String canonicalPath(StringUtil::getString(canonicalPathBlob)); - if (canonicalPath.Length() <= 0) + // If the rel path exists -> a uniqueIdentity MUST exists too + String uniqueIdentity(StringUtil::getString(uniqueIdentityBlob)); + if (uniqueIdentity.Length() <= 0) { - // Canonical path can't be empty + // Unique identity can't be empty return SLANG_FAIL; } pathInfoOut.type = PathInfo::Type::Normal; pathInfoOut.foundPath = combinedPath; - pathInfoOut.canonicalPath = canonicalPath; + pathInfoOut.uniqueIdentity = uniqueIdentity; return SLANG_OK; } @@ -306,7 +306,7 @@ CompileRequest::CompileRequest(Session* session) setSourceManager(&sourceManagerStorage); - sourceManager->initialize(session->getBuiltinSourceManager()); + sourceManager->initialize(session->getBuiltinSourceManager(), nullptr); // Set all the default writers for (int i = 0; i < int(WriterChannel::CountOf); ++i) @@ -314,9 +314,7 @@ CompileRequest::CompileRequest(Session* session) setWriter(WriterChannel(i), nullptr); } - // Set up the default file system - SLANG_ASSERT(fileSystem == nullptr); - fileSystemExt = new CacheFileSystem(OSFileSystem::getSingleton()); + setFileSystem(nullptr); } // Allocate static const storage for the various interface IDs that the Slang API needs to expose @@ -419,7 +417,7 @@ RefPtr CompileRequest::parseTypeString(TranslationUnitRequest * translatio { // Create a SourceManager on the stack, so any allocations for 'SourceFile'/'SourceView' etc will be cleaned up SourceManager localSourceManager; - localSourceManager.initialize(sourceManager); + localSourceManager.initialize(sourceManager, nullptr); Slang::SourceFile* srcFile = localSourceManager.createSourceFileWithString(PathInfo::makeTypeParse(), typeStr); @@ -859,10 +857,10 @@ void CompileRequest::loadParsedModule( RefPtr loadedModule = new LoadedModule(); // Get a path - String mostUniquePath = pathInfo.getMostUniquePath(); - SLANG_ASSERT(mostUniquePath.Length() > 0); + String mostUniqueIdentity = pathInfo.getMostUniqueIdentity(); + SLANG_ASSERT(mostUniqueIdentity.Length() > 0); - mapPathToLoadedModule.Add(mostUniquePath, loadedModule); + mapPathToLoadedModule.Add(mostUniqueIdentity, loadedModule); mapNameToLoadedModules.Add(name, loadedModule); int errorCountBefore = mSink.GetErrorCount(); @@ -985,7 +983,7 @@ RefPtr CompileRequest::findOrImportModule( PathInfo pathIncludedFromInfo = getSourceManager()->getPathInfo(loc, SourceLocType::Actual); PathInfo filePathInfo; - // We are going to allow canonicalPath to be able to hold strings other than paths (like hashes), therefore we have to load via the found path + // We have to load via the found path - as that is how file was originally loaded if (SLANG_FAILED(includeHandler.findFile(fileName, pathIncludedFromInfo.foundPath, filePathInfo))) { this->mSink.diagnose(loc, Diagnostics::cannotFindFile, fileName); @@ -994,7 +992,7 @@ RefPtr CompileRequest::findOrImportModule( } // Maybe this was loaded previously at a different relative name? - if (mapPathToLoadedModule.TryGetValue(filePathInfo.getMostUniquePath(), loadedModule)) + if (mapPathToLoadedModule.TryGetValue(filePathInfo.getMostUniqueIdentity(), loadedModule)) return loadedModule->moduleDecl; // Try to load it @@ -1047,6 +1045,34 @@ void CompileRequest::noteInternalErrorLoc(SourceLoc const& loc) internalErrorLocsNoted++; } +static const Slang::Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; + +void CompileRequest::setFileSystem(ISlangFileSystem* inFileSystem) +{ + // Set the fileSystem + fileSystem = inFileSystem; + + // Set up fileSystemExt appropriately + if (inFileSystem == nullptr) + { + fileSystemExt = new Slang::CacheFileSystem(Slang::OSFileSystem::getSingleton()); + } + else + { + // See if we have the interface + inFileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)fileSystemExt.writeRef()); + + // If not wrap with WrapFileSytem that keeps the old behavior + if (!fileSystemExt) + { + // Construct a wrapper to emulate the extended interface behavior + fileSystemExt = new Slang::CacheFileSystem(fileSystem); + } + } + + // Set the file system used on the source manager + sourceManager->setFileSystemExt(fileSystemExt); +} RefPtr findOrImportModule( CompileRequest* request, @@ -1236,35 +1262,12 @@ SLANG_API void spDestroyCompileRequest( delete req; } -static const Slang::Guid IID_ISlangFileSystemExt = SLANG_UUID_ISlangFileSystemExt; - SLANG_API void spSetFileSystem( SlangCompileRequest* request, ISlangFileSystem* fileSystem) { if(!request) return; - auto req = REQ(request); - - // Set the fileSystem - req->fileSystem = fileSystem; - - // Set up fileSystemExt appropriately - if (fileSystem == nullptr) - { - req->fileSystemExt = new Slang::CacheFileSystem(Slang::OSFileSystem::getSingleton()); - } - else - { - // See if we have the interface - fileSystem->queryInterface(IID_ISlangFileSystemExt, (void**)req->fileSystemExt.writeRef()); - - // If not wrap with WrapFileSytem that keeps the old behavior - if (!req->fileSystemExt) - { - // Construct a wrapper to emulate the extended interface behavior - req->fileSystemExt = new Slang::CacheFileSystem(fileSystem); - } - } + REQ(request)->setFileSystem(fileSystem); } SLANG_API void spSetCompileFlags( -- cgit v1.2.3