[racket-dev] how to disable intra-module constant inlining?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu Jan 19 10:49:22 EST 2012

> If you compile "a.rkt" normally and set
> `compile-context-preservation-enabled' to #f for"b.rkt", then `f' will
> not be inlined (because inlining is disabled), but `c' will still be
> replaced with 10.


This is odd then, because I thought I had tried this yesterday and
still observed inlining.  Let me try again...

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang racket/base
(require compiler/zo-parse
         compiler/decompile)

(define (test b)
  (parameterize ([current-namespace (make-base-namespace)]
                 (compile-enforce-module-constants b))

    (eval (compile '(module foo-1 '#%kernel
                      (#%provide a)
                      (define-values (a) 'hello))))

    (define bytecode (compile '(module foo-2 '#%kernel
                                 (#%require 'foo-1)
                                 (display a)
                                 (newline))))
    (define op (open-output-bytes))
    (write bytecode op)
    (decompile (zo-parse (open-input-bytes (get-output-bytes op))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (test #t)
'(begin (module foo-2 .... (display 'hello) (newline)))
> (test #f)
'(begin (module foo-2 .... (display |_a@(quote foo-1)|) (newline)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


So maybe I'm hallucinating (again).  I confirm that
compile-enforce-module-constants is working here.  I'll need to look
at why it didn't appear as effective in the context of Whalesong;
perhaps I'd set up the parameterization incorrectly.


Thanks!

Posted on the dev mailing list.