summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-17 07:57:42 +0000
committerGitHub <noreply@github.com>2025-07-17 07:57:42 +0000
commit3485710e93d833a1c7b691af707cfd8962af7d17 (patch)
tree5a45f60da92aed422a923b4f62ad3ffa3a10db65
parent28758e0e427ceca196937dc90efe3ab1cb35bd70 (diff)
Merge NamePool and RootNamePool into a single type (#7797)
* Initial plan * Merge NamePool and RootNamePool into single NamePool class Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Remove unnecessary comment from slang-fiddle-scrape.cpp Co-authored-by: Theresa Foley <tangent-vector@users.noreply.github.com> * Address review feedback: initialize namePool to nullptr and remove unnecessary comments Co-authored-by: Theresa Foley <tangent-vector@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Theresa Foley <tangent-vector@users.noreply.github.com> Co-authored-by: Yong He <yonghe@outlook.com>
-rw-r--r--source/compiler-core/slang-doc-extractor.cpp2
-rw-r--r--source/compiler-core/slang-lexer.cpp2
-rw-r--r--source/compiler-core/slang-name.cpp6
-rw-r--r--source/compiler-core/slang-name.h30
-rw-r--r--source/slang/slang-compiler.h6
-rw-r--r--source/slang/slang-language-server-auto-format.cpp2
-rw-r--r--source/slang/slang.cpp6
-rw-r--r--tools/slang-capability-generator/capability-generator-main.cpp2
-rw-r--r--tools/slang-cpp-parser/unit-test.cpp3
-rw-r--r--tools/slang-fiddle/slang-fiddle-main.cpp12
-rw-r--r--tools/slang-fiddle/slang-fiddle-scrape.cpp6
-rw-r--r--tools/slang-fiddle/slang-fiddle-scrape.h2
12 files changed, 20 insertions, 59 deletions
diff --git a/source/compiler-core/slang-doc-extractor.cpp b/source/compiler-core/slang-doc-extractor.cpp
index f2f4775fa..0a5c1355d 100644
--- a/source/compiler-core/slang-doc-extractor.cpp
+++ b/source/compiler-core/slang-doc-extractor.cpp
@@ -885,9 +885,7 @@ SlangResult DocMarkupExtractor::extract(
MemoryArena memoryArena(4096);
- RootNamePool rootNamePool;
NamePool namePool;
- namePool.setRootNamePool(&rootNamePool);
Index viewIndex = -1;
SourceView* sourceView = nullptr;
diff --git a/source/compiler-core/slang-lexer.cpp b/source/compiler-core/slang-lexer.cpp
index 119c34d48..d9ff9c0f0 100644
--- a/source/compiler-core/slang-lexer.cpp
+++ b/source/compiler-core/slang-lexer.cpp
@@ -1921,9 +1921,7 @@ TokenList Lexer::lexAllTokens()
MemoryArena arena;
- RootNamePool rootNamePool;
NamePool namePool;
- namePool.setRootNamePool(&rootNamePool);
lexer.initialize(sourceView, &sink, &namePool, &arena);
diff --git a/source/compiler-core/slang-name.cpp b/source/compiler-core/slang-name.cpp
index 6f79d25b5..da19dfe3b 100644
--- a/source/compiler-core/slang-name.cpp
+++ b/source/compiler-core/slang-name.cpp
@@ -24,12 +24,12 @@ const char* getCstr(Name* name)
Name* NamePool::getName(UnownedStringSlice text)
{
RefPtr<Name> name;
- if (rootPool->names.tryGetValue(text, name))
+ if (names.tryGetValue(text, name))
return name;
name = new Name();
name->text = text;
- rootPool->names.add(text, name);
+ names.add(text, name);
return name;
}
@@ -41,7 +41,7 @@ Name* NamePool::getName(String const& text)
Name* NamePool::tryGetName(String const& text)
{
RefPtr<Name> name;
- if (rootPool->names.tryGetValue(text, name))
+ if (names.tryGetValue(text, name))
return name;
return nullptr;
}
diff --git a/source/compiler-core/slang-name.h b/source/compiler-core/slang-name.h
index 331086d77..aa178968d 100644
--- a/source/compiler-core/slang-name.h
+++ b/source/compiler-core/slang-name.h
@@ -43,28 +43,10 @@ UnownedStringSlice getUnownedStringSliceText(Name* name);
// Get a name as a C style string, or nullptr if name is nullptr
const char* getCstr(Name* name);
-// A `RootNamePool` is used to store and look up names.
+// A `NamePool` is used to store and look up names.
// If two systems need to work together with names, and be sure that they
// get equivalent names for a string like `"Foo"`, then they need to use
-// the same root name pool (directly or indirectly).
-//
-struct RootNamePool
-{
- // The mapping from text strings to the corresponding name.
- Dictionary<String, RefPtr<Name>> names;
-};
-
-// A `NamePool` is effectively a way of storing a subset of the
-// names that have been created through a `RootNamePool`.
-//
-// The intention is that eventually we will add the ability to clean
-// up a `NamePool`, and remove the names it created from the corresponding
-// `RootNamePool` *if* those names are no longer in use.
-//
-// The goal of such an approach would be to ensure that the memory
-// usage of a `Session` can't bloat over time just because of multiple
-// `CompileRequest`s being created, used, and then destroyed (each time
-// adding just a few more strings to the name mapping).
+// the same name pool (directly or indirectly).
//
struct NamePool
{
@@ -74,13 +56,9 @@ struct NamePool
// Try find the `Name` that represents the given `text`.
// If the name does not exist, return nullptr
Name* tryGetName(String const& text);
- // Set the parent name pool to use for lookup
- void setRootNamePool(RootNamePool* rootNamePool) { this->rootPool = rootNamePool; }
-
- //
- // The root name pool to use for storage/lookup
- RootNamePool* rootPool = nullptr;
+ // The mapping from text strings to the corresponding name.
+ Dictionary<String, RefPtr<Name>> names;
};
} // namespace Slang
diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h
index 6054492bc..d45e796d9 100644
--- a/source/slang/slang-compiler.h
+++ b/source/slang/slang-compiler.h
@@ -2353,9 +2353,9 @@ public:
StringSlicePool m_stringSlicePool;
// Name pool for looking up names
- NamePool namePool;
+ NamePool* namePool = nullptr;
- NamePool* getNamePool() { return &namePool; }
+ NamePool* getNamePool() { return namePool; }
ASTBuilder* getASTBuilder() { return m_astBuilder; }
@@ -3740,10 +3740,8 @@ public:
// Name pool stuff for unique-ing identifiers
- RootNamePool rootNamePool;
NamePool namePool;
- RootNamePool* getRootNamePool() { return &rootNamePool; }
NamePool* getNamePool() { return &namePool; }
Name* getNameObj(String name) { return namePool.getName(name); }
Name* tryGetNameObj(String name) { return namePool.tryGetName(name); }
diff --git a/source/slang/slang-language-server-auto-format.cpp b/source/slang/slang-language-server-auto-format.cpp
index b7f601bc2..a65eb64ec 100644
--- a/source/slang/slang-language-server-auto-format.cpp
+++ b/source/slang/slang-language-server-auto-format.cpp
@@ -77,9 +77,7 @@ List<TextRange> extractFormattingExclusionRanges(UnownedStringSlice text)
auto sourceFile = manager.createSourceFileWithString(PathInfo(), text);
auto sourceView = manager.createSourceView(sourceFile, nullptr, SourceLoc());
DiagnosticSink sink;
- RootNamePool rootPool;
NamePool namePool;
- namePool.setRootNamePool(&rootPool);
MemoryArena memory;
memory.init(1 << 16);
lexer.initialize(sourceView, &sink, &namePool, &memory);
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 090e34e9a..f65681e4b 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -167,8 +167,6 @@ void Session::init()
DownstreamCompilerUtil::setDefaultLocators(m_downstreamCompilerLocators);
m_downstreamCompilerSet = new DownstreamCompilerSet;
- // Initialize name pool
- getNamePool()->setRootNamePool(getRootNamePool());
m_completionTokenName = getNamePool()->getName("#?");
m_sharedLibraryLoader = DefaultSharedLibraryLoader::getSingleton();
@@ -1370,7 +1368,7 @@ Linkage::Linkage(Session* session, ASTBuilder* astBuilder, Linkage* builtinLinka
, m_cmdLineContext(new CommandLineContext())
, m_stringSlicePool(StringSlicePool::Style::Default)
{
- getNamePool()->setRootNamePool(session->getRootNamePool());
+ namePool = session->getNamePool();
m_defaultSourceManager.initialize(session->getBuiltinSourceManager(), nullptr);
@@ -3601,7 +3599,7 @@ void FrontEndCompileRequest::parseTranslationUnit(TranslationUnitRequest* transl
#if 0
// Test serialization
{
- ASTSerialTestUtil::testSerialize(translationUnit->getModuleDecl(), getSession()->getRootNamePool(), getLinkage()->getASTBuilder()->getSharedASTBuilder(), getSourceManager());
+ ASTSerialTestUtil::testSerialize(translationUnit->getModuleDecl(), getSession()->getNamePool(), getLinkage()->getASTBuilder()->getSharedASTBuilder(), getSourceManager());
}
#endif
}
diff --git a/tools/slang-capability-generator/capability-generator-main.cpp b/tools/slang-capability-generator/capability-generator-main.cpp
index f6202607a..56b615330 100644
--- a/tools/slang-capability-generator/capability-generator-main.cpp
+++ b/tools/slang-capability-generator/capability-generator-main.cpp
@@ -1326,8 +1326,6 @@ SlangResult parseDefFile(
SourceView* sourceView = sourceManager->createSourceView(sourceFile, nullptr, SourceLoc());
Lexer lexer;
NamePool namePool;
- RootNamePool rootPool;
- namePool.setRootNamePool(&rootPool);
lexer.initialize(sourceView, sink, &namePool, sourceManager->getMemoryArena());
CapabilityDefParser parser(&lexer, sink, capabilitySharedContext);
diff --git a/tools/slang-cpp-parser/unit-test.cpp b/tools/slang-cpp-parser/unit-test.cpp
index 70851fd7c..41420578e 100644
--- a/tools/slang-cpp-parser/unit-test.cpp
+++ b/tools/slang-cpp-parser/unit-test.cpp
@@ -25,13 +25,10 @@ struct TestState
m_sink.init(&m_sourceManager, Lexer::sourceLocationLexer);
- m_namePool.setRootNamePool(&m_rootNamePool);
-
// We don't require marker
m_options.m_requireMark = false;
}
- RootNamePool m_rootNamePool;
Options m_options;
SourceManager m_sourceManager;
DiagnosticSink m_sink;
diff --git a/tools/slang-fiddle/slang-fiddle-main.cpp b/tools/slang-fiddle/slang-fiddle-main.cpp
index b85412454..cf8407995 100644
--- a/tools/slang-fiddle/slang-fiddle-main.cpp
+++ b/tools/slang-fiddle/slang-fiddle-main.cpp
@@ -42,12 +42,12 @@ public:
struct App
{
public:
- App(SourceManager& sourceManager, DiagnosticSink& sink, RootNamePool& rootNamePool)
- : sourceManager(sourceManager), sink(sink), rootNamePool(rootNamePool)
+ App(SourceManager& sourceManager, DiagnosticSink& sink, NamePool& namePool)
+ : sourceManager(sourceManager), sink(sink), namePool(namePool)
{
}
- RootNamePool& rootNamePool;
+ NamePool& namePool;
SourceManager& sourceManager;
DiagnosticSink& sink;
@@ -61,7 +61,7 @@ public:
return fiddle::parseSourceUnit(
inputSourceView,
logicalModule,
- &rootNamePool,
+ &namePool,
&sink,
&sourceManager,
outputFileName);
@@ -409,7 +409,7 @@ int main(int argc, char const* const* argv)
ComPtr<ISlangWriter> writer(new FileWriter(stderr, WriterFlag::AutoFlush));
- RootNamePool rootNamePool;
+ NamePool namePool;
SourceManager sourceManager;
sourceManager.initialize(nullptr, nullptr);
@@ -433,7 +433,7 @@ int main(int argc, char const* const* argv)
try
{
- App app(sourceManager, sink, rootNamePool);
+ App app(sourceManager, sink, namePool);
app.execute(argc, argv);
}
catch (...)
diff --git a/tools/slang-fiddle/slang-fiddle-scrape.cpp b/tools/slang-fiddle/slang-fiddle-scrape.cpp
index a96183130..c3b83527c 100644
--- a/tools/slang-fiddle/slang-fiddle-scrape.cpp
+++ b/tools/slang-fiddle/slang-fiddle-scrape.cpp
@@ -1602,20 +1602,18 @@ bool findOutputFileIncludeDirective(List<TokenWithTrivia> tokens, String outputF
RefPtr<SourceUnit> parseSourceUnit(
SourceView* inputSourceView,
LogicalModule* logicalModule,
- RootNamePool* rootNamePool,
+ NamePool* namePool,
DiagnosticSink* sink,
SourceManager* sourceManager,
String outputFileName)
{
Lexer lexer;
- NamePool namePool;
- namePool.setRootNamePool(rootNamePool);
// We suppress any diagnostics that might get emitted during lexing,
// so that we can ignore any files we don't understand.
//
DiagnosticSink lexerSink;
- lexer.initialize(inputSourceView, &lexerSink, &namePool, sourceManager->getMemoryArena());
+ lexer.initialize(inputSourceView, &lexerSink, namePool, sourceManager->getMemoryArena());
auto inputTokens = lexer.lexAllTokens();
auto tokensWithTrivia = collectTokensWithTrivia(inputTokens);
diff --git a/tools/slang-fiddle/slang-fiddle-scrape.h b/tools/slang-fiddle/slang-fiddle-scrape.h
index 050576674..098c11aad 100644
--- a/tools/slang-fiddle/slang-fiddle-scrape.h
+++ b/tools/slang-fiddle/slang-fiddle-scrape.h
@@ -350,7 +350,7 @@ T* findDecl(ContainerDecl* outerDecl, UnownedStringSlice const& name)
RefPtr<SourceUnit> parseSourceUnit(
SourceView* inputSourceView,
LogicalModule* logicalModule,
- RootNamePool* rootNamePool,
+ NamePool* namePool,
DiagnosticSink* sink,
SourceManager* sourceManager,
String outputFileName);