quil-lang / quilc

The optimizing Quil compiler.
Apache License 2.0
454 stars 73 forks source link

cl-quil/tools now gets compile-file-error in SBCL due to warning with certain compiler settings #737

Open ghost opened 2 years ago

ghost commented 2 years ago

In SBCL shen you declare compiler policy like so

(sb-ext:restrict-compiler-policy 'space 0 0)

and build like so

(asdf:load-system :cl-quil/tools-tests)

you get this compiler warning

; compiling file "/Users/mhdavid/repos/mhdavid-hrl-quilc/src/tools/circuit-diagram.lisp" (written 05 OCT 2021 05:53:02 PM):

; file: /Users/mhdavid/repos/mhdavid-hrl-quilc/src/tools/circuit-diagram.lisp
; in: DEFGENERIC RESOLVE-QUBIT-POSITIONS
;     (SORT
;      (CL-QUIL.TOOLS::QUBITS-IN-APPLICATIONS-OR-MEASUREMENTS
;       CL-QUIL.TOOLS::INSTRS)
;      #'<)
; 
; caught WARNING:
;   Derived type of SEQUENCE is
;     (VALUES VECTOR &OPTIONAL),
;   conflicting with its asserted type
;     LIST.
;   See also:
;     The SBCL Manual, Node "Handling of Types"

With typical environment settings, this causes ASDF to stop the build. You get thrown into the debugger looking something like this:

COMPILE-FILE-ERROR while
compiling #<CL-SOURCE-FILE "cl-quil/tools" "circuit-diagram">
   [Condition of type UIOP/LISP-BUILD:COMPILE-FILE-ERROR]

Restarts:
 0: [RETRY] Retry compiling #<CL-SOURCE-FILE "cl-quil/tools" "circuit-diagram">.
 1: [ACCEPT] Continue, treating compiling #<CL-SOURCE-FILE "cl-quil/tools" "circuit-diagram"> as having been successful.
 2: [RETRY] Retry ASDF operation.
 3: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the configuration.
 4: [RETRY] Retry ASDF operation.
 5: [CLEAR-CONFIGURATION-AND-RETRY] Retry ASDF operation after resetting the configuration.
 --more--

Backtrace:
  0: (UIOP/LISP-BUILD:CHECK-LISP-COMPILE-RESULTS NIL T T "~/asdf-action::format-action/" ((#<ASDF/LISP-ACTION:COMPILE-OP > . #<ASDF/LISP-ACTION:CL-SOURCE-FILE "cl-quil/tools" "circuit-diagram">)))
ghost commented 2 years ago

I believe I narrowed this down to this newish code by @kilimanjaro: https://github.com/quil-lang/quilc/blob/846f8168ef86646a0fce6f5d649e82d8275122fd/src/tools/circuit-diagram.lisp#L350-L356

I believe this is caused by this rather longstanding issue with SBCL: https://bugs.launchpad.net/sbcl/+bug/309115

stylewarning commented 2 years ago

It looks like a way to muffle the warning is to just DECLARE (NOTINLINE SORT). Haven't tried it though.

ghost commented 2 years ago

This is just recently fixed in master in SBCL, so can probably wait. Fixed in this commit

stylewarning commented 2 years ago

Was the timing of the SBCL fix a coincidence?

ghost commented 2 years ago

Was the timing of the SBCL fix a coincidence?

Not exactly. Some complaining on the sbcl-devel list helped inspire it.