[Sbcl-help] Can SBCL detect side-effects of a block?

1 view
Skip to first unread message

Daniel Nagy

unread,
May 27, 2023, 2:11:00 PM5/27/23
to Sbcl...@lists.sourceforge.net
Hello,

I wanted to ask whether SBCL is able to determine side-effect free-ness
on a per-block basis. For example in:

(defun foo ()
(declare (optimize (speed 3) (safety 0)))
(loop for x from 0 to 1000000000 sum x)
nil)

The loop expands of course to something like `(block nil ...)`. If you
disassemble that function you can still see the loop and therefore the
function runs rather slow.

Unless I am unaware of some common lisp implicit behavior, I would
argue, that this function and the block, that the loop expands to,
cannot produce side effects and therefore will always return nil. Would
it be correct of me to assume, that the compiler could have optimized
the block away?

I don't ask because I think code like this gets written by hand very
often. But through macro expansion, I could imagine some of the
generated blocks are not always being used. Could this be an
optimization opportunity?

Thank you,
Daniel


_______________________________________________
Sbcl-help mailing list
Sbcl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help
Reply all
Reply to author
Forward
0 new messages