Skip to content

Commit 018064a

Browse files
committed
use lint to count occurences
1 parent d31bf7a commit 018064a

File tree

2 files changed

+28
-101
lines changed

2 files changed

+28
-101
lines changed

.github/workflows/bench-test.yaml

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ jobs:
4040
${{ runner.os }}-cargo-${{ matrix.project }}-
4141
${{ runner.os }}-cargo-
4242
43-
- name: count occurrences before
44-
working-directory: ./${{ matrix.project }}
45-
run: |
46-
curl -o counters.sh https://raw.githubusercontent.com/trusted-programming/mate/${GITHUB_REF##*/}/scripts/counters.sh
47-
bash counters.sh before
48-
4943
- name: prepare repository for dylint
5044
working-directory: ./${{ matrix.project }}
5145
run: |
5246
curl -o prepare_repo.sh https://raw.githubusercontent.com/trusted-programming/mate/${GITHUB_REF##*/}/scripts/prepare_repo.sh
5347
bash prepare_repo.sh
5448
49+
- name: count occurrences before
50+
working-directory: ./${{ matrix.project }}
51+
run: |
52+
curl -o counters.sh https://raw.githubusercontent.com/trusted-programming/mate/${GITHUB_REF##*/}/scripts/counters.sh
53+
bash counters.sh before
54+
5555
- name: Lint fix (run 5 times)
5656
working-directory: ./${{ matrix.project }}
5757
continue-on-error: true
@@ -77,6 +77,8 @@ jobs:
7777
- name: Calculate and print differences
7878
if: always()
7979
run: |
80+
echo "TOTAL OVERVIEW OF RESULTS"
81+
echo ""
8082
echo "For loop count before: $for_loop_count_before"
8183
echo "For loop count after: $for_loop_count_after"
8284
echo "For loop count difference: $((for_loop_count_after - for_loop_count_before))"
@@ -85,39 +87,6 @@ jobs:
8587
echo "Iter count after: $iter_count_after"
8688
echo "Iter count difference: $((iter_count_after - iter_count_before))"
8789
echo ""
88-
echo "Iter mut count before: $iter_mut_count_before"
89-
echo "Iter mut count after: $iter_mut_count_after"
90-
echo "Iter mut count difference: $((iter_mut_count_after - iter_mut_count_before))"
91-
echo ""
92-
echo "Into iter count before: $into_iter_count_before"
93-
echo "Into iter count after: $into_iter_count_after"
94-
echo "Into iter count difference: $((into_iter_count_after - into_iter_count_before))"
95-
echo ""
96-
general_iter_count_before=$((iter_count_before + iter_mut_count_before + into_iter_count_before))
97-
general_iter_count_after=$((iter_count_after + iter_mut_count_after + into_iter_count_after))
98-
echo "Total .iter*() count before: $general_iter_count_before"
99-
echo "Total .iter*() count after: $general_iter_count_after"
100-
echo "Total .iter*() count difference: $((general_iter_count_after - general_iter_count_before))"
101-
echo ""
10290
echo "Par iter count before: $par_iter_count_before"
10391
echo "Par iter count after: $par_iter_count_after"
10492
echo "Par iter count difference: $((par_iter_count_after - par_iter_count_before))"
105-
echo ""
106-
echo "Into par iter count before: $into_par_iter_count_before"
107-
echo "Into par iter count after: $into_par_iter_count_after"
108-
echo "Into par iter count difference: $((into_par_iter_count_after - into_par_iter_count_before))"
109-
echo ""
110-
echo "Par iter mut count before: $par_iter_mut_count_before"
111-
echo "Par iter mut count after: $par_iter_mut_count_after"
112-
echo "Par iter mut count difference: $((par_iter_mut_count_after - par_iter_mut_count_before))"
113-
echo ""
114-
par_iter_total_count_before=$((par_iter_count_before + into_par_iter_count_before + par_iter_mut_count_before))
115-
par_iter_total_count_after=$((par_iter_count_after + into_par_iter_count_after + par_iter_mut_count_after))
116-
echo "Total .par_iter*() count before: $par_iter_total_count_before"
117-
echo "Total .par_iter*() count after: $par_iter_total_count_after"
118-
echo "Total .par_iter*() count difference: $((par_iter_total_count_after - par_iter_total_count_before))"
119-
echo ""
120-
echo "TOTAL OVERVIEW OF RESULTS"
121-
echo "For loop count difference: $((for_loop_count_after - for_loop_count_before))"
122-
echo "Total .iter*() count difference: $((general_iter_count_after - general_iter_count_before))"
123-
echo "Total .par_iter*() count difference: $((par_iter_total_count_after - par_iter_total_count_before))"

scripts/counters.sh

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,40 @@
11
#!/bin/bash
22

33
suffix=$1
4+
# Find and replace the string in Cargo.toml
5+
sed -i.bak 's|https://github.com/trusted-programming/mate|https://github.com/trusted-programming/count_loop|' Cargo.toml
46

