Fix handling of let rhs that don't return
In the case that a let rhs doesn't return and therefore the bodies of the let are unreachable, the bodies need to be marked as ignored for the optimizer. In addition, don't attempt unboxed let optimization at all if the return type is Nothing since it probably means some body expressions have no type. Closes GH issue #165
This commit is contained in:
parent
6512b52b1d
commit
29144c7932
|
@ -188,6 +188,9 @@
|
|||
|
||||
(define (rec exp)
|
||||
(syntax-parse exp
|
||||
;; if there are unreachable expressions in the body, we can't check
|
||||
;; if it's worth unboxing, so just give up
|
||||
[_:ignore-table^ #f]
|
||||
;; can be used in a complex arithmetic expr, can be a direct child
|
||||
[(~and (~not :id) exp:float-complex-arith-expr)
|
||||
(or (direct-child-of? v #'exp)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#lang racket/unit
|
||||
|
||||
(require "../utils/utils.rkt"
|
||||
(except-in (types utils abbrev filter-ops remove-intersect) -> ->* one-of/c)
|
||||
(except-in (types utils abbrev filter-ops remove-intersect type-table)
|
||||
-> ->* one-of/c)
|
||||
(only-in (types abbrev) (-> t:->) [->* t:->*])
|
||||
(private type-annotation parse-type syntax-properties)
|
||||
(env lexical-env type-alias-helper mvar-env
|
||||
|
@ -85,6 +86,9 @@
|
|||
(get-names+objects namess expected-results)
|
||||
(with-lexical-env/extend-props
|
||||
(apply append props)
|
||||
;; if a let rhs does not return, the body isn't checked
|
||||
#:unreachable (for ([form (in-list (syntax->list body))])
|
||||
(register-ignored! form))
|
||||
;; type-check the rhs exprs
|
||||
(for ([expr (in-list exprs)] [results (in-list expected-results)])
|
||||
(match results
|
||||
|
|
17
typed-racket-test/fail/gh-issue-165.rkt
Normal file
17
typed-racket-test/fail/gh-issue-165.rkt
Normal file
|
@ -0,0 +1,17 @@
|
|||
#;
|
||||
(exn-pred #rx"match-define")
|
||||
#lang typed/racket
|
||||
|
||||
(struct a ([x : Integer]))
|
||||
(struct b ([y : Integer]))
|
||||
|
||||
;; test for original report
|
||||
(: f (-> a Integer))
|
||||
(define (f arg)
|
||||
(match-define (a (b y)) arg)
|
||||
(+ 1 y))
|
||||
|
||||
;; simple test case
|
||||
(let ()
|
||||
(match-define (? string? x) 3)
|
||||
(+ 1 2))
|
Loading…
Reference in New Issue
Block a user