jackfirth / jackfirth/resyntax

Expose local phase levels to rules

Open
#379 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Racket
Stars
70
Forks
11
PR merge metrics
No merged PRs in 30d

Description

This rule:

(define-refactoring-rule redundant-or
  #:description "This `or` expression does nothing and can be replaced with its subexpression."
  #:literals (or)
  (or a1:id a2:id)
  #:when (free-identifier=? #'a1 #'a2)
  a1)

Fails to refactor this code:

(begin-for-syntax
  (define x 42)
  (or x x))

The reason for that is that free-identifier=? checks if two identifiers have the same binding at a specific phase level, and by default it uses (syntax-local-phase-level). This is reasonable for macros, which set (syntax-local-phase-level) to the level of the macro invocation. But refactoring rules aren't run during macro expansion, so (syntax-local-phase-level) always returns zero. This lets free-identifier=? in rules work fine on phase 0 code, but it fails on phase 1 code such as code inside begin-for-syntax.

Resyntax ought to expose the local phase level to rules. I'm not sure how to get that information out of the expander using the current expansion observer hook, but it's probably possible. One way to expose it to rules might be to add a (resyntax-local-phase-level) parameter and let rules use that to access the phase level. On the Resyntax source analysis side, there could be an expansion-visit struct / record type containing the syntax object that the expander visited and the phase level the visit occurred at.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by investigating Resyntax's current expansion observer hook and source-analysis flow, focusing on how visits are represented and how rules obtain phase information. The issue suggests exposing a local phase level to rules; done should include the begin-for-syntax example refactoring successfully while preserving phase-0 behavior.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.