Can compiled and uncompiled versions of a single function exist in a collection?

Suppose

  • I install a collection via raco pkg install.
  • I add a printf to the body of one function within the collection that's called at various places in the same collection.
  • I don't run raco setup after modifying the function.

At this point could it be that some calls to the function in the collection are actually calls to an older, compiled version while others are calls to the new, uncompiled version?

4 Likes

No, I believe it should be the case that all calls are made to the new version of the function. Do you have an example where this doesn't appear to be the case?

I'm using Racket v8.3 [cs] on Linux 5.4 on Chrome OS.

Here's a specific example.

  1. Perform a fresh install of the typed-racket-lib package using raco

  2. Make the changes marked with New to the file
    typed-racket-lib/typed-racket/env/global-env.rkt

;; free-id-table from id -> type or Box[type]
;; where id is a variable, and type is the type of the variable
;; if the result is a box, then the type has not actually been defined, just registered
(define the-mapping (make-free-id-table))

;; ~~~~~ New ~~~~~
(printf "Size of the-mapping is ~a~n"
        (free-id-table-count the-mapping))

(define register-type-first-call? #t)
;; ~~~~~~~~~~~~~~~

;; add a single type to the mapping
;; identifier type -> void
(define (register-type id type)
  ;; ~~~~~ New ~~~~~
  (when register-type-first-call?
    (printf "Size of the-mapping is ~a~n"
        (free-id-table-count the-mapping))
    (set! register-type-first-call? #f))
  ;; ~~~~~~~~~~~~~~~
  (free-id-table-set! the-mapping id type))
  1. Run this code.
#lang typed/racket/base
    
(define-type Z Integer)

Check the output.

Size of the-mapping is 0
Size of the-mapping is 146

If we assume that register-type is the only way to grow the-mapping then it looks like a bunch of printf statements didn't fire.

  1. Modify the file typed-racket-lib/typed-racket/typecheck/tc-structs.rkt. Add this line immediately after the provide block at the start of the file and before (define-syntax-class parent ...)
(printf "I'm in tc-structs.rkt~n")
  1. Run the program from Step 3 again. This time the output is:
Size of the-mapping is 0
I'm in tc-structs.rkt
Size of the-mapping is 0

I suspect that during Step 3, calls to register-type in tc-structs.rkt - such as in the function tc/builtin-struct - actually referred to a compiled version of the old register-type function. One without the printf.