use GC nearly everywhere

This commit is contained in:
WebFreak001 2022-10-12 16:17:02 +02:00 committed by Jan Jurzitza
parent e7c7f86455
commit 5c529f300d
13 changed files with 64 additions and 117 deletions

View File

@ -8,7 +8,7 @@ import dsymbol.string_interning;
import dsymbol.symbol; import dsymbol.symbol;
import std.experimental.allocator.mallocator : Mallocator; import std.experimental.allocator.mallocator : Mallocator;
alias SymbolsAllocator = Mallocator; private alias SymbolsAllocator = Mallocator;
/** /**
* Symbols for the built in types * Symbols for the built in types

View File

@ -53,32 +53,22 @@ import std.typecons : Rebindable;
*/ */
final class FirstPass : ASTVisitor 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: * Params:
* mod = the module to visit * mod = the module to visit
* symbolFile = path to the file being converted * 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, this(const Module mod, istring symbolFile,
RCIAllocator semanticAllocator,
ModuleCache* cache, CacheEntry* entry = null) ModuleCache* cache, CacheEntry* entry = null)
in in
{ {
assert(mod); assert(mod);
assert(!symbolAllocator.isNull);
assert(!semanticAllocator.isNull);
assert(cache); assert(cache);
} }
do do
{ {
this.mod = mod; this.mod = mod;
this.symbolFile = symbolFile; this.symbolFile = symbolFile;
this.symbolAllocator = symbolAllocator;
this.semanticAllocator = semanticAllocator;
this.entry = entry; this.entry = entry;
this.cache = cache; this.cache = cache;
} }
@ -146,7 +136,7 @@ final class FirstPass : ASTVisitor
if (dec.functionBody !is null) if (dec.functionBody !is null)
{ {
pushFunctionScope(dec.functionBody, semanticAllocator, pushFunctionScope(dec.functionBody,
dec.name.index + dec.name.text.length); dec.name.index + dec.name.text.length);
scope (exit) popScope(); scope (exit) popScope();
processParameters(currentSymbol, dec.returnType, processParameters(currentSymbol, dec.returnType,
@ -374,7 +364,7 @@ final class FirstPass : ASTVisitor
rootSymbol = allocateSemanticSymbol(null, CompletionKind.moduleName, rootSymbol = allocateSemanticSymbol(null, CompletionKind.moduleName,
symbolFile); symbolFile);
currentSymbol = rootSymbol; 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; currentScope = moduleScope;
auto objectLocation = cache.resolveImportLocation("object"); auto objectLocation = cache.resolveImportLocation("object");
if (objectLocation is null) if (objectLocation is null)
@ -444,7 +434,7 @@ final class FirstPass : ASTVisitor
scope(exit) structFieldNames = move(savedStructFieldNames); scope(exit) structFieldNames = move(savedStructFieldNames);
scope(exit) structFieldTypes = move(savedStructFieldTypes); 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); CompletionKind.variableName, currentSymbol.acSymbol);
thisSymbol.location = currentScope.startLocation; thisSymbol.location = currentScope.startLocation;
thisSymbol.symbolFile = symbolFile; thisSymbol.symbolFile = symbolFile;
@ -497,7 +487,7 @@ final class FirstPass : ASTVisitor
auto s = currentScope.getSymbolsByName(ip); auto s = currentScope.getSymbolsByName(ip);
if (s.length == 0) if (s.length == 0)
{ {
currentImportSymbol = SymbolAllocator.instance.make!DSymbol(ip, kind); currentImportSymbol = GCAllocator.instance.make!DSymbol(ip, kind);
currentScope.addSymbol(currentImportSymbol, true); currentScope.addSymbol(currentImportSymbol, true);
if (last) if (last)
{ {
@ -514,7 +504,7 @@ final class FirstPass : ASTVisitor
auto s = currentImportSymbol.getPartsByName(ip); auto s = currentImportSymbol.getPartsByName(ip);
if (s.length == 0) 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.addChild(sym, true);
currentImportSymbol = sym; currentImportSymbol = sym;
if (last) if (last)
@ -781,9 +771,6 @@ final class FirstPass : ASTVisitor
/// The module /// The module
SemanticSymbol* rootSymbol; SemanticSymbol* rootSymbol;
/// Allocator used for symbol allocation
RCIAllocator symbolAllocator;
/// Number of symbols allocated /// Number of symbols allocated
uint symbolsAllocated; uint symbolsAllocated;
@ -823,7 +810,7 @@ private:
{ {
assert (startLocation < uint.max); assert (startLocation < uint.max);
assert (endLocation < uint.max || endLocation == size_t.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; s.parent = currentScope;
currentScope.children.insert(s); currentScope.children.insert(s);
currentScope = s; currentScope = s;
@ -834,10 +821,9 @@ private:
currentScope = currentScope.parent; currentScope = currentScope.parent;
} }
void pushFunctionScope(const FunctionBody functionBody, void pushFunctionScope(const FunctionBody functionBody, size_t scopeBegin)
RCIAllocator semanticAllocator, 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); cast(uint) functionBody.endLocation);
s.parent = currentScope; s.parent = currentScope;
currentScope.children.insert(s); currentScope.children.insert(s);
@ -926,8 +912,7 @@ private:
if (functionBody !is null) if (functionBody !is null)
{ {
pushFunctionScope(functionBody, semanticAllocator, pushFunctionScope(functionBody, location + 4); // 4 == "this".length
location + 4); // 4 == "this".length
scope(exit) popScope(); scope(exit) popScope();
currentSymbol = symbol; currentSymbol = symbol;
functionBody.accept(this); functionBody.accept(this);
@ -951,7 +936,7 @@ private:
if (functionBody !is null) if (functionBody !is null)
{ {
pushFunctionScope(functionBody, semanticAllocator, location + 4); // 4 == "this".length pushFunctionScope(functionBody, location + 4); // 4 == "this".length
scope(exit) popScope(); scope(exit) popScope();
currentSymbol = symbol; currentSymbol = symbol;
functionBody.accept(this); functionBody.accept(this);
@ -1108,17 +1093,12 @@ private:
SemanticSymbol* allocateSemanticSymbol(string name, CompletionKind kind, SemanticSymbol* allocateSemanticSymbol(string name, CompletionKind kind,
istring symbolFile, size_t location = 0) istring symbolFile, size_t location = 0)
in
{ {
assert (!symbolAllocator.isNull); DSymbol* acSymbol = GCAllocator.instance.make!DSymbol(istring(name), kind);
}
do
{
DSymbol* acSymbol = SymbolAllocator.instance.make!DSymbol(istring(name), kind);
acSymbol.location = location; acSymbol.location = location;
acSymbol.symbolFile = symbolFile; acSymbol.symbolFile = symbolFile;
symbolsAllocated++; 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, void addTypeToLookups(ref TypeLookups lookups,
@ -1207,8 +1187,6 @@ private:
const Module mod; const Module mod;
RCIAllocator semanticAllocator;
Rebindable!(const ExpressionNode) feExpression; Rebindable!(const ExpressionNode) feExpression;
CacheEntry* entry; CacheEntry* entry;

View File

@ -18,38 +18,38 @@
module dsymbol.conversion; module dsymbol.conversion;
import dparse.ast;
import dparse.lexer;
import dparse.parser;
import dparse.rollback_allocator;
import dsymbol.cache_entry; import dsymbol.cache_entry;
import dsymbol.conversion.first; import dsymbol.conversion.first;
import dsymbol.conversion.second; import dsymbol.conversion.second;
import dsymbol.modulecache; import dsymbol.modulecache;
import dsymbol.scope_; import dsymbol.scope_;
import dsymbol.semantic;
import dsymbol.string_interning; import dsymbol.string_interning;
import dsymbol.symbol; import dsymbol.symbol;
import dsymbol.semantic; import std.algorithm;
import dparse.ast;
import dparse.lexer;
import dparse.parser;
import dparse.rollback_allocator;
import std.experimental.allocator; import std.experimental.allocator;
/** /**
* Used by autocompletion. * Used by autocompletion.
*/ */
ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens, ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens,
RCIAllocator symbolAllocator, RollbackAllocator* parseAllocator, RollbackAllocator* parseAllocator,
size_t cursorPosition, ref ModuleCache cache) size_t cursorPosition, ref ModuleCache cache)
{ {
Module m = parseModuleForAutocomplete(tokens, internString("stdin"), Module m = parseModuleForAutocomplete(tokens, internString("stdin"),
parseAllocator, cursorPosition); parseAllocator, cursorPosition);
scope first = new FirstPass(m, internString("stdin"), symbolAllocator, scope first = new FirstPass(m, internString("stdin"), &cache);
symbolAllocator, &cache);
first.run(); first.run();
secondPass(first.rootSymbol, first.moduleScope, cache); secondPass(first.rootSymbol, first.moduleScope, cache);
auto r = first.rootSymbol.acSymbol; auto r = move(first.rootSymbol.acSymbol);
typeid(SemanticSymbol).destroy(first.rootSymbol); typeid(SemanticSymbol).destroy(first.rootSymbol);
return ScopeSymbolPair(r, first.moduleScope); return ScopeSymbolPair(r, move(first.moduleScope));
} }
struct ScopeSymbolPair struct ScopeSymbolPair

View File

@ -34,8 +34,6 @@ import std.experimental.logger;
import dparse.ast; import dparse.ast;
import dparse.lexer; 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) void secondPass(SemanticSymbol* currentSymbol, Scope* moduleScope, ref ModuleCache cache)
{ {
with (CompletionKind) final switch (currentSymbol.acSymbol.kind) with (CompletionKind) final switch (currentSymbol.acSymbol.kind)
@ -115,7 +113,7 @@ do
if (moduleSymbol is null) if (moduleSymbol is null)
{ {
tryAgain: tryAgain:
DeferredSymbol* deferred = TypeLookupsAllocator.instance.make!DeferredSymbol(acSymbol); DeferredSymbol* deferred = DeferredSymbolsAllocator.instance.make!DeferredSymbol(acSymbol);
deferred.typeLookups.insert(typeLookups[]); deferred.typeLookups.insert(typeLookups[]);
// Get rid of the old references to the lookups, this new deferred // Get rid of the old references to the lookups, this new deferred
// symbol owns them now // symbol owns them now
@ -191,7 +189,7 @@ do
break; break;
immutable qualifier = isAssoc ? SymbolQualifier.assocArray : immutable qualifier = isAssoc ? SymbolQualifier.assocArray :
(isFunction ? SymbolQualifier.func : SymbolQualifier.array); (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.qualifier = qualifier;
lastSuffix.ownType = true; lastSuffix.ownType = true;
if (isFunction) if (isFunction)
@ -335,13 +333,13 @@ void resolveInheritance(DSymbol* symbol, ref TypeLookups typeLookups,
baseClass = symbols[0]; baseClass = symbols[0];
} }
DSymbol* imp = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, DSymbol* imp = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
CompletionKind.importSymbol, baseClass); CompletionKind.importSymbol, baseClass);
symbol.addChild(imp, true); symbol.addChild(imp, true);
symbolScope.addSymbol(imp, false); symbolScope.addSymbol(imp, false);
if (baseClass.kind == CompletionKind.className) 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); CompletionKind.variableName, baseClass);
symbolScope.addSymbol(s, true); symbolScope.addSymbol(s, true);
} }
@ -359,7 +357,7 @@ void resolveAliasThis(DSymbol* symbol,
auto parts = symbol.getPartsByName(aliasThis.breadcrumbs.front); auto parts = symbol.getPartsByName(aliasThis.breadcrumbs.front);
if (parts.length == 0 || parts[0].type is null) if (parts.length == 0 || parts[0].type is null)
continue; continue;
DSymbol* s = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME, DSymbol* s = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
CompletionKind.importSymbol, parts[0].type); CompletionKind.importSymbol, parts[0].type);
symbol.addChild(s, true); symbol.addChild(s, true);
auto symbolScope = moduleScope.getScopeByCursor(s.location); auto symbolScope = moduleScope.getScopeByCursor(s.location);
@ -395,7 +393,7 @@ void resolveMixinTemplates(DSymbol* symbol,
} }
if (currentSymbol !is null) 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); CompletionKind.importSymbol, currentSymbol);
i.ownType = false; i.ownType = false;
symbol.addChild(i, true); symbol.addChild(i, true);
@ -447,7 +445,7 @@ void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup,
else else
if (crumb == ARRAY_LITERAL_SYMBOL_NAME) 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; arr.qualifier = SymbolQualifier.array;
currentSymbol = arr; currentSymbol = arr;
} }

View File

@ -25,10 +25,10 @@ import dsymbol.import_;
import dsymbol.symbol; import dsymbol.symbol;
import dsymbol.type_lookup; import dsymbol.type_lookup;
import std.experimental.allocator : dispose; import std.experimental.allocator : dispose;
import std.experimental.allocator.mallocator : Mallocator; import std.experimental.allocator.gc_allocator : GCAllocator;
import dsymbol.semantic : TypeLookups, TypeLookupsAllocator; import dsymbol.semantic : TypeLookups, TypeLookupsAllocator;
alias ImportsAllocator = Mallocator; alias ImportsAllocator = GCAllocator;
alias Imports = UnrolledList!(DSymbol*, ImportsAllocator); alias Imports = UnrolledList!(DSymbol*, ImportsAllocator);
/** /**

View File

@ -48,8 +48,6 @@ import std.file;
import std.experimental.lexer; import std.experimental.lexer;
import std.path; import std.path;
alias ASTAllocator = AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator);
/** /**
* Returns: true if a file exists at the given path. * Returns: true if a file exists at the given path.
*/ */
@ -71,13 +69,6 @@ struct ModuleCache
/// No copying. /// No copying.
@disable this(this); @disable this(this);
@disable this();
this(RCIAllocator symbolAllocator)
{
this.symbolAllocator = symbolAllocator;
}
~this() ~this()
{ {
clear(); clear();
@ -147,9 +138,6 @@ struct ModuleCache
foreach (symbol; deferredSymbols[]) foreach (symbol; deferredSymbols[])
DeferredSymbolsAllocator.instance.dispose(symbol); 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(); cache.clear();
deferredSymbols.clear(); deferredSymbols.clear();
importPaths.clear(); importPaths.clear();
@ -198,14 +186,11 @@ struct ModuleCache
CacheEntry* newEntry = CacheAllocator.instance.make!CacheEntry(); CacheEntry* newEntry = CacheAllocator.instance.make!CacheEntry();
scope semanticAllocator = new ASTAllocator();
import dparse.rollback_allocator:RollbackAllocator; import dparse.rollback_allocator:RollbackAllocator;
RollbackAllocator parseAllocator; RollbackAllocator parseAllocator;
Module m = parseModuleSimple(tokens[], cachedLocation, &parseAllocator); Module m = parseModuleSimple(tokens[], cachedLocation, &parseAllocator);
assert (!symbolAllocator.isNull); scope first = new FirstPass(m, cachedLocation, &this, newEntry);
scope first = new FirstPass(m, cachedLocation, symbolAllocator,
semanticAllocator.allocatorObject, &this, newEntry);
first.run(); first.run();
secondPass(first.rootSymbol, first.moduleScope, this); secondPass(first.rootSymbol, first.moduleScope, this);
@ -355,8 +340,6 @@ struct ModuleCache
return cache[]; return cache[];
} }
RCIAllocator symbolAllocator;
alias DeferredSymbols = UnrolledList!(DeferredSymbol*, DeferredSymbolsAllocator); alias DeferredSymbols = UnrolledList!(DeferredSymbol*, DeferredSymbolsAllocator);
DeferredSymbols deferredSymbols; DeferredSymbols deferredSymbols;

View File

@ -24,7 +24,7 @@ void expectSymbolsAndTypes(const string source, const string[][] results,
import core.exception : AssertError; import core.exception : AssertError;
import std.exception : enforce; import std.exception : enforce;
ModuleCache mcache = ModuleCache(theAllocator); ModuleCache mcache;
auto pair = generateAutocompleteTrees(source, mcache); auto pair = generateAutocompleteTrees(source, mcache);
scope(exit) pair.destroy(); scope(exit) pair.destroy();
@ -80,7 +80,7 @@ void expectSymbolsAndTypes(const string source, const string[][] results,
// this one used to crash, see #125 // this one used to crash, see #125
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
auto source = q{ auto a = true ? [42] : []; }; auto source = q{ auto a = true ? [42] : []; };
auto pair = generateAutocompleteTrees(source, cache); auto pair = generateAutocompleteTrees(source, cache);
} }
@ -88,7 +88,7 @@ unittest
// https://github.com/dlang-community/D-Scanner/issues/749 // https://github.com/dlang-community/D-Scanner/issues/749
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
auto source = q{ void test() { foo(new class A {});} }; auto source = q{ void test() { foo(new class A {});} };
auto pair = generateAutocompleteTrees(source, cache); auto pair = generateAutocompleteTrees(source, cache);
} }
@ -96,14 +96,14 @@ unittest
// https://github.com/dlang-community/D-Scanner/issues/738 // https://github.com/dlang-community/D-Scanner/issues/738
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
auto source = q{ void b() { c = } alias b this; }; auto source = q{ void b() { c = } alias b this; };
auto pair = generateAutocompleteTrees(source, cache); auto pair = generateAutocompleteTrees(source, cache);
} }
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running function literal tests..."); writeln("Running function literal tests...");
const sources = [ const sources = [
@ -128,7 +128,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running struct constructor tests..."); writeln("Running struct constructor tests...");
auto source = q{ struct A {int a; struct B {bool b;} int c;} }; auto source = q{ struct A {int a; struct B {bool b;} int c;} };
@ -143,7 +143,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running union constructor tests..."); writeln("Running union constructor tests...");
auto source = q{ union A {int a; bool b;} }; auto source = q{ union A {int a; bool b;} };
@ -155,7 +155,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running non-importable symbols tests..."); writeln("Running non-importable symbols tests...");
auto source = q{ auto source = q{
class A { this(int a){} } class A { this(int a){} }
@ -173,7 +173,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running alias this tests..."); writeln("Running alias this tests...");
auto source = q{ struct A {int f;} struct B { A a; alias a this; void fun() { auto var = f; };} }; 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 unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running anon struct tests..."); writeln("Running anon struct tests...");
auto source = q{ struct A { struct {int a;}} }; auto source = q{ struct A { struct {int a;}} };
@ -201,7 +201,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running anon class tests..."); writeln("Running anon class tests...");
const sources = [ const sources = [
@ -230,7 +230,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running the deduction from index expr tests..."); writeln("Running the deduction from index expr tests...");
{ {
@ -278,7 +278,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running `super` tests..."); writeln("Running `super` tests...");
auto source = q{ class A {} class B : A {} }; auto source = q{ class A {} class B : A {} };
@ -296,7 +296,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running the \"access chain with inherited type\" tests..."); writeln("Running the \"access chain with inherited type\" tests...");
auto source = q{ class A {} class B : A {} }; auto source = q{ class A {} class B : A {} };
@ -313,7 +313,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running template type parameters tests..."); writeln("Running template type parameters tests...");
{ {
@ -340,7 +340,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Running template variadic parameters tests..."); writeln("Running template variadic parameters tests...");
auto source = q{ struct Foo(T...){ }}; auto source = q{ struct Foo(T...){ }};
@ -385,7 +385,7 @@ unittest
rmdir(dir); rmdir(dir);
} }
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
cache.addImportPaths([dir]); cache.addImportPaths([dir]);
const a = cache.getModuleSymbol(istring(fnameA)); const a = cache.getModuleSymbol(istring(fnameA));
@ -429,7 +429,7 @@ unittest
unittest unittest
{ {
ModuleCache cache = ModuleCache(theAllocator); ModuleCache cache;
writeln("Testing protection scopes"); writeln("Testing protection scopes");
auto source = q{version(all) { private: } struct Foo{ }}; auto source = q{version(all) { private: } struct Foo{ }};
@ -537,8 +537,7 @@ ScopeSymbolPair generateAutocompleteTrees(string source, string filename, ref Mo
RollbackAllocator rba; RollbackAllocator rba;
Module m = parseModule(tokens, filename, &rba); Module m = parseModule(tokens, filename, &rba);
scope first = new FirstPass(m, internString(filename), scope first = new FirstPass(m, internString(filename), &cache);
theAllocator, theAllocator, &cache);
first.run(); first.run();
secondPass(first.rootSymbol, first.moduleScope, cache); secondPass(first.rootSymbol, first.moduleScope, cache);
@ -557,5 +556,5 @@ ScopeSymbolPair generateAutocompleteTrees(string source, string filename, size_t
auto tokens = lex(source); auto tokens = lex(source);
RollbackAllocator rba; RollbackAllocator rba;
return dsymbol.conversion.generateAutocompleteTrees( return dsymbol.conversion.generateAutocompleteTrees(
tokens, theAllocator, &rba, cursorPosition, cache); tokens, &rba, cursorPosition, cache);
} }

View File

@ -214,10 +214,8 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray,
mixin(TYPE_IDENT_CASES); mixin(TYPE_IDENT_CASES);
case tok!")": case tok!")":
case tok!"]": case tok!"]":
scope allocator = new ASTAllocator();
RollbackAllocator rba; RollbackAllocator rba;
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, &rba, cursorPosition, moduleCache);
allocator.allocatorObject, &rba, cursorPosition, moduleCache);
scope(exit) pair.destroy(); scope(exit) pair.destroy();
response.setCompletions(pair.scope_, getExpression(beforeTokens), response.setCompletions(pair.scope_, getExpression(beforeTokens),
cursorPosition, CompletionType.identifiers, false, partial); cursorPosition, CompletionType.identifiers, false, partial);
@ -230,10 +228,8 @@ AutocompleteResponse dotCompletion(T)(T beforeTokens, const(Token)[] tokenArray,
case tok!";": case tok!";":
case tok!"}": case tok!"}":
case tok!",": case tok!",":
scope allocator = new ASTAllocator();
RollbackAllocator rba; RollbackAllocator rba;
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, &rba, 1, moduleCache);
allocator.allocatorObject, &rba, 1, moduleCache);
scope(exit) pair.destroy(); scope(exit) pair.destroy();
response.setCompletions(pair.scope_, getExpression(beforeTokens), response.setCompletions(pair.scope_, getExpression(beforeTokens),
1, CompletionType.identifiers, false, partial); 1, CompletionType.identifiers, false, partial);
@ -303,10 +299,8 @@ AutocompleteResponse parenCompletion(T)(T beforeTokens,
case tok!")": case tok!")":
case tok!"]": case tok!"]":
mixin(STRING_LITERAL_CASES); mixin(STRING_LITERAL_CASES);
scope allocator = new ASTAllocator();
RollbackAllocator rba; RollbackAllocator rba;
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, &rba, cursorPosition, moduleCache);
allocator.allocatorObject, &rba, cursorPosition, moduleCache);
scope(exit) pair.destroy(); scope(exit) pair.destroy();
auto expression = getExpression(beforeTokens[0 .. $ - 1]); auto expression = getExpression(beforeTokens[0 .. $ - 1]);
response.setCompletions(pair.scope_, expression, response.setCompletions(pair.scope_, expression,

View File

@ -46,10 +46,8 @@ public AutocompleteResponse getDoc(const AutocompleteRequest request,
// trace("Getting doc comments"); // trace("Getting doc comments");
AutocompleteResponse response; AutocompleteResponse response;
RollbackAllocator rba; RollbackAllocator rba;
scope allocator = new ASTAllocator();
auto cache = StringCache(request.sourceCode.length.optimalBucketCount); auto cache = StringCache(request.sourceCode.length.optimalBucketCount);
SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.ddoc, SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.ddoc, &rba, cache, moduleCache);
allocator.allocatorObject, &rba, cache, moduleCache);
if (stuff.symbols.length == 0) if (stuff.symbols.length == 0)
warning("Could not find symbol"); warning("Could not find symbol");
else else

View File

@ -46,7 +46,6 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request,
{ {
AutocompleteResponse response; AutocompleteResponse response;
RollbackAllocator rba; RollbackAllocator rba;
scope allocator = new ASTAllocator();
auto cache = StringCache(request.sourceCode.length.optimalBucketCount); auto cache = StringCache(request.sourceCode.length.optimalBucketCount);
// patchs the original request for the subsequent requests // patchs the original request for the subsequent requests
@ -62,7 +61,7 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request,
auto sortedTokens = assumeSorted(tokenArray); auto sortedTokens = assumeSorted(tokenArray);
auto beforeTokens = sortedTokens.lowerBound(cursorPosition); auto beforeTokens = sortedTokens.lowerBound(cursorPosition);
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray,
allocator.allocatorObject, &rba, request.cursorPosition, moduleCache); &rba, request.cursorPosition, moduleCache);
auto expression = getExpression(beforeTokens); auto expression = getExpression(beforeTokens);
return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression,
cursorPosition, CompletionType.location), pair.symbol, pair.scope_); cursorPosition, CompletionType.location), pair.symbol, pair.scope_);

View File

@ -48,10 +48,9 @@ public AutocompleteResponse findDeclaration(const AutocompleteRequest request,
{ {
AutocompleteResponse response; AutocompleteResponse response;
RollbackAllocator rba; RollbackAllocator rba;
scope allocator = new ASTAllocator();
auto cache = StringCache(request.sourceCode.length.optimalBucketCount); auto cache = StringCache(request.sourceCode.length.optimalBucketCount);
SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.location, SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.location,
allocator.allocatorObject, &rba, cache, moduleCache); &rba, cache, moduleCache);
scope(exit) stuff.destroy(); scope(exit) stuff.destroy();
if (stuff.symbols.length > 0) if (stuff.symbols.length > 0)
{ {
@ -76,10 +75,9 @@ public AutocompleteResponse symbolSearch(const AutocompleteRequest request,
auto cache = StringCache(request.sourceCode.length.optimalBucketCount); auto cache = StringCache(request.sourceCode.length.optimalBucketCount);
const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode, const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode,
config, &cache); config, &cache);
scope allocator = new ASTAllocator();
RollbackAllocator rba; RollbackAllocator rba;
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray,
allocator.allocatorObject, &rba, request.cursorPosition, moduleCache); &rba, request.cursorPosition, moduleCache);
scope(exit) pair.destroy(); scope(exit) pair.destroy();
static struct SearchResults static struct SearchResults

View File

@ -134,13 +134,13 @@ auto getTokensBeforeCursor(const(ubyte[]) sourceCode, size_t cursorPosition,
* the request's source code, cursor position, and completion type. * the request's source code, cursor position, and completion type.
*/ */
SymbolStuff getSymbolsForCompletion(const AutocompleteRequest request, SymbolStuff getSymbolsForCompletion(const AutocompleteRequest request,
const CompletionType type, RCIAllocator allocator, RollbackAllocator* rba, const CompletionType type, RollbackAllocator* rba,
ref StringCache cache, ref ModuleCache moduleCache) ref StringCache cache, ref ModuleCache moduleCache)
{ {
const(Token)[] tokenArray; const(Token)[] tokenArray;
auto beforeTokens = getTokensBeforeCursor(request.sourceCode, auto beforeTokens = getTokensBeforeCursor(request.sourceCode,
request.cursorPosition, cache, tokenArray); request.cursorPosition, cache, tokenArray);
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray, allocator, ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray,
rba, request.cursorPosition, moduleCache); rba, request.cursorPosition, moduleCache);
auto expression = getExpression(beforeTokens); auto expression = getExpression(beforeTokens);
return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression, return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression,

View File

@ -176,7 +176,7 @@ int runServer(string[] args)
info("Sockets shut down."); info("Sockets shut down.");
} }
ModuleCache cache = ModuleCache(new ASTAllocator().allocatorObject); ModuleCache cache;
cache.addImportPaths(importPaths); cache.addImportPaths(importPaths);
infof("Import directories:\n %-(%s\n %)", cache.getImportPaths()); infof("Import directories:\n %-(%s\n %)", cache.getImportPaths());