summaryrefslogtreecommitdiffstats
path: root/source/slang/slang.cpp
diff options
context:
space:
mode:
authorLujin Wang <143145775+lujinwangnv@users.noreply.github.com>2025-06-04 22:55:11 -0700
committerGitHub <noreply@github.com>2025-06-05 05:55:11 +0000
commit0c4c63b4a575f45f5dcf03f26b78becd36b0efca (patch)
treee44bd4b5fc47b1f3b0b76d9a6ab27355fc02f6dd /source/slang/slang.cpp
parent22ebf908f0efdabc0c2ebfad044f35677b6d6660 (diff)
Fix missing debug info for the included slang file (#7281)
* Fix missing debug info in the included slang file Issue: https://github.com/shader-slang/slang/issues/7271 Debug info including DebugFunction, DebugLocation, and DebugValue are missing in IR for "#included" Slang shader file. The included shader file was not added to TranslationUnit's source file list, therefore mapSourceFileToDebugSourceInst.add() was not called for the source in generateIRForTranslationUnit(), and later mapSourceFileToDebugSourceInst.tryGetValue() could not get value for the source to add DebugLocationDecoration, which led to missing DebugFunction, DebugLocation and other debug info for the included file in IR. Adding the include file in TranslationUnit's source file list fixes the issue. * Add source file using PreprocessorHandler Call _addSourceFile from FrontEndPreprocessorHandler::handleFileDependency. * Just use FrontEndPreprocessorHandler * Make _addSourceFile public * format code * Distingush the included source file * Add m_includedFileSet to avoid adding dup file HashSet<SourceFile*> m_includedFileSet; --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang.cpp')
-rw-r--r--source/slang/slang.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 065b9de93..912cd2e10 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -2540,6 +2540,16 @@ void TranslationUnitRequest::addSource(IArtifact* sourceArtifact, SourceFile* so
_addSourceFile(sourceFile);
}
+void TranslationUnitRequest::addIncludedSourceFileIfNotExist(SourceFile* sourceFile)
+{
+ if (m_includedFileSet.contains(sourceFile))
+ return;
+
+ sourceFile->setIncludedFile();
+ m_sourceFiles.add(sourceFile);
+ m_includedFileSet.add(sourceFile);
+}
+
PathInfo TranslationUnitRequest::_findSourcePathInfo(IArtifact* artifact)
{
auto pathRep = findRepresentation<IPathArtifactRepresentation>(artifact);
@@ -2652,7 +2662,6 @@ void TranslationUnitRequest::_addSourceFile(SourceFile* sourceFile)
List<SourceFile*> const& TranslationUnitRequest::getSourceFiles()
{
- SLANG_ASSERT(m_sourceArtifacts.getCount() == m_sourceFiles.getCount());
return m_sourceFiles;
}
@@ -3072,8 +3081,15 @@ FrontEndCompileRequest::FrontEndCompileRequest(
struct FrontEndPreprocessorHandler : PreprocessorHandler
{
public:
- FrontEndPreprocessorHandler(Module* module, ASTBuilder* astBuilder, DiagnosticSink* sink)
- : m_module(module), m_astBuilder(astBuilder), m_sink(sink)
+ FrontEndPreprocessorHandler(
+ Module* module,
+ ASTBuilder* astBuilder,
+ DiagnosticSink* sink,
+ TranslationUnitRequest* translationUnit)
+ : m_module(module)
+ , m_astBuilder(astBuilder)
+ , m_sink(sink)
+ , m_translationUnit(translationUnit)
{
}
@@ -3081,6 +3097,7 @@ protected:
Module* m_module;
ASTBuilder* m_astBuilder;
DiagnosticSink* m_sink;
+ TranslationUnitRequest* m_translationUnit = nullptr;
// The first task that this handler tries to deal with is
// capturing all the files on which a module is dependent.
@@ -3092,6 +3109,7 @@ protected:
void handleFileDependency(SourceFile* sourceFile) SLANG_OVERRIDE
{
m_module->addFileDependency(sourceFile);
+ m_translationUnit->addIncludedSourceFileIfNotExist(sourceFile);
}
// The second task that this handler deals with is detecting
@@ -3358,6 +3376,9 @@ static void _outputIncludes(
// For all the source files
for (SourceFile* sourceFile : sourceFiles)
{
+ if (sourceFile->isIncludedFile())
+ continue;
+
// Find an initial view (this is the view of this file, that doesn't have an initiating loc)
SourceView* sourceView = _findInitialSourceView(sourceFile);
if (!sourceView)
@@ -3429,7 +3450,7 @@ void FrontEndCompileRequest::parseTranslationUnit(TranslationUnitRequest* transl
// preprocessoing can be communicated to later phases of
// compilation.
//
- FrontEndPreprocessorHandler preprocessorHandler(module, astBuilder, getSink());
+ FrontEndPreprocessorHandler preprocessorHandler(module, astBuilder, getSink(), translationUnit);
for (auto sourceFile : translationUnit->getSourceFiles())
{
@@ -4950,7 +4971,11 @@ Linkage::IncludeResult Linkage::findAndIncludeFile(
fileDecl->parentDecl = module->getModuleDecl();
module->getIncludedSourceFileMap().add(sourceFile, fileDecl);
- FrontEndPreprocessorHandler preprocessorHandler(module, module->getASTBuilder(), sink);
+ FrontEndPreprocessorHandler preprocessorHandler(
+ module,
+ module->getASTBuilder(),
+ sink,
+ translationUnit);
auto combinedPreprocessorDefinitions = translationUnit->getCombinedPreprocessorDefinitions();
SourceLanguage sourceLanguage = translationUnit->sourceLanguage;
SlangLanguageVersion slangLanguageVersion = module->getModuleDecl()->languageVersion;