Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identifier-binding-symbol: contract violation after raco demod #1420

Open
benknoble opened this issue Dec 21, 2024 · 2 comments
Open

identifier-binding-symbol: contract violation after raco demod #1420

benknoble opened this issue Dec 21, 2024 · 2 comments

Comments

@benknoble
Copy link

I'm not 100% sure this is a TR bug, but here's the program:

#lang typed/racket

(define length #e1e4)
(define inner-loop (* 10 length))

(define u (cast (string->number (vector-ref (current-command-line-arguments) 0))
                Natural))
(define r (random (add1 length) (make-pseudo-random-generator)))
(: a (Vectorof Natural))
(define a (make-vector length))

(for ([i (in-range 0 length)])
  (for ([j : Natural (in-range 0 inner-loop)])
    (vector-set! a i (+ (vector-ref a i) (remainder j u))))
  (vector-set! a i (+ (vector-ref a i) r)))

(displayln (vector-ref a r))

The compiler steps:

raco make racket/typed-code.rkt
raco demod -o racket/typed-code.zo racket/typed-code.rkt
raco exe  -o racket/typed-code racket/typed-code.zo

And the output:

./racket/typed-code 43
identifier-binding-symbol: contract violation
  expected: identifier?
  given: #f
  context...:
   .../loops/boundmap.rkt:47:12: module-identifier-mapping-put!
   body of '#%mzc:typed-code

Making an exe the normal way (raco exe -o racket/typed-code{,.rkt}) and running as above works just fine. However, the exe is 69MiB instead of 47MiB.


System specs, in case they end up relevant:

OS: macOS 12.7.6 21H1320 x86_64 
Host: MacBookPro11,5 
Kernel: 21.6.0 
CPU: Intel i7-4870HQ (8) @ 2.50GHz 
GPU: Intel Iris Pro, AMD Radeon R9 M370X 
Memory: 8380MiB / 16384MiB 

I uploaded a hexdump of the .zo file created from xxd, if that helps.

@samth
Copy link
Member

samth commented Dec 24, 2024

I think this is a raco demod bug, but maybe @mflatt can say more.

@benknoble
Copy link
Author

I forgot to post Racket versions: 8.15 (latest main release, not a snapshot or self-compiled), and presumably a relatively up-to-date TR package (I haven't run raco pkg update recently, but I did migrate within the last few month; I'm away from the system).

I also know there have been repairs to demod in the snapshot versions, so if I get time to rebuild the latest Racket I'll try to reproduce on latest.

benknoble added a commit to benknoble/bd-languages-race that referenced this issue Jan 3, 2025
A similar but naïve Typed Racket program is slower, though it can't be
demodded at the moment [1] so make the exe without running demod:

    #lang typed/racket

    (define length #e1e4)
    (define inner-loop (* 10 length))

    (define u (cast (string->number (vector-ref (current-command-line-arguments) 0))
                    Natural))
    (define r (random (add1 length) (make-pseudo-random-generator)))
    (: a (Vectorof Natural))
    (define a (make-vector length))

    (for ([i (in-range 0 length)])
      (for ([j : Natural (in-range 0 inner-loop)])
        (vector-set! a i (+ (vector-ref a i) (remainder j u))))
      (vector-set! a i (+ (vector-ref a i) r)))

    (displayln (vector-ref a r))

With just 3 runs in hyperfine:

    ./racket/code 43 ran
      1.69 ± 0.03 times faster than ./racket/typed-code 43

[1]: racket/typed-racket#1420
benknoble added a commit to benknoble/bd-languages-race that referenced this issue Jan 3, 2025
A similar but naïve Typed Racket program is slower, though it can't be
demodded at the moment [1] so make the exe without running demod:

    #lang typed/racket

    (define length #e1e4)
    (define inner-loop (* 10 length))

    (define u (cast (string->number (vector-ref (current-command-line-arguments) 0))
                    Natural))
    (define r (random (add1 length) (make-pseudo-random-generator)))
    (: a (Vectorof Natural))
    (define a (make-vector length))

    (for ([i (in-range 0 length)])
      (for ([j : Natural (in-range 0 inner-loop)])
        (vector-set! a i (+ (vector-ref a i) (remainder j u))))
      (vector-set! a i (+ (vector-ref a i) r)))

    (displayln (vector-ref a r))

With just 3 runs in hyperfine:

    ./racket/code 43 ran
      1.69 ± 0.03 times faster than ./racket/typed-code 43

[1]: racket/typed-racket#1420
benknoble added a commit to benknoble/bd-languages-race that referenced this issue Jan 3, 2025
A similar but naïve Typed Racket program is slower, though it can't be
demodded at the moment [1] so make the exe without running demod:

    #lang typed/racket

    (define length #e1e4)
    (define inner-loop (* 10 length))

    (define u (cast (string->number (vector-ref (current-command-line-arguments) 0))
                    Natural))
    (define r (random (add1 length) (make-pseudo-random-generator)))
    (: a (Vectorof Natural))
    (define a (make-vector length))

    (for ([i (in-range 0 length)])
      (for ([j : Natural (in-range 0 inner-loop)])
        (vector-set! a i (+ (vector-ref a i) (remainder j u))))
      (vector-set! a i (+ (vector-ref a i) r)))

    (displayln (vector-ref a r))

With just 3 runs in hyperfine:

    ./racket/code 43 ran
      1.69 ± 0.03 times faster than ./racket/typed-code 43

[1]: racket/typed-racket#1420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants