Further fixes in overlap checking.

Rhss of code dispatching on overlapping structs are no longer
considered dead, and as such, are now typechecked.

Had to fix a test that passed only because some not-really-dead code
was not being typechecked.

original commit: 4d5b50dee9e04aee167a7e04fbbe23526131fcad
This commit is contained in:
Vincent St-Amour 2010-07-16 18:16:51 -04:00
parent f3a78d1e10
commit 134fb72de1
4 changed files with 46 additions and 12 deletions

View File

@ -0,0 +1,16 @@
#;
(exn-pred 1)
#lang typed/scheme
(define-struct: parent ((x : Integer)))
(define-struct: (child1 parent) ((y : Integer)))
(define-struct: (child2 parent) ((y : Float)))
(: f (parent -> Integer))
(define (f x)
(cond [(child1? x) (+ "a" "b")] ; rhs was considered dead code
[(child2? x) 2]
[else (error "eh?")]))
(f (make-child1 1 2))
(f (make-child2 1 2.0))

View File

@ -0,0 +1,17 @@
#lang typed/scheme #:optimize
;; originally from nucleic3
;; cond on substructs, branches were considered dead
(define-struct: parent ((x : Integer)))
(define-struct: (child1 parent) ((y : Integer)))
(define-struct: (child2 parent) ((y : Float)))
(: f (parent -> Integer))
(define (f x)
(cond [(child1? x) 1]
[(child2? x) 2]
[else (error "eh?")]))
(f (make-child1 1 2))
(f (make-child2 1 2.0))

View File

@ -65,15 +65,15 @@
;; "bug" found - handling of empty heaps
(pdefine: (a) (find-min [pq : (priority-queue a)]) : a
(let ([h (heap pq)])
(if (heap:heap-node? h)
(elm (heap:find-min h))
(error "priority queue empty"))))
(if (heap:empty? h)
(error "priority queue empty")
(elm (heap:find-min h)))))
(pdefine: (a) (find-min-priority [pq : (priority-queue a)]) : number
(let ([h (heap pq)])
(if (heap:heap-node? h)
(pri (heap:find-min h))
(error "priority queue empty"))))
(if (heap:empty? h)
(error "priority queue empty")
(pri (heap:find-min h)))))
(pdefine: (a) (insert [x : a] [p : number] [pq : (priority-queue a)]) : (priority-queue a)
(make (heap:insert (cons p x) (heap pq))))
@ -84,9 +84,9 @@
(pdefine: (a) (delete-min [pq : (priority-queue a)]) : (priority-queue a)
(let ([h (heap pq)])
(if (heap:heap-node? h)
(make (heap:delete-min h))
(error "priority queue empty"))))
(if (heap:empty? h)
(error "priority queue empty")
(make (heap:delete-min h)))))
(pdefine: (a) (size [pq : (priority-queue a)]) : number

View File

@ -24,7 +24,8 @@
[(list (F: _) _) #t]
[(list _ (F: _)) #t]
[(list (Name: n) (Name: n*))
(overlap (resolve-once t1) (resolve-once t2))]
(or (free-identifier=? n n*)
(overlap (resolve-once t1) (resolve-once t2)))]
[(list (? Mu?) _) (overlap (unfold t1) t2)]
[(list _ (? Mu?)) (overlap t1 (unfold t2))]
[(list (Union: e) t)
@ -73,8 +74,8 @@
(and t2 (Struct: n* p* flds* _ _ _ _ _)))
(let ([p1 (if (Name? p) (resolve-name p) p)]
[p2 (if (Name? p*) (resolve-name p*) p*)])
(or (overlap t1 p2)
(overlap t2 p1)
(or (and p2 (overlap t1 p2))
(and p1 (overlap t2 p1))
(and (= (length flds) (length flds*))
(for/and ([f flds] [f* flds*])
(match* (f f*)