Files
lucisv/tools/style_sweep.sh
Guoliang ChenandClaude Mythos 5.2 80017a59f2
release / build-and-publish (push) Successful in 5m22s
Release 0.65.5: named formatting styles
TODO §71.5. One setting picks a house layout — [format] style in
lucisv.toml, --style, the lucisv.format.style drop-down, the server and MCP:
lucisv (default), google, lowrisc, ansi, microsoft, nxp, and auto. Seven
layout rules (indent, width, begin placement, else placement, else after a
labelled end, one-per-line lists, list indent, alignment), one row per style
in one table in crates/vlog_formatter/src/style.rs. google and lowrisc follow
those published guides; ansi, microsoft and nxp are lucisv's guesses and say
so. auto formats with each preset and keeps the result that changes the
fewest lines (crates/vlog_formatter/src/auto.rs); the language server
remembers each document's preset (lucisv_server/src/auto_style.rs) so
selection and on-type formatting do not repeat the search. The style is part
of the format cache key.

Proof: default output byte-identical to 0.65.4 on 4 921 files (corpus +
OpenTitan hw) against an independently rebuilt 0.65.4; every style formatted
three times over the same files with no verification error, crash, token or
comment difference (independent lexer) or second-run change. verify.rs is
untouched.

Dev (three rounds), QA (two rounds, pass with findings) and lead review are
in docs/features/format-styles/README.md. Three one-line calls were added to
lucisv_server/src/server/notification.rs for the memory's invalidation.
TODO.md files the pre-existing bugs QA met on the way.

Version bump (Cargo.toml, Cargo.lock, editors/vscode/package.json and both
package-lock.json spots); notes in CHANGELOG.md (## 0.65.5) and
editors/vscode/CHANGELOG.md.

Gates: tools/gates.sh PASS on this tree; vlog_formatter 376/0,
lucisv_server 1996/0, corpus 814/6.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-19 07:03:20 -08:00

74 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Prove every formatting style safe over real trees: for each preset, format
# a scratch copy of the trees in place, count verification errors and
# crashes, re-check the output for idempotency, and format every A-output
# with B and then A again to measure cross-preset stability.
#
# Usage: tools/style_sweep.sh -b lucisv -w workdir [-s "lucisv google ..."] tree...
#
# Never writes to the trees themselves -- only to copies under workdir.
# Every lucisv run goes through tools/guard.sh. Prints one TSV row per
# preset and one per ordered pair; exit 1 if any verification error, crash
# or idempotency violation was seen.
# See docs/features/format-styles/README.md.
set -u
here=$(cd "$(dirname "$0")" && pwd)
lucisv=
work=
styles="lucisv google lowrisc ansi microsoft nxp auto"
while [ $# -gt 0 ]; do
case $1 in
-b) lucisv=$2; shift 2 ;;
-w) work=$2; shift 2 ;;
-s) styles=$2; shift 2 ;;
-*) echo "usage: $0 -b lucisv -w workdir [-s styles] tree..." >&2; exit 2 ;;
*) break ;;
esac
done
[ -x "$lucisv" ] && [ -n "$work" ] && [ $# -gt 0 ] || {
echo "usage: $0 -b lucisv -w workdir [-s styles] tree..." >&2; exit 2; }
flags="--no-cache --no-config --no-gitignore"
run() { "$here/guard.sh" -t 1200 -- "$lucisv" $flags "$@"; }
# The sources: every .v/.sv/.vh/.svh of every tree (the walk's
# EXTENSIONS), symlinks followed as the walk follows them, paths kept,
# nothing else.
rm -rf "$work" && mkdir -p "$work/src"
for tree in "$@"; do
dest="$work/src/$(basename "$tree")"
(cd "$tree" && find -L . -type f \( -name '*.v' -o -name '*.sv' -o -name '*.vh' -o -name '*.svh' \) -not -path '*/.git/*' |
while IFS= read -r f; do mkdir -p "$dest/$(dirname "$f")"; cp "$f" "$dest/$f"; done)
done
files=$(find "$work/src" -type f | wc -l | tr -d ' ')
status=0
printf 'style\tfiles\tparse-errors\tverification-errors\tcrashes\tnot-idempotent\n'
for s in $styles; do
cp -R "$work/src" "$work/$s"
run --style "$s" "$work/$s" >/dev/null 2>"$work/$s.log"
parse=$(grep -c ': parse error\|: lex error' "$work/$s.log")
verr=$(grep -c 'verification failed' "$work/$s.log")
crash=$(grep -ci 'panic\|guard.sh' "$work/$s.log")
run --check --style "$s" "$work/$s" >"$work/$s.check" 2>/dev/null
again=$(grep -c '^Would reformat' "$work/$s.check")
printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$s" "$files" "$parse" "$verr" "$crash" "$again"
[ "$verr" -eq 0 ] && [ "$crash" -eq 0 ] && [ "$again" -eq 0 ] || status=1
done
printf '\nA\tB\tfiles where A(B(A(x))) != A(x)\n'
for a in $styles; do
for b in $styles; do
[ "$a" = "$b" ] && continue
rm -rf "$work/pair" && cp -R "$work/$a" "$work/pair"
run --style "$b" "$work/pair" >/dev/null 2>&1
run --style "$a" "$work/pair" >/dev/null 2>&1
diff -rq "$work/$a" "$work/pair" >"$work/$a-$b.diff"
printf '%s\t%s\t%s\n' "$a" "$b" "$(wc -l <"$work/$a-$b.diff" | tr -d ' ')"
done
done
rm -rf "$work/pair"
exit $status