Skip to content

Commit

Permalink
Fix equal-always? on fl/fxvector, stencil-vector
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKnauth committed Apr 28, 2024
1 parent 5713201 commit 4433205
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 25 additions & 0 deletions pkgs/racket-test-core/tests/racket/basic.rktl
Expand Up @@ -118,6 +118,19 @@
(test #t equal? 2 2)
(test #t equal? (make-vector 5 'a) (make-vector 5 'a))
(test #t equal? (box "a") (box "a"))
(test #t equal? (make-flvector 5 0.0) (make-flvector 5 0.0))
(test #t equal? (make-fxvector 5 0) (make-fxvector 5 0))
(test #t equal? (stencil-vector #b10010 'a 'b) (stencil-vector #b10010 'a 'b))
(test #t eq?
(equal-hash-code (make-flvector 5 0.0))
(equal-hash-code (make-flvector 5 0.0)))
(test #t eq?
(equal-hash-code (make-fxvector 5 0))
(equal-hash-code (make-fxvector 5 0)))
(test #t eq?
(equal-hash-code (stencil-vector #b10010 'a 'b))
(equal-hash-code (stencil-vector #b10010 'a 'b)))

(test #f equal? "" (string #\null))

(test #f equal? 'a "a")
Expand Down Expand Up @@ -158,6 +171,18 @@
(test #f equal-always? (make-hash '((a . 1))) (make-hash '((a . 1))))
(test #f equal-always? (mcons 'a '()) (mcons 'a '()))
(test #f equal-always? (string #\a) (string #\a))
(test #f equal-always? (make-flvector 5 0.0) (make-flvector 5 0.0))
(test #f equal-always? (make-fxvector 5 0) (make-fxvector 5 0))
(test #f equal-always? (stencil-vector #b10010 'a 'b) (stencil-vector #b10010 'a 'b))
(test #f eq?
(equal-always-hash-code (make-flvector 5 0.0))
(equal-always-hash-code (make-flvector 5 0.0)))
(test #f eq?
(equal-always-hash-code (make-fxvector 5 0))
(equal-always-hash-code (make-fxvector 5 0)))
(test #f eq?
(equal-always-hash-code (stencil-vector #b10010 'a 'b))
(equal-always-hash-code (stencil-vector #b10010 'a 'b)))

(let ()
(struct s (x) #:property prop:procedure 0)
Expand Down
13 changes: 5 additions & 8 deletions racket/src/cs/rumble/equal.ss
Expand Up @@ -104,6 +104,7 @@
(equal? a b ctx)))))))]
[(stencil-vector? a)
(and (stencil-vector? b)
(not (or (eq? mode 'chaperone-of?) (eq? mode 'equal-always?)))
(fx= (stencil-vector-mask a) (stencil-vector-mask b))
(let ([len (stencil-vector-length a)]
[ctx (deeper-context ctx)])
Expand Down Expand Up @@ -169,15 +170,11 @@
(|#%app| rec-equal? orig-a orig-b eql? (or (eq? mode 'equal?)
(eq? mode 'impersonator-of?)))
(|#%app| rec-equal? orig-a orig-b eql?)))])))))])))]
[(and (or (eq? mode 'chaperone-of?) (eq? mode 'equal-always?))
;; Mutable strings and bytevectors must be `eq?` for `chaperone-of?` and `equal-always?`
(or (mutable-string? a)
(mutable-string? b)
(mutable-bytevector? a)
(mutable-bytevector? b)))
#f]
[else
(#%equal? a b)])))))
(and (or (not (or (eq? mode 'chaperone-of?) (eq? mode 'equal-always?)))
(and (immutable-string? a) (immutable-string? b))
(and (immutable-bytevector? a) (immutable-bytevector? b)))
(#%equal? a b))])))))

(define (equal? a b) (do-equal? a b 'equal? #f))
(define (impersonator-of? a b) (do-equal? a b 'impersonator-of? #f))
Expand Down

0 comments on commit 4433205

Please sign in to comment.