From: Klaus Weidner
Subject: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <6q1Re.8624$c95.1188@fe11.news.easynews.com>
Hello,

is there an easy way to recompile a set of Lisp files with specific
optimization settings? For example, let's say I hit a bug in an ASDF packaged
library and don't get a useful backtrace since it's been compiled with minimal
debugging, so I'd like to recompile it with other optimization switches without
touching the source.

What I'd like to be able to do is something similar to the following:

  (asdf:oos 'asdf:recompile-op :cl-foo-library
            :optimize-speed 0 :optimize-debug 3)

which would recompile everything using (declare (optimize (speed 0) (debug 3))).

Currently the only way I know to change it requires putting a declaim line at
the top of each source file, which is messy. Since this sounds like a fairly
typical scenario I'm sure somebody has an elegant solution for this, but a bit
of googling didn't help me find it... I'll have a shot at hacking it into asdf
myself if there's no existing solution.

As a side note, isn't anyone else annoyed by the overly verbose syntax
for loading packages using asdf? I'm using the following macro:

(defmacro asdf::use (&rest pkgs)
  `(eval-when (:compile-toplevel :load-toplevel :execute)
    ,@(loop for pkg in pkgs 
	    collect `(asdf:oos 'asdf:load-op ,pkg))))

This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
packages.

Or put this line at the top of a lisp file to make loading it "just work"
instead of needing special incantations, which is really nice for "#!"
executable Lisp files. (Yes, this was inspired by the Perl module facility...)

For example:

	#!/usr/bin/clisp -C

	(asdf:use :port)

	(port:run-prog "/bin/ls")

This would require the following using plain ASDF:

	#!/usr/bin/clisp -C

	(eval-when (:compile-toplevel :load-toplevel :execute)
	  (asdf:oos 'asdf:load-op :port))

	(port:run-prog "/bin/ls")

I'm sure this verbosity may be a factor why Lisp is less than popular as a
quick scripting solution...

-Klaus

From: John
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <slrndh9fq4.e02.MGYF9fXO@mailinator.com>
On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
>  (defmacro asdf::use (&rest pkgs)
>    `(eval-when (:compile-toplevel :load-toplevel :execute)
>      ,@(loop for pkg in pkgs 
>  	    collect `(asdf:oos 'asdf:load-op ,pkg))))
> 
>  This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
>  packages.

I guess that's a little shorter than:

  (require 'cl-ppcre)
  (require 'xmls)

but not by much.
From: drewc
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <YE3Re.46263$Hk.42831@pd7tw1no>
John wrote:
> On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
> 
>> (defmacro asdf::use (&rest pkgs)
>>   `(eval-when (:compile-toplevel :load-toplevel :execute)
>>     ,@(loop for pkg in pkgs 
>> 	    collect `(asdf:oos 'asdf:load-op ,pkg))))
>>
>> This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
>> packages.
> 
> 
> I guess that's a little shorter than:
> 
>   (require 'cl-ppcre)
>   (require 'xmls)
> 
> but not by much.
> 

I kinda like : (mapcar #'require '(cl-ppcre xmls))

drewc

-- 
Drew Crampsie
drewc at tech dot coop
"Never mind the bollocks -- here's the sexp's tools."
	-- Karl A. Krueger on comp.lang.lisp
From: Klaus Weidner
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <ld8Re.14821$c95.4483@fe11.news.easynews.com>
On 2005-08-30, John <········@mailinator.com> wrote:
> On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
>>  This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
>>  packages.
>
> I guess that's a little shorter than:
>
>   (require 'cl-ppcre)
>   (require 'xmls)
>
> but not by much.

That would be nice if it worked consistently, but on my Debian system it only
appears to be supported for SBCL. It doesn't work for CLISP, CMUCL, and GCL.
How do other CL dialects handle "require"? (It's deprecated and marked as
implementation dependent in the Hyperspec, so that doesn't help here...)

My point is that (as far as I know) making "require" work consistently would
need modifications to each Lisp environment individually (and may not be easily
possible since the language doesn't allow redefining functions in the CL
package), while (asdf:use) could be made to work within ASDF itself, so it
would be easier to make consistent, especially since it's such a simple change.

-Klaus
From: GP lisper
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <1125465124.bf44cc72aedecb555cf3f76b25dc3d11@teranews>
On Wed, 31 Aug 2005 02:02:57 GMT, <········@pobox.com> wrote:
>
>
> On 2005-08-30, John <········@mailinator.com> wrote:
>> On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
>>>  This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
>>>  packages.
>>
>> I guess that's a little shorter than:
>>
>>   (require 'cl-ppcre)
>>   (require 'xmls)
>>
> That would be nice if it worked consistently, but on my Debian system it only
> appears to be supported for SBCL. It doesn't work for CLISP, CMUCL, and GCL.
> How do other CL dialects handle "require"?

Works in ECL, and if you look at Cliki, works in CMUCL.  There is
probably a mod to CLISP someplace.


-- 
Program A uses CLOS, Program B is implemented with structs, leading
to a fourfold increase in execution speed.  --J. B. Heimatseiten
From: Thomas F. Burdick
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <xcvslwqmsm4.fsf@conquest.OCF.Berkeley.EDU>
Klaus Weidner <········@pobox.com> writes:

> On 2005-08-30, John <········@mailinator.com> wrote:
> > On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
> >>  This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
> >>  packages.
> >
> > I guess that's a little shorter than:
> >
> >   (require 'cl-ppcre)
> >   (require 'xmls)
> >
> > but not by much.
> 
> That would be nice if it worked consistently, but on my Debian system it only
> appears to be supported for SBCL. It doesn't work for CLISP, CMUCL, and GCL.
> How do other CL dialects handle "require"? (It's deprecated and marked as
> implementation dependent in the Hyperspec, so that doesn't help here...)
> 
> My point is that (as far as I know) making "require" work consistently would
> need modifications to each Lisp environment individually (and may not be easily
> possible since the language doesn't allow redefining functions in the CL
> package), while (asdf:use) could be made to work within ASDF itself, so it
> would be easier to make consistent, especially since it's such a simple change.

Although it's not portable, you could do something like this in your init files:

  (let ((cl-require #'require))
    (setf (symbol-function 'require)
          (lambda (name &optional pathnames)
            (let ((sys (and (null pathnames)
                            (asdf:find-system name nil))))
              (if sys
                  (asdf:oos 'asdf:load-op sys)
                  (funcall cl-require name pathnames))))))

Then bug the offending implementors to support asdf via require so you
can rid yourself of that awefulness :-)

(Alternately, you can just use SLIME's ,load-system command)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | Free Mumia Abu-Jamal! |
     ,--'    _,'   | Abolish the racist    |
    /       /      | death penalty!        |
   (   -.  |       `-----------------------'
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: John
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <slrndhbl04.jaj.Oto8rZXD@mailinator.com>
On 2005-08-31, Klaus Weidner <········@pobox.com> wrote:
>  On 2005-08-30, John <········@mailinator.com> wrote:
> > On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
> >>  This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
> >>  packages.
> >
> > I guess that's a little shorter than:
> >
> >   (require 'cl-ppcre)
> >   (require 'xmls)
> >
> > but not by much.
> 
>  That would be nice if it worked consistently, but on my Debian system it only
>  appears to be supported for SBCL. It doesn't work for CLISP, CMUCL, and GCL.
>  How do other CL dialects handle "require"? (It's deprecated and marked as
>  implementation dependent in the Hyperspec, so that doesn't help
here...)

I only use sbcl and cmucl. It works out of the box on sbcl and works on
cmucl with the following in my .cmucl-init:

  (defun my-require-asdf-loader (name)
    (not (asdf:operate 'asdf:load-op (string-downcase name))))
  (nconc ext:*module-provider-functions* (list #'my-require-asdf-loader))

If it wasn't as easy to get it to work on other lisp implementations I
would be very surprised.
From: Marco Antoniotti
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <MCkRe.67$DJ5.72405@typhoon.nyu.edu>
John wrote:
> On 2005-08-31, Klaus Weidner <········@pobox.com> wrote:
> 
>> On 2005-08-30, John <········@mailinator.com> wrote:
>>
>>>On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
>>>
>>>> This way, (asdf::use :cl-ppcre :xmls) works interactively to load multiple
>>>> packages.
>>>
>>>I guess that's a little shorter than:
>>>
>>>  (require 'cl-ppcre)
>>>  (require 'xmls)
>>>
>>>but not by much.
>>
>> That would be nice if it worked consistently, but on my Debian system it only
>> appears to be supported for SBCL. It doesn't work for CLISP, CMUCL, and GCL.
>> How do other CL dialects handle "require"? (It's deprecated and marked as
>> implementation dependent in the Hyperspec, so that doesn't help
> 
> here...)
> 
> I only use sbcl and cmucl. It works out of the box on sbcl and works on
> cmucl with the following in my .cmucl-init:
> 
>   (defun my-require-asdf-loader (name)
>     (not (asdf:operate 'asdf:load-op (string-downcase name))))
>   (nconc ext:*module-provider-functions* (list #'my-require-asdf-loader))
> 
> If it wasn't as easy to get it to work on other lisp implementations I
> would be very surprised.

Be prepared to be surprised.  The EXT:*MODULE-PROVIDER-FUNCTION* is not 
standard.  ECL and CLISP may be catching up, but I doubt that the 
commercial implementations have made such change.

Cheers
--
Marco
From: Juanjo
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <1125504946.226225.118530@g47g2000cwa.googlegroups.com>
John wrote:
> I only use sbcl and cmucl. It works out of the box on sbcl and works on
> cmucl with the following in my .cmucl-init:
>   (defun my-require-asdf-loader (name)
>     (not (asdf:operate 'asdf:load-op (string-downcase name))))
>   (nconc ext:*module-provider-functions* (list #'my-require-asdf-loader))

Marco Antioniotti wrote:
> Be prepared to be surprised.  The EXT:*MODULE-PROVIDER-FUNCTION* is
> not standard.

ECL's implementation of REQUIRE (contributed by J. Stecklina) supports
the above code.

Juanjo
From: Marco Antoniotti
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <xGlRe.68$DJ5.73353@typhoon.nyu.edu>
Juanjo wrote:
> John wrote:
> 
>>I only use sbcl and cmucl. It works out of the box on sbcl and works on
>>cmucl with the following in my .cmucl-init:
>>  (defun my-require-asdf-loader (name)
>>    (not (asdf:operate 'asdf:load-op (string-downcase name))))
>>  (nconc ext:*module-provider-functions* (list #'my-require-asdf-loader))
> 
> 
> Marco Antioniotti wrote:
> 
>>Be prepared to be surprised.  The EXT:*MODULE-PROVIDER-FUNCTION* is
>>not standard.
> 
> 
> ECL's implementation of REQUIRE (contributed by J. Stecklina) supports
> the above code.
> 

Thanks Juanio

turns out I have been toying around with ECLS recently and lo and 
behold, after having posted the message, I noticed it in ECL.

This means that MK:DEFSYSTEM will also work with REQUIRE on ECL out of 
the box (in CVS)

Cheers
--
Marco
From: Juanjo
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <1125563542.868903.147250@g43g2000cwa.googlegroups.com>
Marco Antoniotti wrote:
> This means that MK:DEFSYSTEM will also work with REQUIRE on ECL out of
> the box (in CVS)

:-) Good! Now it is only time for somebody to come up with a small
routine that, up from a system definition, builds a unified FASL, DLL
or executable, using ECL's facilities. It shouldn't be too difficult.

Juanjo
From: Klaus Weidner
Subject: Re: ASDF: optimization settings and other enhancements
Date: 
Message-ID: <PwKVe.63329$j34.59570@fe07.news.easynews.com>
On 2005-08-30, Klaus Weidner <········@pobox.com> wrote:
> is there an easy way to recompile a set of Lisp files with specific
> optimization settings? For example, let's say I hit a bug in an ASDF packaged
> library and don't get a useful backtrace since it's been compiled with minimal
> debugging, so I'd like to recompile it with other optimization switches without
> touching the source.
>
> What I'd like to be able to do is something similar to the following:
>
>   (asdf:oos 'asdf:recompile-op :cl-foo-library
>             :optimize-speed 0 :optimize-debug 3)
>
> which would recompile everything using (declare (optimize (speed 0) (debug 3))).

Replying to myself after a bit of hyperspec reading and experimenting...

The following appears to do the job (as long as the source files being compiled
don't explicitly override the optimization settings using declare or declaim):

        (proclaim '(optimize (debug 3) (speed 0)))
        (asdf:oos 'asdf:load-op :cl-foo-library :force t)

I can't find an obvious way to read the current values back out of the global
environment, CLTL mentions (declaration-information 'optimize) but that doesn't
seem to have made it into ANSI CL. So I guess it's best to use a helper
function that maintains its own state if you want to keep track of the current
settings, i.e. for the SLIME GUI.

-Klaus