Skip to content

Commit d0af4a5

Browse files
committed
splitter: Don't try to reduce module names in D source code
Avoid reducing "import std.stdio;" to "import std;".
1 parent 5b65ade commit d0af4a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2601
-1231
lines changed

splitter.d

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import std.string;
1919
import std.traits;
2020
import std.stdio : stderr;
2121
import std.typecons;
22+
import std.utf : byChar;
2223

2324
import polyhash;
2425

@@ -935,6 +936,49 @@ struct DSplitter
935936
}
936937
}
937938

939+
// Join together module names. We should not attempt to reduce "import std.stdio" to "import std" (or "import stdio").
940+
static void postProcessImports(ref Entity[] entities)
941+
{
942+
if (entities.length && entities[0].head.strip == "import" && !entities[0].children.length && !entities[0].tail.length)
943+
foreach (entity; entities[1 .. $])
944+
{
945+
static void visit(Entity entity)
946+
{
947+
static bool isValidModuleName(string s) { return s.byChar.all!(c => isWordChar(c) || isWhite(c) || c == '.'); }
948+
static bool canBeMerged(Entity entity)
949+
{
950+
return
951+
isValidModuleName(entity.head) &&
952+
entity.children.all!(child => canBeMerged(child)) &&
953+
isValidModuleName(entity.tail);
954+
}
955+
956+
if (canBeMerged(entity))
957+
{
958+
auto root = entity;
959+
// Link all ancestors to the root, and in reverse, therefore making them inextricable.
960+
void link(Entity entity)
961+
{
962+
entity.dependents ~= EntityRef(root);
963+
// root.dependents ~= EntityRef(entity);
964+
foreach (child; entity.children)
965+
link(child);
966+
}
967+
foreach (child; entity.children)
968+
link(child);
969+
}
970+
else
971+
{
972+
foreach (child; entity.children)
973+
visit(child);
974+
}
975+
}
976+
977+
foreach (child; entity.children)
978+
visit(child);
979+
}
980+
}
981+
938982
static void postProcessDependency(ref Entity[] entities)
939983
{
940984
if (entities.length < 2)
@@ -1155,6 +1199,7 @@ struct DSplitter
11551199
postProcessRecursive(e.children);
11561200

11571201
postProcessSimplify(entities);
1202+
postProcessImports(entities);
11581203
postProcessTemplates(entities);
11591204
postProcessDependency(entities);
11601205
postProcessBlockKeywords(entities);

tests/args/progress.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
[90.4%] Remove [000010000] => No
159159
[94.2%] Remove [000000110] => No
160160
[95.0%] Remove [000000101] => No
161-
[95.4%] Remove [000000100] => No
161+
[95.4%] Remove [000000100] => No (cached)
162162
============= Depth 10 =============
163163
[ 6.7%] Remove [0010111010] => No
164164
[11.2%] Remove [0010110101] => No
@@ -402,7 +402,7 @@
402402
[88.3%] Remove [000010000] => No
403403
[92.8%] Remove [000000110] => No
404404
[93.9%] Remove [000000101] => No
405-
[94.4%] Remove [000000100] => No
405+
[94.4%] Remove [000000100] => No (cached)
406406
============= Depth 10 =============
407407
[ 7.6%] Remove [0010111010] => No
408408
[12.7%] Remove [0010110101] => No
@@ -560,7 +560,7 @@
560560
[85.2%] Unwrap [0000101] => No
561561
[87.2%] Remove [0000100] => No
562562
[90.8%] Remove [0000010] => No
563-
[92.8%] Remove [0000001] => No
563+
[92.8%] Remove [0000001] => No (cached)
564564
[95.9%] Remove [0000000] => No
565565
============= Depth 8 =============
566566
[ 1.0%] Remove [00111010] => No (cached)
@@ -597,8 +597,8 @@
597597
[87.7%] Remove [00001000] => No
598598
[90.8%] Remove [00000101] => No
599599
[91.3%] Remove [00000100] => No
600-
[92.8%] Remove [00000011] => No
601-
[93.8%] Remove [00000010] => No
600+
[92.8%] Remove [00000011] => No (cached)
601+
[93.8%] Remove [00000010] => No (cached)
602602
============= Depth 9 =============
603603
[ 2.0%] Remove [001110000] => No (cached)
604604
[ 4.5%] Remove [001100000] => No (cached)
@@ -720,4 +720,4 @@
720720
============= Depth 15 =============
721721
[12.7%] Remove [001011010100000] => No (cached)
722722
[17.3%] Remove [001011000100000] => No (cached)
723-
Done in 505 tests
723+
Done in 500 tests

tests/args/src.dump

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
[ "import " /* import */ ]
77
[
88
[
9-
[ "std" ]
10-
[ "." /* . */ ] => 10
11-
]
9+
[ "std" ] =8
10+
[ "." /* . */ ] =9 => 10
11+
] => 8 9
1212
[
13-
[ "stdio" ]
14-
] =10
13+
[ "stdio" ] =11
14+
] =10 => 11
1515
]
1616
";\n\n"
1717
]

