Yes, that's an optimizer bug. The optimizer sees that `unbox` is applied to a known box, so it converts the call to `unsafe-unbox`. Unfortunately, the optimizer also miscategorizes some unsafe operations, including `unsafe-unbox`, as independent of side effects.
One workaround is to add `(set! data data)` to your program, since that defeats the optimizer's tracking of the value of `data`. Meanwhile, I've pushed a repair. Thanks very much for the report! At Fri, 23 Dec 2016 02:43:58 -0800 (PST), Sergey Pinaev wrote: > if i run in repl following code: > > (define (t1 f) > (f '(123)) > 1) > (define (tt) > (lambda (a) > (let* ((data (box '())) > (v (t1 (lambda (d) > (set-box! data d))))) > (cons (unbox data) v)))) > (define tf (tt)) > > and then call (tf 1) i got '((123) . 1) as expected. > > but if i put t1 and tt in foobar.scm: > > #lang racket > (provide tt) > (define (t1 f) > (f '(123)) > 1) > (define (tt) > (lambda (a) > (let* ((data (box '())) > (v (t1 (lambda (d) > (set-box! data d))))) > (cons (unbox data) v)))) > > and then run in repl: > > (require "foobar.scm") > (define tf (tt)) > and call (tf 1) - i got '(() . 1) > > and if i change return value in tt to (cons v (unbox data)) - result will > be correct again. > also if i just put (printf "hello~n") before (cons ..) in tt - result will > be correct also. > so i guess in some case (unbox data) sowehow calculated before computating > value of v. > > p.s. sorry for my poor english. > > -- > You received this message because you are subscribed to the Google Groups > "Racket Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-dev/ff3a8778-98db-45c7-b870-bd8f43422b > 02%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/585d3e7e.02c7620a.3b69e.0671SMTPIN_ADDED_MISSING%40gmr-mx.google.com. For more options, visit https://groups.google.com/d/optout.
