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)
(let ([bx (identifier-binding x phase-x)] (cond [(eqv? phase-x phase-y)
[by (identifier-binding y phase-y)]) (free-identifier=? x y phase-x)]
(cond [(and (list? bx) (list? by)) [else
(let ([modx (module-path-index-resolve (first bx))] (let ([bx (identifier-binding x phase-x)]
[namex (second bx)] [by (identifier-binding y phase-y)])
[phasex (fifth bx)] (cond [(and (pair? bx) (pair? by))
[mody (module-path-index-resolve (first by))] (let ([mpix (first bx)]
[namey (second by)] [namex (second bx)]
[phasey (fifth by)]) [defphasex (fifth bx)]
(and (eq? modx mody) ;; resolved-module-paths are interned [mpiy (first by)]
(eq? namex namey) [namey (second by)]
(equal? phasex phasey)))] [defphasey (fifth by)])
[else (and (eq? namex namey)
;; Module is only way to get phase-shift; if not module-bound names, ;; resolved-module-paths are interned
;; then only identifiers at same phase can refer to same binding. (eq? (module-path-index-resolve mpix)
(and (equal? phase-x phase-y) (module-path-index-resolve mpiy))
(free-identifier=? x y phase-x))]))) (eqv? defphasex defphasey)))]
[else
;; Module is only way to get phase-shift; phases differ, so
;; if not module-bound names, no way can refer to same binding.
#f]))]))
;; ---- ;; ----