Plain _ patterns in syntax-case occurs fairly frequently in code (more than 80 occurrences in Chez Scheme itself), and these patterns never fail. There are used like else clauses for syntax-case.
An easy optimization is to avoid calling $syntax-dispatch for such patterns and directly embed the () return value that would result for such a call. A similar optimization already existed for patterns that consists of a single identifier.
With that optimization, cp0 can easily optimize out the last call to syntax-error that is never reached.
(expand/optimize '(syntax-case x () (_ 'ok)))
(begin x 'ok)
Note: there is something fishy with the GitHub workflows, and one random job would fail. It happened on the main in my fork, as well as with my branch.
Plain
_
patterns insyntax-case
occurs fairly frequently in code (more than 80 occurrences in Chez Scheme itself), and these patterns never fail. There are used likeelse
clauses forsyntax-case
.An easy optimization is to avoid calling
$syntax-dispatch
for such patterns and directly embed the()
return value that would result for such a call. A similar optimization already existed for patterns that consists of a single identifier.With that optimization,
cp0
can easily optimize out the last call tosyntax-error
that is never reached.Before:
After:
Note: there is something fishy with the GitHub workflows, and one random job would fail. It happened on the main in my fork, as well as with my branch.