1

Let's take an example :

(declaim (inline myinlinefunc))

(defun myinlinefunc (a)
  (* a 2))

(defun myglobalfunc (z)
  (+ (myinlinefunc z) 3))

CL-USER> (trace myinlinefunc myglobalfunc)
(MYINLINEFUNC MYGLOBALFUNC)
CL-USER> (myglobalfunc 2)
  0: (MYGLOBALFUNC 2)
  0: MYGLOBALFUNC returned 7
7 (3 bits, #x7, #o7, #b111)

Is tracing the only way to be sure the compiler has inlined the function myinlinefunc into myglobalfunc ?

Is there a way to see the "expanded" myglobalfunc showing inline function calls effectively replaced by there definition, like a macroexpand ?

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Jérôme Radix
  • 10,285
  • 4
  • 34
  • 40
  • 4
    How about the [`DISASSEMBLE`](http://clhs.lisp.se/Body/f_disass.htm) function? That should show whether there's an explicit call to the function. – Barmar Mar 29 '23 at 15:03
  • Thanks @barmar, this is effectively a way to see what's actually compiled underneath. But is there a way to "expand" a function like macroexpand, to see its version with calls to inlined functions replaced by their definition ? – Jérôme Radix Mar 29 '23 at 15:12
  • 4
    I don't think so, that's not how inlining works. It's done by the compiler at the code generation level, not like macro expansion. – Barmar Mar 29 '23 at 15:15

1 Answers1

1

I would expect that the compiler might show you that. Typically an optimizing file compiler.

Example of a compiler note about code inlining using SBCL:

Take SBCL and compile the file with the right settings (speed = 3, ...). SBCL then prints a huge amount of compilation information. Among the huge amounts of output the compiler says:

;     (MYINLINEFUNC Z)
; --> BLOCK 
; ==>
;   (* A 2)
; 

This probably tells us about the expansion it uses.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346