diff --git a/collects/typed-scheme/types/subtype.rkt b/collects/typed-scheme/types/subtype.rkt index c182d8752c..e76654ceec 100644 --- a/collects/typed-scheme/types/subtype.rkt +++ b/collects/typed-scheme/types/subtype.rkt @@ -195,6 +195,13 @@ [else (make-arr (apply map (lambda args (make-Union (sort args type List[(cons Number Number)] ;; potentially raises exn:subtype, when the algorithm fails @@ -236,6 +263,18 @@ [((Value: v) (Base: _ _ pred _)) (if (pred v) A0 (fail! s t))] ;; tvars are equal if they are the same variable [((F: t) (F: t*)) (if (eq? t t*) A0 (fail! s t))] + ;; Avoid needing to resolve things that refer to different structs. + ;; Saves us from non-termination + ;; Must happen *before* the sequence cases, which sometimes call `resolve' in match expanders + [((or (? Struct? s1) (NameStruct: s1)) (or (? Struct? s2) (NameStruct: s2))) + (=> unmatch) + (cond [(unrelated-structs s1 s2) + (dprintf "found unrelated structs: ~a ~a\n" s1 s2) + (fail! s t)] + [else (unmatch)])] + ;; just checking if s/t is a struct misses recursive/union/etc cases + [((? (lambda (_) (eq? ks 'struct))) (Base: _ _ _ _)) (fail! s t)] + [((Base: _ _ _ _) (? (lambda (_) (eq? kt 'struct)))) (fail! s t)] ;; sequences are covariant [((Sequence: ts) (Sequence: ts*)) (subtypes* A0 ts ts*)] @@ -328,7 +367,7 @@ [((Hashtable: _ _) (HashtableTop:)) A0] ;; subtyping on structs follows the declared hierarchy [((Struct: nm (? Type? parent) flds proc _ _ _ _) other) - ;(printf "subtype - hierarchy : ~a ~a ~a\n" nm parent other) + ;(dprintf "subtype - hierarchy : ~a ~a ~a\n" nm parent other) (subtype* A0 parent other)] ;; Promises are covariant [((Struct: (== promise-sym) _ (list t) _ _ _ _ _) (Struct: (== promise-sym) _ (list t*) _ _ _ _ _)) (subtype* A0 t t*)] @@ -354,7 +393,7 @@ (cond [(assq n s) => (lambda (spec) (subtype* A (cadr spec) m))] [else (fail! s t)]))] ;; otherwise, not a subtype - [(_ _) (fail! s t) #;(printf "failed")])))])))) + [(_ _) (fail! s t) #;(dprintf "failed")])))])))) (define (type-compare? a b) (and (subtype a b) (subtype b a)))