Skip to content

Commit cf2f7e4

Browse files
committed
Modified some hash operators' types.
1 parent 36e352e commit cf2f7e4

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed

typed-racket-lib/typed-racket/base-env/base-env.rkt

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,10 @@
964964
[make-immutable-hasheq (-poly (a b) (->opt [(-lst (-pair a b))] (-Immutable-HT a b)))]
965965
[make-immutable-hasheqv (-poly (a b) (->opt [(-lst (-pair a b))] (-Immutable-HT a b)))]
966966

967-
[hash-set (-poly (a b) ((-HT a b) a b . -> . (-Immutable-HT a b)))]
968-
[hash-set* (-poly (a b) (->* (list (-HT a b)) (make-Rest (list a b)) (-Immutable-HT a b)))]
969-
[hash-set! (-poly (a b) ((-HT a b) a b . -> . -Void))]
970-
[hash-set*! (-poly (a b) (->* (list (-HT a b)) (make-Rest (list a b)) -Void))]
967+
[hash-set (-poly (a b) ((-Immutable-HT a b) a b . -> . (-Immutable-HT a b)))]
968+
[hash-set* (-poly (a b) (->* (list (-Immutable-HT a b)) (make-Rest (list a b)) (-Immutable-HT a b)))]
969+
[hash-set! (-poly (a b) ((-Mutable-HT a b) a b . -> . -Void))]
970+
[hash-set*! (-poly (a b) (->* (list (-Mutable-HT a b)) (make-Rest (list a b)) -Void))]
971971
[hash-ref (-poly (a b c)
972972
(cl-> [((-HT a b) a) b]
973973
[((-HT a b) a (-val #f)) (-opt b)]
@@ -978,18 +978,16 @@
978978
[hash-ref! (-poly (a b) (-> (-HT a b) a (-> b) b))]
979979
[hash-has-key? (-HashTableTop Univ . -> . B)]
980980
[hash-update! (-poly (a b)
981-
(cl-> [((-HT a b) a (-> b b)) -Void]
982-
[((-HT a b) a (-> b b) (-> b)) -Void]))]
981+
(cl-> [((-Mutable-HT a b) a (-> b b)) -Void]
982+
[((-Mutable-HT a b) a (-> b b) (-> b)) -Void]))]
983983
[hash-update (-poly (a b)
984-
(cl-> [((-HT a b) a (-> b b)) (-Immutable-HT a b)]
985-
[((-HT a b) a (-> b b) (-> b)) (-Immutable-HT a b)]))]
986-
[hash-remove (-poly (a b) (cl-> [((-HT a b) Univ) (-Immutable-HT a b)]
987-
[(-HashTableTop Univ) (-Immutable-HT Univ Univ)]))]
988-
[hash-remove! (-poly (a b) (cl-> [((-HT a b) a) -Void]
989-
[(-HashTableTop a) -Void]))]
990-
[hash-clear! (-> -HashTableTop -Void)]
991-
[hash-clear (-poly (a b) (cl-> [((-HT a b)) (-Immutable-HT a b)]
992-
[(-HashTableTop) (-Immutable-HT Univ Univ)]))]
984+
(cl-> [((-Immutable-HT a b) a (-> b b)) (-Immutable-HT a b)]
985+
[((-Immutable-HT a b) a (-> b b) (-> b)) (-Immutable-HT a b)]))]
986+
[hash-remove (-poly (a b) (-> (-Immutable-HT a b) Univ (-Immutable-HT a b)))]
987+
[hash-remove! (-poly (a b) (cl-> [((-Mutable-HT a b) a) -Void]
988+
[(-Mutable-HashTableTop a) -Void]))]
989+
[hash-clear! (-> -Mutable-HashTableTop -Void)]
990+
[hash-clear (-poly (a b) (-> (-Immutable-HT a b) (-Immutable-HT a b)))]
993991
[hash-copy-clear (-poly (a b) (cl-> [((-Immutable-HT a b)) (-Immutable-HT a b)]
994992
[((-Mutable-HT a b)) (-Mutable-HT a b)]
995993
[(-Mutable-HashTableTop) -Mutable-HashTableTop]
@@ -1020,7 +1018,7 @@
10201018
[(-Mutable-HashTableTop) -Mutable-HashTableTop]
10211019
[((-Weak-HT a b)) (-Weak-HT a b)]
10221020
[(-Weak-HashTableTop) -Weak-HashTableTop]
1023-
[((-HT a b)) (-HT a b)]))]
1021+
[((-HT a b)) (-Mutable-HT a b)]))]
10241022
[eq-hash-code (-> Univ -Fixnum)]
10251023
[eqv-hash-code (-> Univ -Fixnum)]
10261024
[equal-hash-code (-> Univ -Fixnum)]

