|
57 | 57 | (map vertex-data component))) |
58 | 58 |
|
59 | 59 |
|
60 | | -;; register-all-type-aliases : Listof<Syntax> -> Void |
| 60 | +;; register-all-type-aliases : Listof<Syntax> IDTable<ID, Listof<ID>> -> Void |
61 | 61 | ;; |
62 | 62 | ;; register all type alias definitions carried by the input syntaxes |
63 | | -(define (register-all-type-aliases type-aliases) |
| 63 | +;; dependency-map accounts for the dependencies of struct declarations |
| 64 | +(define (register-all-type-aliases type-aliases [dependency-map (make-immutable-free-id-table)]) |
64 | 65 | (parameterize ([incomplete-name-alias-map (make-free-id-table)]) |
65 | 66 | (define-values (type-alias-names type-alias-map) |
66 | 67 | (for/lists (_1 _2 #:result (values _1 (make-free-id-table |
|
74 | 75 | (values id (list id type-stx args)))) |
75 | 76 |
|
76 | 77 | (begin0 |
77 | | - (register-all-type-alias-info type-alias-names type-alias-map) |
| 78 | + (register-all-type-alias-info type-alias-names type-alias-map dependency-map) |
78 | 79 | (unless (zero? (free-id-table-count (incomplete-name-alias-map))) |
79 | 80 | (define names (free-id-table-keys (incomplete-name-alias-map))) |
80 | 81 | (int-err "not all type alias names are fully registered: ~n ~a" |
|
91 | 92 | ;; of actually registering the type aliases. If struct names or |
92 | 93 | ;; other definitions need to be registered, do that before calling |
93 | 94 | ;; this function. |
94 | | -(define (register-all-type-alias-info type-alias-names type-alias-map) |
| 95 | +(define (register-all-type-alias-info type-alias-names type-alias-map dependency-map) |
95 | 96 | ;; Find type alias dependencies |
96 | 97 | ;; The two maps defined here contains the dependency structure |
97 | 98 | ;; of type aliases in two senses: |
|
102 | 103 | ;; The second is necessary in order to prevent recursive |
103 | 104 | ;; #:implements clauses and to determine the order in which |
104 | 105 | ;; recursive type aliases should be initialized. |
| 106 | + |
| 107 | + (define (free-id-table-union! a b) |
| 108 | + (define struct-names (list->set (free-id-table-keys b))) |
| 109 | + (for ([(id deps) (in-free-id-table b)]) |
| 110 | + (free-id-table-set! a id (filter (lambda (v) |
| 111 | + (or (free-id-table-ref type-alias-map v #f) |
| 112 | + (set-member? struct-names v))) |
| 113 | + deps)))) |
| 114 | + |
105 | 115 | (define-values (type-alias-dependency-map type-alias-class-map type-alias-productivity-map) |
106 | | - (for/lists (_1 _2 _3 #:result (values (make-free-id-table _1) |
| 116 | + (for/lists (_1 _2 _3 #:result (values (let ([tbl1 (make-free-id-table _1)]) |
| 117 | + (free-id-table-union! tbl1 dependency-map) |
| 118 | + tbl1) |
107 | 119 | (make-free-id-table _2) |
108 | 120 | (make-free-id-table _3))) |
109 | 121 | ([(name alias-info) (in-free-id-table type-alias-map)]) |
|
167 | 179 | recursive-aliases |
168 | 180 | free-identifier=?)) |
169 | 181 | (car component))) |
| 182 | + |
170 | 183 | (define other-recursive-aliases |
171 | 184 | (for/list ([alias (in-list recursive-aliases)] |
172 | 185 | #:unless (member alias |
|
204 | 217 | ;; reverse order of that to avoid unbound type aliases. |
205 | 218 | (define acyclic-constr-names |
206 | 219 | (for/fold ([acc '()]) |
207 | | - ([id (in-list acyclic-singletons)]) |
208 | | - (match-define (list _ type-stx args) (free-id-table-ref type-alias-map id)) |
| 220 | + ([id (in-list acyclic-singletons)] |
| 221 | + #:when (free-id-table-ref type-alias-map id #f)) |
| 222 | + (match-define (list _ type-stx args) (free-id-table-ref type-alias-map id #f)) |
209 | 223 | (define acc^ |
210 | 224 | (cond |
211 | 225 | [(not (null? args)) |
|
251 | 265 | #:result |
252 | 266 | (values (reverse type-records) |
253 | 267 | (reverse type-op-records))) |
254 | | - ([id (in-list (append other-recursive-aliases class-aliases))]) |
| 268 | + ([id (in-list (append other-recursive-aliases class-aliases))] |
| 269 | + #:when (free-id-table-ref type-alias-map id #f)) |
255 | 270 | (define record (free-id-table-ref type-alias-map id)) |
256 | 271 | (match-define (list _ type-stx args) record) |
257 | 272 | (if (null? args) |
|
292 | 307 | (define res (in-same-component? id x)) |
293 | 308 | res) |
294 | 309 | type-alias-productivity-map |
295 | | - #:delay-variances? #t)) |
| 310 | + #:delay-variances? #t |
| 311 | + #:recursive? #t)) |
296 | 312 | (register-type-constructor! id ty-op) |
297 | 313 | (complete-type-alias-registration! id) |
298 | 314 | (reset-resolver-cache!) |
|
0 commit comments