diff --git a/dexed-d/src/common.d b/dexed-d/src/common.d index c1ebe255..749736f2 100644 --- a/dexed-d/src/common.d +++ b/dexed-d/src/common.d @@ -20,7 +20,7 @@ extern(C) void minimizeGcHeap() { import core.memory : GC; __gshared ubyte c; - if (c++ > 32) + if (c++ > 31) { GC.collect(); GC.minimize(); diff --git a/dexed-d/src/imports.d b/dexed-d/src/imports.d index 5c4a55e4..b96221fc 100644 --- a/dexed-d/src/imports.d +++ b/dexed-d/src/imports.d @@ -67,7 +67,12 @@ extern(C) string[] listFilesImports(const(char)* joinedFiles) LexerConfig config = LexerConfig("", StringBehavior.source); ImportLister il = construct!(ImportLister)(&result); - scope(exit) destruct(il); + scope(exit) + { + destruct(il); + destroy(sCache); + destroy(rba); + } foreach(fname; joinedFilesToFiles(joinedFiles)) { @@ -85,11 +90,14 @@ extern(C) string[] listFilesImports(const(char)* joinedFiles) return result; } +static assert(!MustAddGcRange!ImportLister); + +@TellRangeAdded private final class ImportLister: ASTVisitor { alias visit = ASTVisitor.visit; size_t mixinDepth; - string[]* results; + @NoGc string[]* results; this(string[]* results) { diff --git a/dexed-d/src/mainfun.d b/dexed-d/src/mainfun.d index bac17098..5ae638dc 100644 --- a/dexed-d/src/mainfun.d +++ b/dexed-d/src/mainfun.d @@ -19,21 +19,26 @@ import */ extern(C) bool hasMainFun(const(char)* src) { - LexerConfig config; - RollbackAllocator rba; - StringCache sCache = StringCache(StringCache.defaultBucketCount); + scope LexerConfig config; + scope RollbackAllocator rba; + scope StringCache sCache = StringCache(StringCache.defaultBucketCount); scope mod = src[0 .. src.strlen] .getTokensForParser(config, &sCache) .parseModule("", &rba, &ignoreErrors); MainFunctionDetector mfd = construct!(MainFunctionDetector); - scope (exit) destruct(mfd); - mfd.visit(mod); - return mfd.hasMain; + const bool result = mfd.hasMain; + destruct(mfd); + destroy(sCache); + destroy(rba); + return result; } +static assert(!MustAddGcRange!MainFunctionDetector); + +@TellRangeAdded private final class MainFunctionDetector: ASTVisitor { alias visit = ASTVisitor.visit; @@ -58,10 +63,11 @@ private final class MainFunctionDetector: ASTVisitor hasMain = true; } - override void visit(const(Unittest)){} - override void visit(const(ClassDeclaration)){} - override void visit(const(StructDeclaration)){} + override void visit(const(Unittest)) {} + override void visit(const(ClassDeclaration)) {} + override void visit(const(StructDeclaration)) {} override void visit(const(InterfaceDeclaration)){} - override void visit(const(FunctionBody)){} + override void visit(const(UnionDeclaration)) {} + override void visit(const(FunctionBody)) {} } diff --git a/src/u_ddemangle.pas b/src/u_ddemangle.pas index f273be2a..1191c426 100644 --- a/src/u_ddemangle.pas +++ b/src/u_ddemangle.pas @@ -25,6 +25,7 @@ begin // note, assign to result has for effect to alloc a FPC string // (by implicit convertion) so the D memory is not used. result := ddemangle(s); + minimizeGcHeap(); end else result := value; diff --git a/src/u_dexed_d.pas b/src/u_dexed_d.pas index 0a7f69ee..4e26cc30 100644 --- a/src/u_dexed_d.pas +++ b/src/u_dexed_d.pas @@ -48,17 +48,17 @@ const libdexedd_name = 'dexed-d'; {$ENDIF} - -// Used to release memroy allocated in external D functions that are called in a thread. -// because managing the GC only work from the main thread. -// memory is released every 96 calls. -procedure minimizeGcHeap(); cdecl; external libdexedd_name; -// Select the precise GC -procedure setRtOptions(); cdecl; external libdexedd_name; // Necessary to start the GC, run the static constructors, etc procedure rt_init(); cdecl; external libdexedd_name; // Cleanup procedure rt_term(); cdecl; external libdexedd_name; +// Used to release memroy allocated in external D functions that are called in a thread, +// because managing the GC only works from the main thread. +// Memory is released every 32 calls. +// This function must be called from the main thread. +procedure minimizeGcHeap(); cdecl; external libdexedd_name; +// noop +procedure setRtOptions(); cdecl; external libdexedd_name; // Demangle a line possibly containing a D mangled name. function ddemangle(const text: PChar): PChar; cdecl; external libdexedd_name; // Detects wether the source code for the module `src` contains the main() function. @@ -97,7 +97,6 @@ begin result := (fPtr + index)^; end; - procedure getModuleImports(source, imports: TStrings); var i: TDStrings; @@ -112,6 +111,7 @@ begin s := e.ptr[0 .. e.length-1]; imports.Add(s); end; + minimizeGcHeap(); end; procedure getModulesImports(files: string; results: TStrings); @@ -128,6 +128,7 @@ begin s := e.ptr[0 .. e.length-1]; results.Add(s); end; + minimizeGcHeap(); end; initialization diff --git a/src/u_synmemo.pas b/src/u_synmemo.pas index 294a5767..13df5aad 100644 --- a/src/u_synmemo.pas +++ b/src/u_synmemo.pas @@ -2406,6 +2406,7 @@ begin false:result := mainNo; true: result := mainYes; end; + minimizeGcHeap(); end; procedure TDexedMemo.autoClosePair(value: TAutoClosedPair);