~ chicken-core (chicken-5) 2ab58471a67b474197714aeb98a17a44b6ca8416
commit 2ab58471a67b474197714aeb98a17a44b6ca8416
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Sun Sep 25 15:26:04 2011 +0200
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Sun Sep 25 15:26:04 2011 +0200
simplified o-a-i, fallback to * for unbound typevars only in exact mode, fixed bug in build-expression-tree for typecase
diff --git a/scrutinizer.scm b/scrutinizer.scm
index 115b118d..176129b3 100755
--- a/scrutinizer.scm
+++ b/scrutinizer.scm
@@ -1015,19 +1015,15 @@
((and (pair? t2) (eq? 'or (car t2)))
(over-all-instantiations
(cdr t2)
- typeenv
- (lambda (t) (match1 t1 t))
- (lambda ()
- (if (or exact all)
- (every
- (cut match1 t1 <>)
- (cdr t2))
- #t))))
+ typeenv
+ (or exact all)
+ (lambda (t) (match1 t1 t))))
;; s.a.
((and (pair? t1) (eq? 'or (car t1)))
(over-all-instantiations
(cdr t1)
typeenv
+ #f
(lambda (t) (match1 t t2)))) ; o-a-i ensures at least one element matches
((and (pair? t1) (eq? 'forall (car t1)))
(match1 (third t1) t2)) ; assumes typeenv has already been extracted
@@ -1435,9 +1431,8 @@
(over-all-instantiations
(cdr t2)
typeenv
- (lambda (t) (test t1 t))
- (lambda ()
- (every (cut test t1 <>) (cdr t2)))))
+ #t
+ (lambda (t) (test t1 t))))
((and (eq? 'vector (car t1)) (eq? 'vector-of (car t2)))
(every (cute test <> (second t2)) (cdr t1)))
((and (eq? 'vector-of (car t1)) (eq? 'vector (car t2)))
@@ -1462,9 +1457,8 @@
(over-all-instantiations
(cdr t1)
typeenv
- (lambda (t) (test t t2))
- (lambda ()
- (every (cut test <> t2) (cdr t1)))))
+ #t
+ (lambda (t) (test t t2))))
((vector-of list-of) (test (second t1) (second t2)))
((pair) (every test (cdr t1) (cdr t2)))
((procedure)
@@ -2277,7 +2271,7 @@
;;; perform check over all typevar instantiations
-(define (over-all-instantiations tlist typeenv process #!optional (combine (constantly #t)))
+(define (over-all-instantiations tlist typeenv exact process)
(let ((insts '())
(anyinst #f)
(trail0 trail))
@@ -2306,15 +2300,17 @@
(all (map (lambda (var)
(cons
var
- (map (lambda (inst)
- (cond ((assq var inst) => cdr)
- (else '*)))
- insts)))
+ (append-map
+ (lambda (inst)
+ (cond ((assq var inst) => (o list cdr))
+ (exact '(*))
+ (else '())))
+ insts)))
vars)))
- ;;(dd " collected: ~s" all) ;XXX remove
+ (dd " collected: ~s" all) ;XXX remove
all))
- (dd " over-all-instantiations: ~s" tlist) ;XXX remove
+ (dd " over-all-instantiations: ~s exact=~a" tlist exact) ;XXX remove
;; process all tlist elements
(let loop ((ts tlist) (ok #f))
(cond ((null? ts)
@@ -2322,13 +2318,17 @@
(for-each
(lambda (i)
(set! trail (cons (car i) trail))
- (set-car! (cdr (assq (car i) typeenv)) `(or ,@(cdr i))))
+ (set-car! (cdr (assq (car i) typeenv))
+ (simplify-type `(or ,@(cdr i)))))
(collect))
- (combine))
+ #t)
(else #f)))
((process (car ts))
(restore)
(loop (cdr ts) #t))
+ (exact
+ (restore)
+ #f)
(else
(restore)
(loop (cdr ts) ok))))))
diff --git a/support.scm b/support.scm
index 299b92f8..cb95c0d6 100644
--- a/support.scm
+++ b/support.scm
@@ -595,7 +595,9 @@
,(walk (first subs))
,@(let loop ((types params) (bodies (cdr subs)))
(if (null? types)
- `((else ,(walk (car bodies))))
+ (if (null? bodies)
+ '()
+ `((else ,(walk (car bodies)))))
(cons (list (car types) (walk (car bodies)))
(loop (cdr types) (cdr bodies)))))))
((##core#call)
diff --git a/tests/typematch-tests.scm b/tests/typematch-tests.scm
index a1048f40..3e4b759a 100644
--- a/tests/typematch-tests.scm
+++ b/tests/typematch-tests.scm
@@ -211,3 +211,16 @@
(symbol 's)
(fixnum 'f)
((or fixnum symbol) 'sf))))
+
+(: f3 (forall (a) ((list-of a) -> a)))
+(define (f3 x) (car x))
+(define xxx '(1))
+
+(compiler-typecase (foo (the (or (vector-of fixnum) (list-of fixnum)) xxx))
+ (fixnum 'ok))
+
+(assert
+ (eq? 'ok
+ (compiler-typecase (list 123)
+ ((forall (a) (or (vector-of a) (list-of a))) 'ok)
+ (else 'not-ok))))
Trap