Skip to content

Commit 5c529f3

Browse files
committed
use GC nearly everywhere
1 parent e7c7f86 commit 5c529f3

File tree

13 files changed

+64
-117
lines changed

13 files changed

+64
-117
lines changed

dsymbol/src/dsymbol/builtin/symbols.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dsymbol.string_interning;
88
import dsymbol.symbol;
99
import std.experimental.allocator.mallocator : Mallocator;
1010

11-
alias SymbolsAllocator = Mallocator;
11+
private alias SymbolsAllocator = Mallocator;
1212

1313
/**
1414
* Symbols for the built in types

dsymbol/src/dsymbol/conversion/first.d

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,22 @@ import std.typecons : Rebindable;
5353
*/
5454
final class FirstPass : ASTVisitor
5555
{
56-
alias SymbolAllocator = GCAllocator; // NOTE using First`Pass.symbolAllocator` instead fails when analyzing Phobos master
57-
alias ScopeAllocator = GCAllocator; // NOTE using `Mallocator` instead fails when analyzing Phobos master
58-
5956
/**
6057
* Params:
6158
* mod = the module to visit
6259
* symbolFile = path to the file being converted
63-
* symbolAllocator = allocator used for the auto-complete symbols
64-
* semanticAllocator = allocator used for semantic symbols
6560
*/
66-
this(const Module mod, istring symbolFile, RCIAllocator symbolAllocator,
67-
RCIAllocator semanticAllocator,
61+
this(const Module mod, istring symbolFile,
6862
ModuleCache* cache, CacheEntry* entry = null)
6963
in
7064
{
7165
assert(mod);
72-
assert(!symbolAllocator.isNull);
73-
assert(!semanticAllocator.isNull);
7466
assert(cache);
7567
}
7668
do
7769
{
7870
this.mod = mod;
7971
this.symbolFile = symbolFile;
80-
this.symbolAllocator = symbolAllocator;
81-
this.semanticAllocator = semanticAllocator;
8272
this.entry = entry;
8373
this.cache = cache;
8474
}
@@ -146,7 +136,7 @@ final class FirstPass : ASTVisitor
146136

147137
if (dec.functionBody !is null)
148138
{
149-
pushFunctionScope(dec.functionBody, semanticAllocator,
139+
pushFunctionScope(dec.functionBody,
150140
dec.name.index + dec.name.text.length);
151141
scope (exit) popScope();
152142
processParameters(currentSymbol, dec.returnType,
@@ -374,7 +364,7 @@ final class FirstPass : ASTVisitor
374364
rootSymbol = allocateSemanticSymbol(null, CompletionKind.moduleName,
375365
symbolFile);
376366
currentSymbol = rootSymbol;
377-
moduleScope = GCAllocator.instance.make!Scope(0, uint.max); // NOTE using `semanticAllocator` here fails as `Segmentation fault (core dumped)`
367+
moduleScope = GCAllocator.instance.make!Scope(0, uint.max);
378368
currentScope = moduleScope;
379369
auto objectLocation = cache.resolveImportLocation("object");
380370
if (objectLocation is null)
@@ -444,7 +434,7 @@ final class FirstPass : ASTVisitor
444434
scope(exit) structFieldNames = move(savedStructFieldNames);
445435
scope(exit) structFieldTypes = move(savedStructFieldTypes);
446436

447-
DSymbol* thisSymbol = SymbolAllocator.instance.make!DSymbol(THIS_SYMBOL_NAME,
437+
DSymbol* thisSymbol = GCAllocator.instance.make!DSymbol(THIS_SYMBOL_NAME,
448438
CompletionKind.variableName, currentSymbol.acSymbol);
449439
thisSymbol.location = currentScope.startLocation;
450440
thisSymbol.symbolFile = symbolFile;
@@ -497,7 +487,7 @@ final class FirstPass : ASTVisitor
497487
auto s = currentScope.getSymbolsByName(ip);
498488
if (s.length == 0)
499489
{
500-
currentImportSymbol = SymbolAllocator.instance.make!DSymbol(ip, kind);
490+
currentImportSymbol = GCAllocator.instance.make!DSymbol(ip, kind);
501491
currentScope.addSymbol(currentImportSymbol, true);
502492
if (last)
503493
{
@@ -514,7 +504,7 @@ final class FirstPass : ASTVisitor
514504
auto s = currentImportSymbol.getPartsByName(ip);
515505
if (s.length == 0)
516506
{
517-
auto sym = SymbolAllocator.instance.make!DSymbol(ip, kind);
507+
auto sym = GCAllocator.instance.make!DSymbol(ip, kind);
518508
currentImportSymbol.addChild(sym, true);
519509
currentImportSymbol = sym;
520510
if (last)
@@ -781,9 +771,6 @@ final class FirstPass : ASTVisitor
781771
/// The module
782772
SemanticSymbol* rootSymbol;
783773

784-
/// Allocator used for symbol allocation
785-
RCIAllocator symbolAllocator;
786-
787774
/// Number of symbols allocated
788775
uint symbolsAllocated;
789776

@@ -823,7 +810,7 @@ private:
823810
{
824811
assert (startLocation < uint.max);
825812
assert (endLocation < uint.max || endLocation == size_t.max);
826-
Scope* s = ScopeAllocator.instance.make!Scope(cast(uint) startLocation, cast(uint) endLocation);
813+
Scope* s = GCAllocator.instance.make!Scope(cast(uint) startLocation, cast(uint) endLocation);
827814
s.parent = currentScope;
828815
currentScope.children.insert(s);
829816
currentScope = s;
@@ -834,10 +821,9 @@ private:
834821
currentScope = currentScope.parent;
835822
}
836823

837-
void pushFunctionScope(const FunctionBody functionBody,
838-
RCIAllocator semanticAllocator, size_t scopeBegin)
824+
void pushFunctionScope(const FunctionBody functionBody, size_t scopeBegin)
839825
{
840-
Scope* s = ScopeAllocator.instance.make!Scope(cast(uint) scopeBegin,
826+
Scope* s = GCAllocator.instance.make!Scope(cast(uint) scopeBegin,
841827
cast(uint) functionBody.endLocation);
842828
s.parent = currentScope;
843829
currentScope.children.insert(s);
@@ -926,8 +912,7 @@ private:
926912

927913
if (functionBody !is null)
928914
{
929-
pushFunctionScope(functionBody, semanticAllocator,
930-
location + 4); // 4 == "this".length
915+
pushFunctionScope(functionBody, location + 4); // 4 == "this".length
931916
scope(exit) popScope();
932917
currentSymbol = symbol;
933918
functionBody.accept(this);
@@ -951,7 +936,7 @@ private:
951936

952937
if (functionBody !is null)
953938
{
954-
pushFunctionScope(functionBody, semanticAllocator, location + 4); // 4 == "this".length
939+
pushFunctionScope(functionBody, location + 4); // 4 == "this".length
955940
scope(exit) popScope();
956941
currentSymbol = symbol;
957942
functionBody.accept(this);
@@ -1108,17 +1093,12 @@ private:
11081093

11091094
SemanticSymbol* allocateSemanticSymbol(string name, CompletionKind kind,
11101095
istring symbolFile, size_t location = 0)
1111-
in
11121096
{
1113-
assert (!symbolAllocator.isNull);
1114-
}
1115-
do
1116-
{
1117-
DSymbol* acSymbol = SymbolAllocator.instance.make!DSymbol(istring(name), kind);
1097+
DSymbol* acSymbol = GCAllocator.instance.make!DSymbol(istring(name), kind);
11181098
acSymbol.location = location;
11191099
acSymbol.symbolFile = symbolFile;
11201100
symbolsAllocated++;
1121-
return SymbolAllocator.instance.make!SemanticSymbol(acSymbol); // NOTE using semanticAllocator here breaks when analysing phobos as: `Segmentation fault (core dumped)‘’
1101+
return GCAllocator.instance.make!SemanticSymbol(acSymbol);
11221102
}
11231103

11241104
void addTypeToLookups(ref TypeLookups lookups,
@@ -1207,8 +1187,6 @@ private:
12071187

12081188
const Module mod;
12091189

1210-
RCIAllocator semanticAllocator;
1211-
12121190
Rebindable!(const ExpressionNode) feExpression;
12131191

12141192
CacheEntry* entry;

dsymbol/src/dsymbol/conversion/package.d

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@
1818

1919
module dsymbol.conversion;
2020

21+
import dparse.ast;
22+
import dparse.lexer;
23+
import dparse.parser;
24+
import dparse.rollback_allocator;
2125
import dsymbol.cache_entry;
2226
import dsymbol.conversion.first;
2327
import dsymbol.conversion.second;
2428
import dsymbol.modulecache;
2529
import dsymbol.scope_;
30+
import dsymbol.semantic;
2631
import dsymbol.string_interning;
2732
import dsymbol.symbol;
28-
import dsymbol.semantic;
29-
import dparse.ast;
30-
import dparse.lexer;
31-
import dparse.parser;
32-
import dparse.rollback_allocator;
33+
import std.algorithm;
3334
import std.experimental.allocator;
3435

3536
/**
3637
* Used by autocompletion.
3738
*/
3839
ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens,
39-
RCIAllocator symbolAllocator, RollbackAllocator* parseAllocator,
40+
RollbackAllocator* parseAllocator,
4041
size_t cursorPosition, ref ModuleCache cache)
4142
{
4243
Module m = parseModuleForAutocomplete(tokens, internString("stdin"),
4344
parseAllocator, cursorPosition);
4445

45-
scope first = new FirstPass(m, internString("stdin"), symbolAllocator,
46-
symbolAllocator, &cache);
46+
scope first = new FirstPass(m, internString("stdin"), &cache);
4747
first.run();
4848

4949
secondPass(first.rootSymbol, first.moduleScope, cache);
50-
auto r = first.rootSymbol.acSymbol;
50+
auto r = move(first.rootSymbol.acSymbol);
5151
typeid(SemanticSymbol).destroy(first.rootSymbol);
52-
return ScopeSymbolPair(r, first.moduleScope);
52+
return ScopeSymbolPair(r, move(first.moduleScope));
5353
}
5454

5555
struct ScopeSymbolPair

dsymbol/src/dsymbol/conversion/second.d

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ import std.experimental.logger;
3434
import dparse.ast;
3535
import dparse.lexer;
3636

37-
alias SymbolAllocator = GCAllocator; // NOTE using cache.symbolAllocator instead fails when analyzing Phobos master
38-
3937
void secondPass(SemanticSymbol* currentSymbol, Scope* moduleScope, ref ModuleCache cache)
4038
{
4139
with (CompletionKind) final switch (currentSymbol.acSymbol.kind)
@@ -115,7 +113,7 @@ do
115113
if (moduleSymbol is null)
116114
{
117115
tryAgain:
118-
DeferredSymbol* deferred = TypeLookupsAllocator.instance.make!DeferredSymbol(acSymbol);
116+
DeferredSymbol* deferred = DeferredSymbolsAllocator.instance.make!DeferredSymbol(acSymbol);
119117
deferred.typeLookups.insert(typeLookups[]);
120118
// Get rid of the old references to the lookups, this new deferred
121119
// symbol owns them now
@@ -191,7 +189,7 @@ do
191189
break;
192190
immutable qualifier = isAssoc ? SymbolQualifier.assocArray :
193191
(isFunction ? SymbolQualifier.func : SymbolQualifier.array);
194-
lastSuffix = SymbolAllocator.instance.make!DSymbol(back, CompletionKind.dummy, lastSuffix);
192+
lastSuffix = GCAllocator.instance.make!DSymbol(back, CompletionKind.dummy, lastSuffix);
195193
lastSuffix.qualifier = qualifier;
196194
lastSuffix.ownType = true;
197195
if (isFunction)
@@ -335,13 +333,13 @@ void resolveInheritance(DSymbol* symbol, ref TypeLookups typeLookups,
335333
baseClass = symbols[0];
336334
}
337335

338-
DSymbol* imp = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
336+
DSymbol* imp = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
339337
CompletionKind.importSymbol, baseClass);
340338
symbol.addChild(imp, true);
341339
symbolScope.addSymbol(imp, false);
342340
if (baseClass.kind == CompletionKind.className)
343341
{
344-
auto s = SymbolAllocator.instance.make!DSymbol(SUPER_SYMBOL_NAME,
342+
auto s = GCAllocator.instance.make!DSymbol(SUPER_SYMBOL_NAME,
345343
CompletionKind.variableName, baseClass);
346344
symbolScope.addSymbol(s, true);
347345
}
@@ -359,7 +357,7 @@ void resolveAliasThis(DSymbol* symbol,
359357
auto parts = symbol.getPartsByName(aliasThis.breadcrumbs.front);
360358
if (parts.length == 0 || parts[0].type is null)
361359
continue;
362-
DSymbol* s = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
360+
DSymbol* s = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
363361
CompletionKind.importSymbol, parts[0].type);
364362
symbol.addChild(s, true);
365363
auto symbolScope = moduleScope.getScopeByCursor(s.location);
@@ -395,7 +393,7 @@ void resolveMixinTemplates(DSymbol* symbol,
395393
}
396394
if (currentSymbol !is null)
397395
{
398-
auto i = SymbolAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
396+
auto i = GCAllocator.instance.make!DSymbol(IMPORT_SYMBOL_NAME,
399397
CompletionKind.importSymbol, currentSymbol);
400398
i.ownType = false;
401399
symbol.addChild(i, true);
@@ -447,7 +445,7 @@ void resolveTypeFromInitializer(DSymbol* symbol, TypeLookup* lookup,
447445
else
448446
if (crumb == ARRAY_LITERAL_SYMBOL_NAME)
449447
{
450-
auto arr = SymbolAllocator.instance.make!(DSymbol)(ARRAY_LITERAL_SYMBOL_NAME, CompletionKind.dummy, currentSymbol);
448+
auto arr = GCAllocator.instance.make!(DSymbol)(ARRAY_LITERAL_SYMBOL_NAME, CompletionKind.dummy, currentSymbol);
451449
arr.qualifier = SymbolQualifier.array;
452450
currentSymbol = arr;
453451
}

dsymbol/src/dsymbol/deferred.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import dsymbol.import_;
2525
import dsymbol.symbol;
2626
import dsymbol.type_lookup;
2727
import std.experimental.allocator : dispose;
28-
import std.experimental.allocator.mallocator : Mallocator;
28+
import std.experimental.allocator.gc_allocator : GCAllocator;
2929
import dsymbol.semantic : TypeLookups, TypeLookupsAllocator;
3030

31-
alias ImportsAllocator = Mallocator;
31+
alias ImportsAllocator = GCAllocator;
3232
alias Imports = UnrolledList!(DSymbol*, ImportsAllocator);
3333

3434
/**

dsymbol/src/dsymbol/modulecache.d

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ import std.file;
4848
import std.experimental.lexer;
4949
import std.path;
5050

51-
alias ASTAllocator = AllocatorList!(n => Region!Mallocator(1024 * 128), Mallocator);
52-
5351
/**
5452
* Returns: true if a file exists at the given path.
5553
*/
@@ -71,13 +69,6 @@ struct ModuleCache
7169
/// No copying.
7270
@disable this(this);
7371

74-
@disable this();
75-
76-
this(RCIAllocator symbolAllocator)
77-
{
78-
this.symbolAllocator = symbolAllocator;
79-
}
80-
8172
~this()
8273
{
8374
clear();
@@ -147,9 +138,6 @@ struct ModuleCache
147138
foreach (symbol; deferredSymbols[])
148139
DeferredSymbolsAllocator.instance.dispose(symbol);
149140

150-
// TODO: This call to deallocateAll is a workaround for issues of
151-
// CAllocatorImpl and GCAllocator not interacting well.
152-
symbolAllocator.deallocateAll();
153141
cache.clear();
154142
deferredSymbols.clear();
155143
importPaths.clear();
@@ -198,14 +186,11 @@ struct ModuleCache
198186

199187
CacheEntry* newEntry = CacheAllocator.instance.make!CacheEntry();
200188

201-
scope semanticAllocator = new ASTAllocator();
202189
import dparse.rollback_allocator:RollbackAllocator;
203190
RollbackAllocator parseAllocator;
204191
Module m = parseModuleSimple(tokens[], cachedLocation, &parseAllocator);
205192

206-
assert (!symbolAllocator.isNull);
207-
scope first = new FirstPass(m, cachedLocation, symbolAllocator,
208-
semanticAllocator.allocatorObject, &this, newEntry);
193+
scope first = new FirstPass(m, cachedLocation, &this, newEntry);
209194
first.run();
210195

211196
secondPass(first.rootSymbol, first.moduleScope, this);
@@ -355,8 +340,6 @@ struct ModuleCache
355340
return cache[];
356341
}
357342

358-
RCIAllocator symbolAllocator;
359-
360343
alias DeferredSymbols = UnrolledList!(DeferredSymbol*, DeferredSymbolsAllocator);
361344
DeferredSymbols deferredSymbols;
362345

0 commit comments

Comments
 (0)