From 7b447bdad29c828b49ba63cefacc677bd7c58b28 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 9 Jul 2021 16:29:23 -0400 Subject: Make Scope non ref counted (#1904) * Add debug symbols for release build. * Hack to try and capture failing compilation. * Typo fix for capture hack. * Specify return type on lambdas. * Added const. * Try breakpoint. * Up count * Let's capture everything so we can valgrind. * Disable always writing repros. * Make Scope non RefCounted. * Fix issue with not serializing Scope. * More comments around changes to Scope. Remove Scope* from serialization. * Remove code used for testing original issue. --- source/slang/slang.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'source/slang/slang.cpp') diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index acc4b6f77..ef92558cc 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -159,20 +159,20 @@ void Session::init() // TODO: load these on-demand to avoid parsing // stdlib code for languages the user won't use. - baseLanguageScope = new Scope(); + baseLanguageScope = builtinAstBuilder->create(); // Will stay in scope as long as ASTBuilder baseModuleDecl = populateBaseLanguageModule( m_builtinLinkage->getASTBuilder(), baseLanguageScope); - coreLanguageScope = new Scope(); + coreLanguageScope = builtinAstBuilder->create(); coreLanguageScope->nextSibling = baseLanguageScope; - hlslLanguageScope = new Scope(); + hlslLanguageScope = builtinAstBuilder->create(); hlslLanguageScope->nextSibling = coreLanguageScope; - slangLanguageScope = new Scope(); + slangLanguageScope = builtinAstBuilder->create(); slangLanguageScope->nextSibling = hlslLanguageScope; { @@ -417,7 +417,7 @@ SlangResult Session::_readBuiltinModule(ISlangFileSystem* fileSystem, Scope* sco else { // We need to create a new scope to link into the whole thing - auto subScope = new Scope(); + auto subScope = linkage->getASTBuilder()->create(); subScope->containerDecl = moduleDecl; subScope->nextSibling = scope->nextSibling; scope->nextSibling = subScope; @@ -1291,7 +1291,7 @@ SlangResult Linkage::loadFile(String const& path, PathInfo& outPathInfo, ISlangB return SLANG_OK; } -Expr* Linkage::parseTermString(String typeStr, RefPtr scope) +Expr* Linkage::parseTermString(String typeStr, Scope* scope) { // Create a SourceManager on the stack, so any allocations for 'SourceFile'/'SourceView' etc will be cleaned up SourceManager localSourceManager; @@ -1354,11 +1354,21 @@ Type* ComponentType::getTypeFromString( if(m_types.TryGetValue(typeStr, type)) return type; + + // TODO(JS): For now just used the linkages ASTBuilder to keep on scope + // + // The parseTermString uses the linkage ASTBuilder for it's parsing. + // + // It might be possible to just create a temporary ASTBuilder - the worry though is + // that the parsing sets a member variable in AST node to one of these scopes, and then + // it become a dangling pointer. So for now we go with the linkages. + auto astBuilder = getLinkage()->getASTBuilder(); + // Otherwise, we need to start looking in // the modules that were directly or // indirectly referenced. // - RefPtr scope = _createScopeForLegacyLookup(); + Scope* scope = _createScopeForLegacyLookup(astBuilder); auto linkage = getLinkage(); Expr* typeExpr = linkage->parseTermString( @@ -1537,7 +1547,7 @@ static void _calcViewInitiatingHierarchy(SourceManager* sourceManager, ViewIniti // This assumes they increase in SourceLoc implies an later within a source file - this is true currently. for (auto& pair : outHierarchy) { - pair.Value.sort([](SourceView* a, SourceView* b) { return a->getInitiatingSourceLoc().getRaw() < b->getInitiatingSourceLoc().getRaw(); }); + pair.Value.sort([](SourceView* a, SourceView* b) -> bool { return a->getInitiatingSourceLoc().getRaw() < b->getInitiatingSourceLoc().getRaw(); }); } } @@ -1675,7 +1685,7 @@ void FrontEndCompileRequest::parseTranslationUnit( // would be checked too (after those on the FrontEndCompileRequest). IncludeSystem includeSystem(&linkage->searchDirectories, linkage->getFileSystemExt(), linkage->getSourceManager()); - RefPtr languageScope; + Scope* languageScope = nullptr; switch (translationUnit->sourceLanguage) { case SourceLanguage::HLSL: @@ -2207,6 +2217,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() SlangResult EndToEndCompileRequest::executeActions() { SlangResult res = executeActionsInner(); + m_diagnosticOutput = getSink()->outputBuffer.ProduceString(); return res; } @@ -3762,7 +3773,7 @@ RefPtr findOrImportModule( } void Session::addBuiltinSource( - RefPtr const& scope, + Scope* scope, String const& path, String const& source) { @@ -3784,7 +3795,6 @@ void Session::addBuiltinSource( Name* moduleName = getNamePool()->getName(path); auto translationUnitIndex = compileRequest->addTranslationUnit(SourceLanguage::Slang, moduleName); - compileRequest->addTranslationUnitSourceString( translationUnitIndex, path, @@ -3819,7 +3829,7 @@ void Session::addBuiltinSource( else { // We need to create a new scope to link into the whole thing - auto subScope = new Scope(); + auto subScope = module->getASTBuilder()->create(); subScope->containerDecl = moduleDecl; subScope->nextSibling = scope->nextSibling; scope->nextSibling = subScope; @@ -4247,7 +4257,7 @@ SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile() return saveRes; } } - else if (m_dumpReproOnError && SLANG_FAILED(res)) + else if (m_dumpReproOnError && SLANG_FAILED(res)) { String reproFileName; SlangResult saveRes = SLANG_FAIL; -- cgit v1.2.3