jackfirth / resyntax

A Racket refactoring engine
Apache License 2.0
51 stars 10 forks source link

Overly conservative let to define conversion #230

Open sorawee opened 8 months ago

sorawee commented 8 months ago
#lang racket/base

(define (test b)
  (let ([x (cond
             [b (define x 1)
                (+ x 1)]
             [else 2])])
    (+ x 1)))

should successfully convert let to define. It doesn't because (define x 1) inside the a cond clause would have shadowed (define x (cond ...)), but that's actually fine.

jackfirth commented 7 months ago

This could be solved by building a data structure containing all the information of DrRacket's binding arrows and passing that to each rule as part of the analysis. The current logic dictates that if the identifier for a let is bound-identifier=? to anything in the right-hand side, it can't be refactored to define. But in this case it works because the binding for the usage in the RHS doesn't resolve to a definition that the define-replacement would shadow. Building that data structure would be a little tricky, but probably quite useful. Onto the todo list it goes.