Thank you all so much! I'm glad it wasn't a huge mystery in the end.

-------- Original Message --------
On Jun 17, 2020, 9:13 AM, Matthew Flatt wrote:

> Yes, clearly a BC compiler bug --- and probably almost as old as
> Racket. The bug was specific to `set!` on a locally bound variable as
> the first subexpression of `begin0`.
>
> I've pushed a repair.
>
> Thanks!
>
> At Wed, 17 Jun 2020 03:35:51 -0500, Alexis King wrote:
>> This is quite curious. It appears to be a compiler bug. Here’s a very 
>> slightly
>> smaller test case:
>>
>> #lang racket/base
>> (define count!
>> (let ([i 0])
>> (λ () (begin0
>> (set! i (add1 i))
>> (+ i)))))
>> (count!)
>>
>> The fully-expanded program looks fine, so it isn’t the expander’s fault:
>>
>> (module counter racket/base
>> (#%module-begin
>> (module configure-runtime '#%kernel
>> (#%module-begin (#%require racket/runtime-config) (#%app configure
>> '#f)))
>> (define-values
>> (count!)
>> (let-values (((i) '0))
>> (lambda () (begin0 (set! i (#%app add1 i)) (#%app + i)))))
>> (#%app call-with-values (lambda () (#%app count!)) print-values)))
>>
>> But `raco decompile` reveals that begin0 has been mysteriously replaced with
>> begin in the compiled program:
>>
>> (module counter ....
>> (require (lib "racket/base.rkt"))
>> (provide)
>> (define-values
>> (count!)
>> (let ((local54 '0))
>> (begin
>> (set! local54 (#%box local54))
>> (lambda ()
>> '#(count! #<path:/tmp/counter.rkt> 4 4 53 63 #f)
>> '(flags: preserves-marks single-result)
>> '(captures: (val/ref local54))
>> (begin
>> (#%set-boxes! (local54) (add1 (#%unbox local54)))
>> (+ (#%unbox local54)))))))
>> (#%apply-values print-values (count!))
>> (void)
>> (module (counter configure-runtime) ....
>> (require '#%kernel (lib "racket/runtime-config.rkt"))
>> (provide)
>> (print-as-expression '#t)
>> (void)))
>>
>> It seems perhaps an optimization has gone awry. The bug appears to be quite
>> old: I can reproduce it as far back as 6.1.1. (I didn’t test any versions
>> earlier than that.) Unsurprisingly, the issue does not occur on Racket CS,
>> which is consistent with the hypothesis that this is a compiler bug.
>>
>> Alexis
>>
>> > On Jun 17, 2020, at 02:04, Sage Gerard <[email protected]> wrote:
>> >
>> > I attached a video demonstrating what I'm seeing. In case it does not load
>> or is not available, I'll summarize here. Forgive any typos; it's been a late
>> night of coding.
>> >
>> > Here's a module with an incorrect counter. It's incorrect because it uses
>> begin0, and is therefore expected to return void instead of an incrementing
>> integer.
>> >
>> > #lang racket
>> > (provide count!)
>> > (define count!
>> > (let ([i 0])
>> > (λ () (begin0
>> > (set! i (add1 i))
>> > (~v i)))))
>> >
>> > Notice that I added the ~v to format the return value. If I launch Racket
>> v7.7.0.5 using racket -it prog.rkt, (count!) returns the formatted value. But
>> if I remove the ~v, it behaves as written (returning void).
>> >
>> > The video shows the behavior with and without ~v, both in DrRacket and
>> racket. DrRacket is the only environment that consistently runs the code
>> correctly.
>> >
>> > ~slg
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/racket-users/781BE0E5-E6E5-4F0B-8B46-5227FDFB
>> 8835%40gmail.com.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/20200617071306.bc%40sirmail.smtp.cs.utah.edu.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/IH8l5cBwN3MPSWGHBWcbvDTEMikj3_ZDa5UWVtZ36bEabxTUzD8qamaPRE42q8U6mYRKYGKWit9Zh6cGYc7J7ibz2DmCeJ3dt0_4zJU5Vyc%3D%40sagegerard.com.

Reply via email to