chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] [PATCH] small scrutinizer enhancement


From: Felix
Subject: Re: [Chicken-hackers] [PATCH] small scrutinizer enhancement
Date: Sat, 13 Oct 2012 09:45:18 +0200 (CEST)

From: Peter Bex <address@hidden>
Subject: Re: [Chicken-hackers] [PATCH] small scrutinizer enhancement
Date: Fri, 12 Oct 2012 21:19:59 +0200

> On Fri, Oct 12, 2012 at 07:21:52PM +0200, Felix wrote:
>> During flow-analysis, when a predicate is applied to a variable, the
>> variable is assumed to have the corresponding type in the consequent
>> branch of a conditional that depends on this predicate call. This
>> patch adds a small enhancement that, in case the variable type is
>> known to be a typeset (an "(or ...)" type), reduces the typeset by
>> removing those types that match the predicate-type:
>> 
>> (let ((a ...))  ; say "a" is of type "(or string number)"
>>   (if (number? a)
>>       ...           ; "a" is known to be of type "number"
>>       ...))         ; "a" is now known to be of type "string"  <- new
>> 
>> Here "number" matches the predicate type of "number?" ("number"),
>> is removed from the "(or string number)" type, and results in
>> type "string" for "a" in the second "if" branch.
> 
> I always assumed it already did that ;) Thanks for the patch, to
> actually make it so!  I've pushed it.

Thanks - turns out there was a bug: the type-matching of the typeset
elements must be "precise" to handle subtypes, consider:

(let ((a (the (or string number) ...)))
  (if (fixnum? a)
      ...                 ; a : fixnum
      ...))               ; a : (or number string) <- "number" is supertype of 
"fixnum"

I added this modification, plus a testcase in srutiny-tests-3.scm:

diff --git a/scrutinizer.scm b/scrutinizer.scm
index b4f4b3d..3cfbe93 100755
--- a/scrutinizer.scm
+++ b/scrutinizer.scm
@@ -456,7 +456,7 @@
                            (and-let* ((t2 (rec (third t))))
                              `(forall ,(second t) ,t2)))
                           ((or) 
-                           `(or ,@(remove (cut match-types <> pt typeenv) (cdr 
t))))
+                           `(or ,@(remove (cut match-types <> pt typeenv #t) 
(cdr t))))
                           (else #f))))))
        (simplify-type tnew)))


cheers,
felix



reply via email to

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