|
45 | 45 | (provide star ddd/bound |
46 | 46 | current-referenced-aliases |
47 | 47 | current-referenced-class-parents |
48 | | - current-type-alias-name) |
| 48 | + current-type-alias-name |
| 49 | + check-type-invariants-while-parsing?) |
49 | 50 |
|
50 | 51 | ;; current-term-names : Parameter<(Listof Id)> |
51 | 52 | ;; names currently "bound" by a type we are parsing |
|
96 | 97 | (parameterize ([current-arities (cons arity (current-arities))]) |
97 | 98 | e ...)) |
98 | 99 |
|
| 100 | + |
| 101 | +;; code in type-alias-helper.rkt calls `parse-type` for effect to build up |
| 102 | +;; info about how types depend on eachother -- during this parsing, we can't |
| 103 | +;; check certain invariant successfully (i.e. when a user writes `(car p)` |
| 104 | +;; `p` is <: (Pair Any Any), etc), so we use this flag to disable/enable |
| 105 | +;; invariant checking while parsing |
| 106 | +(define check-type-invariants-while-parsing? (make-parameter #t)) |
| 107 | + |
99 | 108 | (define-literal-syntax-class #:for-label car) |
100 | 109 | (define-literal-syntax-class #:for-label cdr) |
101 | 110 | (define-literal-syntax-class #:for-label vector-length) |
|
379 | 388 | (pattern o:symbolic-object |
380 | 389 | #:do [(define obj (attribute o.val)) |
381 | 390 | (define obj-ty (lookup-obj-type/lexical obj))] |
382 | | - #:fail-unless (subtype obj-ty -Int) |
| 391 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 392 | + (not (subtype obj-ty -Int))) |
383 | 393 | (format "terms in linear constraints must be integers, got ~a for ~a" |
384 | 394 | obj-ty obj) |
385 | 395 | #:attr val (attribute o.val))) |
|
398 | 408 | (pattern (:*^ ~! n:exact-integer o:symbolic-object-w/o-lexp) |
399 | 409 | #:do [(define obj (attribute o.val)) |
400 | 410 | (define obj-ty (lookup-obj-type/lexical obj))] |
401 | | - #:fail-unless (subtype obj-ty -Int) |
| 411 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 412 | + (not (subtype obj-ty -Int))) |
402 | 413 | (format "terms in linear constraints must be integers, got ~a for ~a" |
403 | 414 | obj-ty obj) |
404 | 415 | #:attr val (-lexp (list (syntax->datum #'n) (attribute o.val)))) |
|
424 | 435 | (pattern (:car^ ~! o:symbolic-object-w/o-lexp) |
425 | 436 | #:do [(define obj (attribute o.val)) |
426 | 437 | (define obj-ty (lookup-obj-type/lexical obj))] |
427 | | - #:fail-unless (subtype obj-ty (-pair Univ Univ)) |
| 438 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 439 | + (not (subtype obj-ty (-pair Univ Univ)))) |
428 | 440 | (format "car expects a pair, but got ~a for ~a" |
429 | 441 | obj-ty obj) |
430 | 442 | #:attr val (-car-of (attribute o.val))) |
431 | 443 | (pattern (:cdr^ ~! o:symbolic-object-w/o-lexp) |
432 | 444 | #:do [(define obj (attribute o.val)) |
433 | 445 | (define obj-ty (lookup-obj-type/lexical obj))] |
434 | | - #:fail-unless (subtype obj-ty (-pair Univ Univ)) |
| 446 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 447 | + (not (subtype obj-ty (-pair Univ Univ)))) |
435 | 448 | (format "cdr expects a pair, but got ~a for ~a" |
436 | 449 | obj-ty obj) |
437 | 450 | #:attr val (-cdr-of (attribute o.val))) |
438 | 451 | (pattern (:vector-length^ ~! o:symbolic-object-w/o-lexp) |
439 | 452 | #:do [(define obj (attribute o.val)) |
440 | 453 | (define obj-ty (lookup-obj-type/lexical obj))] |
441 | | - #:fail-unless (subtype obj-ty -VectorTop) |
| 454 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 455 | + (not (subtype obj-ty -VectorTop))) |
442 | 456 | (format "vector-length expects a vector, but got ~a for ~a" |
443 | 457 | obj-ty obj) |
444 | 458 | #:attr val (-vec-len-of (attribute o.val)))) |
|
461 | 475 | (pattern (:*^ ~! coeff:exact-integer o:symbolic-object-w/o-lexp) |
462 | 476 | #:do [(define obj (attribute o.val)) |
463 | 477 | (define obj-ty (lookup-obj-type/lexical obj))] |
464 | | - #:fail-unless (subtype obj-ty -Int) |
| 478 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 479 | + (not (subtype obj-ty -Int))) |
465 | 480 | (format "terms in linear expressions must be integers, got ~a for ~a" |
466 | 481 | obj-ty obj) |
467 | 482 | #:attr val (-lexp (list (syntax->datum #'coeff) (attribute o.val)))) |
|
470 | 485 | (pattern o:symbolic-object-w/o-lexp |
471 | 486 | #:do [(define obj (attribute o.val)) |
472 | 487 | (define obj-ty (lookup-obj-type/lexical obj))] |
473 | | - #:fail-unless (subtype obj-ty -Int) |
| 488 | + #:fail-when (and (check-type-invariants-while-parsing?) |
| 489 | + (not (subtype obj-ty -Int))) |
474 | 490 | (format "terms in linear expressions must be integers, got ~a for ~a" |
475 | 491 | obj-ty obj) |
476 | 492 | #:attr val (attribute o.val)) |
|
0 commit comments