[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-hackers] [PATCH] smash types in implicit global type declar
From: |
Peter Bex |
Subject: |
Re: [Chicken-hackers] [PATCH] smash types in implicit global type declarations |
Date: |
Thu, 21 Jun 2012 21:31:56 +0200 |
User-agent: |
Mutt/1.4.2.3i |
On Tue, Jun 19, 2012 at 08:27:01PM +0200, Felix wrote:
> The attached patch fixes a bug in the scrutinizer that may cause "implicit"
> type declarations for global variables to be incorrect. An example:
>
> (declare (block)) ; globals are known
> (define foo (make-vector 100 #f)) ; foo is assumed to be "(vector-of
> boolean)"
> (vector-set! foo 0 99)
> (print (+ (vector-ref foo 0) 1)) ; triggers warning
>
> The flow-analysis "smashes" known type information for variables holding
> mutable data, but did not do so for globals with known values (compiling
> in block- or local-mode or using modules). With this patch it does.
Thanks, looks good. Pushed.
There's one thing I don't completely understand: When I change this test
so the variable is local (in a LET) instead of global (as a DEFINE), it
fails when I remove the vector-set! (as the scrutinizer correctly infers
it's a vector of booleans), but when it's defined global without the
vector-set! it still succeeds.
Example:
(define vec (make-vector 10 #f))
;; With this commented out, it still succeeds since the vector is smashed
;;(vector-set! vec 0 99)
(assert
(compiler-typecase vec
((vector-of boolean) #f)
(vector #t)))
;;;; Versus:
(let ((vec (make-vector 10 #f)))
;; With this commented out, the test fails: the scrutinizer knows it's
;; not modified so it can keep the (vector-of boolean) type.
;;(vector-set! vec 0 99)
(assert
(compiler-typecase vec
((vector-of boolean) #f)
(vector #t))))
How do globals in block mode differ from locals?
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