Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread Neil Van Dyke
Compiler bugs have been so blessedly rare in Racket, maybe there should 
be a page on the Web, honoring those who found a compiler bug?


I would nominate Sage and Alexis for this one.

And Matthew, though we'd have to make sure he's not mis-incentivized by 
the glory of bug-finding, to start making bugs. :)


--
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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/68d508ac-b702-10b8-1d04-e6afa79e0248%40neilvandyke.org.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread Sage Gerard
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! # 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  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 racket-users+unsubscr...@googlegroups.com.
>> 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 racket-users+unsubscr...@googlegroups.com.
> 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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/IH8l5cBwN3MPSWGHBWcbvDTEMikj3_ZDa5UWVtZ36bEabxTUzD8qamaPRE42q8U6mYRKYGKWit9Zh6cGYc7J7ibz2DmCeJ3dt0_4zJU5Vyc%3D%40sagegerard.com.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread Matthew Flatt
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! # 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  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 racket-users+unsubscr...@googlegroups.com.
> 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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200617071306.bc%40sirmail.smtp.cs.utah.edu.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread George Neuner



Sorry for the noise:  it behaves as you say returning "!", "2", ...    
Somehow I paths screwed up and was running CS when I thought I was 
running regular (bytecode) Racket.


Sigh!
George

--
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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/abbcdae5-f88e-8a4c-f48b-c6f4fb6be38c%40comcast.net.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread George Neuner


It seems to work ... i.e. returns # ... in Windows.  I tried it in 
7.6 and 7.7,  both 32 and 64 bit versions.   Not near my Linux machine 
to try it there.


The expansion in all cases is the same and seems reasonable:

   (module count racket
  (#%module-begin
   (module configure-runtime '#%kernel
 (#%module-begin (#%require racket/runtime-config) (#%app
   configure '#f)))
   (#%provide count!)
   (define-values
    (lifted/2)
    (begin
  (with-continuation-mark
   contract-continuation-mark-key
   (#%app cons idB12 'no-negative-party)
   (let-values ()
 (#%app
  idX9
  (#%app
   module-name-fixup
   (#%app
    variable-reference->module-source/submod
    (#%variable-reference))
   (#%app list)))
   (define-values
    (count!)
    (let-values (((i) '0))
  (lambda () (begin0 (set! i (#%app add1 i)) (#%app lifted/2
   i)))



Btw:  my Racket installations report only  "7.7", not  "7.7.0.5". Are 
you running a snapshot build?


George


On 6/17/2020 3:04 AM, Sage Gerard 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.




--
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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/626cee23-fa67-c17f-781c-44554a50cf2e%40comcast.net.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread Alexis King
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! # 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  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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/781BE0E5-E6E5-4F0B-8B46-5227FDFB8835%40gmail.com.