Skip tokenizer/CST parsing when no CST rules are active

Check filter-rules-by-config before invoking the tokenizer in
lint-file. When all CST rules are disabled (e.g. --disable
comment-semicolons), the expensive tokenize+parse-cst pass is
skipped entirely.

On the Guix tree (1336 files), this saves ~2s on surface-only
runs (15.6s → 13.7s). The savings are more pronounced on
projects with fewer monster files.
This commit is contained in:
2026-04-04 13:44:31 +02:00
parent f979d48e54
commit 1734ebe381

View File

@@ -93,17 +93,20 @@ and '%min-severity with value 'error, 'warning, or 'info (default)."
(when (memq pass '(all surface))
(set! diagnostics (append (run-line-rules file lines config)
diagnostics))
;; Pass 1b: CST rules (if tokenizer is loaded)
(let ((tok-mod (resolve-module '(gulie tokenizer) #:ensure #f)))
(when tok-mod
(let ((tokenize (module-ref tok-mod 'tokenize))
(cst-mod (resolve-module '(gulie cst) #:ensure #f)))
(when cst-mod
(let* ((parse-cst (module-ref cst-mod 'parse-cst))
(tokens (tokenize text file))
(cst (parse-cst tokens)))
(set! diagnostics (append (run-cst-rules file cst config)
diagnostics))))))))
;; Pass 1b: CST rules — only tokenize if there are active CST rules
(let ((cst-rules (filter-rules-by-config (rules-of-type 'cst) config)))
(when (not (null? cst-rules))
(let ((tok-mod (resolve-module '(gulie tokenizer) #:ensure #f)))
(when tok-mod
(let ((tokenize (module-ref tok-mod 'tokenize))
(cst-mod (resolve-module '(gulie cst) #:ensure #f)))
(when cst-mod
(let* ((parse-cst (module-ref cst-mod 'parse-cst))
(tokens (tokenize text file))
(cst (parse-cst tokens)))
(set! diagnostics
(append (run-cst-rules file cst config)
diagnostics))))))))))
;; Pass 2: semantic rules (if compiler module is loaded)
(when (memq pass '(all semantic))
(let ((comp-mod (resolve-module '(gulie compiler) #:ensure #f)))