Skip to content

Commit

Permalink
Authentic structs for static contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
samth committed Jul 19, 2022
1 parent d922f74 commit 987db71
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

(struct any-combinator combinator ()
#:transparent
#:authentic
#:methods gen:sc
[(define (sc-map v f) v)
(define (sc-traverse v f) (void))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

(struct case-combinator combinator ()
#:transparent
#:authentic
#:property prop:combinator-name "case->/sc"
#:methods gen:sc
[(define (sc-map v f)
Expand All @@ -38,6 +39,7 @@
(struct arr-combinator combinator ()
#:transparent
#:property prop:combinator-name "arr/sc"
#:authentic
#:methods gen:sc
[(define (sc-map v f)
(arr-combinator (arr-seq-sc-map f (combinator-args v))))
Expand Down Expand Up @@ -83,6 +85,7 @@


(struct arr-seq (args rest range)
#:authentic
#:transparent
#:property prop:sequence
(match-lambda
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[prompt-tag/sc ((listof static-contract?) (or/c (listof static-contract?) #f) . -> . static-contract?)])

(struct prompt-tag-combinator combinator ()
#:authentic
#:transparent
#:property prop:combinator-name "prompt-tag/sc"
#:methods gen:sc
Expand All @@ -36,6 +37,7 @@
(merge-restricts* 'chaperone (map f (pt-seq->list (combinator-args v)))))])

(struct pt-seq (vals call-cc)
#:authentic
#:transparent
#:property prop:sequence
(lambda (s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
pre-deps
rng
rng-deps)
#:authentic
#:transparent
#:property prop:combinator-name "dep->/sc"
#:methods gen:sc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@


(struct exist-combinator combinator ()
#:authentic
#:transparent
#:methods gen:sc
[(define (sc-map v f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
static-contract?)])

(struct function-combinator combinator (indices mand-kws opt-kws typed-side?)
#:authentic
#:property prop:combinator-name "->/sc"
#:methods gen:equal+hash [(define (equal-proc a b recur) (function-sc-equal? a b recur))
(define (hash-proc v recur) (function-sc-hash v recur))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
(list typed-sc untyped-sc both-sc)))

(struct name-combinator combinator (gen-name)
#:authentic
#:transparent
#:property prop:combinator-name "name/sc"
#:methods gen:sc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
(display "#<none/sc>" port)))

(struct none-combinator combinator ()
#:authentic
#:transparent
#:methods gen:sc
[(define (sc-map v f) v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
typed-racket/utils/opaque-object)
(for-syntax racket/base syntax/parse))

(struct member-spec (modifier id sc) #:transparent)
(struct member-spec (modifier id sc) #:authentic #:transparent)

(define field-modifiers '(field init init-field inherit-field))
(define method-modifiers '(method inherit super inner override augment augride))

(struct object-combinator combinator (opaque?)
#:authentic
#:transparent
#:property prop:combinator-name "object/sc"
#:methods gen:sc
Expand All @@ -34,6 +35,7 @@
(merge-restricts* 'impersonator (map f (member-seq->list (combinator-args v)))))])

(struct class-combinator combinator (opaque absents)
#:authentic
#:transparent
#:property prop:combinator-name "class/sc"
#:methods gen:sc
Expand All @@ -52,6 +54,7 @@
(merge-restricts* 'impersonator (map f (member-seq->list (combinator-args v)))))])

(struct instanceof-combinator combinator ()
#:authentic
#:transparent
#:property prop:combinator-name "instanceof/sc"
#:methods gen:sc
Expand All @@ -78,8 +81,9 @@
(filter-map member-spec-sc vals)]))

(struct member-seq (vals)
#:transparent
#:property prop:sequence member-seq->list)
#:authentic
#:transparent
#:property prop:sequence member-seq->list)

(define (member-seq-sc-map f seq)
(match seq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
[sealing-var/sc (identifier? . -> . static-contract?)])

(struct parametric-combinator combinator (vars)
#:authentic
#:transparent
#:property prop:combinator-name "parametric->/sc"
#:methods gen:sc
Expand Down Expand Up @@ -66,6 +67,7 @@

;; combinator for sealing-> contracts for row polymorphism
(struct sealing-combinator combinator (vars members)
#:authentic
#:transparent
#:property prop:combinator-name "sealing->/sc"
#:methods gen:sc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

(struct prefab-combinator combinator (key field-mutability)
#:transparent
#:authentic
#:property prop:combinator-name "prefab/sc"
#:methods gen:sc
[(define (sc-map v f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(provide-for-cond-contract proposition-contract?)

(struct proposition-contract static-contract () #:transparent)
(struct proposition-contract static-contract () #:transparent #:authentic)


(define/match (flat-lambda-write v port mode)
Expand Down Expand Up @@ -54,6 +54,7 @@
;; in the contract syntax they generate.
(struct flat-named-lambda/sc static-contract (name arg body)
#:transparent
#:authentic
#:methods gen:sc
[(define/match (sc-map v f)
[((flat-named-lambda/sc name arg body) f)
Expand Down Expand Up @@ -88,6 +89,7 @@
;; so we can use it directly as a predicate.
(struct is-flat-type/sc proposition-contract (obj type)
#:transparent
#:authentic
#:methods gen:sc
[(define/match (sc-map v f)
[((is-flat-type/sc obj type) f)
Expand All @@ -112,6 +114,7 @@
;; See is-flat-type/sc for more details.
(struct not-flat-type/sc proposition-contract (obj type)
#:transparent
#:authentic
#:methods gen:sc
[(define/match (sc-map v f)
[((not-flat-type/sc obj type) f)
Expand All @@ -135,6 +138,7 @@
;; flat-named-lambda/sc.
(struct leq/sc proposition-contract (lhs rhs)
#:transparent
#:authentic
#:methods gen:sc
[(define/match (sc-map v f)
[((leq/sc lhs rhs) f)
Expand All @@ -152,6 +156,7 @@

(struct and-prop/sc proposition-contract (args)
#:transparent
#:authentic
#:methods gen:sc
[(define/match (sc-map v f)
[((and-prop/sc args) f)
Expand All @@ -172,6 +177,7 @@

(struct or-prop/sc proposition-contract (args)
#:transparent
#:authentic
#:methods gen:sc
[(define/match (sc-map v f)
[((or-prop/sc args) f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
(equal?/recur s1 s2 stx-equal?))]))

(struct simple-contract static-contract (syntax kind name)
#:authentic
#:transparent
#:methods gen:equal+hash
[(define (equal-proc s1 s2 recur)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
[struct-type/sc (any/c . -> . static-contract?)])

(struct struct-combinator combinator (name mut?)
#:authentic
#:transparent
#:property prop:combinator-name "struct/sc"
#:methods gen:sc
Expand Down Expand Up @@ -61,6 +62,7 @@
;; reflective use.
(struct struct-type/sc combinator ()
#:transparent
#:authentic
#:property prop:combinator-name "struct-type/sc"
#:methods gen:sc
[(define (sc-map v f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
[(_ sc:static-combinator-form c:expr kind:contract-category-keyword)
#'(begin
(struct sc.struct-name combinator ()
#:authentic
#:transparent
#:methods gen:sc
[(define sc-map sc.map)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@

(provide-for-cond-contract symbolic-object-contract?)

(struct symbolic-object-contract static-contract () #:transparent)
(struct symbolic-object-contract static-contract () #:transparent #:authentic)

;; an identifier symbolic object e.g. x
(struct id/sc symbolic-object-contract (syntax)
#:authentic
#:transparent
#:methods gen:equal+hash
[(define/match (equal-proc a b rec)
Expand All @@ -35,6 +36,7 @@

;; a path element access into a symbolic object e.g. (car o)
(struct acc-obj/sc symbolic-object-contract (acc-stx obj)
#:authentic
#:transparent
#:methods gen:equal+hash
[(define/match (equal-proc a b recur)
Expand All @@ -58,6 +60,7 @@

;; a linear expression symbolic obj, e.g. 42, or x, or (+ 1 (* 2 y)), etc...
(struct linear-exp/sc symbolic-object-contract (const terms)
#:authentic
#:transparent
#:methods gen:sc
[(define/match (sc-map v f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
(for-template racket/base racket/unit)
(for-syntax racket/base syntax/parse))

(struct signature-spec (name members scs) #:transparent)
(struct signature-spec (name members scs) #:transparent #:authentic)

(struct unit-combinator combinator ()
#:authentic
#:transparent
#:property prop:combinator-name "unit/sc"
#:methods gen:sc
Expand Down Expand Up @@ -40,6 +41,7 @@
(filter-map (lambda (x) x) invoke)))]))

(struct unit-spec (imports exports init-depends invoke)
#:authentic
#:transparent
#:property prop:sequence unit-spec->list)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

; equations: (hash/c var? (-> value?))
; initial-values: (hash/c var? (-> value?))
(struct equation-set (equations initial-values))
(struct equation-set (equations initial-values) #:transparent #:authentic)

(define (make-equation-set)
(equation-set (make-hasheq) (make-hasheq)))
Expand Down
8 changes: 6 additions & 2 deletions typed-racket-lib/typed-racket/static-contracts/structures.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@

;; Super struct of static contracts
(struct static-contract ()
#:transparent
#:property prop:custom-print-quotable 'never)
#:transparent
#:property prop:custom-print-quotable 'never
#:authentic)

;; Represents a recursive contract.
;; In each value and the body, each name is bound to a the corresponding value contract.
Expand All @@ -121,6 +122,7 @@
;; - body : static-contract?
;; names and value must have the same length.
(struct recursive-sc static-contract (names values body)
#:authentic
#:transparent
#:methods gen:sc
[(define (sc-map v f)
Expand All @@ -140,6 +142,7 @@
;; A use of a contract bound by recursive-sc
;; - name : identifier?
(struct recursive-sc-use static-contract (name)
#:authentic
#:transparent
#:methods gen:sc
[(define (sc-map v f) v)
Expand All @@ -152,6 +155,7 @@
;; Provides printing functionality.
;; - args : (sequenceof static-contract?)
(struct combinator static-contract (args)
#:authentic
#:transparent
#:property prop:combinator-name "combinator/sc"
#:methods gen:custom-write [(define write-proc combinator-write-proc)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
[(_ name:id (args:id ...) kind:kind-keyword p:printer body:expr)
#'(struct name static-contract (args ...)
#:transparent
#:authentic
p.methods ...
#:methods gen:sc
[(define (sc-map v f) v)
Expand Down

0 comments on commit 987db71

Please sign in to comment.