[Openmcl-devel] two portability issues
joswig at lisp.de
Sat Dec 20 21:12:25 UTC 2014
> Am 20.12.2014 um 21:37 schrieb Gary Byers <gb at clozure.com>:
> On 12/20/2014 10:53:40 AM, Rainer Joswig wrote:
>> I just looked a small benchmark someone wrote and tried to improve it.
>> The result is here:
>> https://gist.github.com/lispm/6066e1eeadf943910c47 <https://gist.github.com/lispm/6066e1eeadf943910c47>
>> The corresponding data file is here:
>> There were two issues I saw with CCL:
>> ** first issue: DEFSTRUCT defined type at compile time unknown? **
>> There is a structure declaration ROUTE via a DEFSTRUCT.
>> I wanted to use the type ROUTE in a LOOP later in the function
>> (defun get-longest-path (nodes node-id visited &aux (max 0))
>> (declare (optimize (speed 3) (space 0) (debug 0) (safety 0) (compilation-speed 0)
>> #+lispworks (fixnum-safety 0))
>> (fixnum max))
>> (setf (svref visited node-id) t)
>> (setf max (loop for neighbour of-type route in (svref nodes node-id) ; <— declaration
>> unless (svref visited (route-dest neighbour))
>> maximize (+ (the fixnum (route-cost neighbour))
>> (the fixnum (get-longest-path nodes
>> (route-dest neighbour)
>> #+lispworks fixnum))
>> (setf (svref visited node-id) nil)
>> The CCL compiler did not know about the type ROUTE, so I had to use EVAL-WHEN around the structure definition. Shouldn’t the compiler recognize the type at compile time? The ANSI CL documentation for DEFSTRUCT indicates that…
> Please read and try to understand section 220.127.116.11.1, then think about whether your understanding of the issues here is correct. I strongly suspect that it isn’t.
Okay, read it...
How about: http://www.lispworks.com/documentation/HyperSpec/Body/m_defstr.htm#defstruct <http://www.lispworks.com/documentation/HyperSpec/Body/m_defstr.htm#defstruct>
> If a defstruct form appears as a top level form, the compiler must make the structure type name recognized as a valid type name in subsequent declarations
My interpretation would be that a type declaration in a LOOP should be able to use a structure type, without compile-time evaluation.
like in the code here: (loop for neighbour of-type route in (svref nodes node-id) …
The CCL compiler complains about an unknown type ROUTE.
>> ** second issue: LOOP clause MAXIMIZE**
>> in above function there is a clause MAXIMIZE … FIXNUM .
>> In CCL (and several other implementations, with the exception of LispWorks) this causes that a wrong result (a negative number) is computed. Without the FIXNUM declaration the result is correct.
> Does it return the same result (perhaps more slowly) if the FIXNUM declaration is retained and the OPTIMIZE declaration is changed to something like (SAFETY 3) (SPEED 0) ?
The problem seems to appear without optimize declarations...
(defun get-longest-path (nodes node-id visited &aux (max 0))
(setf (svref visited node-id) t)
(setf max (loop for neighbour of-type route in (svref nodes node-id)
unless (svref visited (route-dest neighbour))
maximize (+ (the fixnum (route-cost neighbour))
(the fixnum (get-longest-path nodes
(setf (svref visited node-id) nil)
Safety 3 and Speed 0 takes a long time and returns the wrong result: -1152921504606837995
The expected result would have been 8981.
> Does the (non-portable, LispWorks-specific) (FIXNUM-SAFETY 0) declaration affect the result returned in LispWorks ?
>> Rainer Joswig
> ------quoted attachment------
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Openmcl-devel