|
222 | 222 | [check-formal*
|
223 | 223 | (let protect-loop ([args #'formals]
|
224 | 224 | [dom* dom*])
|
225 |
| - (if (or (identifier? args) |
226 |
| - (null? args) |
227 |
| - (and (syntax? args) (null? (syntax-e args)))) |
228 |
| - '() |
229 |
| - (let*-values ([(fst rst) |
230 |
| - (cond |
231 |
| - [(pair? args) |
232 |
| - (values (car args) (cdr args))] |
233 |
| - [(syntax? args) |
234 |
| - (let ((e (syntax-e args))) |
235 |
| - (values (car e) (cdr e)))] |
236 |
| - [else |
237 |
| - (raise-syntax-error 'shallow-rewrite-top "#%plain-lambda formals" #'formals args)])] |
238 |
| - [(check*) |
239 |
| - (let ((dom+ |
240 |
| - (for/fold ((acc '())) |
241 |
| - ((dom (in-list dom*))) |
242 |
| - (if (pair? dom) (cons (cdr dom) acc) acc)))) |
243 |
| - (protect-loop rst dom+))] |
244 |
| - [(fst-ty) |
245 |
| - (let ((ann-ty (and (type-annotation fst #:infer #f) (get-type fst #:infer #t #:default Univ)))) |
246 |
| - (if (and ann-ty (not (Error? ann-ty))) |
247 |
| - ann-ty |
248 |
| - (apply Un (for/list ((dom (in-list dom*)) #:when (pair? dom)) (car dom)))))] |
249 |
| - [(ex* fst+) |
250 |
| - (if skip-dom? |
251 |
| - (values '() #f) |
252 |
| - (protect-domain fst-ty fst (build-source-location-list fst) ctc-cache))]) |
253 |
| - (void (register-extra-defs! ex*)) |
254 |
| - (if fst+ (cons fst+ check*) check*))))]) |
| 225 | + (cond |
| 226 | + [(or (identifier? args) |
| 227 | + (null? args) |
| 228 | + (and (syntax? args) (null? (syntax-e args)))) |
| 229 | + '()] |
| 230 | + [else |
| 231 | + (define-values (fst rst) |
| 232 | + (cond |
| 233 | + [(pair? args) (values (car args) (cdr args))] |
| 234 | + [(syntax? args) |
| 235 | + (let ([e (syntax-e args)]) (values (car e) (cdr e)))] |
| 236 | + [else |
| 237 | + (raise-syntax-error 'shallow-rewrite-top |
| 238 | + "#%plain-lambda formals" |
| 239 | + #'formals |
| 240 | + args)])) |
| 241 | + (define check* |
| 242 | + (let ([dom+ (for/fold ([acc '()]) ([dom (in-list dom*)]) |
| 243 | + (if (pair? dom) |
| 244 | + (cons (cdr dom) acc) |
| 245 | + acc))]) |
| 246 | + (protect-loop rst dom+))) |
| 247 | + (define fst-ty |
| 248 | + (let ([ann-ty (and (type-annotation fst #:infer #f) |
| 249 | + (get-type fst #:infer #t #:default Univ))]) |
| 250 | + (if (and ann-ty (not (Error? ann-ty))) |
| 251 | + ann-ty |
| 252 | + (apply Un |
| 253 | + (for/list ([dom (in-list dom*)] |
| 254 | + #:when (pair? dom)) |
| 255 | + (car dom)))))) |
| 256 | + (define-values (ex* fst+) |
| 257 | + (if skip-dom? |
| 258 | + (values '() #f) |
| 259 | + (protect-domain fst-ty |
| 260 | + fst |
| 261 | + (build-source-location-list fst) |
| 262 | + ctc-cache))) |
| 263 | + (void (register-extra-defs! ex*)) |
| 264 | + (if fst+ |
| 265 | + (cons fst+ check*) |
| 266 | + check*)]))]) |
255 | 267 | (if (null? check-formal*)
|
256 | 268 | body+
|
257 | 269 | (cons
|
|
272 | 284 | ;; no type
|
273 | 285 | (quasisyntax/loc formals [#,formals . #,body])]
|
274 | 286 | [else
|
| 287 | + (define len (formals-length formals)) |
275 | 288 | (define matching-dom*
|
276 |
| - (let ([len (formals-length formals)]) |
277 |
| - (for/list ((dom (in-list all-dom*)) |
278 |
| - #:when (= len (length dom))) |
279 |
| - dom))) |
| 289 | + (for/list ([dom (in-list all-dom*)] |
| 290 | + #:when (= len (length dom))) |
| 291 | + dom)) |
280 | 292 | (quasisyntax/loc stx
|
281 | 293 | [#,formals .
|
282 | 294 | #,(let* ([body+
|
283 | 295 | (copy-props (loop body #f trusted-fn*) body)]
|
284 | 296 | [check-formal*
|
285 | 297 | (let protect-loop ([args formals]
|
286 | 298 | [dom* matching-dom*])
|
287 |
| - (if (or (identifier? args) |
288 |
| - (null? args) |
289 |
| - (and (syntax? args) (null? (syntax-e args)))) |
290 |
| - '() |
291 |
| - (let*-values ([(fst rst) |
292 |
| - (cond |
293 |
| - [(pair? args) |
294 |
| - (values (car args) (cdr args))] |
295 |
| - [(syntax? args) |
296 |
| - (let ((e (syntax-e args))) |
297 |
| - (values (car e) (cdr e)))] |
298 |
| - [else |
299 |
| - (raise-syntax-error 'shallow-rewrite-top "#%plain-lambda formals" formals args)])] |
300 |
| - [(check*) |
301 |
| - (let ((dom+ |
302 |
| - (for/fold ((acc '())) |
303 |
| - ((dom (in-list dom*))) |
304 |
| - (if (pair? dom) (cons (cdr dom) acc) acc)))) |
305 |
| - (protect-loop rst dom+))] |
306 |
| - [(fst-ty) |
307 |
| - (if (type-annotation fst #:infer #f) |
308 |
| - (get-type fst #:infer #t #:default Univ) |
309 |
| - (apply Un |
310 |
| - (for/fold ((acc '())) |
311 |
| - ((dom (in-list dom*))) |
312 |
| - (if (pair? dom) (cons (car dom) acc) acc))))] |
313 |
| - [(ex* fst+) |
314 |
| - (if skip-dom? |
315 |
| - (values '() #f) |
316 |
| - (protect-domain fst-ty fst (build-source-location-list fst) ctc-cache))]) |
317 |
| - (void (register-extra-defs! ex*)) |
318 |
| - (if fst+ (cons fst+ check*) check*))))]) |
| 299 | + (cond |
| 300 | + [(or (identifier? args) |
| 301 | + (null? args) |
| 302 | + (and (syntax? args) (null? (syntax-e args)))) |
| 303 | + '()] |
| 304 | + [else |
| 305 | + (define-values (fst rst) |
| 306 | + (cond |
| 307 | + [(pair? args) (values (car args) (cdr args))] |
| 308 | + [(syntax? args) |
| 309 | + (let ([e (syntax-e args)]) |
| 310 | + (values (car e) (cdr e)))] |
| 311 | + [else |
| 312 | + (raise-syntax-error 'shallow-rewrite-top |
| 313 | + "#%plain-lambda formals" |
| 314 | + formals |
| 315 | + args)])) |
| 316 | + (define check* |
| 317 | + (let ([dom+ (for/fold ([acc '()]) |
| 318 | + ([dom (in-list dom*)]) |
| 319 | + (if (pair? dom) |
| 320 | + (cons (cdr dom) acc) |
| 321 | + acc))]) |
| 322 | + (protect-loop rst dom+))) |
| 323 | + (define fst-ty |
| 324 | + (if (type-annotation fst #:infer #f) |
| 325 | + (get-type fst #:infer #t #:default Univ) |
| 326 | + (apply Un |
| 327 | + (for/fold ([acc '()]) |
| 328 | + ([dom (in-list dom*)]) |
| 329 | + (if (pair? dom) |
| 330 | + (cons (car dom) acc) |
| 331 | + acc))))) |
| 332 | + (define-values (ex* fst+) |
| 333 | + (if skip-dom? |
| 334 | + (values '() #f) |
| 335 | + (protect-domain fst-ty |
| 336 | + fst |
| 337 | + (build-source-location-list fst) |
| 338 | + ctc-cache))) |
| 339 | + (void (register-extra-defs! ex*)) |
| 340 | + (if fst+ |
| 341 | + (cons fst+ check*) |
| 342 | + check*)]))]) |
319 | 343 | (if (null? check-formal*)
|
320 | 344 | body+
|
321 | 345 | (cons
|
|
415 | 439 | stx)
|
416 | 440 |
|
417 | 441 | (define (maybe-add-typeof-expr new-stx old-stx)
|
418 |
| - (let ((old-type (maybe-type-of old-stx))) |
419 |
| - (when old-type |
420 |
| - (add-typeof-expr new-stx old-type)))) |
| 442 | + (define old-type (maybe-type-of old-stx)) |
| 443 | + (when old-type |
| 444 | + (add-typeof-expr new-stx old-type))) |
421 | 445 |
|
422 | 446 | (define (maybe-add-test-position new-stx old-stx)
|
423 | 447 | (maybe-add-test-true new-stx old-stx)
|
424 | 448 | (maybe-add-test-false new-stx old-stx)
|
425 | 449 | (void))
|
426 | 450 |
|
427 | 451 | (define (maybe-add-scoped-tvar new-stx old-stx)
|
428 |
| - (let ([old-layer (lookup-scoped-tvar-layer old-stx)]) |
429 |
| - (when old-layer |
430 |
| - (add-scoped-tvars new-stx old-layer)))) |
| 452 | + (define old-layer (lookup-scoped-tvar-layer old-stx)) |
| 453 | + (when old-layer |
| 454 | + (add-scoped-tvars new-stx old-layer))) |
431 | 455 |
|
432 | 456 | (define (maybe-add-test-true new-stx old-stx)
|
433 | 457 | (when (test-position-takes-true-branch old-stx)
|
|
449 | 473 |
|
450 | 474 | (define (formals-fold init f stx)
|
451 | 475 | (let loop ((v stx))
|
452 |
| - (if (or (identifier? v) |
453 |
| - (null? v) |
454 |
| - (and (syntax? v) (null? (syntax-e v)))) |
455 |
| - init |
456 |
| - (let*-values (((fst rst) |
457 |
| - (cond |
458 |
| - [(pair? v) |
459 |
| - (values (car v) (cdr v))] |
460 |
| - [(syntax? v) |
461 |
| - (let ((e (syntax-e v))) |
462 |
| - (values (car e) (cdr e)))] |
463 |
| - [else |
464 |
| - (raise-syntax-error 'formals-fold "lambda formals" stx)]))) |
465 |
| - (f (loop rst) fst))))) |
| 476 | + (cond |
| 477 | + [(or (identifier? v) (null? v) (and (syntax? v) (null? (syntax-e v)))) init] |
| 478 | + [else |
| 479 | + (define-values (fst rst) |
| 480 | + (cond |
| 481 | + [(pair? v) (values (car v) (cdr v))] |
| 482 | + [(syntax? v) (let ([e (syntax-e v)]) (values (car e) (cdr e)))] |
| 483 | + [else (raise-syntax-error 'formals-fold "lambda formals" stx)])) |
| 484 | + (f (loop rst) fst)]))) |
466 | 485 |
|
467 | 486 | ;; is-application? : Syntax -> Boolean
|
468 | 487 | ;; Returns #true if `stx` is a function application (an app that may need dynamic checking)
|
|
629 | 648 | (λ (mpi)
|
630 | 649 | (hash-ref! cache mpi
|
631 | 650 | (λ () ;; Typed Racket always installs a `#%type-decl` submodule
|
632 |
| - (let* ([mpi+ (module-path-index-join '(submod "." #%type-decl) mpi)]) |
633 |
| - (parameterize ([current-namespace (make-base-namespace)]) |
634 |
| - (with-handlers ([exn:fail:contract? (lambda (exn) #f)]) |
635 |
| - (and mpi+ |
636 |
| - (dynamic-require mpi+ #f) |
637 |
| - #t))))))))) |
| 651 | + (define mpi+ (module-path-index-join '(submod "." #%type-decl) mpi)) |
| 652 | + (parameterize ([current-namespace (make-base-namespace)]) |
| 653 | + (with-handlers ([exn:fail:contract? (lambda (exn) #f)]) |
| 654 | + (and mpi+ (dynamic-require mpi+ #f) #t)))))))) |
638 | 655 |
|
639 | 656 | (define (protect-domain dom-type dom-stx ctx ctc-cache)
|
640 | 657 | (define-values [extra-def* ctc-stx]
|
|
0 commit comments