|
49 | 49 | (define-struct/cond-contract context |
50 | 50 | ([bounds (listof symbol?)] |
51 | 51 | [vars (listof symbol?)] |
52 | | - [indices (listof symbol?)] |
53 | | - [type-bounds (hash/c symbol? Type?)]) #:transparent) |
| 52 | + [indices (listof symbol?)]) #:transparent) |
54 | 53 |
|
55 | 54 | (define (context-add-vars ctx vars) |
56 | 55 | (match ctx |
57 | | - [(context V X Y TB) |
58 | | - (context V (append vars X) Y TB)])) |
| 56 | + [(context V X Y) |
| 57 | + (context V (append vars X) Y)])) |
59 | 58 |
|
60 | 59 | (define (context-add-var ctx var) |
61 | 60 | (match ctx |
62 | | - [(context V X Y TB) |
63 | | - (context V (cons var X) Y TB)])) |
| 61 | + [(context V X Y) |
| 62 | + (context V (cons var X) Y)])) |
64 | 63 |
|
65 | 64 | (define (context-add ctx #:bounds [bounds empty] #:vars [vars empty] #:indices [indices empty]) |
66 | 65 | (match ctx |
67 | | - [(context V X Y TB) |
68 | | - (context (append bounds V) (append vars X) (append indices Y) TB)])) |
| 66 | + [(context V X Y) |
| 67 | + (context (append bounds V) (append vars X) (append indices Y))])) |
69 | 68 |
|
70 | 69 | (define (inferable-index? ctx bound) |
71 | 70 | (match ctx |
72 | | - [(context _ _ Y TB) |
| 71 | + [(context _ _ Y) |
73 | 72 | (memq bound Y)])) |
74 | 73 |
|
75 | 74 | (define ((inferable-var? ctx) var) |
76 | 75 | (match ctx |
77 | | - [(context _ X _ TB) |
| 76 | + [(context _ X _) |
78 | 77 | (memq var X)])) |
79 | 78 |
|
80 | 79 | (define (empty-cset/context ctx) |
81 | 80 | (match ctx |
82 | | - [(context _ X Y TB) |
| 81 | + [(context _ X Y) |
83 | 82 | (empty-cset X Y)])) |
84 | 83 |
|
85 | 84 |
|
|
570 | 569 |
|
571 | 570 | ;; variables that are in X and should be constrained |
572 | 571 | ;; all other variables are compatible only with themselves |
573 | | - [((F: (? (inferable-var? context) v)) T) |
| 572 | + [((F: (? (inferable-var? context) v) maybe-type-bound) T) |
574 | 573 | #:return-when |
575 | 574 | (match T |
576 | 575 | ;; fail when v* is an index variable |
577 | 576 | [(F: v*) (and (bound-index? v*) (not (bound-tvar? v*)))] |
578 | 577 | [_ #f]) |
579 | 578 | #f |
580 | 579 | ;; constrain v to be below T (but don't mention bounds) |
581 | | - (define maybe-type-bound (hash-ref (context-type-bounds context) v #f)) |
582 | 580 | (let ([sing (curryr singleton v (var-demote T (context-bounds context)))]) |
583 | 581 | (cond |
584 | 582 | [(and maybe-type-bound (subtype maybe-type-bound T obj)) |
585 | 583 | (sing maybe-type-bound)] |
586 | 584 | [(not maybe-type-bound) (sing -Bottom)] |
587 | 585 | [else #f]))] |
588 | 586 |
|
589 | | - [(S (F: (? (inferable-var? context) v))) |
| 587 | + [(S (F: (? (inferable-var? context) v) maybe-type-bound)) |
590 | 588 | #:return-when |
591 | 589 | (match S |
592 | 590 | [(F: v*) (and (bound-index? v*) (not (bound-tvar? v*)))] |
593 | 591 | [_ #f]) |
594 | 592 | #f |
595 | 593 | ;; constrain v to be above S (but don't mention bounds) |
596 | | - (define maybe-type-bound (hash-ref (context-type-bounds context) v #f)) |
597 | 594 | (let ([sing (curry singleton (var-promote S (context-bounds context)) v)]) |
598 | 595 | (cond |
599 | 596 | [(and maybe-type-bound (subtype S maybe-type-bound obj)) |
|
1017 | 1014 | (let () |
1018 | 1015 | (define/cond-contract (infer X Y S T R [expected #f] |
1019 | 1016 | #:multiple? [multiple-substitutions? #f] |
1020 | | - #:bounds [bounds '#hash()] |
1021 | 1017 | #:objs [objs '()]) |
1022 | 1018 | (((listof symbol?) (listof symbol?) (listof Type?) (listof Type?) |
1023 | 1019 | (or/c #f Values/c AnyValues? ValuesDots?)) |
1024 | 1020 | ((or/c #f Values/c AnyValues? ValuesDots?) |
1025 | 1021 | #:multiple? boolean? |
1026 | | - #:bounds (hash/c symbol? Type?) |
1027 | 1022 | #:objs (listof OptObject?)) |
1028 | 1023 | . ->* . (or/c boolean? |
1029 | 1024 | substitution/c |
1030 | 1025 | (cons/c substitution/c |
1031 | 1026 | (listof substitution/c)))) |
1032 | | - (define ctx (context null X Y bounds)) |
| 1027 | + (define ctx (context null X Y)) |
1033 | 1028 | (define expected-cset |
1034 | 1029 | (if expected |
1035 | 1030 | (cgen ctx R expected) |
|
1046 | 1041 |
|
1047 | 1042 | ;; like infer, but T-var is the vararg type: |
1048 | 1043 | (define (infer/vararg X Y S T T-var R [expected #f] |
1049 | | - #:objs [objs '()] |
1050 | | - #:bounds [bounds '#hash()]) |
| 1044 | + #:objs [objs '()]) |
1051 | 1045 | (and ((length S) . >= . (length T)) |
1052 | 1046 | (let* ([fewer-ts (- (length S) (length T))] |
1053 | 1047 | [new-T (match T-var |
|
1057 | 1051 | (append T (repeat-list rst-ts |
1058 | 1052 | (quotient fewer-ts (length rst-ts))))] |
1059 | 1053 | [_ T])]) |
1060 | | - (infer X Y S new-T R expected #:objs objs |
1061 | | - #:bounds bounds)))) |
| 1054 | + (infer X Y S new-T R expected #:objs objs)))) |
1062 | 1055 |
|
1063 | 1056 | ;; like infer, but dotted-var is the bound on the ... |
1064 | 1057 | ;; and T-dotted is the repeated type |
|
1073 | 1066 | (generate-dbound-prefix dotted-var T-dotted (length rest-S) #f)) |
1074 | 1067 | (define (subst t) |
1075 | 1068 | (substitute-dots (map make-F new-vars) #f dotted-var t)) |
1076 | | - (define ctx (context null (append new-vars X) (list dotted-var) '#hash())) |
| 1069 | + (define ctx (context null (append new-vars X) (list dotted-var))) |
1077 | 1070 |
|
1078 | 1071 | (define expected-cset (if expected |
1079 | 1072 | (cgen ctx (subst R) expected) |
|
0 commit comments