Make union simplification not happen during subtyping.
Union simplification calls subtype, calling subtype during subtyping is slow so we want to avoid it. Closes PR 14582. original commit: cfe35fa0a4c035b07343ad3318c0082e507405a3
This commit is contained in:
parent
5e4b80b498
commit
d0d9bef5a9
|
@ -3,7 +3,7 @@
|
|||
(require "../utils/utils.rkt"
|
||||
(rep type-rep rep-utils)
|
||||
(prefix-in c: (contract-req))
|
||||
(types subtype base-abbrev resolve)
|
||||
(types subtype base-abbrev resolve current-seen)
|
||||
racket/match
|
||||
racket/list)
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
|||
;; a is a Type (not a union type)
|
||||
;; b is a List[Type] (non overlapping, non Union-types)
|
||||
;; The output is a non overlapping list of non Union types.
|
||||
;; The overlapping constraint is lifted if we are in the midst of subtyping. This is because during
|
||||
;; subtyping calls to subtype are expensive.
|
||||
(define (merge a b)
|
||||
(define b* (make-union* b))
|
||||
(match* (a b)
|
||||
|
@ -32,6 +34,7 @@
|
|||
;; so that bad applications are rejected early.
|
||||
(resolve-app-check-error rator rands stx)
|
||||
(cons a b)]
|
||||
[(_ _) #:when (currently-subtyping?) (cons a b)]
|
||||
[((? (λ _ (subtype a b*))) _) b]
|
||||
[((? (λ _ (subtype b* a))) _) (list a)]
|
||||
[(_ _) (cons a (filter-not (λ (b-elem) (subtype b-elem a)) b))]))
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
#lang typed/racket/base
|
||||
(define-type CodeOfBoolean (Code Boolean))
|
||||
(define-type CodeOfInteger (Code Integer))
|
||||
(define-type CodeOfAny
|
||||
(U CodeOfInteger
|
||||
CodeOfBoolean))
|
||||
|
||||
(define-type (Code Type)
|
||||
(U Type
|
||||
(If Type)
|
||||
(Begin Type)))
|
||||
|
||||
|
||||
(struct (Type) If
|
||||
([cond : CodeOfBoolean]
|
||||
[then : (Code Type)]
|
||||
[else : (Code Type)])
|
||||
#:transparent)
|
||||
|
||||
|
||||
|
||||
(define-type (ListEndingIn ListType EndType)
|
||||
(U (Pair EndType Null)
|
||||
(Pair ListType (ListEndingIn ListType EndType))))
|
||||
|
||||
(struct (Type) Begin
|
||||
([exprs : (ListEndingIn CodeOfAny (Code Type))]))
|
||||
|
||||
|
||||
(define QuotedCode : CodeOfInteger
|
||||
(If #t
|
||||
1
|
||||
(Begin
|
||||
(list 2 #f (If #t 3 4)))))
|
Loading…
Reference in New Issue
Block a user