typed-racket-lib/typed-racket/base-env/prims.rkt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -609,16 +609,13 @@ the typed racket language.
609609
a2:optional-standalone-annotation*
610610
body ...) ; body is not always an expression, can be a break-clause
611611
(define a.ty (or (attribute a2.ty) (attribute a1.ty)))
612-
(if a.ty
613-
(quasisyntax/loc stx
614-
(for/fold: : #,a.ty
615-
((return-hash : #,a.ty (ann (#,hash-maker null) #,a.ty)))
616-
(clause.expand ... ...)
617-
(let-values (((key val) (let () body ...)))
618-
(hash-set return-hash key val))))
619-
(syntax/loc stx
620-
(for/hash (clause.expand ... ...)
621-
body ...)))])))
612+
(unless a.ty (set! a.ty #'(Immutable-HashTable Any Any)))
613+
(quasisyntax/loc stx
614+
(for/fold: : #,a.ty
615+
((return-hash : #,a.ty (ann (#,hash-maker null) #,a.ty)))
616+
(clause.expand ... ...)
617+
(let-values (((key val) (let () body ...)))
618+
(hash-set return-hash key val))))])))
622619

623620
(define-syntax for/hash: (define-for/hash:-variant #'make-immutable-hash))
624621
(define-syntax for/hasheq: (define-for/hash:-variant #'make-immutable-hasheq))

typed-racket-test/unit-tests/typecheck-tests.rkt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,7 +2535,7 @@
25352535
[tc-e (set-remove (set 1 2 3) 'a) (-set -PosByte)]
25362536
;; don't return HashTableTop
25372537
[tc-e (hash-remove #hash((a . 5) (b . 7)) 3) (-Immutable-HT -Symbol -Integer)]
2538-
[tc-e (hash-remove #hash((a . 5) (b . 7)) 3) (-Immutable-HT -Symbol -Integer)]
2538+
[tc-e (hash-remove #hash((a . 5) (b . 7)) 'b) (-Immutable-HT -Symbol -Integer)]
25392539
;; these should actually work
25402540
[tc-e (vector-memq 3 #(a b c)) (t:Un (-val #f) -Index)]
25412541
[tc-e (vector-memv 3 #(a b c)) (t:Un (-val #f) -Index)]
@@ -2676,49 +2676,49 @@
26762676
-FlVector]
26772677

26782678
;; for/hash, for*/hash - PR 14306
2679-
[tc-e (for/hash: : (HashTable Symbol String)
2679+
[tc-e (for/hash: : (Immutable-HashTable Symbol String)
26802680
([x (in-list '(x y z))]
26812681
[y (in-list '("a" "b" "c"))]
26822682
#:when (eq? x 'x))
26832683
(values x y))
2684-
#:ret (tc-ret (-HT -Symbol -String))]
2685-
[tc-e (for*/hash: : (HashTable Symbol String)
2684+
#:ret (tc-ret (-Immutable-HT -Symbol -String))]
2685+
[tc-e (for*/hash: : (Immutable-HashTable Symbol String)
26862686
([k (in-list '(x y z))]
26872687
[v (in-list '("a" "b"))]
26882688
#:when (eq? k 'x))
26892689
(values k v))
2690-
#:ret (tc-ret (-HT -Symbol -String))]
2690+
#:ret (tc-ret (-Immutable-HT -Symbol -String))]
26912691

26922692
;; PR 13937
26932693
[tc-e (let ()
2694-
(: foo ((HashTable String Symbol) -> (HashTable Symbol String)))
2694+
(: foo ((HashTable String Symbol) -> (Immutable-HashTable Symbol String)))
26952695
(define (foo map)
2696-
(for/hash : (HashTable Symbol String)
2696+
(for/hash : (Immutable-HashTable Symbol String)
26972697
([(str sym) map])
26982698
(values sym str)))
26992699
(foo #hash(("foo" . foo))))
2700-
(-HT -Symbol -String)]
2700+
(-Immutable-HT -Symbol -String)]
27012701

27022702
;; for/hash doesn't always need a return annotation inside
27032703
[tc-e/t (let ()
2704-
(tr:define h : (HashTable Any Any)
2704+
(tr:define h : (Immutable-HashTable Any Any)
27052705
(for/hash ([(k v) (in-hash #hash(("a" . a)))])
27062706
(values v k)))
27072707
h)
2708-
(-HT Univ Univ)]
2708+
(-Immutable-HT Univ Univ)]
27092709
[tc-e/t (let ()
2710-
(tr:define h : (HashTable Any Any)
2710+
(tr:define h : (Immutable-HashTable Any Any)
27112711
(for/hash ([k (in-hash-keys #hash(("a" . a)))]
27122712
[v (in-hash-values #hash(("a" . a)))])
27132713
(values v k)))
27142714
h)
2715-
(-HT Univ Univ)]
2715+
(-Immutable-HT Univ Univ)]
27162716
[tc-e/t (let ()
2717-
(tr:define h : (HashTable Any Any)
2717+
(tr:define h : (Immutable-HashTable Any Any)
27182718
(for/hash ([k+v (in-hash-pairs #hash(("a" . a)))])
27192719
(values (cdr k+v) (car k+v))))
27202720
h)
2721-
(-HT Univ Univ)]
2721+
(-Immutable-HT Univ Univ)]
27222722

27232723
;; for/vector doesn't always need a return annotation inside
27242724
[tc-e/t (let ()

0 commit comments

Comments
 (0)