From 38aab21142690375ed302036c7e93206d245320c Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Wed, 21 Sep 2022 11:13:14 +0200 Subject: [PATCH 01/11] fix memory leak caused by global hash tables in dmd --- CHANGES | 2 +- doc/VersionHistory.dd | 4 ++-- tools/tracegc.d | 28 ++++++++++++++-------------- vdc/dmdserver/dmd | 2 +- vdc/dmdserver/dmdinit.d | 3 +++ vdc/dmdserver/semanalysis.d | 13 ++++++++++--- visuald/pkgutil.d | 24 ++++++++++++------------ 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/CHANGES b/CHANGES index bc9a7d80..46642fc5 100644 --- a/CHANGES +++ b/CHANGES @@ -1330,7 +1330,7 @@ Version history * bugzilla 22764: now searches the 32-bit registry hive for install paths of DMD and LDC * bugzilla 23069: mago crashing when debugging VARIANT data type in VS 2022 * bugzilla 23043: project templates missing in VS 2022 until configuration manually updated - * semantic analysis: without a project loaded, a D file is now analized using the compile options + * semantic analysis: without a project loaded, a D file is now analyzed using the compile options of "Compile and Run" with an import path derived from the module declaration. * visualdproj: exit code printed for failed commands * cv2pdb 0.52: improved DWARF support for non-contiguous functions, bug fixes diff --git a/doc/VersionHistory.dd b/doc/VersionHistory.dd index 787c3895..552af47c 100644 --- a/doc/VersionHistory.dd +++ b/doc/VersionHistory.dd @@ -9,8 +9,8 @@ $(H2 2022-06-05 Version 1.3.0) $(LI bugzilla 22764: now searches the 32-bit registry hive for install paths of DMD and LDC) $(LI bugzilla 23069: mago crashing when debugging VARIANT data type in VS 2022) $(LI bugzilla 23043: project templates missing in VS 2022 until configuration manually updated) - $(LI semantic analysis: without a project loaded, a D file is now analized using the compile options) - $(LI of "Compile and Run" with an import path derived from the module declaration.) + $(LI semantic analysis: without a project loaded, a D file is now analyzed using the compile options + of "Compile and Run" with an import path derived from the module declaration.) $(LI visualdproj: exit code printed for failed commands) $(LI cv2pdb 0.52: improved DWARF support for non-contiguous functions, bug fixes) ) diff --git a/tools/tracegc.d b/tools/tracegc.d index 905bfce8..f32cf8a1 100644 --- a/tools/tracegc.d +++ b/tools/tracegc.d @@ -321,7 +321,7 @@ class GCTraceProxy : GC return p; } - BlkInfo qalloc(size_t size, uint bits, const TypeInfo ti) nothrow + BlkInfo qalloc(size_t size, uint bits, scope const TypeInfo ti) nothrow { BlkInfo bi = gc.qalloc(size, bits, ti); traceAlloc(bi.base); @@ -706,7 +706,7 @@ void dumpAddr(AddrTracePair[] traceMap, void* addr, size_t size) filename = ": "; auto xtra = dumpExtra(addr); - trace_printf("%s(%d): %p %llx%.*s\n", filename, line, addr, cast(long) size, cast(int)xtra.length, xtra.ptr); + trace_printf("%s(%d): %p %llx %.*s\n", filename, line, addr, cast(long) size, cast(int)xtra.length, xtra.ptr); } struct AddrInfoStat @@ -969,7 +969,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references printf("\t\tfound pool %p, base=%p, pn = %lld, bin = %d\n", pool, pool.baseAddr, cast(long)pn, bin); // Adjust bit to be at start of allocated memory block - if (bin < B_PAGE) + if (bin < Bins.B_PAGE) { // We don't care abou setting pointsToBase correctly // because it's ignored for small object pools anyhow. @@ -994,7 +994,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references goto LaddRange; } } - else if (bin == B_PAGE) + else if (bin == Bins.B_PAGE) { biti = offset >> Pool.ShiftBy.Large; //debug(PRINTF) printf("\t\tbiti = x%x\n", biti); @@ -1018,7 +1018,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references goto LaddLargeRange; } } - else if (bin == B_PAGEPLUS) + else if (bin == Bins.B_PAGEPLUS) { pn -= pool.bPageOffsets[pn]; biti = pn * (PAGESIZE >> Pool.ShiftBy.Large); @@ -1075,7 +1075,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references else { // Don't mark bits in B_FREE pages - assert(bin == B_FREE); + assert(bin == Bins.B_FREE); } } LnextPtr: @@ -1175,7 +1175,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references //debug(PRINTF) printf("\t\tfound pool %p, base=%p, pn = %zd, bin = %d, biti = x%x\n", pool, pool.baseAddr, pn, bin, biti); // Adjust bit to be at start of allocated memory block - if (bin < B_PAGE) + if (bin < Bins.B_PAGE) { // We don't care abou setting pointsToBase correctly // because it's ignored for small object pools anyhow. @@ -1193,7 +1193,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references break; } } - else if (bin == B_PAGE) + else if (bin == Bins.B_PAGE) { auto offsetBase = offset & ~cast(size_t)(PAGESIZE-1); base = pool.baseAddr + offsetBase; @@ -1329,7 +1329,7 @@ void dumpGC(GC _gc) { foreach (pn, bin; pool.pagetable[0 .. pool.npages]) { - if (bin == B_PAGE) + if (bin == Bins.B_PAGE) { auto lpool = cast(LargeObjectPool*) pool; size_t npages = lpool.bPageOffsets[pn]; @@ -1338,11 +1338,11 @@ void dumpGC(GC _gc) dumpAddr(traceMap, addr, npages * PAGESIZE); usedSize += npages * PAGESIZE; } - else if (bin == B_FREE) + else if (bin == Bins.B_FREE) { freeSize += PAGESIZE; } - else if (bin < B_PAGE) + else if (bin < Bins.B_PAGE) { immutable size = binsize[bin]; void *p = pool.baseAddr + pn * PAGESIZE; @@ -1415,7 +1415,7 @@ void dumpGC(GC _gc) Bins bin = cast(Bins)pool.pagetable[pn]; void* base = void; - if (bin < B_PAGE) + if (bin < Bins.B_PAGE) { auto offsetBase = baseOffset(offset, cast(Bins)bin); base = pool.baseAddr + offsetBase; @@ -1423,12 +1423,12 @@ void dumpGC(GC _gc) if (pool.freebits.test(biti)) continue; } - else if (bin == B_PAGE) + else if (bin == Bins.B_PAGE) { auto offsetBase = offset & ~cast(size_t)(PAGESIZE-1); base = pool.baseAddr + offsetBase; } - else if (bin == B_PAGEPLUS) + else if (bin == Bins.B_PAGEPLUS) { pn -= pool.bPageOffsets[pn]; base = pool.baseAddr + (pn * PAGESIZE); diff --git a/vdc/dmdserver/dmd b/vdc/dmdserver/dmd index b17fbeaf..ec6efcc1 160000 --- a/vdc/dmdserver/dmd +++ b/vdc/dmdserver/dmd @@ -1 +1 @@ -Subproject commit b17fbeaf48fe0fd4c7c8919495801620c4eb92ce +Subproject commit ec6efcc17574b348efa683167f2be3c7dbb1c9da diff --git a/vdc/dmdserver/dmdinit.d b/vdc/dmdserver/dmdinit.d index 39bc9a22..a95f02e8 100644 --- a/vdc/dmdserver/dmdinit.d +++ b/vdc/dmdserver/dmdinit.d @@ -30,6 +30,7 @@ import dmd.objc; import dmd.target; import dmd.common.outbuffer; +import dmd.root.ctfloat; import std.string; import core.stdc.string; @@ -160,6 +161,7 @@ void dmdInit() target._init(global.params); // needed by Type._init Type._init(); Module._init(); + CTFloat.initialize(); } struct Options @@ -353,6 +355,7 @@ void dmdSetupParams(const ref Options opts) // for another platform/architecture, different versions) void dmdReinit() { + // Dsymbol.deinitialize(); target._init(global.params); // needed by Type._init Type._reinit(); diff --git a/vdc/dmdserver/semanalysis.d b/vdc/dmdserver/semanalysis.d index 75c1dc11..ca5e7e78 100644 --- a/vdc/dmdserver/semanalysis.d +++ b/vdc/dmdserver/semanalysis.d @@ -1990,7 +1990,8 @@ void test_ana_dmd() bool dump = false; string source; Module m; - int i = 0; //foreach(i; 0..40) + int i = 0; + //foreach(i; 0..40) { filename = __FILE_FULL_PATH__; source = cast(string)std.file.read(filename); @@ -2003,14 +2004,19 @@ void test_ana_dmd() else m = checkErrors(source, ""); + import std.stdio; version(traceGC) { - import std.stdio; if ((i % 10) == 0) GC.collect(); auto stats = GC.stats; writeln(stats); } + else + { + GC.collect(); + writeln(GC.stats); + } version(traceGC) { if (stats.usedSize >= 400_000_000) @@ -2032,7 +2038,8 @@ void test_ana_dmd() } } } - // test_sem(); + test_sem(); + void test_leaks() { bool dump = false; diff --git a/visuald/pkgutil.d b/visuald/pkgutil.d index bd2eae6a..284ae4de 100644 --- a/visuald/pkgutil.d +++ b/visuald/pkgutil.d @@ -240,18 +240,18 @@ void writeGCStatsToOutputPane() GCStats stats = gc_stats(); writeToBuildOutputPane(format("numpools = %s, poolsize = %s, usedsize = %s, freelistsize = %s\n", stats.numpools, stats.poolsize, stats.usedsize, stats.freelistsize)); - writeToBuildOutputPane(format("pool[B_16] = %s\n", stats.numpool[B_16] )); - writeToBuildOutputPane(format("pool[B_32] = %s\n", stats.numpool[B_32] )); - writeToBuildOutputPane(format("pool[B_64] = %s\n", stats.numpool[B_64] )); - writeToBuildOutputPane(format("pool[B_128] = %s\n", stats.numpool[B_128] )); - writeToBuildOutputPane(format("pool[B_256] = %s\n", stats.numpool[B_256] )); - writeToBuildOutputPane(format("pool[B_512] = %s\n", stats.numpool[B_512] )); - writeToBuildOutputPane(format("pool[B_1024] = %s\n", stats.numpool[B_1024] )); - writeToBuildOutputPane(format("pool[B_2048] = %s\n", stats.numpool[B_2048] )); - writeToBuildOutputPane(format("pool[B_PAGE] = %s\n", stats.numpool[B_PAGE] )); - writeToBuildOutputPane(format("pool[B_PAGE+] = %s\n", stats.numpool[B_PAGEPLUS])); - writeToBuildOutputPane(format("pool[B_FREE] = %s\n", stats.numpool[B_FREE] )); - writeToBuildOutputPane(format("pool[B_UNCOM] = %s\n", stats.numpool[B_UNCOMMITTED])); + writeToBuildOutputPane(format("pool[B_16] = %s\n", stats.numpool[Bins.B_16] )); + writeToBuildOutputPane(format("pool[B_32] = %s\n", stats.numpool[Bins.B_32] )); + writeToBuildOutputPane(format("pool[B_64] = %s\n", stats.numpool[Bins.B_64] )); + writeToBuildOutputPane(format("pool[B_128] = %s\n", stats.numpool[Bins.B_128] )); + writeToBuildOutputPane(format("pool[B_256] = %s\n", stats.numpool[Bins.B_256] )); + writeToBuildOutputPane(format("pool[B_512] = %s\n", stats.numpool[Bins.B_512] )); + writeToBuildOutputPane(format("pool[B_1024] = %s\n", stats.numpool[Bins.B_1024] )); + writeToBuildOutputPane(format("pool[B_2048] = %s\n", stats.numpool[Bins.B_2048] )); + writeToBuildOutputPane(format("pool[B_PAGE] = %s\n", stats.numpool[Bins.B_PAGE] )); + writeToBuildOutputPane(format("pool[B_PAGE+] = %s\n", stats.numpool[Bins.B_PAGEPLUS])); + writeToBuildOutputPane(format("pool[B_FREE] = %s\n", stats.numpool[Bins.B_FREE] )); + writeToBuildOutputPane(format("pool[B_UNCOM] = %s\n", stats.numpool[Bins.B_UNCOMMITTED])); writeClasses(); } From 7c6fcf51dbc26c87aa5b246c3c7d73018963c158 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Wed, 21 Sep 2022 15:45:13 +0200 Subject: [PATCH 02/11] trying to find more leaks --- tools/tracegc.d | 32 +++++++++++++++++------- vdc/dmdserver/dmdrmem.d | 8 +++--- vdc/dmdserver/dmdserver.d | 7 ++---- vdc/dmdserver/semanalysis.d | 49 +++++++++++++++++++++---------------- 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/tools/tracegc.d b/tools/tracegc.d index f32cf8a1..5c1efaa2 100644 --- a/tools/tracegc.d +++ b/tools/tracegc.d @@ -874,7 +874,8 @@ HashTab!(void*, void*) *g_references; HashTab!(void*, size_t) *g_objects; ConservativeGC g_cgc; -void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references, ref HashTab!(void*, size_t) objects) +void collectReferences(ConservativeGC cgc, bool precise, + ref HashTab!(void*, void*) references, ref HashTab!(void*, size_t) objects) { g_cgc = cgc; g_references = &references; @@ -895,7 +896,7 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references */ static void mark(bool precise)(Gcx.ScanRange!precise rng) nothrow { - auto pooltable = g_cgc.gcx.pooltable; + auto pooltable = g_cgc.gcx.pooltable; alias toscan = scanStack!precise; debug(MARK_PRINTF) @@ -1282,16 +1283,29 @@ void collectReferences(ConservativeGC cgc, ref HashTab!(void*, void*) references thread_suspendAll(); cgc.gcx.prepare(); // set freebits - foreach(root; cgc.rootIter) - mark!true(Gcx.ScanRange!true(&root, &root + 1, null)); - foreach(range; cgc.rangeIter) - mark!true(Gcx.ScanRange!true(range.pbot, range.ptop, null)); + if (precise) + { + foreach(root; cgc.rootIter) + mark!true(Gcx.ScanRange!true(&root, &root + 1, null)); + foreach(range; cgc.rangeIter) + mark!true(Gcx.ScanRange!true(range.pbot, range.ptop, null)); + thread_scanAll((b, t) => mark!true(Gcx.ScanRange!true(b, t))); + } + else + { + foreach(root; cgc.rootIter) + mark!false(Gcx.ScanRange!false(&root, &root + 1)); + foreach(range; cgc.rangeIter) + mark!false(Gcx.ScanRange!false(range.pbot, range.ptop)); + thread_scanAll((b, t) => mark!false(Gcx.ScanRange!false(b, t))); + } + + toscanConservative.clear(); + toscanPrecise.clear(); g_cgc = null; g_references = null; g_objects = null; - toscanConservative.clear(); - toscanPrecise.clear(); //thread_scanAll(&mark); thread_resumeAll(); @@ -1575,7 +1589,7 @@ void findRoot(void* sobj) HashTab!(void*, void*)* preferences = &references; pp_references = &preferences; - collectReferences(cgc, references, objects); + collectReferences(cgc, true, references, objects); const(void*) minAddr = cgc.gcx.pooltable.minAddr; const(void*) maxAddr = cgc.gcx.pooltable.maxAddr; diff --git a/vdc/dmdserver/dmdrmem.d b/vdc/dmdserver/dmdrmem.d index 539fc424..d2fed109 100644 --- a/vdc/dmdserver/dmdrmem.d +++ b/vdc/dmdserver/dmdrmem.d @@ -42,12 +42,12 @@ extern (C++) struct Mem static void* xrealloc(void* p, size_t size) nothrow pure { - return GC.realloc(p, size); + return check(GC.realloc(p, size)); } static void* xrealloc_noscan(void* p, size_t size) nothrow pure { - return GC.realloc(p, size, GC.BlkAttr.NO_SCAN); + return check(GC.realloc(p, size, GC.BlkAttr.NO_SCAN)); } static void error() nothrow @@ -55,10 +55,10 @@ extern (C++) struct Mem __gshared static oom = new Error("out of memory"); throw oom; } - static void* check(void* p) nothrow + static void* check(void* p) nothrow pure { if (!p) - error(); + (cast(void function() nothrow pure)&error)(); return p; } diff --git a/vdc/dmdserver/dmdserver.d b/vdc/dmdserver/dmdserver.d index f15c46e7..eb93bb86 100644 --- a/vdc/dmdserver/dmdserver.d +++ b/vdc/dmdserver/dmdserver.d @@ -336,11 +336,8 @@ class DMDServer : ComObject, IVDServer version(traceGC) { - wipeStack(); - GC.collect(); - auto nstats = GC.stats(); - printf("reinit: stats.usedSize %zd -> %zd\n", stats.usedSize, nstats.usedSize); - dumpGC(); + mModules = null; + check_leaks(); } else GC.collect(); diff --git a/vdc/dmdserver/semanalysis.d b/vdc/dmdserver/semanalysis.d index ca5e7e78..cd1506aa 100644 --- a/vdc/dmdserver/semanalysis.d +++ b/vdc/dmdserver/semanalysis.d @@ -235,7 +235,7 @@ string[] guessImportPaths() { import std.file; - string path = r"c:\D\dmd-" ~ to!string(__VERSION__ * 0.001) ~ ".0"; + string path = r"c:\D\dmd-" ~ to!string(__VERSION__)[0..1] ~ "." ~ to!string(__VERSION__)[1..$] ~ ".0"; if (std.file.exists(path ~ r"\src\druntime\import\object.d")) return [ path ~ r"\src\druntime\import", path ~ r"\src\phobos" ]; path ~= "-beta.1"; @@ -1929,6 +1929,27 @@ unittest checkOutline(source, 3, expected); } +void check_leaks() +{ + import core.memory; + import std.stdio; + + //mModules = null; + lastContext = null; + Module.loadModuleHandler = null; + dmdInit(); + dmdReinit(); + + version(traceGC) + wipeStack(); + GC.collect(); + + auto stats = GC.stats; + writeln(stats); + version(traceGC) + dumpGC(); +} + void test_ana_dmd() { import core.memory; @@ -2004,24 +2025,18 @@ void test_ana_dmd() else m = checkErrors(source, ""); - import std.stdio; version(traceGC) { - if ((i % 10) == 0) - GC.collect(); - auto stats = GC.stats; - writeln(stats); + m = null; + check_leaks(); } else { - GC.collect(); + import std.stdio; + if ((i % 10) == 0) + GC.collect(); writeln(GC.stats); } - version(traceGC) - { - if (stats.usedSize >= 400_000_000) - dumpGC(); - } } foreach(f; ["expressionsem.d", "typesem.d", "statementsem.d"]) @@ -2059,18 +2074,10 @@ void test_ana_dmd() writeln(stats); if (stats.usedSize > 200_000_000) { - //mModules = null; m = null; - lastContext = null; - Module.loadModuleHandler = null; - dmdInit(); - dmdReinit(); - - wipeStack(); - GC.collect(); + check_leaks(); auto nstats = GC.stats(); printf("reinit: stats.usedSize %zd -> %zd\n", stats.usedSize, nstats.usedSize); - dumpGC(); } } } From 0a55e1a97ed413009c2a3f85d959e0427b73203c Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Wed, 21 Sep 2022 17:26:02 +0200 Subject: [PATCH 03/11] try github action --- .github/workflows/build-and-test.yml | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..d21bb889 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,61 @@ +name: build visuald + +on: [push, pull_request] + +env: + # Path to the solution file relative to the root of the project. + SOLUTION_FILE_PATH: src/visuald_vs10.vcxproj + + # Configuration type to build. + BUILD_CONFIGURATION: Release + BUILD_PLATFORM: x64 + BUILD_PLATFORM_TOOLSET: v142 + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout visuald + uses: actions/checkout@v3 + with: + path: visuald/trunk + submodules: true +# - name: Checkout cv2pdb +# uses: actions/checkout@v3 +# with: +# repository: rainers/cv2pdb +# path: cv2pdb/trunk +# - name: Checkout mago +# uses: actions/checkout@v3 +# with: +# repository: rainers/mago +# path: mago + - name: Prepare D compiler + uses: dlang-community/setup-dlang@v1 + with: + compiler: dmd-2.098.1 + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + - name: Setup VS environment + uses: seanmiddleditch/gha-setup-vsdevenv@v4 + - name: Download Visual D + uses: supplypike/setup-bin@v1 + with: + uri: 'https://github.com/dlang/visuald/releases/download/v1.3.0/VisualD-v1.3.0.exe' + name: 'VisualD-v1.3.0.exe' + version: '1.3.0' + command: ./VisualD-v1.3.0.exe /S + - name: Register visuald + run: | + reg add "HKLM\SOFTWARE\DMD" /v "InstallationDir" /t REG_SZ /d "c:\hostedtoolcache\windows\dc\dmd-2.098.1\x64" /reg:32 /f + reg add "HKLM\SOFTWARE\VisualD" /v "DMDInstallDir" /t REG_SZ /d "c:\hostedtoolcache\windows\dc\dmd-2.098.1\x64\dmd2" /reg:32 /f + - name: Build visuald + working-directory: visuald/trunk + run: nmake install_modules + - name: Upload binaries + uses: actions/upload-artifact@v2 + if: failure() + with: + name: bin + path: visuald/trunk/bin From 6f0a8f82cfc8a0bc727b9c38be506ce033bb602b Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Thu, 22 Sep 2022 14:39:04 +0200 Subject: [PATCH 04/11] allow building against WinSDK 10.0.22621.0 --- c2d/idl2d.d | 51 ++++++++++++++++++++++++++--- sdk/port/base.d | 3 ++ vdc/dmdserver/dmdserver.visualdproj | 4 +-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/c2d/idl2d.d b/c2d/idl2d.d index e99b8343..a3511ce5 100644 --- a/c2d/idl2d.d +++ b/c2d/idl2d.d @@ -622,6 +622,22 @@ class idl2d case "RtlFlushNonVolatileMemoryRanges": return 1; + // SDK 10.0.22621.0 + case "WIN_NOEXCEPT": + case "ReadLongPtrAcquire": + case "ReadLongPtrNoFence": + case "ReadLongPtrRaw": + case "WriteLongPtrRelease": + case "WriteLongPtrNoFence": + case "WriteLongPtrRaw": + case "ReadULongPtrAcquire": + case "ReadULongPtrNoFence": + case "ReadULongPtrRaw": + case "WriteULongPtrRelease": + case "WriteULongPtrNoFence": + case "WriteULongPtrRaw": + return 1; + default: break; } @@ -1086,6 +1102,8 @@ version(all) while(replaceTokenSequence(tokens, "$_not $_ident($_ident1)($expr)", "$_not cast($_ident1)($expr)", true) > 0) {} replaceTokenSequence(tokens, "$_not $_ident($_ident1)cast", "$_not cast($_ident1)cast", true); replaceTokenSequence(tokens, "$_not $_ident($_ident1*)$_not_semi;", "$_not cast($_ident1*)$_not_semi", true); + replaceTokenSequence(tokens, "$_not $_ident(const $_ident1*)$_not_semi;", "$_not cast(const $_ident1*)$_not_semi", true); + replaceTokenSequence(tokens, "$_not $_ident(volatile const $_ident1*)$_not_semi;", "$_not cast(volatile const $_ident1*)$_not_semi", true); replaceTokenSequence(tokens, "$_not $_ident(struct $_ident1*)$_not_semi;", "$_not cast(struct $_ident1*)$_not_semi", true); replaceTokenSequence(tokens, "$_not $_ident($_ident1 $_ident2*)", "$_not cast($_ident1 $_ident2*)", true); replaceTokenSequence(tokens, "HRESULT cast", "HRESULT", true); @@ -1270,6 +1288,11 @@ version(all) replaceTokenSequence(tokens, "#ifndef TRUE\n#define TRUE$def\n#endif\n", "#define TRUE 1\n", false); } + if(currentModule == "memoryapi") + { + replaceTokenSequence(tokens, "typedef struct DECLSPEC_ALIGN($_num)", "align($_num) typedef struct", true); + } + if(currentModule == "winnt") { replaceTokenSequence(tokens, "#if defined(MIDL_PASS)\ntypedef struct $_ident {\n" @@ -1299,6 +1322,11 @@ version(all) replaceTokenSequence(tokens, "RtlZeroMemory($dest,$length)", "import core.stdc.string: memset; memset($dest,0,$length)", true); + // win 10.0.22621.0: duplicate definition + replaceTokenSequence(tokens, "POWER_SETTING_ALTITUDE, *PPOWER_SETTING_ALTITUDE;", + "*PPOWER_SETTING_ALTITUDE;", true); + replaceTokenSequence(tokens, "FORCEINLINE BYTE ReadUCharAcquire $code WriteULong64Raw($args) { $code2 }", + "/+ $* +/", true); } if(currentModule == "commctrl") @@ -1385,7 +1413,10 @@ version(all) // type name and field name identical replaceTokenSequence(tokens, "ImageMoniker ImageMoniker;", "ImageMoniker mImageMoniker;", true); } - + if(currentModule.startsWith("webprop")) + { + replaceTokenSequence(tokens, "importlib(\"Microsoft.VisualStudio.Interop.tlb\");", "/+ $* +/;", true); + } // select unicode version of the API when defining without postfix A/W replaceTokenSequence(tokens, "#ifdef UNICODE\nreturn $_identW(\n#else\nreturn $_identA(\n#endif\n", " return $_identW(", false); @@ -1573,6 +1604,8 @@ version(all) enums[tok.text] = true; break; } + if(indexOf(tok.pretext, "\\\n") >= 0) + tok.pretext = replace(tok.pretext, "\\\n", "\n"); prevtext = tok.text; ++tokIt; } @@ -1653,6 +1686,10 @@ version(none) version(vsi) replaceTokenSequence(tokens, "InterlockedCompareExchange($args __in LONG ExChange, __in LONG Comperand);", "$* +/", true); replaceTokenSequence(tokens, "InterlockedOr(&Barrier, 0);", "InterlockedExchangeAdd(&Barrier, 0);", true); // InterlockedOr exist only as intrinsic } + if (currentModule == "winerror") + { + replaceTokenSequence(tokens, "HRESULT HRESULT_FROM_SETUPAPI($args) { $code }", "/+ $* +/", true); + } if(currentModule == "ocidl") { // move alias out of interface declaration, it causes circular definitions with dmd 2.065+ @@ -2134,6 +2171,8 @@ else TokenIterator inAlias = tokens.end(); for(TokenIterator tokIt = tokens.begin(); !tokIt.atEnd(); ++tokIt) { + bool isAssign(string txt) { return txt == "=" || txt == "&=" || txt == "|=" || txt == "+=" || txt == "-="; } + Token tok = *tokIt; //tok.pretext = tok.pretext.replace("//D", ""); tok.text = translateToken(tok.text); @@ -2150,8 +2189,9 @@ else } else if(tok.text == "[" && tokIt[1].text != "]") { - if((tokIt.atBegin() || tokIt[-1].text != "{" || tokIt[-2].text != "=") && + if((tokIt.atBegin() || tokIt[-1].text != "{" || !isAssign(tokIt[-2].text)) && (tokIt[1].type != Token.Number || tokIt[2].text != "]") && + tokIt[1].text != "i" && // RtlConstantTimeEqualMemory (tokIt[2].text != "]" || tokIt[3].text != ";")) { TokenIterator bit = tokIt; @@ -2168,8 +2208,9 @@ else { TokenIterator openit = tokIt; if(retreatToOpeningBracket(openit) && - (openit.atBegin || (openit-1).atBegin || openit[-1].text != "{" || openit[-2].text != "=")) + (openit.atBegin || (openit-1).atBegin || openit[-1].text != "{" || !isAssign(openit[-2].text))) if((tokIt[-1].type != Token.Number || tokIt[-2].text != "[") && + tokIt[-1].text != "i" && // RtlConstantTimeEqualMemory (tokIt[-2].text != "[" || tokIt[1].text != ";")) tok.text = "]+/"; } @@ -2900,8 +2941,8 @@ unittest string exptxt = " int convert() { return " ~ " hello; } -// #define noconvert(n,m) \\ -// hallo1 |\\ +// #define noconvert(n,m) +// hallo1 | // hallo2 "; version(macro2template) exptxt = replace(exptxt, "int", "auto"); diff --git a/sdk/port/base.d b/sdk/port/base.d index 59d1427e..3c8f91e9 100644 --- a/sdk/port/base.d +++ b/sdk/port/base.d @@ -175,6 +175,9 @@ enum CCM_TRANSLATEACCELERATOR = (WM_USER+97); // msdbg*.d alias ULONG32 XINT32; +// Win SDK 10.0.22621.0 +struct _UNWIND_HISTORY_TABLE; + version(sdk) {} else { diff --git a/vdc/dmdserver/dmdserver.visualdproj b/vdc/dmdserver/dmdserver.visualdproj index 6744e950..9302a36d 100644 --- a/vdc/dmdserver/dmdserver.visualdproj +++ b/vdc/dmdserver/dmdserver.visualdproj @@ -572,7 +572,7 @@ 0 c:\l\d\dmd2\windows\bin\dmd.exe dmd\src ..\.. - dmd dmd\src\dmd\res + dmd dmd\res dmd\src\dmd\res ..\..\bin\$(ConfigurationName) $(OutDir)\$(PlatformName)\$(ProjectName) @@ -1072,7 +1072,7 @@ 0 c:\l\d\dmd2\windows\bin\dmd.exe dmd\src ..\.. - dmd dmd\res + dmd dmd\res dmd\src\dmd\res ..\..\bin\$(ConfigurationName) $(OutDir)\$(PlatformName)\$(ProjectName) From d63058e9fe0a0bfc362e24946fcbc407294b8358 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Thu, 22 Sep 2022 16:39:31 +0200 Subject: [PATCH 05/11] gha: recursive checkout --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index d21bb889..6402d452 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v3 with: path: visuald/trunk - submodules: true + submodules: recursive # - name: Checkout cv2pdb # uses: actions/checkout@v3 # with: From 693d2b86c8717b7134858f5ad084c5e98bbd35e9 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Thu, 22 Sep 2022 17:36:45 +0200 Subject: [PATCH 06/11] fixed projects no longer considered failing --- CHANGES | 5 +++++ VERSION | 2 +- c2d/idl2d.d | 2 ++ visuald/config.d | 18 +++++++++++------- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 46642fc5..fdc7a135 100644 --- a/CHANGES +++ b/CHANGES @@ -1334,3 +1334,8 @@ Version history of "Compile and Run" with an import path derived from the module declaration. * visualdproj: exit code printed for failed commands * cv2pdb 0.52: improved DWARF support for non-contiguous functions, bug fixes + +2022-09-22 version 1.3.1 + * dmdserver: fixed memory leak + * fixed building against WinSDK 10.0.22621.0 + * fixed projects no longer considered failing diff --git a/VERSION b/VERSION index 9b3b8cbb..d0bbf450 100644 --- a/VERSION +++ b/VERSION @@ -1,5 +1,5 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 3 -#define VERSION_REVISION 0 +#define VERSION_REVISION 1 #define VERSION_BETA #define VERSION_BUILD 0 diff --git a/c2d/idl2d.d b/c2d/idl2d.d index a3511ce5..e444476c 100644 --- a/c2d/idl2d.d +++ b/c2d/idl2d.d @@ -1327,6 +1327,8 @@ version(all) "*PPOWER_SETTING_ALTITUDE;", true); replaceTokenSequence(tokens, "FORCEINLINE BYTE ReadUCharAcquire $code WriteULong64Raw($args) { $code2 }", "/+ $* +/", true); + replaceTokenSequence(tokens, "FORCEINLINE PVOID ReadPointerAcquire $code WritePointerRaw($args) { $code2 }", + "/+ $* +/", true); } if(currentModule == "commctrl") diff --git a/visuald/config.d b/visuald/config.d index 5a8ce448..bd6fb334 100644 --- a/visuald/config.d +++ b/visuald/config.d @@ -3191,12 +3191,14 @@ class Config : DisposingComObject, { cmd = getEnvironmentChanges() ~ cmd ~ addopt ~ "\n"; cmd ~= ":reportError\n"; - cmd ~= "set ERR=%ERRORLEVEL%\n"; - cmd ~= "if %ERR% LSS -65535 then ERR=0x%=EXITCODE%\n"; + cmd ~= "set ERR=%ERRORLEVEL%\n"; // clears errorlevel + cmd ~= "set DISPERR=%ERR%\n"; + cmd ~= "if %ERR% LSS -65535 then DISPERR=0x%=EXITCODE%\n"; if(syntaxOnly) - cmd ~= "if %errorlevel% neq 0 echo Compiling " ~ file.GetFilename() ~ " failed (error code %ERR%)!\n"; + cmd ~= "if %errorlevel% neq 0 echo Compiling " ~ file.GetFilename() ~ " failed (error code %DISPERR%)!\n"; else - cmd ~= "if %errorlevel% neq 0 echo Building " ~ outfile ~ " failed (error code %ERR%)!\n"; + cmd ~= "if %errorlevel% neq 0 echo Building " ~ outfile ~ " failed (error code %DISPERR%)!\n"; + cmd ~= "exit /B %ERR%\n"; cmd = mProjectOptions.replaceEnvironment(cmd, this, file.GetFilename(), outfile); } return cmd; @@ -3878,9 +3880,11 @@ class Config : DisposingComObject, } cmd ~= "\ngoto noError\n"; cmd ~= "\n:reportError\n"; - cmd ~= "set ERR=%ERRORLEVEL%\n"; - cmd ~= "if %ERR% LSS -65535 then ERR=0x%=EXITCODE%\n"; - cmd ~= "echo Building " ~ GetTargetPath() ~ " failed (error code %ERR%)!\n"; + cmd ~= "set ERR=%ERRORLEVEL%\n"; // clears errorlevel + cmd ~= "set DISPERR=%ERR%\n"; + cmd ~= "if %ERR% LSS -65535 then DISPERR=0x%=EXITCODE%\n"; + cmd ~= "echo Building " ~ GetTargetPath() ~ " failed (error code %DISPERR%)!\n"; + cmd ~= "exit /B %ERR%\n"; cmd ~= "\n:noError\n"; return mProjectOptions.replaceEnvironment(cmd, this); From 31020e7480940c905303501e766e09d6b6b3498b Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Thu, 22 Sep 2022 17:39:33 +0200 Subject: [PATCH 07/11] gha: use windows-2019 --- .github/workflows/build-and-test.yml | 5 +++-- Makefile | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 6402d452..06867917 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -13,7 +13,8 @@ env: jobs: build: - runs-on: windows-latest + # windows-latest doesn't have .net framework 4.0 + runs-on: windows-2019 steps: - name: Checkout visuald @@ -52,7 +53,7 @@ jobs: reg add "HKLM\SOFTWARE\VisualD" /v "DMDInstallDir" /t REG_SZ /d "c:\hostedtoolcache\windows\dc\dmd-2.098.1\x64\dmd2" /reg:32 /f - name: Build visuald working-directory: visuald/trunk - run: nmake install_modules + run: nmake d_modules - name: Upload binaries uses: actions/upload-artifact@v2 if: failure() diff --git a/Makefile b/Makefile index a6ac4269..af255954 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,9 @@ install_vs_no_vs2017: install_modules fake_dparser cv2pdb mago magogc dbuild12 install_vs_only_vs2017: install_modules dparser dparser_test cv2pdb_vs15 mago_vs15 magogc fake_dbuild12 fake_dbuild14 dbuild15 install_only -install_modules: prerequisites visuald_vs visuald_vs_x64 vdserver dmdserver vdextension vdext15 visualdwizard dcxxfilt +install_modules: d_modules vdextension vdext15 visualdwizard dcxxfilt + +d_modules: prerequisites visuald_vs visuald_vs_x64 vdserver dmdserver install_only: if not exist ..\downloads\nul md ..\downloads From 80d7457a50f86ab8c454c5b22021285ea2ff5414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkerim=20G=C3=BCven?= Date: Mon, 3 Oct 2022 13:01:00 +0300 Subject: [PATCH 08/11] Add support for VS2022 17.3 and 17.4 --- msbuild/dbuild/dbuild.csproj | 58 +++++++++++++++++++++++++++++++-- msbuild/dcompile_defaults.props | 4 ++- nsis/visuald.nsi | 2 ++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/msbuild/dbuild/dbuild.csproj b/msbuild/dbuild/dbuild.csproj index 2e6411aa..1e837191 100644 --- a/msbuild/dbuild/dbuild.csproj +++ b/msbuild/dbuild/dbuild.csproj @@ -159,6 +159,50 @@ MinimumRecommendedRules.ruleset 17.2 + + bin\Release-v17_3\ + TRACE;TOOLS_V17 + true + true + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + 17.3 + + + bin\Debug-v17_3\ + TRACE;DEBUG;TOOLS_V17 + true + false + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + 17.3 + + + bin\Release-v17_4\ + TRACE;TOOLS_V17 + true + true + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + 17.4 + + + bin\Debug-v17_4\ + TRACE;DEBUG;TOOLS_V17 + true + false + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + 17.4 + true full @@ -202,7 +246,7 @@ v4.6 v4.5.2 v4.7.2 - v4.7.2 + v4.7.2 false false false @@ -433,7 +477,7 @@ - + assemblies\v17\Microsoft.Build.dll @@ -471,6 +515,16 @@ assemblies\v17_2\Microsoft.Build.CPPTasks.Common.dll + + + assemblies\v17_2\Microsoft.Build.CPPTasks.Common.dll + + + + + assemblies\v17_2\Microsoft.Build.CPPTasks.Common.dll + + Designer diff --git a/msbuild/dcompile_defaults.props b/msbuild/dcompile_defaults.props index 6a6738a4..e56853d0 100644 --- a/msbuild/dcompile_defaults.props +++ b/msbuild/dcompile_defaults.props @@ -49,7 +49,9 @@ 16.1 17.0 17.1 - 17.2 + 17.2 + 17.3 + 17.4 diff --git a/nsis/visuald.nsi b/nsis/visuald.nsi index e21cfa1a..4e2ed8a0 100644 --- a/nsis/visuald.nsi +++ b/nsis/visuald.nsi @@ -332,6 +332,8 @@ Section "Visual Studio package" SecPackage ${File} ..\msbuild\dbuild\obj\release-v17\ dbuild.17.0.dll ${File} ..\msbuild\dbuild\obj\release-v17_1\ dbuild.17.1.dll ${File} ..\msbuild\dbuild\obj\release-v17_2\ dbuild.17.2.dll + ${File} ..\msbuild\dbuild\obj\release-v17_3\ dbuild.17.3.dll + ${File} ..\msbuild\dbuild\obj\release-v17_4\ dbuild.17.4.dll !endif WriteRegStr HKLM "Software\${APPNAME}" "msbuild" $INSTDIR\msbuild !endif From af797b1d675c2f6183ef8253605dd45bb1f290b9 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Sun, 9 Oct 2022 14:01:27 +0200 Subject: [PATCH 09/11] DParser: make buildable with older version --- vdc/abothe/Parser | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vdc/abothe/Parser b/vdc/abothe/Parser index c4f7813b..43fb9e50 160000 --- a/vdc/abothe/Parser +++ b/vdc/abothe/Parser @@ -1 +1 @@ -Subproject commit c4f7813b69cf1ccf2125587da1a119264a3a60a7 +Subproject commit 43fb9e50ae0014964eb9b374488521c8d66d993e From e91747c32c23824f9775708c479efcf1a7dba1c6 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Sun, 9 Oct 2022 14:25:08 +0200 Subject: [PATCH 10/11] build dbuild.17.3.dll and dbuild.17.4.dll --- Makefile | 8 ++++++++ msbuild/dbuild/dbuild.csproj | 4 ++-- msbuild/dcompile.targets | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index af255954..19508668 100644 --- a/Makefile +++ b/Makefile @@ -143,6 +143,14 @@ dbuild17_1: dbuild17_2: cd msbuild\dbuild && $(MSBUILD) dbuild.csproj /p:Configuration=Release-v17_2;Platform=AnyCPU /t:Rebuild +dbuild17_3: + cd msbuild\dbuild && $(MSBUILD) dbuild.csproj /p:Configuration=Release-v17_3;Platform=AnyCPU /t:Rebuild + +dbuild17_4: + cd msbuild\dbuild && $(MSBUILD) dbuild.csproj /p:Configuration=Release-v17_4;Platform=AnyCPU /t:Rebuild + +dbuild17_all: dbuild17 dbuild17_1 dbuild17_2 dbuild17_3 dbuild17_4 + mago: cd ..\..\mago && devenv /Build "Release|Win32" /Project "MagoNatDE" magodbg_2010.sln cd ..\..\mago && devenv /Build "Release|x64" /Project "MagoRemote" magodbg_2010.sln diff --git a/msbuild/dbuild/dbuild.csproj b/msbuild/dbuild/dbuild.csproj index 1e837191..c7b47486 100644 --- a/msbuild/dbuild/dbuild.csproj +++ b/msbuild/dbuild/dbuild.csproj @@ -517,12 +517,12 @@ - assemblies\v17_2\Microsoft.Build.CPPTasks.Common.dll + assemblies\v17_3\Microsoft.Build.CPPTasks.Common.dll - assemblies\v17_2\Microsoft.Build.CPPTasks.Common.dll + assemblies\v17_4\Microsoft.Build.CPPTasks.Common.dll diff --git a/msbuild/dcompile.targets b/msbuild/dcompile.targets index f5e45ffb..452607ec 100644 --- a/msbuild/dcompile.targets +++ b/msbuild/dcompile.targets @@ -136,7 +136,7 @@ Condition="'@(DCompile)' != '' and '$(DCompiler)' != 'None'" DependsOnTargets="_collectDFiles;_replacePackageName"> - + From 660d701f971c26c414f4adb7579521976d55a3d5 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Sun, 9 Oct 2022 17:12:27 +0200 Subject: [PATCH 11/11] use new versions dmd 2.100.2 and ldc 1.30.0 for full installer --- CHANGES | 5 ++++- nsis/visuald.nsi | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index fdc7a135..594ffb28 100644 --- a/CHANGES +++ b/CHANGES @@ -1335,7 +1335,10 @@ Version history * visualdproj: exit code printed for failed commands * cv2pdb 0.52: improved DWARF support for non-contiguous functions, bug fixes -2022-09-22 version 1.3.1 +2022-10-09 version 1.3.1 + * full installer now bundled with DMD 2.100.2 and LDC 1.30.0 * dmdserver: fixed memory leak * fixed building against WinSDK 10.0.22621.0 * fixed projects no longer considered failing + * D files in VC projects failed to build in VS 2022 17.3 and 17.4, added separate versions of + dbuild.17.x.dll linked respective Microsoft.Build.CPPTasks.Common.dll diff --git a/nsis/visuald.nsi b/nsis/visuald.nsi index 4e2ed8a0..49c020b6 100644 --- a/nsis/visuald.nsi +++ b/nsis/visuald.nsi @@ -29,12 +29,12 @@ ; define DMD source path to include dmd installation ; !define DMD -!define DMD_VERSION "2.100.0" +!define DMD_VERSION "2.100.2" !define DMD_SRC c:\d\dmd-${DMD_VERSION} ; define LDC to include ldc installation ; !define LDC -!define LDC_VERSION "1.29.0" +!define LDC_VERSION "1.30.0" !define LDC_SRC c:\d\ldc2-${LDC_VERSION}-windows-multilib ; define VS2019 to include VS2019 support