optimizer: local known to satisfy predicate => #t in a boolean context
For example, `(if (pair? x) (if x e1 e2) e3)` => `(if (pair? x) e1 e3)`.
This commit is contained in:
parent
7cb37d1bc8
commit
2063511bfd
|
@ -1340,6 +1340,15 @@
|
|||
(test-comp '(if (if (list? (cons 1 null)) #t #t) 1 2)
|
||||
'1)
|
||||
|
||||
(test-comp '(let ([x '(7)])
|
||||
(list x x (if (if (list? (cons 1 null)) x 3) 0 1)))
|
||||
'(let ([x '(7)])
|
||||
(list x x 0)))
|
||||
(test-comp '(lambda (x)
|
||||
(cons (car x) (if x 1 2)))
|
||||
'(lambda (x)
|
||||
(cons (car x) 1)))
|
||||
|
||||
(test-comp '(lambda (y)
|
||||
(let ([f (lambda (x) x)])
|
||||
(if f
|
||||
|
|
|
@ -6298,6 +6298,12 @@ Scheme_Object *scheme_optimize_expr(Scheme_Object *expr, Optimize_Info *info, in
|
|||
}
|
||||
} else if (is_mutated) {
|
||||
info->vclock += 1;
|
||||
} else if (context & OPT_CONTEXT_BOOLEAN) {
|
||||
Scheme_Object *pred;
|
||||
pred = optimize_get_predicate(pos, info);
|
||||
if (pred)
|
||||
return scheme_true;
|
||||
/* all predicates recognize non-#f things */
|
||||
}
|
||||
|
||||
delta = optimize_info_get_shift(info, pos);
|
||||
|
|
Loading…
Reference in New Issue
Block a user