Skip to content

Commit

Permalink
yet more repairs to the interaction of errors and let-values
Browse files Browse the repository at this point in the history
Continuing the saga that includes 8190a77 and d1ba9fb, it turns
out that a 0-binding clause as the last one isn't so special after
all. A little later in the optimizer, now that we're sometimes moving
an error to the body, we can't assume that the body can be discard
if an error was detected.
  • Loading branch information
mflatt committed Jan 21, 2017
1 parent d1ba9fb commit 736cdfb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pkgs/racket-test-core/tests/racket/optimize.rktl
Original file line number Diff line number Diff line change
Expand Up @@ -3892,6 +3892,21 @@
'(error "oops"))
(test-comp '(letrec-values ([(x y) (error "oops")]) 11)
'(error "oops"))
(test-comp '(let-values (((y) (read)) (() (error "oops"))) 11)
'(let () (begin (read) (error "oops"))))
(test-comp '(let-values (((y) (read)) (() (error "oops"))) 11)
'(let () (begin (read) (error "oops"))))
(test-comp '(let-values ((() (error "oops")) ((x) 9)) 11)
'(error "oops"))
(test-comp '(let-values ((() (error "oops")) (() (values))) 11)
'(error "oops"))
(test-comp '(let-values (((y) (read)) (() (error "oops")) ((x) 9)) 11)
'(let () (begin (read) (error "oops"))))
(test-comp '(let-values (((y) (read)) (() (error "oops")) (() (values))) 11)
'(let () (begin (read) (error "oops"))))
(test-comp '(error "oops")
'(let () (begin (read) (error "oops")))
#f)

(test-comp '(with-continuation-mark
'x 'y
Expand Down
12 changes: 10 additions & 2 deletions racket/src/racket/src/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -7523,6 +7523,14 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in
naya2->value = scheme_false;
naya2 = (Scheme_IR_Let_Value *)naya2->body;
}

if (!pre_body->count && !SCHEME_FALSEP(value)) {
/* Since `value` is not false, this clause must be the one
that is escaping. We'll end up dropping the remaining
clauses and the original body, but we need to keep the
erroring expression. */
escape_body = value;
}
}

if (prev_body)
Expand Down Expand Up @@ -8060,8 +8068,8 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in

if (head->num_clauses)
seq->array[1] = (Scheme_Object *)head;
else if (found_escapes) {
/* don't need the body, because some RHS escapes */
else if (found_escapes && SCHEME_FALSEP(head->body)) {
/* don't need the `#f` for the body, because some RHS escapes */
new_body = ensure_noncm(rhs);
} else
seq->array[1] = head->body;
Expand Down

0 comments on commit 736cdfb

Please sign in to comment.