Skip to content

Commit

Permalink
Fix bitvector type sharing in extract and use hasheq (emina#207)
Browse files Browse the repository at this point in the history
extract seems to unintentionally de-shares bitvector types. This PR
makes the types shared properly again.

The hasheq change is technically backward-incompatible for programs that use
(bitvector 2^64), but I really hope no one does that in practice.
  • Loading branch information
sorawee authored Nov 18, 2021
1 parent 2e2896d commit c6e8dbc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions rosette/base/core/bitvector.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
;; ----------------- Bitvector Types ----------------- ;;

; Cache of all bitvector types constructed so far, mapping sizes to types.
(define bitvector-types (make-hash))
(define bitvector-types (make-hasheq))

; Returns the bitvector type of the given size.
(define (bitvector-type size)
(assert (exact-positive-integer? size) (argument-error 'bitvector "exact-positive-integer?" size))
(or (hash-ref bitvector-types size #f)
(let ([t (bitvector size)])
(hash-set! bitvector-types size t)
t)))
(assert (and (exact-positive-integer? size) (fixnum? size))
(argument-error 'bitvector "(and/c exact-positive-integer? fixnum?)" size))
(hash-ref! bitvector-types size (λ () (bitvector size))))

; Represents a bitvector type.
(struct bitvector (size)
Expand Down Expand Up @@ -595,7 +593,7 @@
_))
(if (< i size)
(extract i j a)
(expression @bvop a (bitvector (add1 i))))]
(expression @bvop a (bitvector-type (add1 i))))]
[(_ _ _) (expression @extract i j x)]))

(define-operator @extract
Expand Down

0 comments on commit c6e8dbc

Please sign in to comment.