|
110 | 110 |
|
111 | 111 |
|
112 | 112 | ;; Reduce a static contract assuming that we trusted the current side
|
113 |
| -(define (trusted-side-reduce sc flat?) |
| 113 | +(define (trusted-side-reduce sc) |
114 | 114 | (match sc
|
115 | 115 | [(->/sc: mand-args opt-args mand-kw-args opt-kw-args rest-arg (list (any/sc:) ...))
|
116 | 116 | (function/sc #t mand-args opt-args mand-kw-args opt-kw-args rest-arg #f)]
|
117 | 117 | [(arr/sc: args rest (list (any/sc:) ...))
|
118 | 118 | (arr/sc args rest #f)]
|
119 | 119 | [(none/sc:) any/sc]
|
120 |
| - [(or/sc: (? flat?) ...) any/sc] |
121 |
| - [(? flat?) any/sc] |
| 120 | + [(or/sc: (? flat-terminal-kind?) ...) any/sc] |
| 121 | + [(? flat-terminal-kind?) any/sc] |
122 | 122 | [(syntax/sc: (? recursive-sc?))
|
123 | 123 | ;;bg; _temporary_ case to allow contracts from the `Syntax` type.
|
124 | 124 | ;; This is temporary until TR has types for immutable-vector
|
|
176 | 176 | ;; update-side : sc? weak-side? -> weak-side?
|
177 | 177 | ;; Change the current side to something safe & strong-as-possible
|
178 | 178 | ;; for optimizing the sub-contracts of the given `sc`.
|
179 |
| -(define (update-side sc side flat?) |
| 179 | +(define (update-side sc side) |
180 | 180 | (match sc
|
181 | 181 | [(or/sc: scs ...)
|
182 |
| - #:when (not (andmap flat? scs)) |
| 182 | + #:when (not (andmap flat-terminal-kind? scs)) |
183 | 183 | (weaken-side side)]
|
184 | 184 | [_
|
185 |
| - #:when (guarded-sc? sc flat?) |
| 185 | + #:when (guarded-sc? sc) |
186 | 186 | (strengthen-side side)]
|
187 | 187 | [_
|
188 | 188 | ;; Keep same side by default.
|
|
193 | 193 | ;; guarded-sc? : sc? -> boolean?
|
194 | 194 | ;; Returns #true if the given static contract represents a type with a "real"
|
195 | 195 | ;; type constructor. E.g. list/sc is "real" and or/sc is not.
|
196 |
| -(define (guarded-sc? sc flat?) |
| 196 | +(define (guarded-sc? sc) |
197 | 197 | (match sc
|
198 |
| - [(or (? flat?) |
| 198 | + [(or (? flat-terminal-kind?) |
199 | 199 | (->/sc: _ _ _ _ _ _)
|
200 | 200 | (arr/sc: _ _ _)
|
201 | 201 | (async-channel/sc: _)
|
|
295 | 295 |
|
296 | 296 |
|
297 | 297 | ;; If we trust a specific side then we drop all contracts protecting that side.
|
298 |
| -(define (optimize sc #:trusted-positive [trusted-positive #f] #:trusted-negative [trusted-negative #f] #:recursive-kinds [recursive-kinds #f]) |
299 |
| - (define flat?/sc |
300 |
| - (let* ([flat-names |
301 |
| - (and recursive-kinds |
302 |
| - (for/set ([(k v) (in-hash recursive-kinds)] |
303 |
| - #:when (eq? 'flat v)) |
304 |
| - k))]) |
305 |
| - (if flat-names |
306 |
| - (λ (sc) |
307 |
| - (match sc |
308 |
| - [(name/sc: name) |
309 |
| - (set-member? flat-names name)] |
310 |
| - [_ |
311 |
| - (flat-terminal-kind? sc)])) |
312 |
| - flat-terminal-kind?))) |
313 |
| - |
| 298 | +(define (optimize sc #:trusted-positive [trusted-positive #f] #:trusted-negative [trusted-negative #f]) |
314 | 299 | ;; single-step: reduce and trusted-side-reduce if appropriate
|
315 | 300 | (define (single-step sc maybe-weak-side)
|
316 | 301 | (define trusted
|
|
323 | 308 |
|
324 | 309 | (reduce
|
325 | 310 | (if trusted
|
326 |
| - (trusted-side-reduce sc flat?/sc) |
| 311 | + (trusted-side-reduce sc) |
327 | 312 | sc)))
|
328 | 313 |
|
329 | 314 | ;; full-pass: single-step at every static contract subpart
|
330 | 315 | (define (full-pass sc)
|
331 | 316 | (define ((recur side) sc variance)
|
332 | 317 | (define curr-side (combine-variance side variance))
|
333 |
| - (define next-side (update-side sc curr-side flat?/sc)) |
| 318 | + (define next-side (update-side sc curr-side)) |
334 | 319 | (single-step (sc-map sc (recur next-side)) curr-side))
|
335 | 320 | ((recur 'positive) sc 'covariant))
|
336 | 321 |
|
|
0 commit comments