|
90 | 90 | (define (generate-contract-def stx cache sc-cache)
|
91 | 91 | (define prop (get-contract-def-property stx))
|
92 | 92 | (match-define (contract-def type-stx flat? exact? maker? typed-side) prop)
|
| 93 | + (define orig-stx-ctx (and type-stx (syntax-property type-stx 'orig-stx-ctx))) |
93 | 94 | (define *typ (if type-stx (parse-type type-stx) t:-Dead-Code))
|
94 | 95 | (define kind (if (and type-stx flat?) 'flat 'impersonator))
|
95 | 96 | (syntax-parse stx #:literals (define-values)
|
|
104 | 105 | ((map fld-t (Struct-flds ty)) #f . t:->* . *typ)])]
|
105 | 106 | [else *typ]))
|
106 | 107 | (match-define (list defs ctc)
|
107 |
| - (type->contract |
108 |
| - typ |
109 |
| - ;; this value is from the typed side (require/typed, make-predicate, etc) |
110 |
| - ;; unless it's used for with-type |
111 |
| - #:typed-side (from-typed? typed-side) |
112 |
| - #:kind kind |
113 |
| - #:exact? exact? |
114 |
| - #:cache cache |
115 |
| - #:sc-cache sc-cache |
116 |
| - (type->contract-fail |
117 |
| - typ type-stx |
118 |
| - #:ctc-str (if flat? "predicate" "contract")))) |
| 108 | + (parameterize ([current-syntax-context orig-stx-ctx]) |
| 109 | + (type->contract |
| 110 | + typ |
| 111 | + ;; this value is from the typed side (require/typed, make-predicate, etc) |
| 112 | + ;; unless it's used for with-type |
| 113 | + #:typed-side (from-typed? typed-side) |
| 114 | + #:kind kind |
| 115 | + #:exact? exact? |
| 116 | + #:cache cache |
| 117 | + #:sc-cache sc-cache |
| 118 | + (type->contract-fail |
| 119 | + typ type-stx |
| 120 | + #:ctc-str (if flat? "predicate" "contract"))))) |
119 | 121 | (ignore ; should be ignored by the optimizer
|
120 | 122 | (quasisyntax/loc stx
|
121 | 123 | (begin #,@defs (define-values (n) #,ctc))))]
|
|
546 | 548 | (promise/sc (t->sc t))]
|
547 | 549 | [(Opaque: p?)
|
548 | 550 | (when exact?
|
549 |
| - (eprintf |
550 |
| - "warning: Opaque predicates cannot be used as exact decisions yes/no:\n predicate: ~s\n" |
551 |
| - (syntax-e p?))) |
| 551 | + (define stx (current-syntax-context)) |
| 552 | + (display-syntax-warning |
| 553 | + #f |
| 554 | + (format |
| 555 | + (string-append |
| 556 | + "warning: cannot safely generate exact predicate for Opaque type\n" |
| 557 | + (case (and (syntax? stx) (pair? (syntax-e stx)) (syntax-e (car (syntax-e stx)))) |
| 558 | + [(define-predicate) " (consider using define-positive-predicate instead)\n"] |
| 559 | + [(make-predicate) " (consider using make-positive-predicate instead)\n"] |
| 560 | + [else " (consider generating a positive-predicate instead)\n"]) |
| 561 | + " type: ~a\n" |
| 562 | + " pred: ~s\n") |
| 563 | + type |
| 564 | + (syntax-e p?)) |
| 565 | + stx)) |
552 | 566 | (flat/sc #`(flat-named-contract (quote #,(syntax-e p?)) #,p?))]
|
553 | 567 | [(Continuation-Mark-Keyof: t)
|
554 | 568 | (continuation-mark-key/sc (t->sc t))]
|
|
1237 | 1251 | [(== t:-NonPosExtFlonum) nonpositive-extflonum/sc]
|
1238 | 1252 | [(== t:-ExtFlonum) extflonum/sc]
|
1239 | 1253 | [else #f]))
|
| 1254 | + |
| 1255 | + |
| 1256 | + |
| 1257 | +;; display-syntax-warning is like raise-syntax-error, except that it displays to |
| 1258 | +;; stderr and keeps going, instead of raising an exception |
| 1259 | +(define (display-syntax-warning name message [expr #f] [sub-expr #f]) |
| 1260 | + (define (display-exn e) ((error-display-handler) (exn-message e) e)) |
| 1261 | + (with-handlers ([exn:fail:syntax? display-exn]) |
| 1262 | + (raise-syntax-error name message expr sub-expr))) |
| 1263 | + |
0 commit comments