diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/lengths.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/lengths.rkt index 71c31e21..b8d13d71 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/lengths.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/lengths.rkt @@ -35,6 +35,8 @@ [(define (sc-map v f) v) (define (sc->contract v f) (length-contract-syntax v)) (define (sc->constraints v f) 'flat)] + #:methods gen:terminal-sc + [(define (terminal-sc-kind v) 'flat)] #:methods gen:custom-write [(define write-proc length-contract-write-proc)]) (define (list-length/sc n) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt index 48e2287b..15f5af48 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/combinators/simple.rkt @@ -37,6 +37,8 @@ [(define (sc-map v f) v) (define (sc->contract v f) (simple-contract-syntax v)) (define (sc->constraints v f) (simple-contract-restrict (simple-contract-kind v)))] + #:methods gen:terminal-sc + [(define (terminal-sc-kind v) (simple-contract-kind v))] #:methods gen:custom-write [(define write-proc simple-contract-write-proc)]) (define (flat/sc ctc) (simple-contract ctc 'flat)) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/optimize.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/optimize.rkt index 88d27850..08501d80 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/optimize.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/optimize.rkt @@ -78,7 +78,7 @@ [(arr/sc: args rest (list (any/sc:) ...)) (arr/sc args rest #f)] [(none/sc:) any/sc] - [(? flat/sc?) any/sc] + [(app terminal-sc-kind 'flat) any/sc] [else sc])) diff --git a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/structures.rkt b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/structures.rkt index 1070eba4..b32eb74a 100644 --- a/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/structures.rkt +++ b/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/static-contracts/structures.rkt @@ -17,12 +17,14 @@ [sc-map (static-contract? (static-contract? variance/c . -> . static-contract?) . -> . static-contract?)] [sc->contract (static-contract? (static-contract? . -> . syntax?) . -> . syntax?)] [sc->constraints (static-contract? (static-contract? . -> . contract-restrict?) . -> . contract-restrict?)] + [terminal-sc-kind (static-contract? . -> . (or/c #f contract-kind?))] [sc? predicate/c] ) prop:combinator-name - gen:sc) + gen:sc + gen:terminal-sc) (define variance/c (or/c 'covariant 'contravariant 'invariant)) @@ -103,6 +105,16 @@ ;; The function argument should be used for sub parts of the static contract. [sc->constraints sc f]) +;; Functionality that terminal static contracts should support +;; Terminal static contracts are ones without any sub static contracts +(define-generics terminal-sc + ;; terminal-sc-kind: terminal-static-contract? -> (or/c #f contract-kind?) + ;; Returns the kind of contract that this represents + ;; Returns #f if it is not a terminal contract + [terminal-sc-kind terminal-sc] + #:defaults ([(λ (v) #t) + (define (terminal-sc-kind v) #f)])) + ;; Super struct of static contracts (struct static-contract () #:transparent