Skip to content

On CCL, compiler-macros are invoked before loading magicl/ext-blas but not after it #178

Open
@digikar99

Description

@digikar99

EDIT: I'm able to boil down the issue to the loading of src/bindings/blas-cffi.lisp, and in particular:

(COMMON-LISP:DECLAIM
 (COMMON-LISP:OPTIMIZE (COMMON-LISP:SPEED 0) COMMON-LISP:SAFETY
  COMMON-LISP:DEBUG COMMON-LISP:COMPILATION-SPEED))

CLHS states:

As with other defining macros, it is unspecified whether or not the compile-time side-effects of a declaim persist after the file has been compiled.

So, it seems the responsibility to revert back the compilation policy to as they were before the file was loaded rests with the file. introspect-environment:policy-quality might be handy:

CL-USER> (mapcar (lambda (quality)
                   (cons quality (introspect-environment:policy-quality quality)))
                 '(speed safety debug compilation-speed))
((SPEED . 1) (SAFETY . 1) (DEBUG . 1) (COMPILATION-SPEED . 1))
CL-USER> (ql:quickload "magicl/ext-blas")
To load "magicl/ext-blas":
  Load 1 ASDF system:
    magicl/ext-blas
; Loading "magicl/ext-blas"

("magicl/ext-blas")
CL-USER> (mapcar (lambda (quality)
                   (cons quality (introspect-environment:policy-quality quality)))
                 '(speed safety debug compilation-speed))
((SPEED . 0) (SAFETY . 3) (DEBUG . 3) (COMPILATION-SPEED . 3))

ORIGINAL POST:

This definitely seems like a weird issue, but:

CL-USER> (defun fun () 'runtime-fun)
(define-compiler-macro fun () (print :invoked) ''compile-time-fun)
(defun bar () (fun))

:INVOKED
BAR
CL-USER> (ql:quickload "magicl/ext")
To load "magicl/ext":
  Load 1 ASDF system:
    magicl/ext
; Loading "magicl/ext"

("magicl/ext")
CL-USER> (defun fun () 'runtime-fun)
(define-compiler-macro fun () (print :invoked) ''compile-time-fun)
(defun bar () (fun))

:INVOKED
BAR
CL-USER> (ql:quickload "magicl/ext-blas")
To load "magicl/ext-blas":
  Load 1 ASDF system:
    magicl/ext-blas
; Loading "magicl/ext-blas"

("magicl/ext-blas")
CL-USER> (defun fun () 'runtime-fun)
(define-compiler-macro fun () (print :invoked) ''compile-time-fun)
(defun bar () (fun))
BAR
CL-USER> (bar)
RUNTIME-FUN
CL-USER> (lisp-implementation-version)
"Version 1.12.1 (v1.12.1) LinuxX8664"
CL-USER> (lisp-implementation-type)
"Clozure Common Lisp"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions