From 5c529f300d3a64d9ce8729ff99e3007922719bc8 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 12 Oct 2022 16:17:02 +0200 Subject: [PATCH] use GC nearly everywhere --- dsymbol/src/dsymbol/builtin/symbols.d | 2 +- dsymbol/src/dsymbol/conversion/first.d | 48 +++++++----------------- dsymbol/src/dsymbol/conversion/package.d | 20 +++++----- dsymbol/src/dsymbol/conversion/second.d | 16 ++++---- dsymbol/src/dsymbol/deferred.d | 4 +- dsymbol/src/dsymbol/modulecache.d | 19 +--------- dsymbol/src/dsymbol/tests.d | 41 ++++++++++---------- src/dcd/server/autocomplete/complete.d | 12 ++---- src/dcd/server/autocomplete/doc.d | 4 +- src/dcd/server/autocomplete/localuse.d | 3 +- src/dcd/server/autocomplete/symbols.d | 6 +-- src/dcd/server/autocomplete/util.d | 4 +- src/dcd/server/main.d | 2 +- 13 files changed, 64 insertions(+), 117 deletions(-) diff --git a/dsymbol/src/dsymbol/builtin/symbols.d b/dsymbol/src/dsymbol/builtin/symbols.d index 94422c5..2675776 100644 --- a/dsymbol/src/dsymbol/builtin/symbols.d +++ b/dsymbol/src/dsymbol/builtin/symbols.d @@ -8,7 +8,7 @@ import dsymbol.string_interning; import dsymbol.symbol; import std.experimental.allocator.mallocator : Mallocator; -alias SymbolsAllocator = Mallocator; +private alias SymbolsAllocator = Mallocator; /** * Symbols for the built in types diff --git a/dsymbol/src/dsymbol/conversion/first.d b/dsymbol/src/dsymbol/conversion/first.d index 69b51a0..e488566 100644 --- a/dsymbol/src/dsymbol/conversion/first.d +++ b/dsymbol/src/dsymbol/conversion/first.d @@ -53,32 +53,22 @@ import std.typecons : Rebindable; */ final class FirstPass : ASTVisitor { - alias SymbolAllocator = GCAllocator; // NOTE using First`Pass.symbolAllocator` instead fails when analyzing Phobos master - alias ScopeAllocator = GCAllocator; // NOTE using `Mallocator` instead fails when analyzing Phobos master - /** * Params: * mod = the module to visit * symbolFile = path to the file being converted - * symbolAllocator = allocator used for the auto-complete symbols - * semanticAllocator = allocator used for semantic symbols */ - this(const Module mod, istring symbolFile, RCIAllocator symbolAllocator, - RCIAllocator semanticAllocator, + this(const Module mod, istring symbolFile, ModuleCache* cache, CacheEntry* entry = null) in { assert(mod); - assert(!symbolAllocator.isNull); - assert(!semanticAllocator.isNull); assert(cache); } do { this.mod = mod; this.symbolFile = symbolFile; - this.symbolAllocator = symbolAllocator; - this.semanticAllocator = semanticAllocator; this.entry = entry; this.cache = cache; } @@ -146,7 +136,7 @@ final class FirstPass : ASTVisitor if (dec.functionBody !is null) { - pushFunctionScope(dec.functionBody, semanticAllocator, + pushFunctionScope(dec.functionBody, dec.name.index + dec.name.text.length); scope (exit) popScope(); processParameters(currentSymbol, dec.returnType, @@ -374,7 +364,7 @@ final class FirstPass : ASTVisitor rootSymbol = allocateSemanticSymbol(null, CompletionKind.moduleName, symbolFile); currentSymbol = rootSymbol; - moduleScope = GCAllocator.instance.make!Scope(0, uint.max); // NOTE using `semanticAllocator` here fails as `Segmentation fault (core dumped)` + moduleScope = GCAllocator.instance.make!Scope(0, uint.max); currentScope = moduleScope; auto objectLocation = cache.resolveImportLocation("object"); if (objectLocation is null) @@ -444,7 +434,7 @@ final class FirstPass : ASTVisitor scope(exit) structFieldNames = move(savedStructFieldNames); scope(exit) structFieldTypes = move(savedStructFieldTypes); - DSymbol* thisSymbol = SymbolAllocator.instance.make!DSymbol(THIS_SYMBOL_NAME, + DSymbol* thisSymbol = GCAllocator.instance.make!DSymbol(THIS_SYMBOL_NAME, CompletionKind.variableName, currentSymbol.acSymbol); thisSymbol.location = currentScope.startLocation; thisSymbol.symbolFile = symbolFile; @@ -497,7 +487,7 @@ final class FirstPass : ASTVisitor auto s = currentScope.getSymbolsByName(ip); if (s.length == 0) { - currentImportSymbol = SymbolAllocator.instance.make!DSymbol(ip, kind); + currentImportSymbol = GCAllocator.instance.make!DSymbol(ip, kind); currentScope.addSymbol(currentImportSymbol, true); if (last) { @@ -514,7 +504,7 @@ final class FirstPass : ASTVisitor auto s = currentImportSymbol.getPartsByName(ip); if (s.length == 0) { - auto sym = SymbolAllocator.instance.make!DSymbol(ip, kind); + auto sym = GCAllocator.instance.make!DSymbol(ip, kind); currentImportSymbol.addChild(sym, true); currentImportSymbol = sym; if (last) @@ -781,9 +771,6 @@ final class FirstPass : ASTVisitor /// The module SemanticSymbol* rootSymbol; - /// Allocator used for symbol allocation - RCIAllocator symbolAllocator; - /// Number of symbols allocated uint symbolsAllocated; @@ -823,7 +810,7 @@ private: { assert (startLocation < uint.max); assert (endLocation < uint.max || endLocation == size_t.max); - Scope* s = ScopeAllocator.instance.make!Scope(cast(uint) startLocation, cast(uint) endLocation); + Scope* s = GCAllocator.instance.make!Scope(cast(uint) startLocation, cast(uint) endLocation); s.parent = currentScope; currentScope.children.insert(s); currentScope = s; @@ -834,10 +821,9 @@ private: currentScope = currentScope.parent; } - void pushFunctionScope(const FunctionBody functionBody, - RCIAllocator semanticAllocator, size_t scopeBegin) + void pushFunctionScope(const FunctionBody functionBody, size_t scopeBegin) { - Scope* s = ScopeAllocator.instance.make!Scope(cast(uint) scopeBegin, + Scope* s = GCAllocator.instance.make!Scope(cast(uint) scopeBegin, cast(uint) functionBody.endLocation); s.parent = currentScope; currentScope.children.insert(s); @@ -926,8 +912,7 @@ private: if (functionBody !is null) { - pushFunctionScope(functionBody, semanticAllocator, - location + 4); // 4 == "this".length + pushFunctionScope(functionBody, location + 4); // 4 == "this".length scope(exit) popScope(); currentSymbol = symbol; functionBody.accept(this); @@ -951,7 +936,7 @@ private: if (functionBody !is null) { - pushFunctionScope(functionBody, semanticAllocator, location + 4); // 4 == "this".length + pushFunctionScope(functionBody, location + 4); // 4 == "this".length scope(exit) popScope(); currentSymbol = symbol; functionBody.accept(this); @@ -1108,17 +1093,12 @@ private: SemanticSymbol* allocateSemanticSymbol(string name, CompletionKind kind, istring symbolFile, size_t location = 0) - in { - assert (!symbolAllocator.isNull); - } - do - { - DSymbol* acSymbol = SymbolAllocator.instance.make!DSymbol(istring(name), kind); + DSymbol* acSymbol = GCAllocator.instance.make!DSymbol(istring(name), kind); acSymbol.location = location; acSymbol.symbolFile = symbolFile; symbolsAllocated++; - return SymbolAllocator.instance.make!SemanticSymbol(acSymbol); // NOTE using semanticAllocator here breaks when analysing phobos as: `Segmentation fault (core dumped)‘’ + return GCAllocator.instance.make!SemanticSymbol(acSymbol); } void addTypeToLookups(ref TypeLookups lookups, @@ -1207,8 +1187,6 @@ private: const Module mod; - RCIAllocator semanticAllocator; - Rebindable!(const ExpressionNode) feExpression; CacheEntry* entry; diff --git a/dsymbol/src/dsymbol/conversion/package.d b/dsymbol/src/dsymbol/conversion/package.d index 9249173..0cd5919 100644 --- a/dsymbol/src/dsymbol/conversion/package.d +++ b/dsymbol/src/dsymbol/conversion/package.d @@ -18,38 +18,38 @@ module dsymbol.conversion; +import dparse.ast; +import dparse.lexer; +import dparse.parser; +import dparse.rollback_allocator; import dsymbol.cache_entry; import dsymbol.conversion.first; import dsymbol.conversion.second; import dsymbol.modulecache; import dsymbol.scope_; +import dsymbol.semantic; import dsymbol.string_interning; import dsymbol.symbol; -import dsymbol.semantic; -import dparse.ast; -import dparse.lexer; -import dparse.parser; -import dparse.rollback_allocator; +import std.algorithm; import std.experimental.allocator; /** * Used by autocompletion. */ ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens, - RCIAllocator symbolAllocator, RollbackAllocator* parseAllocator, + RollbackAllocator* parseAllocator, size_t cursorPosition, ref ModuleCache cache) { Module m = parseModuleForAutocomplete(tokens, internString("stdin"), parseAllocator, cursorPosition); - scope first = new FirstPass(m, internString("stdin"), symbolAllocator, - symbolAllocator, &cache); + scope first = new FirstPass(m, internString("stdin"), &cache); first.run(); secondPass(first.rootSymbol, first.moduleScope, cache); - auto r = first.rootSymbol.acSymbol; + auto r = move(first.rootSymbol.acSymbol); typeid(SemanticSymbol).destroy(first.rootSymbol); - return ScopeSymbolPair(r, first.moduleScope); + return ScopeSymbolPair(r, move(first.moduleScope)); } struct ScopeSymbolPair diff --git a/dsymbol/src/dsymbol/conversion/second.d b/dsymbol/src/dsymbol/conversion/second.d index f1d0e02..bd56763 100644 --- a/dsymbol/src/dsymbol/conversion/second.d +++ b/dsymbol/src/dsymbol/conversion/second.d @@ -34,8 +34,6 @@ import std.experimental.logger; import dparse.ast; import dparse.lexer; -alias SymbolAllocator = GCAllocator; // NOTE using cache.symbolAllocator instead fails when analyzing Phobos master - void secondPass(SemanticSymbol* currentSymbol, Scope* moduleScope, ref ModuleCache cache) { with (CompletionKind) final switch (currentSymbol.acSymbol.kind) @@ -115,7 +113,7 @@ do if (moduleSymbol is null) { tryAgain: - DeferredSymbol* deferred = TypeLookupsAllocator.instance.make!DeferredSymbol(acSymbol); + DeferredSymbol* deferred = DeferredSymbolsAllocator.instance.make!DeferredSymbol(acSymbol); deferred.typeLookups.insert(typeLookups[]); // Get rid of the old references to the lookups, this new deferred // symbol owns them now @@ -191,7 +189,7 @@ do break; immutable qualifier = isAssoc ? SymbolQualifier.assocArray : (isFunction ? SymbolQualifier.func : SymbolQualifier.array); - lastSuffix = SymbolAllocator.instance.make!DSymbol(back, CompletionKind.dummy, lastSuffix); + lastSuffix = GCAllocator.instance.make!DSymbol(back, CompletionKind.dummy, lastSuffix); lastSuffix.qualifier = qualifier; lastSuffix.ownType = true; if (isFunction) @@ -335,13 +333,13 @@ void resolveInheritance(DSymbol* symbol, ref TypeLookups typeLookups, baseClass = symbols[0]; } - DSymbol* imp = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, + DSymbol* imp = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, CompletionKind.importSymbol, baseClass); symbol.addChild(imp, true); symbolScope.addSymbol(imp, false); if (baseClass.kind == CompletionKind.className) { - auto s = SymbolAllocator.instance.make!DSymbol(SUPER_SYMBOL_NAME, + auto s = GCAllocator.instance.make!DSymbol(SUPER_SYMBOL_NAME, CompletionKind.variableName, baseClass); symbolScope.addSymbol(s, true); } @@ -359,7 +357,7 @@ void resolveAliasThis(DSymbol* symbol, auto parts = symbol.getPartsByName(aliasThis.breadcrumbs.front); if (parts.length == 0 || parts[0].type is null) continue; - DSymbol* s = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, + DSymbol* s = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, CompletionKind.importSymbol, parts[0].type); symbol.addChild(s, true); auto symbolScope = moduleScope.getScopeByCursor(s.location); @@ -395,7 +393,7 @@ void resolveMixinTemplates(DSymbol* symbol, } if (currentSymbol !is null) { - auto i = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, + auto i = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, CompletionKind.importSymbol, currentSymbol); i.ownType = false; symbol.addChild(i, true); @@ -447,7 +445,7 @@ void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup, else if (crumb == ARRAY_LITERAL_SYMBOL_NAME) { - auto arr = SymbolAllocator.instance.make!(DSymbol)(ARRAY_LITERAL_SYMBOL_NAME, CompletionKind.dummy, currentSymbol); + auto arr = GCAllocator.instance.make!(DSymbol)(ARRAY_LITERAL_SYMBOL_NAME, CompletionKind.dummy, currentSymbol); arr.qualifier = SymbolQualifier.array; currentSymbol = arr; } diff --git a/dsymbol/src/dsymbol/deferred.d b/dsymbol/src/dsymbol/deferred.d index 10dac5a..a7403c9 100644 --- a/dsymbol/src/dsymbol/deferred.d +++ b/dsymbol/src/dsymbol/deferred.d @@ -25,10 +25,10 @@ import dsymbol.import_; import dsymbol.symbol; import dsymbol.type_lookup; import std.experimental.allocator : dispose; -import std.experimental.allocator.mallocator : Mallocator; +import std.experimental.allocator.gc_allocator : GCAllocator; import dsymbol.semantic : TypeLookups, TypeLookupsAllocator; -alias ImportsAllocator = Mallocator; +alias ImportsAllocator = GCAllocator; alias Imports = UnrolledList!(DSymbol*, ImportsAllocator); /** diff --git a/dsymbol/src/dsymbol/modulecache.d b/dsymbol/src/dsymbol/modulecache.d index 7240176..ca1ba9f 100644 --- a/dsymbol/src/dsymbol/modulecache.d +++ b/dsymbol/src/dsymbol/modulecache.d @@ -48,8 +48,6 @@ import std.file; import std.experimental.lexer; import std.path; -alias ASTAllocator = AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator); - /** * Returns: true if a file exists at the given path. */ @@ -71,13 +69,6 @@ struct ModuleCache /// No copying. @disable this(this); - @disable this(); - - this(RCIAllocator symbolAllocator) - { - this.symbolAllocator = symbolAllocator; - } - ~this() { clear(); @@ -147,9 +138,6 @@ struct ModuleCache foreach (symbol; deferredSymbols[]) DeferredSymbolsAllocator.instance.dispose(symbol); - // TODO: This call to deallocateAll is a workaround for issues of - // CAllocatorImpl and GCAllocator not interacting well. - symbolAllocator.deallocateAll(); cache.clear(); deferredSymbols.clear(); importPaths.clear(); @@ -198,14 +186,11 @@ struct ModuleCache CacheEntry* newEntry = CacheAllocator.instance.make!CacheEntry(); - scope semanticAllocator = new ASTAllocator(); import dparse.rollback_allocator:RollbackAllocator; RollbackAllocator parseAllocator; Module m = parseModuleSimple(tokens[], cachedLocation, &parseAllocator); - assert (!symbolAllocator.isNull); - scope first = new FirstPass(m, cachedLocation, symbolAllocator, - semanticAllocator.allocatorObject, &this, newEntry); + scope first = new FirstPass(m, cachedLocation, &this, newEntry); first.run(); secondPass(first.rootSymbol, first.moduleScope, this); @@ -355,8 +340,6 @@ struct ModuleCache return cache[]; } - RCIAllocator symbolAllocator; - alias DeferredSymbols = UnrolledList!(DeferredSymbol*, DeferredSymbolsAllocator); DeferredSymbols deferredSymbols; diff --git a/dsymbol/src/dsymbol/tests.d b/dsymbol/src/dsymbol/tests.d index 4a56b69..3652388 100644 --- a/dsymbol/src/dsymbol/tests.d +++ b/dsymbol/src/dsymbol/tests.d @@ -24,7 +24,7 @@ void expectSymbolsAndTypes(const string source, const string[][] results, import core.exception : AssertError; import std.exception : enforce; - ModuleCache mcache = ModuleCache(theAllocator); + ModuleCache mcache; auto pair = generateAutocompleteTrees(source, mcache); scope(exit) pair.destroy(); @@ -80,7 +80,7 @@ void expectSymbolsAndTypes(const string source, const string[][] results, // this one used to crash, see #125 unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; auto source = q{ auto a = true ? [42] : []; }; auto pair = generateAutocompleteTrees(source, cache); } @@ -88,7 +88,7 @@ unittest // https://github.com/dlang-community/D-Scanner/issues/749 unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; auto source = q{ void test() { foo(new class A {});} }; auto pair = generateAutocompleteTrees(source, cache); } @@ -96,14 +96,14 @@ unittest // https://github.com/dlang-community/D-Scanner/issues/738 unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; auto source = q{ void b() { c = } alias b this; }; auto pair = generateAutocompleteTrees(source, cache); } unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running function literal tests..."); const sources = [ @@ -128,7 +128,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running struct constructor tests..."); auto source = q{ struct A {int a; struct B {bool b;} int c;} }; @@ -143,7 +143,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running union constructor tests..."); auto source = q{ union A {int a; bool b;} }; @@ -155,7 +155,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running non-importable symbols tests..."); auto source = q{ class A { this(int a){} } @@ -173,7 +173,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running alias this tests..."); auto source = q{ struct A {int f;} struct B { A a; alias a this; void fun() { auto var = f; };} }; @@ -188,7 +188,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running anon struct tests..."); auto source = q{ struct A { struct {int a;}} }; @@ -201,7 +201,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running anon class tests..."); const sources = [ @@ -230,7 +230,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running the deduction from index expr tests..."); { @@ -278,7 +278,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running `super` tests..."); auto source = q{ class A {} class B : A {} }; @@ -296,7 +296,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running the \"access chain with inherited type\" tests..."); auto source = q{ class A {} class B : A {} }; @@ -313,7 +313,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running template type parameters tests..."); { @@ -340,7 +340,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Running template variadic parameters tests..."); auto source = q{ struct Foo(T...){ }}; @@ -385,7 +385,7 @@ unittest rmdir(dir); } - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; cache.addImportPaths([dir]); const a = cache.getModuleSymbol(istring(fnameA)); @@ -429,7 +429,7 @@ unittest unittest { - ModuleCache cache = ModuleCache(theAllocator); + ModuleCache cache; writeln("Testing protection scopes"); auto source = q{version(all) { private: } struct Foo{ }}; @@ -537,8 +537,7 @@ ScopeSymbolPair generateAutocompleteTrees(string source, string filename, ref Mo RollbackAllocator rba; Module m = parseModule(tokens, filename, &rba); - scope first = new FirstPass(m, internString(filename), - theAllocator, theAllocator, &cache); + scope first = new FirstPass(m, internString(filename), &cache); first.run(); secondPass(first.rootSymbol, first.moduleScope, cache); @@ -557,5 +556,5 @@ ScopeSymbolPair generateAutocompleteTrees(string source, string filename, size_t auto tokens = lex(source); RollbackAllocator rba; return dsymbol.conversion.generateAutocompleteTrees( - tokens, theAllocator, &rba, cursorPosition, cache); + tokens, &rba, cursorPosition, cache); } diff --git a/src/dcd/server/autocomplete/complete.d b/src/dcd/server/autocomplete/complete.d index 3e84b30..c761bce 100644 --- a/src/dcd/server/autocomplete/complete.d +++ b/src/dcd/server/autocomplete/complete.d @@ -214,10 +214,8 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray, mixin(TYPE_IDENT_CASES); case tok!")": case tok!"]": - scope allocator = new ASTAllocator(); RollbackAllocator rba; - ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, - allocator.allocatorObject, &rba, cursorPosition, moduleCache); + ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, &rba, cursorPosition, moduleCache); scope(exit) pair.destroy(); response.setCompletions(pair.scope_, getExpression(beforeTokens), cursorPosition, CompletionType.identifiers, false, partial); @@ -230,10 +228,8 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray, case tok!";": case tok!"}": case tok!",": - scope allocator = new ASTAllocator(); RollbackAllocator rba; - ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, - allocator.allocatorObject, &rba, 1, moduleCache); + ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, &rba, 1, moduleCache); scope(exit) pair.destroy(); response.setCompletions(pair.scope_, getExpression(beforeTokens), 1, CompletionType.identifiers, false, partial); @@ -303,10 +299,8 @@ AutocompleteResponse parenCompletion(T)(T beforeTokens, case tok!")": case tok!"]": mixin(STRING_LITERAL_CASES); - scope allocator = new ASTAllocator(); RollbackAllocator rba; - ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, - allocator.allocatorObject, &rba, cursorPosition, moduleCache); + ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, &rba, cursorPosition, moduleCache); scope(exit) pair.destroy(); auto expression = getExpression(beforeTokens[0 .. $ - 1]); response.setCompletions(pair.scope_, expression, diff --git a/src/dcd/server/autocomplete/doc.d b/src/dcd/server/autocomplete/doc.d index f3103ea..060ba30 100644 --- a/src/dcd/server/autocomplete/doc.d +++ b/src/dcd/server/autocomplete/doc.d @@ -46,10 +46,8 @@ public AutocompleteResponse getDoc(const AutocompleteRequest request, // trace("Getting doc comments"); AutocompleteResponse response; RollbackAllocator rba; - scope allocator = new ASTAllocator(); auto cache = StringCache(request.sourceCode.length.optimalBucketCount); - SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.ddoc, - allocator.allocatorObject, &rba, cache, moduleCache); + SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.ddoc, &rba, cache, moduleCache); if (stuff.symbols.length == 0) warning("Could not find symbol"); else diff --git a/src/dcd/server/autocomplete/localuse.d b/src/dcd/server/autocomplete/localuse.d index 9195624..00ef824 100644 --- a/src/dcd/server/autocomplete/localuse.d +++ b/src/dcd/server/autocomplete/localuse.d @@ -46,7 +46,6 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request, { AutocompleteResponse response; RollbackAllocator rba; - scope allocator = new ASTAllocator(); auto cache = StringCache(request.sourceCode.length.optimalBucketCount); // patchs the original request for the subsequent requests @@ -62,7 +61,7 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request, auto sortedTokens = assumeSorted(tokenArray); auto beforeTokens = sortedTokens.lowerBound(cursorPosition); ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, - allocator.allocatorObject, &rba, request.cursorPosition, moduleCache); + &rba, request.cursorPosition, moduleCache); auto expression = getExpression(beforeTokens); return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, cursorPosition, CompletionType.location), pair.symbol, pair.scope_); diff --git a/src/dcd/server/autocomplete/symbols.d b/src/dcd/server/autocomplete/symbols.d index 5c8bd3a..4b16a1c 100644 --- a/src/dcd/server/autocomplete/symbols.d +++ b/src/dcd/server/autocomplete/symbols.d @@ -48,10 +48,9 @@ public AutocompleteResponse findDeclaration(const AutocompleteRequest request, { AutocompleteResponse response; RollbackAllocator rba; - scope allocator = new ASTAllocator(); auto cache = StringCache(request.sourceCode.length.optimalBucketCount); SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.location, - allocator.allocatorObject, &rba, cache, moduleCache); + &rba, cache, moduleCache); scope(exit) stuff.destroy(); if (stuff.symbols.length > 0) { @@ -76,10 +75,9 @@ public AutocompleteResponse symbolSearch(const AutocompleteRequest request, auto cache = StringCache(request.sourceCode.length.optimalBucketCount); const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode, config, &cache); - scope allocator = new ASTAllocator(); RollbackAllocator rba; ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, - allocator.allocatorObject, &rba, request.cursorPosition, moduleCache); + &rba, request.cursorPosition, moduleCache); scope(exit) pair.destroy(); static struct SearchResults diff --git a/src/dcd/server/autocomplete/util.d b/src/dcd/server/autocomplete/util.d index 9c06c50..009c59f 100644 --- a/src/dcd/server/autocomplete/util.d +++ b/src/dcd/server/autocomplete/util.d @@ -134,13 +134,13 @@ auto getTokensBeforeCursor(const(ubyte[]) sourceCode, size_t cursorPosition, * the request's source code, cursor position, and completion type. */ SymbolStuff getSymbolsForCompletion(const AutocompleteRequest request, - const CompletionType type, RCIAllocator allocator, RollbackAllocator* rba, + const CompletionType type, RollbackAllocator* rba, ref StringCache cache, ref ModuleCache moduleCache) { const(Token)[] tokenArray; auto beforeTokens = getTokensBeforeCursor(request.sourceCode, request.cursorPosition, cache, tokenArray); - ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, allocator, + ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, rba, request.cursorPosition, moduleCache); auto expression = getExpression(beforeTokens); return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, diff --git a/src/dcd/server/main.d b/src/dcd/server/main.d index 4fa4d3b..94e19be 100644 --- a/src/dcd/server/main.d +++ b/src/dcd/server/main.d @@ -176,7 +176,7 @@ int runServer(string[] args) info("Sockets shut down."); } - ModuleCache cache = ModuleCache(new ASTAllocator().allocatorObject); + ModuleCache cache; cache.addImportPaths(importPaths); infof("Import directories:\n %-(%s\n %)", cache.getImportPaths());