[Chicken-users] scrutiny

2009-05-29 Thread felix winkelmann
Hello!


I have merged the recent work on the scrutiny branch into trunk (r14828).
Scrutiny is a lightweight local conservative (read: simple) flow analysis
pass over the internal representation of the code and performs a check on
argument-count/-types and results of calls to core library procedures.
Additionally, the number of result values is checked in various places.
Local variable bindings are taken into account and an attempt has been
made to provide useful error messages (which has only partially
succeeded).

When I write something from scratch, I usually go through a phase
of fixing typos and trivial errors (forgetting an pass an argument, etc.),
and to help out with this tedious work, the scrutiny feature was implemented.
Note that this is not an optimization, it is just for checking code correctness.

Running the scrutinizer on the core libraries and compiler has already
found two bugs:

Index: eval.scm
===
--- eval.scm(revision 14524)
+++ eval.scm(revision 14525)
@@ -1311,7 +1311,7 @@
   ((symbol? x) (##sys#slot x 1))
   ((number? x) (##sys#number-string x))
   (else (error invalid extension version x)) ) )
-   (if (and (list spec) (fx= 3 (length spec)))
+   (if (and (list? spec) (fx= 3 (length spec)))
(let* ((info (extension-information (cadr spec)))
  (vv (and info (assq 'version info))) )
 (unless (and vv (string=? (-string (car vv)) (-string (caddr 
spec

% Index: optimizer.scm
===
--- optimizer.scm   (revision 14527)
+++ optimizer.scm   (revision 14528)
@@ -299,7 +299,7 @@
((eq? '##core#variable (node-class k)))
(kvar (first (node-parameters k)))
(lval (and (not (test kvar 'unknown)) 
(test kvar 'value)))
-   (eq? '##core#lambda (node-class lval))
+   ((eq? '##core#lambda (node-class lval)))
(llist (third (node-parameters lval)))
((or (test (car llist) 'unused)
 (and (not (test (car llist) 
'references))

It is likely that the type-database still contains some bugs, so if you
try it out and get strange warnings, please mail them to me.

Usage is simple: just pass -scrutinize (or -S in csc).


cheers,
felix


___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] scrutiny

2009-05-29 Thread Peter Bex
On Fri, May 29, 2009 at 04:18:55PM +0200, felix winkelmann wrote:
 Hello!
 
 I have merged the recent work on the scrutiny branch into trunk (r14828).
 Scrutiny is a lightweight local conservative (read: simple) flow analysis
 pass over the internal representation of the code and performs a check on
 argument-count/-types and results of calls to core library procedures.
 Additionally, the number of result values is checked in various places.

This is really great!

 It is likely that the type-database still contains some bugs, so if you
 try it out and get strange warnings, please mail them to me.

The one thing that I keep getting when I compile
is warnings that procedures return a different number of arguments in
branches like this:

(if (number? foo)
(values foo (add1 foo))
(error foo is not a number))

I think procedures like ERROR, RAISE etc that can invoke different
continuations should probably be treated specially.

Also, it gives errors for each branch of a COND:

(cond ((number? foo) (values foo (add1 foo)))
  ((string? foo) (values foo (string-append foo  etc)))
  (else (error blah)))

This is a bit annoying in 9p for example, where there's a procedure
with 7 cases and one error in the ELSE branch, it gives 7 warnings :)

 Usage is simple: just pass -scrutinize (or -S in csc).

Why is it not enabled by default?  It only issues warnings, so even if
it's wrong, it'll still compile the code properly...

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music.
-- Donald Knuth


pgptsUSYbM914.pgp
Description: PGP signature
___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users