Skip to content

Commit d0c3f1f

Browse files
committed
Rework some more
1 parent 5c6e203 commit d0c3f1f

4 files changed

Lines changed: 47 additions & 16 deletions

File tree

src/dmd/ctorflow.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct CtorFlow
9797
{
9898
auto fi = &fieldinit[i];
9999
fi.csx |= u.csx;
100-
if (fi.loc == Loc.init)
100+
if (fi.loc is Loc.init)
101101
fi.loc = u.loc;
102102
}
103103
}

src/dmd/dscope.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ struct Scope
292292
bool mustInit = (v.storage_class & STC.nodefaultctor || v.type.needsNested());
293293
auto fieldInit = &this.ctorflow.fieldinit[i];
294294
const fiesCurrent = fies[i];
295-
if (fieldInit.loc == Loc.init)
295+
if (fieldInit.loc is Loc.init)
296296
fieldInit.loc = fiesCurrent.loc;
297297
if (!mergeFieldInit(this.ctorflow.fieldinit[i].csx, fiesCurrent.csx) && mustInit)
298298
{

src/dmd/globals.d

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,28 +462,42 @@ nothrow:
462462
return buf.extractString();
463463
}
464464

465+
/* Checks for equivalence,
466+
* a) comparing the filename contents (not the pointer), case-
467+
* insensitively on Windows, and
468+
* b) ignoring charnum if `global.params.showColumns` is false.
469+
*/
465470
extern (C++) bool equals(ref const(Loc) loc) const
466471
{
467472
return (!global.params.showColumns || charnum == loc.charnum) &&
468473
linnum == loc.linnum &&
469474
FileName.equals(filename, loc.filename);
470475
}
471476

472-
extern (D) bool opEquals(Loc loc) const pure
477+
/* opEquals() / toHash() for AA key usage:
478+
*
479+
* Compare filename contents (case-sensitively on Windows too), not
480+
* the pointer - a static foreach loop repeatedly mixing in a mixin
481+
* may lead to multiple equivalent filenames (`foo.d-mixin-<line>`),
482+
* e.g., for test/runnable/test18880.d.
483+
*/
484+
extern (D) bool opEquals(ref const(Loc) loc) const @trusted pure nothrow @nogc
473485
{
486+
import core.stdc.string : strcmp;
487+
474488
return charnum == loc.charnum &&
475489
linnum == loc.linnum &&
476-
FileName.equals(filename, loc.filename);
490+
(filename == loc.filename ||
491+
(filename && loc.filename && strcmp(filename, loc.filename) == 0));
477492
}
478493

479-
extern (D) hash_t toHash() const pure
494+
extern (D) size_t toHash() const @trusted pure nothrow
480495
{
481-
import dmd.root.hash;
482-
import dmd.utils;
496+
import dmd.utils : toDString;
483497

484498
auto hash = hashOf(linnum);
485-
hash = mixHash(hash, hashOf(charnum));
486-
hash = mixHash(hash, hashOf(filename.toDString));
499+
hash = hashOf(charnum, hash);
500+
hash = hashOf(filename.toDString, hash);
487501
return hash;
488502
}
489503

src/dmd/identifier.d

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,25 +163,42 @@ nothrow:
163163
idBuf.print(loc.charnum);
164164

165165
/**
166-
* Make sure the identifiers are unique per module. See issues
166+
* Make sure the identifiers are unique per filename, i.e., per module/mixin
167+
* (`path/to/foo.d` and `path/to/foo.d-mixin-<line>`). See issues
167168
* https://issues.dlang.org/show_bug.cgi?id=16995
168169
* https://issues.dlang.org/show_bug.cgi?id=18097
169170
* https://issues.dlang.org/show_bug.cgi?id=18111
170171
* https://issues.dlang.org/show_bug.cgi?id=18880
171172
* https://issues.dlang.org/show_bug.cgi?id=18868
172-
* https://issues.dlang.org/show_bug.cgi?id=19058.
173+
* https://issues.dlang.org/show_bug.cgi?id=19058
173174
*/
174175
static struct Key { Loc loc; string prefix; }
175176
__gshared uint[Key] counters;
176177

177-
const key = Key(loc, prefix);
178-
if (auto pCounter = key in counters)
178+
static if (__traits(compiles, counters.update(Key.init, () => 0u, (ref uint a) => 0u)))
179179
{
180-
idBuf.writestring("_");
181-
idBuf.print((*pCounter)++);
180+
// 2.082+
181+
counters.update(Key(loc, prefix),
182+
() => 1u, // insertion
183+
(ref uint counter) // update
184+
{
185+
idBuf.writestring("_");
186+
idBuf.print(counter);
187+
return counter + 1;
188+
}
189+
);
182190
}
183191
else
184-
counters[key] = 1;
192+
{
193+
const key = Key(loc, prefix);
194+
if (auto pCounter = key in counters)
195+
{
196+
idBuf.writestring("_");
197+
idBuf.print((*pCounter)++);
198+
}
199+
else
200+
counters[key] = 1;
201+
}
185202

186203
return idPool(idBuf.peekSlice());
187204
}

0 commit comments

Comments
 (0)