Skip to content

Commit 0b61102

Browse files
committed
Stop reduce subcommand if it’s not making progress
If the chunk sizes are really tiny compared to the reduced source file, it looks like we aren't making any progress reducing. Just abort the reduction in that case.
1 parent 1bc237a commit 0b61102

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Sources/swift-parser-test/swift-parser-test.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ class Reduce: ParsableCommand {
265265
var reduced = source
266266
var chunkSize = source.count / 4
267267
while chunkSize > 0 {
268+
if chunkSize < reduced.count / 20 {
269+
// The chunk sizes are really tiny compared to the source file. Looks like we aren't making any progress reducing. Abort.
270+
break
271+
}
268272
if verbose {
269273
printerr("Current source size \(reduced.count), reducing with chunk size \(chunkSize)")
270274
}

0 commit comments

Comments
 (0)