chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-hackers] [PATCH] Fix list-ref type derivation for smashed lists


From: Peter Bex
Subject: [Chicken-hackers] [PATCH] Fix list-ref type derivation for smashed lists [was: Re: [PATCH] A few small performance and scrutiny warning improvements to assignments]
Date: Sun, 24 Jul 2016 20:32:31 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, Jul 14, 2016 at 09:08:57PM +0200, Peter Bex wrote:
> Patch 0003 is a simple modification based on the preceding one: it
> gives a scrutiny warning when you try to set or ref a vector at an
> index that is known not to exist.  For completeness, I also did this
> for list-ref, list-tail, take and drop.

There's a small problem with this: it doesn't deal well with lists
constructed from lists of smashed components:

$ cat list-ref-test.scm
(let ((l1 (list 'a 'b c)))
  (define (something) (print l1))
  (let ((l2 (cons 'd l1)))
    (define (fourth) (list-ref l2 4))
    (print (fourth))))

$ csc -O3 list-ref-test.scm

Warning: in toplevel procedure `fourth':
  (list-ref-test.scm:4) in procedure call to `list-ref', index 4 out of range 
for list of type (pair symbol (or pair null))

The attached patch fixes this by only allowing this specialisation
for lists that are known to be proper.  This means anything that
ends with a smashed component, which is (or pair null), it will not
be considered to be a known proper list, so the optimisation is skipped.

I decided that it's still useful to warn on these unknown lists when
list-ref receives a negative index because that's never valid.

So, I split the check in two: first check for negative index, then
perform the already existing check, but only if the list is known to
be a proper list.

Cheers,
Peter

Attachment: 0001-Do-not-warn-for-out-of-range-indices-into-possibly-s.chicken-5.patch
Description: Text Data

Attachment: 0001-Do-not-warn-for-out-of-range-indices-into-possibly-s.master.patch
Description: Text Data

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]