bytes-utf-8-{length,index}: fix bytecode optimizer bug

The `bytes-utf-8-{length,index}` function was incorrectly marked as
always returning a fixnum.

Thanks to Jonathan Simpson for reporting the bug.
This commit is contained in:
Matthew Flatt 2017-12-08 17:13:55 -07:00
parent 1e1426a570
commit 6a9a269546
4 changed files with 16 additions and 5 deletions

View File

@ -12,7 +12,7 @@
(define collection 'multi)
(define version "6.11.0.2")
(define version "6.11.0.3")
(define deps `("racket-lib"
["racket" #:version ,version]))

View File

@ -6043,6 +6043,15 @@
(test 'fail "compilation took too long" (/ b a 1.0))
(loop (sub1 tries)))))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Make sure the optimizer doesn't assume that `bytes-utf-8-{length,index}`
;; returns a fixnum:
(test #f 'not-utf-8 (bytes-utf-8-length (bytes 255)))
(test #t 'not-not-utf-8 (not (bytes-utf-8-length (bytes 255))))
(test #f 'not-utf-8 (bytes-utf-8-index (bytes 255) 1))
(test #t 'not-not-utf-8 (not (bytes-utf-8-index (bytes 255) 1)))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try a program that triggers lots of inlining, which at one point
;; exposed a bug related to the closing of `lambda` forms within

View File

@ -13,12 +13,12 @@
consistently.)
*/
#define MZSCHEME_VERSION "6.11.0.2"
#define MZSCHEME_VERSION "6.11.0.3"
#define MZSCHEME_VERSION_X 6
#define MZSCHEME_VERSION_Y 11
#define MZSCHEME_VERSION_Z 0
#define MZSCHEME_VERSION_W 2
#define MZSCHEME_VERSION_W 3
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)

View File

@ -677,11 +677,13 @@ scheme_init_string (Scheme_Env *env)
env);
p = scheme_make_immed_prim(byte_string_utf8_index, "bytes-utf-8-index", 2, 4);
SCHEME_PRIM_PROC_FLAGS(p) |= scheme_intern_prim_opt_flags(SCHEME_PRIM_PRODUCES_FIXNUM);
/* Incorrect, since the result can be #f:
SCHEME_PRIM_PROC_FLAGS(p) |= scheme_intern_prim_opt_flags(SCHEME_PRIM_PRODUCES_FIXNUM); */
scheme_add_global_constant("bytes-utf-8-index", p, env);
p = scheme_make_immed_prim(byte_string_utf8_length, "bytes-utf-8-length", 1, 4);
SCHEME_PRIM_PROC_FLAGS(p) |= scheme_intern_prim_opt_flags(SCHEME_PRIM_PRODUCES_FIXNUM);
/* Incorrect, since the result can be #f:
SCHEME_PRIM_PROC_FLAGS(p) |= scheme_intern_prim_opt_flags(SCHEME_PRIM_PRODUCES_FIXNUM); */
scheme_add_global_constant("bytes-utf-8-length", p, env);
scheme_add_global_constant("bytes-utf-8-ref",