-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathminimise.py
executable file
·66 lines (53 loc) · 1.84 KB
/
minimise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import os
import subprocess
import string
end_bb = "Return()"
def check(file: os.PathLike) -> bool:
out = subprocess.run(["timeout", "5", "target/release/difftest", str(file)], capture_output=True)
if out.returncode == 124:
return False
err = out.stderr.decode(encoding = 'utf-8')
return "didn't pass" in err and "stderr" not in err
def mutate(orig: str) -> str:
if len(orig) == 0:
return orig
if orig[0] in string.ascii_uppercase and orig.endswith(")") and orig != end_bb:
return end_bb
else:
return f"//{orig}"
if __name__ == "__main__":
with open("minimised.rs", "w", encoding='utf-8') as working:
with open("repro.rs", "r", encoding='utf-8') as orig:
source = orig.readlines()
progress = True
while progress:
progress = False
limit = len(source)-1
for line in reversed(range(limit)):
saved = source[line].strip()
if saved.startswith("//"):
continue
elif len(saved) == 0:
continue
elif saved.endswith("{"):
continue
elif saved == "}":
continue
elif saved.startswith("#"):
continue
print(line, end='\r')
source[line] = mutate(saved) + "\n"
working.seek(0)
working.writelines(source)
working.truncate()
working.flush()
if check(working.name):
progress = True
else:
source[line] = saved + "\n"
working.seek(0)
working.writelines(source)
working.truncate()
working.flush()
print(f"done pass")