syntax/parse: speed up free-identifier=?/phases when phases are same

This commit is contained in:
Ryan Culpepper 2011-09-06 02:07:01 -06:00
parent 15e3640191
commit 68e76a9876

View File

@ -273,23 +273,27 @@
;; that y has at phase-level y. ;; that y has at phase-level y.
;; At least one of the identifiers MUST have a binding (module or lexical) ;; At least one of the identifiers MUST have a binding (module or lexical)
(define (free-identifier=?/phases x phase-x y phase-y) (define (free-identifier=?/phases x phase-x y phase-y)
(cond [(eqv? phase-x phase-y)
(free-identifier=? x y phase-x)]
[else
(let ([bx (identifier-binding x phase-x)] (let ([bx (identifier-binding x phase-x)]
[by (identifier-binding y phase-y)]) [by (identifier-binding y phase-y)])
(cond [(and (list? bx) (list? by)) (cond [(and (pair? bx) (pair? by))
(let ([modx (module-path-index-resolve (first bx))] (let ([mpix (first bx)]
[namex (second bx)] [namex (second bx)]
[phasex (fifth bx)] [defphasex (fifth bx)]
[mody (module-path-index-resolve (first by))] [mpiy (first by)]
[namey (second by)] [namey (second by)]
[phasey (fifth by)]) [defphasey (fifth by)])
(and (eq? modx mody) ;; resolved-module-paths are interned (and (eq? namex namey)
(eq? namex namey) ;; resolved-module-paths are interned
(equal? phasex phasey)))] (eq? (module-path-index-resolve mpix)
(module-path-index-resolve mpiy))
(eqv? defphasex defphasey)))]
[else [else
;; Module is only way to get phase-shift; if not module-bound names, ;; Module is only way to get phase-shift; phases differ, so
;; then only identifiers at same phase can refer to same binding. ;; if not module-bound names, no way can refer to same binding.
(and (equal? phase-x phase-y) #f]))]))
(free-identifier=? x y phase-x))])))
;; ---- ;; ----