Skip to content

Commit

Permalink
Use fileOffset in generateIdWithLoc
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Feb 18, 2025
1 parent edd9eb5 commit 1104e90
Show file tree
Hide file tree
Showing 27 changed files with 88 additions and 100 deletions.
16 changes: 6 additions & 10 deletions compiler/src/dmd/identifier.d
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,11 @@ nothrow:
*/
extern (D) static Identifier generateIdWithLoc(string prefix, Loc loc, string parent = "")
{
// generate `<prefix>_L<line>_C<col>`
auto sl = SourceLoc(loc);
const(char)[] fname = loc.filename.toDString();
const fileOffset = loc.fileOffset;
OutBuffer idBuf;
idBuf.writestring(prefix);
idBuf.writestring("_L");
idBuf.print(sl.line);
idBuf.writestring("_C");
idBuf.print(sl.column);
idBuf.print(fileOffset);

/**
* Make sure the identifiers are unique per filename, i.e., per module/mixin
Expand All @@ -248,14 +245,13 @@ nothrow:
* directly, but that would unnecessary lengthen symbols names. See issue:
* https://issues.dlang.org/show_bug.cgi?id=23722
*/
static struct Key { string locKey; string prefix; string parent; }
static struct Key { const(char)[] fname; uint fileOffset; string prefix; string parent; }
__gshared uint[Key] counters;

string locKey = cast(string) (sl.filename ~ idBuf[]);
static if (__traits(compiles, counters.update(Key.init, () => 0u, (ref uint a) => 0u)))
{
// 2.082+
counters.update(Key(locKey, prefix, parent),
counters.update(Key(fname, fileOffset, prefix, parent),
() => 1u, // insertion
(ref uint counter) // update
{
Expand All @@ -267,7 +263,7 @@ nothrow:
}
else
{
const key = Key(locKey, prefix, parent);
const key = Key(fname, fileOffset, prefix, parent);
if (auto pCounter = key in counters)
{
idBuf.writestring("_");
Expand Down
12 changes: 6 additions & 6 deletions compiler/test/compilable/extra-files/json.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"endline": 8,
"kind": "shared static constructor",
"line": 8,
"name": "_sharedStaticCtor_L8_C1",
"name": "_sharedStaticCtor263",
"protection": "public",
"storageClass": [
"static"
Expand All @@ -36,7 +36,7 @@
"endline": 10,
"kind": "shared static destructor",
"line": 10,
"name": "_sharedStaticDtor_L10_C1",
"name": "_sharedStaticDtor304",
"protection": "public",
"storageClass": [
"static"
Expand Down Expand Up @@ -66,7 +66,7 @@
"endline": 15,
"kind": "shared static constructor",
"line": 15,
"name": "_sharedStaticCtor_L15_C5",
"name": "_sharedStaticCtor368",
"storageClass": [
"static"
]
Expand All @@ -88,7 +88,7 @@
"endline": 17,
"kind": "shared static destructor",
"line": 17,
"name": "_sharedStaticDtor_L17_C5",
"name": "_sharedStaticDtor417",
"storageClass": [
"static"
]
Expand Down Expand Up @@ -134,7 +134,7 @@
"endline": 25,
"kind": "shared static constructor",
"line": 25,
"name": "_sharedStaticCtor_L25_C5",
"name": "_sharedStaticCtor511",
"protection": "public",
"storageClass": [
"static"
Expand All @@ -160,7 +160,7 @@
"endline": 27,
"kind": "shared static destructor",
"line": 27,
"name": "_sharedStaticDtor_L27_C5",
"name": "_sharedStaticDtor560",
"protection": "public",
"storageClass": [
"static"
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/compilable/test21330.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
REQUIRED_ARGS: -unittest
TEST_OUTPUT:
---
AliasSeq!(__unittest_L14_C5_1, __unittest_L14_C5_2)
AliasSeq!(__unittest_L14_C5_2)
AliasSeq!(__unittest221_1, __unittest221_2)
AliasSeq!(__unittest221_2)
---
*/
// https://issues.dlang.org/show_bug.cgi?id=21330
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/diag15411.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag15411.d(17): Error: function `diag15411.test15411.__funcliteral_L17_C15` cannot access variable `i` in frame of function `diag15411.test15411`
fail_compilation/diag15411.d(17): Error: function `diag15411.test15411.__funcliteral783` cannot access variable `i` in frame of function `diag15411.test15411`
fail_compilation/diag15411.d(16): `i` declared here
fail_compilation/diag15411.d(18): Error: function `diag15411.test15411.__funcliteral_L18_C15` cannot access variable `i` in frame of function `diag15411.test15411`
fail_compilation/diag15411.d(18): Error: function `diag15411.test15411.__funcliteral826` cannot access variable `i` in frame of function `diag15411.test15411`
fail_compilation/diag15411.d(16): `i` declared here
fail_compilation/diag15411.d(26): Error: `static` function `diag15411.testNestedFunction.myFunc2` cannot access function `myFunc1` in frame of function `diag15411.testNestedFunction`
fail_compilation/diag15411.d(25): `myFunc1` declared here
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/diag20268.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag20268.d(12): Error: template `__lambda_L11_C1` is not callable using argument types `!()(int)`
fail_compilation/diag20268.d(11): Candidate is: `__lambda_L11_C1(__T1, __T2)(x, y)`
fail_compilation/diag20268.d(12): Error: template `__lambda278` is not callable using argument types `!()(int)`
fail_compilation/diag20268.d(11): Candidate is: `__lambda278(__T1, __T2)(x, y)`
---
*/

Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/diag9831.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag9831.d(13): Error: function `diag9831.main.__lambda_L13_C12(__T1)(x)` cannot access variable `c` in frame of function `D main`
fail_compilation/diag9831.d(13): Error: function `diag9831.main.__lambda305(__T1)(x)` cannot access variable `c` in frame of function `D main`
fail_compilation/diag9831.d(11): `c` declared here
---
*/
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/fail12236.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ fail_compilation/fail12236.d(16): while evaluating `pragma(msg, f1.mangle
fail_compilation/fail12236.d(21): Error: forward reference to inferred return type of function `f2`
fail_compilation/fail12236.d(21): while evaluating `pragma(msg, f2(T)(T).mangleof)`
fail_compilation/fail12236.d(27): Error: template instance `fail12236.f2!int` error instantiating
fail_compilation/fail12236.d(31): Error: forward reference to inferred return type of function `__lambda_L29_C5`
fail_compilation/fail12236.d(31): while evaluating `pragma(msg, __lambda_L29_C5(__T1)(a).mangleof)`
fail_compilation/fail12236.d(31): Error: forward reference to inferred return type of function `__lambda911`
fail_compilation/fail12236.d(31): while evaluating `pragma(msg, __lambda911(__T1)(a).mangleof)`
---
*/

Expand Down
6 changes: 3 additions & 3 deletions compiler/test/fail_compilation/fail12378.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fail_compilation/fail12378.d(18): Error: undefined identifier `ANYTHING`
fail_compilation/fail12378.d(18): Error: undefined identifier `GOES`
fail_compilation/fail12378.d(91): instantiated from here: `MapResultS!((x0) => ANYTHING - GOES, Result)`
fail_compilation/fail12378.d(17): instantiated from here: `mapS!(Result)`
fail_compilation/fail12378.d(100): instantiated from here: `__lambda_L16_C19!int`
fail_compilation/fail12378.d(100): instantiated from here: `__lambda708!int`
fail_compilation/fail12378.d(91): instantiated from here: `MapResultS!((y0) => iota(2).mapS!((x0) => ANYTHING - GOES), Result)`
fail_compilation/fail12378.d(16): instantiated from here: `mapS!(Result)`
---
Expand All @@ -27,7 +27,7 @@ fail_compilation/fail12378.d(40): Error: undefined identifier `ANYTHING`
fail_compilation/fail12378.d(40): Error: undefined identifier `GOES`
fail_compilation/fail12378.d(112): instantiated from here: `MapResultC!((x0) => ANYTHING - GOES, Result)`
fail_compilation/fail12378.d(39): instantiated from here: `mapC!(Result)`
fail_compilation/fail12378.d(123): instantiated from here: `__lambda_L38_C19!int`
fail_compilation/fail12378.d(123): instantiated from here: `__lambda1499!int`
fail_compilation/fail12378.d(112): instantiated from here: `MapResultC!((y0) => iota(2).mapC!((x0) => ANYTHING - GOES), Result)`
fail_compilation/fail12378.d(38): instantiated from here: `mapC!(Result)`
---
Expand All @@ -49,7 +49,7 @@ fail_compilation/fail12378.d(64): Error: undefined identifier `ANYTHING`
fail_compilation/fail12378.d(64): Error: undefined identifier `GOES`
fail_compilation/fail12378.d(135): instantiated from here: `MapResultI!((x0) => ANYTHING - GOES, Result)`
fail_compilation/fail12378.d(63): instantiated from here: `mapI!(Result)`
fail_compilation/fail12378.d(143): instantiated from here: `__lambda_L62_C19!int`
fail_compilation/fail12378.d(143): instantiated from here: `__lambda2292!int`
fail_compilation/fail12378.d(135): instantiated from here: `MapResultI!((y0) => iota(2).mapI!((x0) => ANYTHING - GOES), Result)`
fail_compilation/fail12378.d(62): instantiated from here: `mapI!(Result)`
---
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/fail12908.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail12908.d(14): Error: `pure` delegate `fail12908.main.__foreachbody_L12_C5` cannot call impure function `fail12908.g`
fail_compilation/fail12908.d(14): Error: `pure` delegate `fail12908.main.__foreachbody197` cannot call impure function `fail12908.g`
---
*/

Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/fail13120.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail13120.d(13): Error: `pure` delegate `fail13120.g1.__foreachbody_L12_C5` cannot call impure function `fail13120.f1`
fail_compilation/fail13120.d(13): Error: `@nogc` delegate `fail13120.g1.__foreachbody_L12_C5` cannot call non-@nogc function `fail13120.f1`
fail_compilation/fail13120.d(13): Error: `pure` delegate `fail13120.g1.__foreachbody344` cannot call impure function `fail13120.f1`
fail_compilation/fail13120.d(13): Error: `@nogc` delegate `fail13120.g1.__foreachbody344` cannot call non-@nogc function `fail13120.f1`
---
*/
void f1() {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/fail17969.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* TEST_OUTPUT:
---
fail_compilation/fail17969.d(10): Error: no property `sum` for type `fail17969.__lambda_L10_C1!(int[]).__lambda_L10_C1.MapResult2!((b) => b)`
fail_compilation/fail17969.d(10): Error: no property `sum` for type `fail17969.__lambda288!(int[]).__lambda288.MapResult2!((b) => b)`
fail_compilation/fail17969.d(16): struct `MapResult2` defined here
---
* https://issues.dlang.org/show_bug.cgi?id=17969
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/fail39.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail39.d(12): Error: function `fail39.main.__funcliteral_L12_C27` cannot access function `foo` in frame of function `D main`
fail_compilation/fail39.d(12): Error: function `fail39.main.__funcliteral281` cannot access function `foo` in frame of function `D main`
fail_compilation/fail39.d(11): `foo` declared here
---
*/
Expand Down
8 changes: 4 additions & 4 deletions compiler/test/fail_compilation/fail7848.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail7848.d(27): Error: `pure` function `fail7848.C.__unittest_L25_C30` cannot call impure function `fail7848.func`
fail_compilation/fail7848.d(27): Error: `@safe` function `fail7848.C.__unittest_L25_C30` cannot call `@system` function `fail7848.func`
fail_compilation/fail7848.d(27): Error: `pure` function `fail7848.C.__unittest1414` cannot call impure function `fail7848.func`
fail_compilation/fail7848.d(27): Error: `@safe` function `fail7848.C.__unittest1414` cannot call `@system` function `fail7848.func`
fail_compilation/fail7848.d(21): `fail7848.func` is declared here
fail_compilation/fail7848.d(27): Error: `@nogc` function `fail7848.C.__unittest_L25_C30` cannot call non-@nogc function `fail7848.func`
fail_compilation/fail7848.d(27): Error: `@nogc` function `fail7848.C.__unittest1414` cannot call non-@nogc function `fail7848.func`
fail_compilation/fail7848.d(27): Error: function `fail7848.func` is not `nothrow`
fail_compilation/fail7848.d(25): Error: function `fail7848.C.__unittest_L25_C30` may throw but is marked as `nothrow`
fail_compilation/fail7848.d(25): Error: function `fail7848.C.__unittest1414` may throw but is marked as `nothrow`
fail_compilation/fail7848.d(32): Error: `pure` function `fail7848.C.invariant` cannot call impure function `fail7848.func`
fail_compilation/fail7848.d(32): Error: `@safe` function `fail7848.C.invariant` cannot call `@system` function `fail7848.func`
fail_compilation/fail7848.d(21): `fail7848.func` is declared here
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/iasm1.d
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void test5()

/* TEST_OUTPUT:
---
fail_compilation/iasm1.d(615): Error: delegate `iasm1.test6.__foreachbody_L611_C5` label `L1` is undefined
fail_compilation/iasm1.d(615): Error: delegate `iasm1.test6.__foreachbody2319` label `L1` is undefined
---
*/

Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/ice10922.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice10922.d(11): Error: function `(in uint n) { enum self = __lambda_L10_C12; return n < 2 ? n : self(n - 1) + ...` is not callable using argument types `()`
fail_compilation/ice10922.d(11): Error: function `(in uint n) { enum self = __lambda378; return n < 2 ? n : self(n - 1) + self(...` is not callable using argument types `()`
fail_compilation/ice10922.d(11): too few arguments, expected 1, got 0
fail_compilation/ice10922.d(10): `ice10922.__lambda_L10_C12(in uint n)` declared here
fail_compilation/ice10922.d(10): `ice10922.__lambda378(in uint n)` declared here
---
*/

Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/ice11822.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
TEST_OUTPUT:
---
fail_compilation/ice11822.d(33): Deprecation: function `ice11822.d` is deprecated
fail_compilation/ice11822.d(16): instantiated from here: `__lambda_L33_C15!int`
fail_compilation/ice11822.d(22): instantiated from here: `S!(__lambda_L33_C15)`
fail_compilation/ice11822.d(16): instantiated from here: `__lambda589!int`
fail_compilation/ice11822.d(22): instantiated from here: `S!(__lambda589)`
fail_compilation/ice11822.d(33): instantiated from here: `g!((n) => d(i))`
---
*/
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/ice11850.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ EXTRA_FILES: imports/a11850.d
TEST_OUTPUT:
---
fail_compilation/ice11850.d(15): Error: incompatible types for `(a) < ([0])`: `uint[]` and `int[]`
fail_compilation/imports/a11850.d(9): instantiated from here: `FilterResult!(__lambda_L15_C13, uint[][])`
fail_compilation/imports/a11850.d(9): instantiated from here: `FilterResult!(__lambda408, uint[][])`
fail_compilation/ice11850.d(15): instantiated from here: `filter!(uint[][])`
---
*/
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/fail_compilation/ice12235.d
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice12235.d(14): Error: forward reference to inferred return type of function `__lambda_L12_C5`
fail_compilation/ice12235.d(15): Error: forward reference to inferred return type of function `__lambda_L12_C5`
fail_compilation/ice12235.d(15): while evaluating `pragma(msg, __lambda_L12_C5.mangleof)`
fail_compilation/ice12235.d(14): Error: forward reference to inferred return type of function `__lambda355`
fail_compilation/ice12235.d(15): Error: forward reference to inferred return type of function `__lambda355`
fail_compilation/ice12235.d(15): while evaluating `pragma(msg, __lambda355.mangleof)`
---
*/

Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/ice14424.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice14424.d(13): Error: `AliasSeq!(__unittest_L3_C1)` has no effect
fail_compilation/ice14424.d(13): Error: `AliasSeq!(__unittest24)` has no effect
---
*/

Expand Down
4 changes: 2 additions & 2 deletions compiler/test/fail_compilation/test15306.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
TEST_OUTPUT:
---
fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral_L15_C16` cannot access mutable data `i`
fail_compilation/test15306.d(19): Error: `shared` delegate `test15306.main.__dgliteral_L19_C16` cannot access non-shared data `p`
fail_compilation/test15306.d(15): Error: `immutable` delegate `test15306.main.__dgliteral413` cannot access mutable data `i`
fail_compilation/test15306.d(19): Error: `shared` delegate `test15306.main.__dgliteral530` cannot access non-shared data `p`
---
*/

Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/test17451.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
fail_compilation/test17451.d(22): Error: undefined identifier `allocator`
fail_compilation/test17451.d(23): Error: `false` has no effect
fail_compilation/test17451.d(30): Error: variable `test17451.HashMap!(ThreadSlot).HashMap.__lambda_L30_C20.v` - size of type `ThreadSlot` is invalid
fail_compilation/test17451.d(30): Error: variable `test17451.HashMap!(ThreadSlot).HashMap.__lambda796.v` - size of type `ThreadSlot` is invalid
fail_compilation/test17451.d(44): Error: template instance `test17451.HashMap!(ThreadSlot)` error instantiating
---
*/
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/test20626.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
REQUIRED_ARGS: -check=invariant=off
TEST_OUTPUT:
----
fail_compilation/test20626.d(2): Error: expression `__unittest_L1_C1` has no type
fail_compilation/test20626.d(2): Error: undefined identifier `__unittest_L1_C1`
_error_
const void()
----
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/test20719.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
fail_compilation/test20719.d(14): Error: struct `test20719.SumType` no size because of forward reference
fail_compilation/test20719.d(17): error on member `test20719.SumType.storage`
fail_compilation/test20719.d(33): Error: variable `test20719.isCopyable!(SumType).__lambda_L33_C22.foo` - size of type `SumType` is invalid
fail_compilation/test20719.d(33): Error: variable `test20719.isCopyable!(SumType).__lambda904.foo` - size of type `SumType` is invalid
fail_compilation/test20719.d(19): Error: template instance `test20719.isCopyable!(SumType)` error instantiating
---
*/
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/fail_compilation/test23170.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/test23170.d(10): Error: this array literal causes a GC allocation in `@nogc` delegate `__lambda_L10_C15`
fail_compilation/test23170.d(10): Error: this array literal causes a GC allocation in `@nogc` delegate `__lambda225`
---
*/
// https://issues.dlang.org/show_bug.cgi?id=23170
Expand Down
Loading

0 comments on commit 1104e90

Please sign in to comment.