tests/args/src.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@
1515
{
1616
"children": [
1717
{
18+
"dependents": [
19+
"7"
20+
],
1821
"head": "std"
1922
},
2023
{
24+
"dependents": [
25+
"7"
26+
],
2127
"label": "9",
2228
"tail": "."
2329
}
24-
]
30+
],
31+
"label": "7"
2532
},
2633
{
2734
"children": [
2835
{
36+
"dependents": [
37+
"10"
38+
],
2939
"head": "stdio"
3040
}
3141
],
3242
"dependents": [
3343
"9"
34-
]
44+
],
45+
"label": "10"
3546
}
3647
]
3748
}

tests/constructs/progress.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
[95.1%] Remove [000101] => No
2727
[95.1%] Unwrap [000101] => No (cached)
2828
[95.3%] Remove [000100] => No
29-
[96.7%] Remove [000011] => No
29+
[96.7%] Remove [000011] => No (cached)
3030
[97.2%] Remove [000010] => No
3131
============= Depth 7 =============
3232
[ 0.8%] Remove [0001111] => No
@@ -37,7 +37,7 @@
3737
[95.6%] Remove [0001000] => No
3838
[96.7%] Remove [0000110] => No
3939
[97.2%] Remove [0000101] => No
40-
[97.5%] Remove [0000100] => No
40+
[97.5%] Remove [0000100] => No (cached)
4141
============= Depth 8 =============
4242
[ 1.0%] Remove [00011111] => No
4343
[ 4.6%] Remove [00011110] => No
@@ -118,17 +118,17 @@
118118
[71.8%] Remove [000101] => No
119119
[71.8%] Unwrap [000101] => No (cached)
120120
[73.4%] Remove [000100] => No
121-
[81.2%] Remove [000011] => No
121+
[81.2%] Remove [000011] => No (cached)
122122
[84.3%] Remove [000010] => No
123123
============= Depth 7 =============
124124
[ 4.6%] Remove [0001111] => No
125125
[39.0%] Remove [0001110] => No (cached)
126126
[51.5%] Remove [0001100] => No (cached)
127127
[73.4%] Remove [0001001] => No
128128
[75.0%] Remove [0001000] => No
129-
[81.2%] Remove [0000110] => No
130-
[84.3%] Remove [0000101] => No
131-
[85.9%] Remove [0000100] => No
129+
[81.2%] Remove [0000110] => No (cached)
130+
[84.3%] Remove [0000101] => No (cached)
131+
[85.9%] Remove [0000100] => No (cached)
132132
============= Depth 8 =============
133133
[ 4.6%] Remove [00011111] => No
134134
[20.3%] Remove [00011110] => No
@@ -173,4 +173,4 @@
173173
[39.0%] Remove [0001110000000] => No (cached)
174174
[56.2%] Remove [0001100000001] => No (cached)
175175
[57.8%] Remove [0001100000000] => No (cached)
176-
Done in 94 tests
176+
Done in 88 tests

tests/constructs/src.dump

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
[ "import " /* import */ ]
77
[
88
[
9-
[ "std" ]
10-
[ "." /* . */ ] => 10
11-
]
9+
[ "std" ] =8
10+
[ "." /* . */ ] =9 => 10
11+
] => 8 9
1212
[
13-
[ "stdio" ]
14-
] =10
13+
[ "stdio" ] =11
14+
] =10 => 11
1515
]
1616
";\n\n"
1717
]

