On Tue, Oct 01, 2002 at 02:01:42PM +0400, Alexey Dejneka wrote:
> Christophe Rhodes <csr21@...> writes:
> > > +(defun bug110 (x)
> > > + (declare (optimize (safety 2) (speed 3)))
> > > + (declare (type (or string stream) x))
> > > + (cond ((typep x 'string) 'string)
> > > + ((typep x 'stream) 'stream)
> > > + (t
> > > + 'none)))
> > Am I right in thinking that there is no type check within the
> > disassembly of BUG110 (because of SPEED dominating SAFETY),
> No. Type checking of arguments is performed in XEP, which is not shown
> by DISASSEMBLE. Use COMPILE-FILE and see the trace file.
Yeah, or DISASSEMBLE-MEMORY; I was speaking loosely.
> > and that the
> > type check is coming from the call to BUG110? If so, would
> > (locally (declare (optimize (speed 3) (safety 2)))
> > (bug110 0))
> > return NONE?
OK; I was wrong here for two reasons; one that Alexey has already
pointed out, and another is that the 'NONE clause is optimized away.
> > I would argue that this is the behaviour I would expect,
> > but I'd just like to confirm that that's the idea.
> Current policy is to perform type checking, perhaps weakened, unless
OK, but here comes the rub:
With (SAFETY 2) (SPEED 3), the type check is not weakened; however,
normally, the type test for (OR STRING STREAM) would be weakened to T
(and hence flushed), because T is the only convenient supertype (see
MAYBE-WEAKEN-CHECK in checkgen.lisp).
Why don't we get weakened type checking in the XEP with (SAFETY 2)
(SPEED 3), then? Well, it's because compilation of the XEP occurs with a
hardwired (SPEED 2) (DEBUG 1) to enable tail recursion (see MAKE-XEP in
locall.lisp); if the prevailing SAFETY optimization is also 2, then this
causes the test not to be weakened; if it is 1, then the test will be
weakened and flushed, so
(defun bug110-again (x)
(declare (optimize (speed 3) (safety 1)))
(declare (type (or string stream) x))
(cond ((typep x 'string) 'string)
((typep x 'stream) 'stream)
will effectively not check its argument type.
This isn't to say that your changes leading towards this aren't a good
one; it's much more to point out that there still exist circumstances
where problems can arise.
Personally, I'm in favour of some kind of weakened type checking with
effects like the above, but I may not be in a majority on this one.
http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge)