Summary

(scrutinizer) Types for global variables are not refined by predicates

Metadata

Description

 (: g1 (list-of fixnum))
 (define g1 '())
 ;; Aliased global gets refined
 (let ((a g1))
   (compiler-typecase a ((list-of fixnum) 1))
   (if (null? a)
       (compiler-typecase a (null 1))
       (compiler-typecase a ((not null) 1))))
 
 (: g2 (list-of fixnum))
 (define g2 '())
 (if (null? g2)
     (compiler-typecase g2 (null 1)) ;; <- error
     (compiler-typecase g2 ((pair fixnum (list-of fixnum)) 1)))
 
 ;; $ csc -O3 globals.scm
 ;; 
 ;; Error: at toplevel:
 ;;   (globals.scm:13) no clause applies in `compiler-typecase' for expression of type `(list-of fixnum)':
 ;;     null

I don't think this is an issue of non-local mutation (e.g. from other threads). You should use mutexes or some other measures to prevent mutation while, you're working on a global.

Changes and comments

[2018-06-15 09:09:35 UTC] megane wrote:

Forgot to mention that I have a patch for this, if you think this should be fixed.

[2019-04-07 12:23:24 UTC] sjamaan changed milestone from 5.1 to 5.2

[2019-04-07 12:23:24 UTC] sjamaan wrote:

Getting ready for 5.1, moving tickets which won't make it in to 5.2.

[2019-08-25 15:57:02 UTC] felix wrote:

You can only assume that "null" is valid for g2 directly after the predicate test - any global procedure call between predicate and use could jump back via a continuation, making the assumption invalid. I don't recall, whether the scrutinizer takes this into account. Does it? If yes, then I thunk your request makes sense.

[2019-11-07 18:22:40 UTC] megane changed milestone from 5.2 to 5.3

[2019-11-07 18:22:40 UTC] megane wrote:

Not for 5.2

[2021-04-12 13:44:31 UTC] sjamaan changed milestone from 5.3 to 5.4

[2023-11-06 22:12:45 UTC] felix changed milestone from 5.4 to someday