tests/constructs/src.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,34 @@
1515
{
1616
"children": [
1717
{
18+
"dependents": [
19+
"7"
20+
],
1821
"head": "std"
1922
},
2023
{
24+
"dependents": [
25+
"7"
26+
],
2127
"label": "9",
2228
"tail": "."
2329
}
24-
]
30+
],
31+
"label": "7"
2532
},
2633
{
2734
"children": [
2835
{
36+
"dependents": [
37+
"10"
38+
],
2939
"head": "stdio"
3040
}
3141
],
3242
"dependents": [
3343
"9"
34-
]
44+
],
45+
"label": "10"
3546
}
3647
]
3748
}

tests/empty/src.dump

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
[ "import " /* import */ ]
3131
[
3232
[
33-
[ "std" ]
34-
[ "." /* . */ ] => 22
35-
]
33+
[ "std" ] =20
34+
[ "." /* . */ ] =21 => 22
35+
] => 20 21
3636
[
37-
[ "stdio" ]
38-
] =22
37+
[ "stdio" ] =23
38+
] =22 => 23
3939
]
4040
";\n"
4141
]

tests/empty/src.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,34 @@
6565
{
6666
"children": [
6767
{
68+
"dependents": [
69+
"19"
70+
],
6871
"head": "std"
6972
},
7073
{
74+
"dependents": [
75+
"19"
76+
],
7177
"label": "21",
7278
"tail": "."
7379
}
74-
]
80+
],
81+
"label": "19"
7582
},
7683
{
7784
"children": [
7885
{
86+
"dependents": [
87+
"22"
88+
],
7989
"head": "stdio"
8090
}
8191
],
8292
"dependents": [
8393
"21"
84-
]
94+
],
95+
"label": "22"
8596
}
8697
]
8798
}

tests/emptyset/src.dump

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
[ "import " /* import */ ]
3131
[
3232
[
33-
[ "std" ]
34-
[ "." /* . */ ] => 22
35-
]
33+
[ "std" ] =20
34+
[ "." /* . */ ] =21 => 22
35+
] => 20 21
3636
[
37-
[ "stdio" ]
38-
] =22
37+
[ "stdio" ] =23
38+
] =22 => 23
3939
]
4040
";\n"
4141
]

tests/emptyset/src.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,34 @@
6565
{
6666
"children": [
6767
{
68+
"dependents": [
69+
"19"
70+
],
6871
"head": "std"
6972
},
7073
{
74+
"dependents": [
75+
"19"
76+
],
7177
"label": "21",
7278
"tail": "."
7379
}
74-
]
80+
],
81+
"label": "19"
7582
},
7683
{
7784
"children": [
7885
{
86+
"dependents": [
87+
"22"
88+
],
7989
"head": "stdio"
8090
}
8191
],
8292
"dependents": [
8393
"21"
84-
]
94+
],
95+
"label": "22"
8596
}
8697
]
8798
}

tests/imports-only/progress.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
============= Depth 11 =============
2121
[45.4%] Remove [00001000000] => No (cached)
2222
============= Depth 12 =============
23-
[45.4%] Remove [000010000001] => No
24-
[51.5%] Remove [000010000000] => No
23+
[45.4%] Remove [000010000001] => No (cached)
24+
[51.5%] Remove [000010000000] => No (cached)
2525
============= Depth 13 =============
26-
[45.4%] Remove [0000100000010] => No
27-
[51.5%] Remove [0000100000001] => No
28-
[54.5%] Remove [0000100000000] => No
26+
[45.4%] Remove [0000100000010] => No (cached)
27+
[51.5%] Remove [0000100000001] => No (cached)
28+
[54.5%] Remove [0000100000000] => No (cached)
2929
############### ITERATION 1 ################
3030
============= Depth 4 =============
3131
[45.4%] Remove [0000] => No (cached)
@@ -51,4 +51,4 @@
5151
[45.4%] Remove [0000100000010] => No (cached)
5252
[51.5%] Remove [0000100000001] => No (cached)
5353
[54.5%] Remove [0000100000000] => No (cached)
54-
Done in 15 tests
54+
Done in 10 tests

0 commit comments

Comments
 (0)