From 9885c972a6bfa6f856e505cdd90d9b71fdbdadaf Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 14 Aug 2017 14:48:37 -0700 Subject: Add an explicit `Name` type Fixes #23 Up to this point, the compiler has used the ordinary `String` type to represent declaration names, which means a bunch of lookup structures throughout the compiler were string-to-whatever maps, which can reduce efficiency. It also means that things like the `Token` type end up carying a `String` by value and paying for things like reference-counting. This change adds a `Name` type that is used to represent names of variables, types, macros, etc. Names are cached and unique'd globally for a session, and the string-to-name mapping gets done during lexing. From that point on, most mapping is from pointers, which should make all the various table lookups faster. More importantly (possibly), this brings us one step closer to being able to pool-allocate the AST nodes. --- source/slang/compiler.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'source/slang/compiler.h') diff --git a/source/slang/compiler.h b/source/slang/compiler.h index a2d29f445..b6eca1b36 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -4,6 +4,7 @@ #include "../core/basic.h" #include "diagnostics.h" +#include "name.h" #include "profile.h" #include "syntax.h" @@ -90,7 +91,7 @@ namespace Slang CompileRequest* compileRequest = nullptr; // The name of the entry point function (e.g., `main`) - String name; + Name* name; // The profile that the entry point will be compiled for // (this is a combination of the target state, and also @@ -222,6 +223,11 @@ namespace Slang SourceManager sourceManagerStorage; SourceManager* sourceManager; + // Name pool for looking up names + NamePool namePool; + + NamePool* getNamePool() { return &namePool; } + // Output stuff DiagnosticSink mSink; String mDiagnosticOutput; @@ -241,7 +247,7 @@ namespace Slang Dictionary> mapPathToLoadedModule; // Map from the path of a module file to its definition - Dictionary> mapNameToLoadedModules; + Dictionary> mapNameToLoadedModules; CompileRequest(Session* session); @@ -277,7 +283,7 @@ namespace Slang Profile profile); RefPtr loadModule( - String const& name, + Name* name, String const& path, String const& source, SourceLoc const& loc); @@ -287,8 +293,8 @@ namespace Slang TokenList const& tokens); RefPtr findOrImportModule( - String const& name, - SourceLoc const& loc); + Name* name, + SourceLoc const& loc); SourceManager* getSourceManager() { @@ -335,6 +341,14 @@ namespace Slang SourceManager* getBuiltinSourceManager() { return &builtinSourceManager; } + // Name pool stuff for unique-ing identifiers + + RootNamePool rootNamePool; + NamePool namePool; + + RootNamePool* getRootNamePool() { return &rootNamePool; } + NamePool* getNamePool() { return &namePool; } + // // Generated code for stdlib, etc. @@ -372,9 +386,9 @@ namespace Slang Type* getOverloadedType(); Type* getErrorType(); - SyntaxClass findSyntaxClass(String const& name); + SyntaxClass findSyntaxClass(Name* name); - Dictionary > mapNameToSyntaxClass; + Dictionary > mapNameToSyntaxClass; // -- cgit v1.2.3