Skip to content

Commit

Permalink
fix optimizer bug related to errors and zero-values binding
Browse files Browse the repository at this point in the history
  • Loading branch information
mflatt committed Jan 20, 2017
1 parent d0b5de3 commit 8190a77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkgs/racket-test-core/tests/racket/optimize.rktl
Original file line number Diff line number Diff line change
Expand Up @@ -3884,6 +3884,15 @@
(test-comp '(lambda (f) (letrec ([z (error 'error)] [x #f] [y #f]) #f))
'(lambda (f) (letrec ([z (error 'error)] [x (lambda() y)] [y (lambda () x)]) (f x y z)) 5))

(test-comp '(let-values ([() (error "oops")]) 11)
'(error "oops"))
(test-comp '(let-values ([(x y) (error "oops")]) 11)
'(error "oops"))
(test-comp '(letrec-values ([() (error "oops")]) 11)
'(error "oops"))
(test-comp '(letrec-values ([(x y) (error "oops")]) 11)
'(error "oops"))

(test-comp `(module m racket/base
(define x 5)
(set! x 3)
Expand Down
17 changes: 16 additions & 1 deletion racket/src/racket/src/optimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -7210,6 +7210,7 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in
Scheme_IR_Let_Header *head = (Scheme_IR_Let_Header *)form;
Scheme_IR_Let_Value *irlv, *pre_body, *retry_start, *prev_body;
Scheme_Object *body, *value, *ready_pairs = NULL, *rp_last = NULL, *ready_pairs_start;
Scheme_Object *escape_body = scheme_false;
Scheme_Once_Used *once_used;
Scheme_Hash_Tree *merge_skip_vars;
int i, j, is_rec, not_simply_let_star = 0, undiscourage, skip_opts = 0;
Expand Down Expand Up @@ -7486,6 +7487,13 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in
here messes up the loop for letrec. So wait and
remove it at the end. */
remove_last_one = 1;
/* If `found_escapes`, either this expression is the
one that escaped, or `value` should have been simplified
to `#f`. So, if it's not `#f`, we'll need to keep
the expression part */
if (!found_escapes)
value = scheme_false;
pre_body->value = value;
} else {
Scheme_IR_Let_Value *naya;
Scheme_Object *rest = pre_body->body;
Expand Down Expand Up @@ -7804,6 +7812,13 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in
if (remove_last_one) {
head->num_clauses -= 1;
body = (Scheme_Object *)pre_body->body;

if (found_escapes && !SCHEME_FALSEP(pre_body->value)) {
/* Since `pre_body->value` wasn't simplified to #f,
keep this as the new body */
escape_body = pre_body->value;
}

if (prev_body) {
prev_body->body = body;
pre_body = prev_body;
Expand Down Expand Up @@ -7835,7 +7850,7 @@ static Scheme_Object *optimize_lets(Scheme_Object *form, Optimize_Info *info, in
if (!found_escapes) {
body = scheme_optimize_expr(body, body_info, scheme_optimize_tail_context(context));
} else {
body = scheme_false;
body = escape_body;
body_info->single_result = 1;
body_info->preserves_marks = 1;
body_info->escapes = 1;
Expand Down

0 comments on commit 8190a77

Please sign in to comment.