|
5 | 5 |
|
6 | 6 | import |
7 | 7 | std/[ |
8 | | - algorithm, |
9 | | - os, |
10 | | - sets |
| 8 | + os |
11 | 9 | ], |
12 | 10 | compiler/ast/[ |
13 | 11 | ast, |
|
21 | 19 | compiler/sem/[ |
22 | 20 | passes, |
23 | 21 | sem, |
24 | | - sighashes, |
25 | 22 | ], |
26 | 23 | compiler/utils/[astrepr,], |
27 | 24 | std/options as std_options, # due to legacy reports stupidity |
@@ -117,50 +114,31 @@ proc dust*(args: openArray[string]): ErrorCode = |
117 | 114 |
|
118 | 115 | # make note of the expected number of errors |
119 | 116 | let expected = config.errorCounter |
120 | | - var seen: HashSet[SigHash] |
121 | 117 |
|
122 | 118 | 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 | | - |
137 | 119 | echo best |
138 | 120 | echo "----- current score: ", calculateScore(config, best) |
139 | 121 |
|
140 | 122 | 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): |
145 | 126 | 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) |
151 | 128 |
|
152 | 129 | # extra errors are a problem |
153 | 130 | if config.errorCounter > expected: |
154 | 131 | echo "(unexpected errors)" |
| 132 | + iter.next() |
155 | 133 | # if we didn't unhook the errors, |
156 | 134 | # it means we didn't find the error we were looking for |
157 | 135 | elif config.structuredReportHook != dustReportHook: |
158 | 136 | echo "(uninteresting errors)" |
159 | | - # i guess this node is a viable reproduction |
| 137 | + iter.next() |
160 | 138 | else: |
161 | 139 | # found a viable tree |
| 140 | + iter.keep() |
162 | 141 | found = node |
163 | | - break |
164 | 142 |
|
165 | 143 | if found.isNil: |
166 | 144 | # none of the candidates reproduces the property; we're done |
|
0 commit comments