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:
Asumu Takikawa 2015-08-11 02:16:19 -04:00
parent 6512b52b1d
commit 29144c7932
3 changed files with 25 additions and 1 deletions

View File

@ -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)

View File

@ -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

View 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))