8.10 Collapsible Contracts
(require racket/contract/collapsible) | package: base |
Added in version 7.1.0.10 of package base.
Collapsible contracts are an optimization in the contract system designed to avoid a particular pathological build up of contract wrappers on higher-order values. The vectorof, vector/c, and -> contract combinators support collapsing for vector contracts and function contracts for functions returning a single value.
Intuitively, a collapsible contract is a tree structure. The tree nodes represent higher-order contracts (e.g., ->) and the tree leaves represent sequences of flat contracts. Two trees can collapse into one tree via the merge procedure, which removes unnecessary flat contracts from the leaves.
For more information on the motivation and design of collapsible contracts, see [Feltey18]. For the theoretical foundations, see [Greenberg15].
Warning: the features described in this section are experimental and may not be sufficient to implement new collapsible contracts. Implementing new collapsible contracts requires the use of unsafe chaperones and impersonators which are only supported for vector and procedure values. This documentation exists primarily to allow future maintenance of the racket/contract/collapsible library. End Warning
If c does not have a collapsible-late-neg projection, then this function uses the original projection for it and constructs a leaf as its collapsible representation.
syntax
(with-collapsible-contract-continuation-mark body ...)
procedure
v : any/c
procedure
(merge new-cc new-neg old-cc old-neg) → collapsible-contract?
new-cc : collapsible-contract? new-neg : any/c old-cc : collapsible-contract? old-neg : any/c
procedure
(collapsible-guard cc val neg-party) → any/c
cc : collapsible-contract? val : any/c neg-party : any/c
procedure
v : any/c
procedure
(build-collapsible-contract-property [ #:try-merge try-merge #:collapsible-guard collapsible-guard]) → collapsible-contract-property?
try-merge :
(or/c #f (-> collapsible-contract? any/c collapsible-contract? any/c (or/c #f collapsible-contract?))) = #f
collapsible-guard : (-> collapsible-contract? any/c any/c any/c) =
(λ (cc v neg) (error "internal error: contract does not support `collapsible-guard`" cc))
struct
(struct collapsible-ho/c (latest-blame missing-party latest-ctc))
latest-blame : blame? missing-party : any/c latest-ctc : contract?
struct
(struct collapsible-leaf/c ( proj-list contract-list blame-list missing-party-list)) proj-list : (listof (-> any/c any/c any/c)) contract-list : (listof contract?) blame-list : (listof blame?) missing-party-list : (listof any/c)
value
procedure
v : any/c
procedure
(get-impersonator-prop:collapsible v) → collapsible-property?
v : any/c
struct
(struct collapsible-property (c-c neg-party ref))
c-c : collapsible-contract? neg-party : any/c ref : (or/c #f impersonator?)
struct
(struct collapsible-count-property collapsible-property ( count prev)) count : natural-number/c prev : (or/c collapsible-count-property? any/c)
struct
(struct collapsible-wrapper-property collapsible-property (checking-wrapper) checking-wrapper : impersonator?