|
8 | 8 | "type-alias-env.rkt" |
9 | 9 | "type-name-env.rkt" |
10 | 10 | "../rep/type-rep.rkt" |
| 11 | + "../rep/free-variance.rkt" |
11 | 12 | "../rep/type-constr.rkt" |
12 | 13 | "tvar-env.rkt" |
13 | 14 | "type-constr-env.rkt" |
14 | 15 | "../private/parse-type.rkt" |
| 16 | + "../private/user-defined-type-constr.rkt" |
15 | 17 | "../typecheck/internal-forms.rkt" |
16 | 18 | "../types/resolve.rkt" |
17 | 19 | "../types/base-abbrev.rkt" |
|
70 | 72 | ;; start registering type alias names |
71 | 73 | (start-type-alias-registration! id (make-Name id (length args) #f)) |
72 | 74 | (values id (list id type-stx args)))) |
73 | | - (register-all-type-alias-info type-alias-names type-alias-map) |
74 | | - (unless (zero? (free-id-table-count (incomplete-name-alias-map))) |
75 | | - (define names (free-id-table-keys (incomplete-name-alias-map))) |
76 | | - (int-err "not all type alias names are fully registered: ~n ~a" |
77 | | - names)))) |
| 75 | + |
| 76 | + (begin0 |
| 77 | + (register-all-type-alias-info type-alias-names type-alias-map) |
| 78 | + (unless (zero? (free-id-table-count (incomplete-name-alias-map))) |
| 79 | + (define names (free-id-table-keys (incomplete-name-alias-map))) |
| 80 | + (int-err "not all type alias names are fully registered: ~n ~a" |
| 81 | + names))))) |
78 | 82 |
|
79 | 83 | ;; Identifier -> Type |
80 | 84 | ;; Construct a fresh placeholder type |
|
198 | 202 | ;; Note that the connected component algorithm returns results |
199 | 203 | ;; in topologically sorted order, so we want to go through in the |
200 | 204 | ;; reverse order of that to avoid unbound type aliases. |
201 | | - (for ([id (in-list acyclic-singletons)]) |
202 | | - (match-define (list _ type-stx args) (free-id-table-ref type-alias-map id)) |
203 | | - (cond |
204 | | - [(not (null? args)) |
205 | | - (define ty-op (parse-type-operator-abstraction id args type-stx #f |
206 | | - type-alias-productivity-map)) |
207 | | - (register-type-constructor! id ty-op)] |
208 | | - [else |
209 | | - ;; id can be a simple abbreviation for another type constructor |
210 | | - (define rv (parse-type-or-type-constructor type-stx)) |
211 | | - ((if (TypeConstructor? rv) |
212 | | - register-type-constructor! |
213 | | - register-resolved-type-alias) id rv)]) |
214 | | - (complete-type-alias-registration! id)) |
| 205 | + (define acyclic-constr-names |
| 206 | + (for/fold ([acc '()]) |
| 207 | + ([id (in-list acyclic-singletons)]) |
| 208 | + (match-define (list _ type-stx args) (free-id-table-ref type-alias-map id)) |
| 209 | + (define acc^ |
| 210 | + (cond |
| 211 | + [(not (null? args)) |
| 212 | + (define ty-op (parse-type-operator-abstraction id args type-stx #f |
| 213 | + type-alias-productivity-map)) |
| 214 | + |
| 215 | + (register-type-constructor! id ty-op) |
| 216 | + (cons id acc)] |
| 217 | + [else |
| 218 | + ;; id can be a simple abbreviation for another type constructor |
| 219 | + (define rv (parse-type-or-type-constructor type-stx)) |
| 220 | + (match rv |
| 221 | + [(? TypeConstructor?) |
| 222 | + (register-type-constructor! id rv) |
| 223 | + (if (user-defined-type-constr? rv) |
| 224 | + (cons id acc) |
| 225 | + acc)] |
| 226 | + [else (register-resolved-type-alias id rv) |
| 227 | + acc])])) |
| 228 | + (complete-type-alias-registration! id) |
| 229 | + acc^)) |
215 | 230 |
|
216 | 231 | ;; Clear the resolver cache of Name types from this block |
217 | 232 |
|
|
250 | 265 | (for/lists (_1 _2 _3) |
251 | 266 | ([record (in-list type-records)]) |
252 | 267 | (match-define (list id type-stx args) record) |
253 | | - ;; TODO try parse-type |
254 | 268 | (define type (parse-type type-stx type-alias-productivity-map)) |
255 | 269 | (reset-resolver-cache!) |
256 | 270 | (register-type-name id type) |
257 | 271 | (complete-type-alias-registration! id) |
258 | | - (add-constant-variance! id args) |
259 | 272 | (values id type (map syntax-e args)))) |
260 | 273 |
|
261 | | - ;; do a pass to refine the variance |
262 | | - (refine-variance! names-to-refine types-to-refine tvarss) |
263 | | - |
264 | 274 | (define-values (productive unproductive) |
265 | 275 | (partition (match-lambda |
266 | 276 | [(cons a _) |
267 | 277 | (equal? (free-id-table-ref type-alias-productivity-map a #f) #t)]) |
268 | 278 | type-op-records)) |
269 | 279 |
|
270 | | - (let (;; sort unproductive constructors by the number of dependent |
271 | | - ;; user-defined constructors in increasing order |
272 | | - [unproductive (sort unproductive < |
| 280 | + ;; sort unproductive constructors by the number of dependent |
| 281 | + ;; user-defined constructors in increasing order |
| 282 | + (let ([unproductive (sort unproductive < |
273 | 283 | #:key |
274 | 284 | (match-lambda |
275 | 285 | [(cons a _) |
276 | 286 | (length (free-id-table-ref type-alias-dependency-map a #f))]))]) |
277 | | - (for/list ([record (in-list (append productive unproductive))]) |
278 | | - (match-define (list id type-stx args) record) |
279 | | - (define ty-op (parse-type-operator-abstraction id args type-stx |
280 | | - (lambda (x) |
281 | | - (define res (in-same-component? id x)) |
282 | | - res) |
283 | | - type-alias-productivity-map)) |
284 | | - (register-type-constructor! id ty-op) |
285 | | - (complete-type-alias-registration! id) |
286 | | - (reset-resolver-cache!) |
287 | | - (add-constant-variance! id args)))) |
| 287 | + (define constr-names |
| 288 | + (for/list ([record (in-list (append productive unproductive))]) |
| 289 | + (match-define (list id type-stx args) record) |
| 290 | + (define ty-op (parse-type-operator-abstraction id args type-stx |
| 291 | + (lambda (x) |
| 292 | + (define res (in-same-component? id x)) |
| 293 | + res) |
| 294 | + type-alias-productivity-map |
| 295 | + #:delay-variances? #t)) |
| 296 | + (register-type-constructor! id ty-op) |
| 297 | + (complete-type-alias-registration! id) |
| 298 | + (reset-resolver-cache!) |
| 299 | + id)) |
| 300 | + (refine-user-defined-constructor-variances! constr-names) |
| 301 | + (append acyclic-constr-names constr-names))) |
288 | 302 |
|
289 | 303 | ;; Syntax -> Syntax Syntax (Listof Syntax) |
290 | 304 | ;; Parse a type alias internal declaration |
|
0 commit comments