Skip to content

Commit 5d17fd2

Browse files
committed
order-of-evaluation props
Use props from checking a function to check its first argument, use props from checking the first argument to check the second, and so on.
1 parent bbf456c commit 5d17fd2

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

typed-racket-lib/typed-racket/typecheck/signatures.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
[cond-contracted tc-body/check (syntax? (or/c tc-results/c #f) . -> . full-tc-results/c)]
1515
[cond-contracted tc-expr/t (syntax? . -> . Type?)]
1616
[cond-contracted single-value ((syntax?) ((or/c tc-results/c #f)) . ->* . full-tc-results/c)]
17+
[cond-contracted map-single-value ((listof syntax?) . -> . (listof full-tc-results/c))]
1718
[cond-contracted tc-dep-fun-arg ((syntax?) ((or/c tc-results/c #f)) . ->* . full-tc-results/c)]))
1819

1920
(define-signature check-subforms^

typed-racket-lib/typed-racket/typecheck/tc-app/tc-app-main.rkt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"../signatures.rkt" "../tc-funapp.rkt"
1010
(types abbrev utils prop-ops)
1111
(env lexical-env)
12-
(typecheck tc-subst tc-envops check-below)
12+
(typecheck tc-subst tc-envops check-below tc-metafunctions)
1313
(rep type-rep prop-rep object-rep values-rep))
1414

1515
(import tc-expr^ tc-app-keywords^
@@ -80,8 +80,10 @@
8080
(define (tc/app-regular form expected)
8181
(syntax-case form ()
8282
[(f . args)
83-
(let ([f-ty (tc-expr/t #'f)]
84-
[args* (syntax->list #'args)])
83+
(let* ([f-res (single-value #'f)]
84+
[f-ty (match f-res [(tc-result1: t _ _) t])]
85+
[f-prop (unconditional-prop f-res)]
86+
[args* (syntax->list #'args)])
8587
(define (matching-arities arrs)
8688
(for/list ([arr (in-list arrs)] #:when (arrow-matches? arr args*)) arr))
8789
(define (has-drest/props? arrs)
@@ -94,7 +96,8 @@
9496
(cond
9597
[(with-refinements?)
9698
(map tc-dep-fun-arg args*)]
97-
[else (map single-value args*)]))
99+
[else
100+
(map-single-value args* (list f-prop))]))
98101
(tc/funapp #'f #'args f-ty arg-types expected)]
99102
[(or (? DepFun?)
100103
(Poly-unsafe: _ (? DepFun?)))
@@ -119,5 +122,5 @@
119122
(single-value arg-stx (ret dom-ty))]
120123
[else (single-value arg-stx)])))
121124
(tc/funapp #'f #'args f-ty arg-types expected)]
122-
[_ (tc/funapp #'f #'args f-ty (map single-value args*) expected)]))]))
125+
[_ (tc/funapp #'f #'args f-ty (map-single-value args* (list f-prop)) expected)]))]))
123126

typed-racket-lib/typed-racket/typecheck/tc-expr-unit.rkt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
racket/list
1717
racket/private/class-internal
1818
syntax/parse
19-
(typecheck internal-forms tc-envops)
19+
(typecheck internal-forms tc-envops tc-metafunctions)
2020
racket/sequence
2121
racket/extflonum
2222
;; Needed for current implementation of typechecking letrec-syntax+values
@@ -352,6 +352,25 @@
352352
#:stx form
353353
"expected single value, got multiple (or zero) values")]))
354354

355+
;; Apply `single-value` to a list of forms in order, accumulate the prop info
356+
(define (map-single-value forms [props '()])
357+
(define any-res (-tc-any-results #f))
358+
(let loop ((forms forms)
359+
(props props))
360+
(match forms
361+
['()
362+
'()]
363+
[(cons e rst)
364+
(define tcr
365+
(with-lexical-env+props
366+
props
367+
#:expected any-res
368+
#:unreachable (for-each register-ignored! rst)
369+
(single-value e)))
370+
(define prop+
371+
(cons (unconditional-prop tcr) props))
372+
(cons tcr (loop rst prop+))])))
373+
355374
(define (tc-dep-fun-arg form [expected #f])
356375
(define t (tc-expr/check form expected #t))
357376
(match t

typed-racket-lib/typed-racket/typecheck/tc-metafunctions.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
combine-props
1414
merge-tc-results
1515
tc-results->values
16-
erase-existentials)
16+
erase-existentials
17+
unconditional-prop)
1718

1819
;; Objects representing the rest argument are currently not supported
1920
(define/cond-contract (abstract-results results arg-names #:rest-id [rest-id #f])

typed-racket-test/unit-tests/typecheck-tests.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4467,6 +4467,9 @@
44674467
[tc-e/t (let: ([x : (Un Flonum Natural) 0.0])
44684468
(if (not (natural? x)) x 1.0))
44694469
-Flonum]
4470+
;; props + evaluation order
4471+
[tc-e ((lambda: ((x : (Un Symbol Natural))) (+ (assert x integer?) x)) 1) -Nat]
4472+
[tc-e ((lambda: ((x : (Un Symbol Natural))) ((begin (assert x integer?) +) x x)) 1) -Nat]
44704473
)
44714474

44724475
(test-suite

0 commit comments

Comments
 (0)