Skip to content

Commit 755a62c

Browse files
committed
simplify code
1 parent 2d92176 commit 755a62c

File tree

4 files changed

+21
-40
lines changed

4 files changed

+21
-40
lines changed

typed-racket-lib/typed-racket/infer/infer-unit.rkt

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,37 +49,36 @@
4949
(define-struct/cond-contract context
5050
([bounds (listof symbol?)]
5151
[vars (listof symbol?)]
52-
[indices (listof symbol?)]
53-
[type-bounds (hash/c symbol? Type?)]) #:transparent)
52+
[indices (listof symbol?)]) #:transparent)
5453

5554
(define (context-add-vars ctx vars)
5655
(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)]))
5958

6059
(define (context-add-var ctx var)
6160
(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)]))
6463

6564
(define (context-add ctx #:bounds [bounds empty] #:vars [vars empty] #:indices [indices empty])
6665
(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))]))
6968

7069
(define (inferable-index? ctx bound)
7170
(match ctx
72-
[(context _ _ Y TB)
71+
[(context _ _ Y)
7372
(memq bound Y)]))
7473

7574
(define ((inferable-var? ctx) var)
7675
(match ctx
77-
[(context _ X _ TB)
76+
[(context _ X _)
7877
(memq var X)]))
7978

8079
(define (empty-cset/context ctx)
8180
(match ctx
82-
[(context _ X Y TB)
81+
[(context _ X Y)
8382
(empty-cset X Y)]))
8483

8584

@@ -570,30 +569,28 @@
570569

571570
;; variables that are in X and should be constrained
572571
;; 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)
574573
#:return-when
575574
(match T
576575
;; fail when v* is an index variable
577576
[(F: v*) (and (bound-index? v*) (not (bound-tvar? v*)))]
578577
[_ #f])
579578
#f
580579
;; constrain v to be below T (but don't mention bounds)
581-
(define maybe-type-bound (hash-ref (context-type-bounds context) v #f))
582580
(let ([sing (curryr singleton v (var-demote T (context-bounds context)))])
583581
(cond
584582
[(and maybe-type-bound (subtype maybe-type-bound T obj))
585583
(sing maybe-type-bound)]
586584
[(not maybe-type-bound) (sing -Bottom)]
587585
[else #f]))]
588586

589-
[(S (F: (? (inferable-var? context) v)))
587+
[(S (F: (? (inferable-var? context) v) maybe-type-bound))
590588
#:return-when
591589
(match S
592590
[(F: v*) (and (bound-index? v*) (not (bound-tvar? v*)))]
593591
[_ #f])
594592
#f
595593
;; constrain v to be above S (but don't mention bounds)
596-
(define maybe-type-bound (hash-ref (context-type-bounds context) v #f))
597594
(let ([sing (curry singleton (var-promote S (context-bounds context)) v)])
598595
(cond
599596
[(and maybe-type-bound (subtype S maybe-type-bound obj))
@@ -1017,19 +1014,17 @@
10171014
(let ()
10181015
(define/cond-contract (infer X Y S T R [expected #f]
10191016
#:multiple? [multiple-substitutions? #f]
1020-
#:bounds [bounds '#hash()]
10211017
#:objs [objs '()])
10221018
(((listof symbol?) (listof symbol?) (listof Type?) (listof Type?)
10231019
(or/c #f Values/c AnyValues? ValuesDots?))
10241020
((or/c #f Values/c AnyValues? ValuesDots?)
10251021
#:multiple? boolean?
1026-
#:bounds (hash/c symbol? Type?)
10271022
#:objs (listof OptObject?))
10281023
. ->* . (or/c boolean?
10291024
substitution/c
10301025
(cons/c substitution/c
10311026
(listof substitution/c))))
1032-
(define ctx (context null X Y bounds))
1027+
(define ctx (context null X Y))
10331028
(define expected-cset
10341029
(if expected
10351030
(cgen ctx R expected)
@@ -1046,8 +1041,7 @@
10461041

10471042
;; like infer, but T-var is the vararg type:
10481043
(define (infer/vararg X Y S T T-var R [expected #f]
1049-
#:objs [objs '()]
1050-
#:bounds [bounds '#hash()])
1044+
#:objs [objs '()])
10511045
(and ((length S) . >= . (length T))
10521046
(let* ([fewer-ts (- (length S) (length T))]
10531047
[new-T (match T-var
@@ -1057,8 +1051,7 @@
10571051
(append T (repeat-list rst-ts
10581052
(quotient fewer-ts (length rst-ts))))]
10591053
[_ 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))))
10621055

10631056
;; like infer, but dotted-var is the bound on the ...
10641057
;; and T-dotted is the repeated type
@@ -1073,7 +1066,7 @@
10731066
(generate-dbound-prefix dotted-var T-dotted (length rest-S) #f))
10741067
(define (subst t)
10751068
(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)))
10771070

10781071
(define expected-cset (if expected
10791072
(cgen ctx (subst R) expected)

typed-racket-lib/typed-racket/infer/signatures.rkt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
((or/c #f Values/c AnyValues? ValuesDots?)
4040
;; optional multiple substitutions?
4141
#:multiple? boolean?
42-
#:objs (listof OptObject?)
43-
#:bounds (hash/c symbol? Type?))
42+
#:objs (listof OptObject?))
4443
. ->* . any)]
4544
[cond-contracted infer/vararg ((;; variables from the forall
4645
(listof symbol?)
@@ -56,8 +55,7 @@
5655
(or/c #f Values/c AnyValues? ValuesDots?))
5756
;; [optional] expected type
5857
((or/c #f Values/c AnyValues? ValuesDots?)
59-
#:objs (listof OptObject?)
60-
#:bounds (hash/c symbol? Type?))
58+
#:objs (listof OptObject?))
6159
. ->* . any)]
6260
[cond-contracted infer/dots (((listof symbol?)
6361
symbol?

typed-racket-lib/typed-racket/rep/type-rep.rkt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,16 +1777,7 @@
17771777
(let* ([n (Poly-n t)]
17781778
[syms (build-list n (lambda _ (gensym)))])
17791779
(list syms (Poly-body* syms t))))
1780-
(list nps bp)))]
1781-
[(_ nps bounds bp)
1782-
#'(? Poly?
1783-
(app (lambda (t)
1784-
(let* ([n (Poly-n t)]
1785-
[syms (build-list n (lambda _ (gensym)))]
1786-
[bounds (for/hash ([(idx v) (Poly-bounds t)])
1787-
(values (list-ref syms idx) v))])
1788-
(list syms bounds (Poly-body* syms t))))
1789-
(list nps bounds bp)))])))
1780+
(list nps bp)))])))
17901781

17911782
;; This match expander uses the names from the hashtable
17921783
(define-match-expander Poly-names:

typed-racket-lib/typed-racket/typecheck/tc-funapp.rkt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
#:expected expected)]
193193
;; regular polymorphic functions without dotted rest,
194194
;; we do not choose any instantiations with mandatory keyword arguments
195-
[(Poly: vars bounds (Fun: arrows))
195+
[(Poly: vars (Fun: arrows))
196196
;; check there are no RestDots
197197
#:when (not (for/or ([a (in-list arrows)])
198198
(RestDots? (Arrow-rst a))))
@@ -214,8 +214,7 @@
214214
(infer/vararg vars null argtys dom rst rng
215215
(and expected
216216
(tc-results->values expected))
217-
#:objs argobjs
218-
#:bounds bounds)))
217+
#:objs argobjs)))
219218
#:function-type f-type
220219
#:args-results args-res
221220
#:expected expected)]

0 commit comments

Comments
 (0)