From f56e3e0f10a4b987d4fb2b3b7fedc1475cd1cf13 Mon Sep 17 00:00:00 2001 From: Jack Firth Date: Sat, 11 Jul 2026 03:12:09 -0700 Subject: [PATCH] Fail fast on head identifier in syntax-tree class Check the branch identifier before recursively parsing subtrees, so forms whose head isn't the branch identifier no longer descend the entire subtree only to be rejected afterward. Fixes #800 Co-Authored-By: Claude Opus 4.8 --- default-recommendations/private/syntax-tree.rkt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/default-recommendations/private/syntax-tree.rkt b/default-recommendations/private/syntax-tree.rkt index 335d155..b98bd2b 100644 --- a/default-recommendations/private/syntax-tree.rkt +++ b/default-recommendations/private/syntax-tree.rkt @@ -30,9 +30,11 @@ #:attributes ([leaf 1] rank) #:commit - (pattern (id:id subtree ...) + ;; The head identifier is checked before the subtrees are recursively parsed, so that forms whose + ;; head isn't the branch identifier fail fast instead of paying to descend the entire subtree only + ;; to be rejected afterward (see issue #800). + (pattern ((~and id:id (~fail #:unless (free-identifier=? #'id branch-identifier))) subtree ...) #:declare subtree (syntax-tree branch-identifier) - #:when (free-identifier=? #'id branch-identifier) #:cut #:with (leaf ...) #'(subtree.leaf ... ...) #:attr rank (add1 (option-get (transduce (attribute subtree.rank) #:into (into-max)) 0)))