schemify: ensure that deserialized constants are immutable

Closes #2394
This commit is contained in:
Matthew Flatt 2018-11-21 10:16:19 -07:00
parent 669e51768d
commit 744d440ab9
2 changed files with 26 additions and 8 deletions

View File

@ -2185,6 +2185,26 @@
(test 'cons exn:fail:contract:variable-id e)
(test #t regexp-match? #rx"^cons: " (exn-message e)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Check immutability after saving and restoring quoted constants
(let ([m `(module defines-immutable-objects racket/base
(provide objs)
(define objs
'(#"x"
"x"
#()
#(1)
#(#:x)
#(#"x")
#&1
#&#:x
#&#"x"
#hasheq((a . b)))))])
(define c (compile m))
(eval c)
(test #t andmap immutable? (dynamic-require ''defines-immutable-objects 'objs)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(report-errs)

View File

@ -181,16 +181,14 @@
`(cons ,a ,d))))]
[(vector? q)
(let ([args (map make-construct (vector->list q))])
(if (and (andmap quote? args)
(not (impersonator? q)))
`(quote ,q)
`(vector ,@args)))]
`(vector->immutable-vector
,(if (and (andmap quote? args)
(not (impersonator? q)))
`(quote ,q)
`(vector ,@args))))]
[(box? q)
(let ([arg (make-construct (unbox q))])
(if (and (quote? arg)
(not (impersonator? q)))
`(quote ,q)
`(box ,arg)))]
`(box-immutable ,arg))]
[(prefab-struct-key q)
=> (lambda (key)
`(make-prefab-struct ',key ,@(map make-construct