5-
#!/bin/bash
6-
rs_files=($(find -L . -type d \( -name target -o -name benches -o -name bench -o -name tests -o -name test \) -prune -o -type f -name '*.rs' -print | grep -vE "/benches?/|/bench/|/tests?/"))
7-
8-
echo "### COUNTING FOR LOOPS ###"
9-
for_loop_count=0 # Initialize total count
10-
for file in "${rs_files[@]}"; do
11-
echo "Checking: $file"
12-
# First, use grep to exclude comment lines, then count for loops
13-
for_loop_count_in_file=$(grep -vE '^\s*(//|/\*|\*/)' "$file" | grep -oE 'for\s+(\([^)]+\)|\w+)\s+in\s+[^{]+' | wc -l)
14-
echo "Count in file: $for_loop_count_in_file"
15-
((for_loop_count += for_loop_count_in_file))
16-
done
17-
echo "Total for loop count: $for_loop_count"
18-
19-
iter_count=0
20-
iter_mut_count=0
21-
into_iter_count=0
7+
echo
8+
echo "### FILE OUTPUT ###"
9+
echo
2210

23-
echo "### COUNTING ITERS ###"
24-
for file in "${rs_files[@]}"; do
25-
echo "Checking: $file"
26-
iter_count_in_file=$(grep -oE '\.iter\(\)' "$file" | wc -l)
27-
iter_mut_count_in_file=$(grep -oE '\.iter_mut\(\)' "$file" | wc -l)
28-
into_iter_count_in_file=$(grep -oE '\.into_iter\(\)' "$file" | wc -l)
29-
echo "iter_count_in_file: $iter_count_in_file"
30-
echo "iter_mut_count_in_file: $iter_mut_count_in_file"
31-
echo "into_iter_count_in_file: $into_iter_count_in_file"
11+
if ! dylint_output=$(cargo dylint --workspace --all 2>&1); then
12+
echo "Error running cargo dylint" >&2
13+
exit 1
14+
fi
3215

33-
((iter_count += iter_count_in_file))
34-
((iter_mut_count += iter_mut_count_in_file))
35-
((into_iter_count += into_iter_count_in_file))
36-
done
37-
general_iter_count=$((iter_count + iter_mut_count + into_iter_count))
16+
echo "$dylint_output"
17+
echo
18+
echo "### FILE OUTPUT END ###"
3819

39-
par_iter_count=0
40-
into_par_iter_count=0
41-
par_iter_mut_count=0
4220

43-
echo "### COUNTING PAR ITERS ###"
44-
for file in "${rs_files[@]}"; do
45-
echo "Checking: $file"
46-
par_iter_count_in_file=$(grep -oE '\.par_iter\(\)' "$file" | wc -l)
47-
into_par_iter_count_in_file=$(grep -oE '\.into_par_iter\(\)' "$file" | wc -l)
48-
par_iter_mut_count_in_file=$(grep -oE '\.par_iter_mut\(\)' "$file" | wc -l)
49-
echo "par_iter_count_in_file: $par_iter_count_in_file"
50-
echo "into_par_iter_count_in_file: $into_par_iter_count_in_file"
51-
echo "par_iter_mut_count_in_file: $par_iter_mut_count_in_file"
52-
((par_iter_count += par_iter_count_in_file))
53-
((into_par_iter_count += into_par_iter_count_in_file))
54-
((par_iter_mut_count += par_iter_mut_count_in_file))
55-
done
56-
par_iter_total_count=$((par_iter_count + into_par_iter_count + par_iter_mut_count))
21+
for_loop_count=$(echo "$dylint_output" | grep -c "warning: found for loop, code: 213423")
22+
iter_count=$(echo "$dylint_output" | grep -c "warning: found iterator, code: 213932")
23+
par_iter_count=$(echo "$dylint_output" | grep -c "warning: found par iterator, code: 213312")
5724

5825
echo
5926
echo "### FINAL RESULTS ###"
6027
echo
6128
echo "for loop occurrences: $for_loop_count"
62-
echo ".iter() occurrences: $iter_count"
63-
echo ".iter_mut() occurrences: $iter_mut_count"
64-
echo ".into_iter() occurrences: $into_iter_count"
65-
echo "Total .iter*() occurrences: $general_iter_count"
66-
echo ".par_iter() occurrences: $par_iter_count"
67-
echo ".into_par_iter() occurrences: $into_par_iter_count"
68-
echo ".par_iter_mut() occurrences: $par_iter_mut_count"
69-
echo "Total .par_iter*() occurrences: $par_iter_total_count"
29+
echo "Total iter occurrences: $iter_count"
30+
echo "Total par iter occurrences: $par_iter_count"
7031
echo
7132
echo "### ALL DONE ###"
7233

7334
# Echo the variables with the suffix to set them in the GitHub environment
7435
echo "for_loop_count_${suffix}=$for_loop_count" >>$GITHUB_ENV
7536
echo "iter_count_${suffix}=$iter_count" >>$GITHUB_ENV
76-
echo "iter_mut_count_${suffix}=$iter_mut_count" >>$GITHUB_ENV
77-
echo "into_iter_count_${suffix}=$into_iter_count" >>$GITHUB_ENV
78-
echo "general_iter_count_${suffix}=$((iter_count + iter_mut_count + into_iter_count))" >>$GITHUB_ENV
7937
echo "par_iter_count_${suffix}=$par_iter_count" >>$GITHUB_ENV
80-
echo "into_par_iter_count_${suffix}=$into_par_iter_count" >>$GITHUB_ENV
81-
echo "par_iter_mut_count_${suffix}=$par_iter_mut_count" >>$GITHUB_ENV
82-
echo "par_iter_total_count_${suffix}=$((par_iter_count + into_par_iter_count + par_iter_mut_count))" >>$GITHUB_ENV
38+
39+
# Change the string back in Cargo.toml
40+
mv Cargo.toml.bak Cargo.toml

0 commit comments

Comments
 (0)