|
236 | 236 | (optres-superlifts an-optres)
|
237 | 237 | (bind-lifts
|
238 | 238 | (optres-lifts an-optres)
|
239 |
| - #`(make-opt-contract |
| 239 | + #`(make-an-opt-contract |
240 | 240 | (λ (ctc)
|
241 | 241 | (λ (blame)
|
242 | 242 | #,(bind-superlifts
|
|
246 | 246 | (λ (this that) #f)
|
247 | 247 | (vector)
|
248 | 248 | (begin-lifted (box #f))
|
249 |
| - #,(optres-chaperone an-optres)))) |
| 249 | + #,(optres-chaperone an-optres) |
| 250 | + #,(let ([f (optres-flat an-optres)]) |
| 251 | + (if f |
| 252 | + #`(λ (val) #,f) |
| 253 | + #'#f))))) |
250 | 254 | #`(coerce-contract '#,error-name-sym #,exp))))
|
251 | 255 |
|
252 | 256 | ;; this macro optimizes 'e' as a contract,
|
|
324 | 328 | (optres-superlifts an-optres)
|
325 | 329 | (bind-lifts
|
326 | 330 | (optres-lifts an-optres)
|
327 |
| - #`(make-opt-contract |
| 331 | + #`(make-an-opt-contract |
328 | 332 | (λ (ctc)
|
329 | 333 | (λ (blame)
|
330 | 334 | (λ (val)
|
|
333 | 337 | (λ (this that) #f)
|
334 | 338 | (vector)
|
335 | 339 | (begin-lifted (box #f))
|
336 |
| - #,(optres-chaperone an-optres))))) |
| 340 | + #,(optres-chaperone an-optres) |
| 341 | + #,(let ([f (optres-flat an-optres)]) |
| 342 | + (if f |
| 343 | + #`(λ (val) #,f) |
| 344 | + #'#f)))))) |
337 | 345 | (values f1 f2)))]))
|
338 | 346 |
|
339 | 347 | ;; optimized contracts
|
|
346 | 354 | (define-values (orig-ctc-prop orig-ctc-pred? orig-ctc-get)
|
347 | 355 | (make-struct-type-property 'original-contract))
|
348 | 356 |
|
| 357 | +(define (make-an-opt-contract proj name stronger stronger-vars stamp |
| 358 | + chaperone? flat) |
| 359 | + (cond |
| 360 | + [flat |
| 361 | + (make-flat-opt-contract proj name stronger stronger-vars stamp flat)] |
| 362 | + [chaperone? |
| 363 | + (make-chaperone-opt-contract proj name stronger stronger-vars stamp)] |
| 364 | + [else |
| 365 | + (make-impersonator-opt-contract proj name stronger stronger-vars stamp)])) |
| 366 | + |
349 | 367 | ;; the stronger-vars don't seem to be used anymore for stronger; probably
|
350 | 368 | ;; they should be folded into the lifts and then there should be a separate
|
351 | 369 | ;; setup for consolidating stronger checks
|
352 |
| -(define-struct opt-contract (proj name stronger stronger-vars stamp chaperone?) |
353 |
| - #:property prop:opt-chaperone-contract (λ (ctc) (opt-contract-chaperone? ctc)) |
354 |
| - #:property prop:custom-write (λ (val port mode) (fprintf port "#<opt-contract: ~.s>" (opt-contract-name val))) |
| 370 | +(define-struct opt-contract (proj name stronger stronger-vars stamp)) |
| 371 | + |
| 372 | +(define (opt-contract-stronger-proc this that) |
| 373 | + (and (opt-contract? that) |
| 374 | + (eq? (opt-contract-stamp this) (opt-contract-stamp that)) |
| 375 | + ((opt-contract-stronger this) this that))) |
| 376 | + |
| 377 | +(define-struct (flat-opt-contract opt-contract) (predicate) |
| 378 | + #:property prop:custom-write |
| 379 | + (λ (val port mode) (fprintf port "#<opt-flat-contract: ~.s>" (opt-contract-name val))) |
| 380 | + #:property prop:flat-contract |
| 381 | + (build-flat-contract-property |
| 382 | + #:projection (λ (ctc) ((opt-contract-proj ctc) ctc)) |
| 383 | + #:first-order (λ (ctc) (flat-opt-contract-predicate ctc)) |
| 384 | + #:name (λ (ctc) (opt-contract-name ctc)) |
| 385 | + #:stronger opt-contract-stronger-proc)) |
| 386 | +(define-struct (chaperone-opt-contract opt-contract) () |
| 387 | + #:property prop:custom-write |
| 388 | + (λ (val port mode) (fprintf port "#<opt-chaperone-contract: ~.s>" (opt-contract-name val))) |
| 389 | + #:property prop:chaperone-contract |
| 390 | + (build-chaperone-contract-property |
| 391 | + #:projection (λ (ctc) ((opt-contract-proj ctc) ctc)) |
| 392 | + #:name (λ (ctc) (opt-contract-name ctc)) |
| 393 | + #:stronger opt-contract-stronger-proc)) |
| 394 | +(define-struct (impersonator-opt-contract opt-contract) () |
| 395 | + #:property prop:custom-write |
| 396 | + (λ (val port mode) (fprintf port "#<opt-contract: ~.s>" (opt-contract-name val))) |
355 | 397 | #:property prop:contract
|
356 | 398 | (build-contract-property
|
357 | 399 | #:projection (λ (ctc) ((opt-contract-proj ctc) ctc))
|
358 | 400 | #:name (λ (ctc) (opt-contract-name ctc))
|
359 |
| - #:stronger |
360 |
| - (λ (this that) |
361 |
| - (and (opt-contract? that) |
362 |
| - (eq? (opt-contract-stamp this) (opt-contract-stamp that)) |
363 |
| - ((opt-contract-stronger this) this that))))) |
| 401 | + #:stronger opt-contract-stronger-proc)) |
0 commit comments