diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-19 17:01:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-19 17:01:45 -0700 |
| commit | 2b55de9263dc594fd2b037b7f3e3727f9a3ce9fd (patch) | |
| tree | bc62aeca59b55e3fa26aee579e1ce057c4d13f73 | |
| parent | 50c268e534c84c57ec79871fab1a6e8302dcc8fe (diff) | |
Fix inconsistent digest of precompiled module. (#3796)
| -rw-r--r-- | source/slang/slang-serialize-container.cpp | 8 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 35 |
2 files changed, 40 insertions, 3 deletions
diff --git a/source/slang/slang-serialize-container.cpp b/source/slang/slang-serialize-container.cpp index 2378050e6..2454256c2 100644 --- a/source/slang/slang-serialize-container.cpp +++ b/source/slang/slang-serialize-container.cpp @@ -457,8 +457,12 @@ static List<ExtensionDecl*>& _getCandidateExtensionList( { auto srcManager = options.linkage->getSourceManager(); auto modulePathInfo = PathInfo::makePath(options.modulePath); - auto srcFile = srcManager->createSourceFileWithString(modulePathInfo, String()); - srcManager->addSourceFile(options.modulePath, srcFile); + auto srcFile = srcManager->findSourceFileByPathRecursively(modulePathInfo.foundPath); + if (!srcFile) + { + srcFile = srcManager->createSourceFileWithString(modulePathInfo, String()); + srcManager->addSourceFile(options.modulePath, srcFile); + } auto srcView = srcManager->createSourceView(srcFile, &modulePathInfo, SourceLoc()); binaryModuleLoc = srcView->getRange().begin; } diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 241ec7f43..6d40b46a2 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -3347,6 +3347,7 @@ RefPtr<Module> Linkage::loadModuleFromIRBlobImpl( readOptions.sink = sink; readOptions.sourceManager = getSourceManager(); readOptions.namePool = getNamePool(); + readOptions.modulePath = filePathInfo.foundPath; SerialContainerData containerData; if (SLANG_FAILED(SerialContainerUtil::read(&container, readOptions, additionalLoadedModules, containerData)) || containerData.modules.getCount() != 1) @@ -3692,6 +3693,21 @@ bool Linkage::isBinaryModuleUpToDate(String fromPath, RiffContainer* container) auto version = String(getBuildTagString()); digestBuilder.append(version); m_optionSet.buildHash(digestBuilder); + + // Find the canonical path of the directory containing the module source file. + String moduleSrcPath = ""; + if (moduleHeader.dependentFiles.getCount()) + { + moduleSrcPath = moduleHeader.dependentFiles.getFirst(); + IncludeSystem includeSystem(&getSearchDirectories(), getFileSystemExt(), getSourceManager()); + PathInfo modulePathInfo; + if (SLANG_SUCCEEDED(includeSystem.findFile(moduleSrcPath, fromPath, modulePathInfo))) + { + moduleSrcPath = modulePathInfo.foundPath; + Path::getCanonical(moduleSrcPath, moduleSrcPath); + } + } + for (auto file : moduleHeader.dependentFiles) { auto sourceFile = loadSourceFile(fromPath, file); @@ -3700,7 +3716,7 @@ bool Linkage::isBinaryModuleUpToDate(String fromPath, RiffContainer* container) // If we cannot find the source file from `fromPath`, // try again from the module's source file path. if (moduleHeader.dependentFiles.getCount() != 0) - sourceFile = loadSourceFile(Path::getParentDirectory(moduleHeader.dependentFiles.getFirst()), file); + sourceFile = loadSourceFile(moduleSrcPath, file); } if (!sourceFile) return false; @@ -5245,9 +5261,26 @@ void Linkage::prepareDeserializedModule(SerialContainerData::Module& moduleEntry module->setIRModule(moduleEntry.irModule); module->setModuleDecl(as<ModuleDecl>(moduleEntry.astRootNode)); module->clearFileDependency(); + String moduleSourcePath = filePathInfo.foundPath; + bool isFirst = true; for (auto file : moduleEntry.dependentFiles) { auto sourceFile = loadSourceFile(filePathInfo.foundPath, file); + if (isFirst) + { + // The first file is the source for the main module file. + // We store the module path as the basis for finding the remaining + // dependent files. + if (sourceFile) + moduleSourcePath = sourceFile->getPathInfo().foundPath; + isFirst = false; + } + // If we cannot find the dependent file directly, try to find + // it relative to the module source path. + if (!sourceFile) + { + sourceFile = loadSourceFile(moduleSourcePath, file); + } if (sourceFile) { module->addFileDependency(sourceFile); |
