Skip to content

Commit 5a47786

Browse files
committed
dust: implement and use a new reduction strategy
1 parent 1d36f68 commit 5a47786

File tree

2 files changed

+341
-169
lines changed

2 files changed

+341
-169
lines changed

tools/dust/dust.nim

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
import
77
std/[
8-
algorithm,
9-
os,
10-
sets
8+
os
119
],
1210
compiler/ast/[
1311
ast,
@@ -21,7 +19,6 @@ import
2119
compiler/sem/[
2220
passes,
2321
sem,
24-
sighashes,
2522
],
2623
compiler/utils/[astrepr,],
2724
std/options as std_options, # due to legacy reports stupidity
@@ -117,50 +114,31 @@ proc dust*(args: openArray[string]): ErrorCode =
117114

118115
# make note of the expected number of errors
119116
let expected = config.errorCounter
120-
var seen: HashSet[SigHash]
121117

122118
while true:
123-
var remains: seq[(SigHash, PNode)]
124-
# gather all possible, not-yet-tried mutations:
125-
for mutant in mutations(best):
126-
let hash = hashTree(mutant)
127-
if hash notin seen:
128-
remains.add (hash, mutant)
129-
130-
if remains.len == 0:
131-
# there are none; we're done
132-
break
133-
# sort by their score. The one with the lowest score has to come first
134-
sort(remains, proc(a, b: auto): int =
135-
calculateScore(config, a[1]) - calculateScore(config, b[1]))
136-
137119
echo best
138120
echo "----- current score: ", calculateScore(config, best)
139121

140122
var found = PNode nil
141-
# try all candidates, starting with the smallest one
142-
for (hash, node) in remains.items:
143-
seen.incl(hash)
144-
123+
var iter = initMutator(best)
124+
# go over all mutations, committing the ones that reproduce the error
125+
while (let node = iter.get(); node != nil):
145126
semcheck:
146-
try:
147-
writeFile(config.projectFull.string, $node)
148-
except IndexError:
149-
echo "cheating to get around rendering bug"
150-
continue
127+
writeFile(config.projectFull.string, $node)
151128

152129
# extra errors are a problem
153130
if config.errorCounter > expected:
154131
echo "(unexpected errors)"
132+
iter.next()
155133
# if we didn't unhook the errors,
156134
# it means we didn't find the error we were looking for
157135
elif config.structuredReportHook != dustReportHook:
158136
echo "(uninteresting errors)"
159-
# i guess this node is a viable reproduction
137+
iter.next()
160138
else:
161139
# found a viable tree
140+
iter.keep()
162141
found = node
163-
break
164142

165143
if found.isNil:
166144
# none of the candidates reproduces the property; we're done

0 commit comments

Comments
 (0)