Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize _ pattern in syntax-case clauses #728

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

Jarhmander
Copy link
Contributor

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.

Before:

> (expand/optimize '(syntax-case x () (_ 'ok)))
(let ([tmp x])
  (let ([tmp (#3%$syntax-dispatch tmp '_)])
    (if tmp 'ok (#3%syntax-error tmp))))

After:

(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.

Avoid emitting a call to $syntax-dispatch for _ patterns and emit ()
instead. This allow cp0 optimizations for such patterns.
@burgerrg burgerrg merged commit cc6159a into cisco:main Oct 16, 2023
20 checks passed
@burgerrg
Copy link
Contributor

Thank you for this useful optimization!

mflatt pushed a commit to mflatt/ChezScheme that referenced this pull request Oct 17, 2023
Avoid emitting a call to $syntax-dispatch for _ patterns and emit ()
instead. This allow cp0 optimizations for such patterns.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants