Compiler can generate code it cannot load....
Patrick Stein
pat at nklein.com
Wed Sep 2 21:34:48 UTC 2015
This is a short program for which the compiler creates a file it cannot load. Save this program to a file, then try: (load (compile-file “this-file.lisp”))
;;; This program causes the ABCL compiler to generate code it cannot load.
;;;
;;; The code compiles and loads correctly if you do any of the following:
;;; * change BUFSIZE to be 'INTEGER instead of '(INTEGER 0 100)
;;; * delete the INLINE declaration for BUFFER-LENGTH
;;; * delete the FTYPE declaration for BUFFER-LENGTH
;;; * delete the TYPE declaration for NEW-CAPACITY
(deftype bufsize () '(integer 0 100))
(declaim (inline buffer-length)
(ftype (function () bufsize) buffer-length))
(defun buffer-length ()
(the bufsize 10))
(defun calculate-new-buffer-length (new-capacity)
(declare (type bufsize new-capacity))
(min (buffer-length) new-capacity))
As noted in the comment, it is very finicky. There are at least four ways this code could be slightly less-specific and then not trigger the bug. I tried it both with ABCL-1.3.1 and ABCL-1.3.2. The logs of the output are below.
I’d love to be able to say that I’m looking at the compiler now to try to figure out where it’s going wrong, but realistically, I’m not going to have time to delve into it myself, I’ve never really looked at the ABCL compiler before, and I suspect the problem is in the compiling but doesn’t show up until the loading… so it won’t be as easy as exploring the stack when the error shows up.
Thanks,
Patrick
Script started on Tue Sep 1 16:33:56 2015
bash-3.2$ cat compile-problem.lisp
;;; This program causes the ABCL compiler to generate code it cannot load.
;;;
;;; The code compiles and loads correctly if you do any of the following:
;;; * change BUFSIZE to be 'INTEGER instead of '(INTEGER 0 100)
;;; * delete the INLINE declaration for BUFFER-LENGTH
;;; * delete the FTYPE declaration for BUFFER-LENGTH
;;; * delete the TYPE declaration for NEW-CAPACITY
(deftype bufsize () '(integer 0 100))
(declaim (inline buffer-length)
(ftype (function () bufsize) buffer-length))
(defun buffer-length ()
(the bufsize 10))
(defun calculate-new-buffer-length (new-capacity)
(declare (type bufsize new-capacity))
(min (buffer-length) new-capacity))
bash-3.2$ ABCL_HOME=/usr/local/src/abcl-1.3.2 abcl
Armed Bear Common Lisp 1.3.2
Java 1.8.0_45 Oracle Corporation
Java HotSpot(TM) 64-Bit Server VM
Low-level initialization completed in 0.524 seconds.
Startup completed in 2.65 seconds.
Type ":help" for a list of available commands.
CL-USER(1): (load (compile-file "compile-problem.lisp"))
; Compiling /Users/pat/compile-problem.lisp ...
; (DEFTYPE BUFSIZE ...)
; (DECLAIM (INLINE BUFFER-LENGTH) ...)
; (DEFUN BUFFER-LENGTH ...)
; (DEFUN CALCULATE-NEW-BUFFER-LENGTH ...)
; Wrote /Users/pat/compile-problem.abcl (0.208 seconds)
java.lang.VerifyError: (class: org/armedbear/lisp/compile_problem_2, method: execute signature: (Lorg/armedbear/lisp/LispObject;)Lorg/armedbear/lisp/LispObject;) Unable to pop operand off an empty stack
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.armedbear.lisp.FaslClassLoader.loadFunction(FaslClassLoader.java:130)
at org.armedbear.lisp.FaslClassLoader$pf_get_fasl_function.execute(FaslClassLoader.java:165)
at org.armedbear.lisp.LispThread.execute(LispThread.java:832)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:582)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:577)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Load.faslLoadStream(Load.java:667)
at org.armedbear.lisp.Load$init_fasl.execute(Load.java:457)
at org.armedbear.lisp.LispThread.execute(LispThread.java:832)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:582)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Load.loadStream(Load.java:629)
at org.armedbear.lisp.Load.loadFileFromStream(Load.java:597)
at org.armedbear.lisp.Load.load(Load.java:224)
at org.armedbear.lisp.Load.load(Load.java:745)
at org.armedbear.lisp.Load$_load.execute(Load.java:693)
at org.armedbear.lisp.Symbol.execute(Symbol.java:852)
at org.armedbear.lisp.LispThread.execute(LispThread.java:894)
at org.armedbear.lisp.load_1.execute(load.lisp:33)
at org.armedbear.lisp.CompiledClosure.execute(CompiledClosure.java:98)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:575)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Lisp.eval(Lisp.java:538)
at org.armedbear.lisp.Primitives$pf__eval.execute(Primitives.java:345)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:575)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Lisp.progn(Lisp.java:709)
at org.armedbear.lisp.Primitives$sf_block.execute(Primitives.java:3742)
at org.armedbear.lisp.Lisp.eval(Lisp.java:530)
at org.armedbear.lisp.Lisp.progn(Lisp.java:709)
at org.armedbear.lisp.Closure.execute(Closure.java:220)
at org.armedbear.lisp.Closure.execute(Closure.java:148)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.Lisp$1.execute(Lisp.java:285)
at org.armedbear.lisp.Symbol.execute(Symbol.java:803)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.top_level_47.execute(top-level.lisp:407)
at org.armedbear.lisp.CompiledClosure.execute(CompiledClosure.java:89)
at org.armedbear.lisp.Symbol.execute(Symbol.java:793)
at org.armedbear.lisp.LispThread.execute(LispThread.java:798)
at org.armedbear.lisp.top_level_48.execute(top-level.lisp:415)
at org.armedbear.lisp.LispThread.execute(LispThread.java:798)
at org.armedbear.lisp.Interpreter.run(Interpreter.java:361)
at org.armedbear.lisp.Main$1.run(Main.java:48)
at java.lang.Thread.run(Thread.java:745)
Error loading /Users/pat/compile-problem.abcl at line 15 (offset 668)
#<THREAD "interpreter" {33E81276}>: Debugger invoked on condition of type ERROR
Compiled function can't be loaded: org.armedbear.lisp.compile_problem_2 from org.armedbear.lisp.Pathname at 2acec9eb
Restarts:
0: TOP-LEVEL Return to top level.
[1] CL-USER(2): 0
CL-USER(3): (quit)
bash-3.2$ ABCL_HOME=/usr/local/src/abcl-bin-1.3.1 abcl
Armed Bear Common Lisp 1.3.1
Java 1.8.0_45 Oracle Corporation
Java HotSpot(TM) 64-Bit Server VM
Low-level initialization completed in 0.471 seconds.
Startup completed in 2.651 seconds.
Type ":help" for a list of available commands.
CL-USER(1): (load (compile-file "compile-problem.lisp"))
; Compiling /Users/pat/compile-problem.lisp ...
; (DEFTYPE BUFSIZE ...)
; (DECLAIM (INLINE BUFFER-LENGTH) ...)
; (DEFUN BUFFER-LENGTH ...)
; (DEFUN CALCULATE-NEW-BUFFER-LENGTH ...)
; Wrote /Users/pat/compile-problem.abcl (0.199 seconds)
java.lang.VerifyError: (class: org/armedbear/lisp/compile_problem_2, method: execute signature: (Lorg/armedbear/lisp/LispObject;)Lorg/armedbear/lisp/LispObject;) Unable to pop operand off an empty stack
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at org.armedbear.lisp.FaslClassLoader.loadFunction(FaslClassLoader.java:130)
at org.armedbear.lisp.FaslClassLoader$pf_get_fasl_function.execute(FaslClassLoader.java:165)
at org.armedbear.lisp.LispThread.execute(LispThread.java:832)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:582)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:577)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Load.faslLoadStream(Load.java:667)
at org.armedbear.lisp.Load$init_fasl.execute(Load.java:457)
at org.armedbear.lisp.LispThread.execute(LispThread.java:832)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:582)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Load.loadStream(Load.java:629)
at org.armedbear.lisp.Load.loadFileFromStream(Load.java:597)
at org.armedbear.lisp.Load.load(Load.java:224)
at org.armedbear.lisp.Load.load(Load.java:745)
at org.armedbear.lisp.Load$_load.execute(Load.java:693)
at org.armedbear.lisp.Symbol.execute(Symbol.java:852)
at org.armedbear.lisp.LispThread.execute(LispThread.java:894)
at org.armedbear.lisp.load_1.execute(load.lisp:33)
at org.armedbear.lisp.CompiledClosure.execute(CompiledClosure.java:98)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:575)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Lisp.eval(Lisp.java:538)
at org.armedbear.lisp.Primitives$pf__eval.execute(Primitives.java:345)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.Lisp.evalCall(Lisp.java:575)
at org.armedbear.lisp.Lisp.eval(Lisp.java:540)
at org.armedbear.lisp.Lisp.progn(Lisp.java:709)
at org.armedbear.lisp.Primitives$sf_block.execute(Primitives.java:3742)
at org.armedbear.lisp.Lisp.eval(Lisp.java:530)
at org.armedbear.lisp.Lisp.progn(Lisp.java:709)
at org.armedbear.lisp.Closure.execute(Closure.java:220)
at org.armedbear.lisp.Closure.execute(Closure.java:148)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.Lisp$1.execute(Lisp.java:285)
at org.armedbear.lisp.Symbol.execute(Symbol.java:803)
at org.armedbear.lisp.LispThread.execute(LispThread.java:814)
at org.armedbear.lisp.top_level_47.execute(top-level.lisp:407)
at org.armedbear.lisp.CompiledClosure.execute(CompiledClosure.java:89)
at org.armedbear.lisp.Symbol.execute(Symbol.java:793)
at org.armedbear.lisp.LispThread.execute(LispThread.java:798)
at org.armedbear.lisp.top_level_48.execute(top-level.lisp:415)
at org.armedbear.lisp.LispThread.execute(LispThread.java:798)
at org.armedbear.lisp.Interpreter.run(Interpreter.java:361)
at org.armedbear.lisp.Main$1.run(Main.java:48)
at java.lang.Thread.run(Thread.java:745)
Error loading /Users/pat/compile-problem.abcl at line 15 (offset 668)
#<THREAD "interpreter" {3F8D7E88}>: Debugger invoked on condition of type ERROR
Compiled function can't be loaded: org.armedbear.lisp.compile_problem_2 from org.armedbear.lisp.Pathname at 28015d1d
Restarts:
0: TOP-LEVEL Return to top level.
[1] CL-USER(2): 0
CL-USER(3): (quit)
bash-3.2$ ccl --no-init
Welcome to Clozure Common Lisp Version 1.11-dev-r16393-trunk (DarwinX8664)!
CCL is developed and maintained by Clozure Associates. For more information
about CCL visit http://ccl.clozure.com. To enquire about Clozure's Common Lisp
consulting services e-mail info at clozure.com or visit http://www.clozure.com.
? (load (compile-file "compile-problem.lisp"))
#P"/Users/pat/compile-problem.dx64fsl"
? (quit)
bash-3.2$ sbcl --no-init
This is SBCL 1.2.3.13-3446e1a-dirty, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (load (compile-file "compile-problem.lisp"))
; compiling file "/Users/pat/compile-problem.lisp" (written 01 SEP 2015 04:33:38 PM):
; compiling (DEFTYPE BUFSIZE ...)
; compiling (DECLAIM (INLINE BUFFER-LENGTH) ...)
; compiling (DEFUN BUFFER-LENGTH ...)
; compiling (DEFUN CALCULATE-NEW-BUFFER-LENGTH ...)
; /Users/pat/compile-problem.fasl written
; compilation finished in 0:00:00.007
T
* (quit)
bash-3.2$ exit
Script done on Tue Sep 1 16:36:21 2015
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20150902/0a1e4d14/attachment-0001.html>
More information about the armedbear-devel
mailing list