From 04c3851ebc1e7c78d314f833de1c76ab458202ed Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Tue, 11 Mar 2014 23:47:56 -0400 Subject: [PATCH] Clarify a few comments in TR These are for letrec typechecking and Tarjan's algorithm --- .../typed-racket/typecheck/tc-let-unit.rkt | 8 +++++--- .../typed-racket-lib/typed-racket/utils/tarjan.rkt | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-let-unit.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-let-unit.rkt index dcbcbcbdec..877f70c3d9 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-let-unit.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/typecheck/tc-let-unit.rkt @@ -189,8 +189,9 @@ (struct lr-clause (names expr clause) #:transparent) ;; get-non-recursive-clauses : (Listof lr-clause) (Listof Identifier) -> -;; (Listof lr-clause) (Listof ) -;; Find letrec-values clauses that do not create variable cycles +;; (Listof lr-clause) (Listof lr-clause) +;; Find letrec-values clauses that do not create variable cycles. Return +;; both the non-recursive clauses and the remaining recursive ones. (define (get-non-recursive-clauses clauses flat-names) ;; Set up vertices for Tarjan's algorithm, where each letrec-values @@ -215,7 +216,8 @@ (andmap (λ (id2) (not (bound-identifier=? id id2))) (vertex-adjacent vertex)))) - ;; The components with only one entry are non-recursive + ;; The components with only one entry are non-recursive if they also + ;; contain no self-cycles. (for/fold ([non-recursive '()] [remaining '()]) ([component components]) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/utils/tarjan.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/utils/tarjan.rkt index bfd53dc1b0..b032e27761 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/utils/tarjan.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/utils/tarjan.rkt @@ -35,6 +35,10 @@ ;; tarjan : (Dict K (Vertex K V)) -> (Listof (Listof (Vertex K V))) ;; Implements Tarjan's algorithm. See Wikipedia ;; http://en.wikipedia.org/wiki/Tarjan's_strongly_connected_components_algorithm +;; +;; Note that because this accumulates the result with `cons`, the components +;; are actually output in topological order rather than *reverse* topological order. +;; If you want reverse topological order, reverse the result. (define (tarjan vertices) (define (strongly-connected vtx) (set-vertex-index! vtx index)