Fix bug in type propagation to avoid the reduction of mutable variables
This fixes the bug twice: * Don't reduce mutable variables with a type to #t in a Boolean context. * Don't record the type of mutable variables when a predicate is checked in a test condition.
This commit is contained in:
parent
b7ae673ee0
commit
58300857db
|
@ -1702,6 +1702,11 @@
|
|||
'(lambda (x) (not (if x #f #t))))
|
||||
(test-comp '(lambda (x) (let ([z 2]) (not (if x #f z))))
|
||||
'(lambda (x) (let ([z 2]) (not (if x #f #t)))))
|
||||
(test-comp '(lambda (z) (when (pair? z) #f))
|
||||
'(lambda (z) (when (pair? z) (not z))))
|
||||
(test-comp '(lambda (z) (when (pair? z) (set! z #f) #f))
|
||||
'(lambda (z) (when (pair? z) (set! z #f) (not z)))
|
||||
#f)
|
||||
|
||||
(test-comp '(lambda (x) (if x x #f))
|
||||
'(lambda (x) x))
|
||||
|
|
|
@ -4019,6 +4019,7 @@ static void add_types(Scheme_Object *t, Optimize_Info *info, int fuel)
|
|||
Scheme_App2_Rec *app = (Scheme_App2_Rec *)t;
|
||||
if (SCHEME_PRIMP(app->rator)
|
||||
&& SAME_TYPE(SCHEME_TYPE(app->rand), scheme_local_type)
|
||||
&& !optimize_is_mutated(info, SCHEME_LOCAL_POS(app->rand))
|
||||
&& relevant_predicate(app->rator)) {
|
||||
/* Looks like a predicate on a local variable. Record that the
|
||||
predicate succeeded, which may allow conversion of safe
|
||||
|
@ -7400,7 +7401,8 @@ Scheme_Object *scheme_optimize_expr(Scheme_Object *expr, Optimize_Info *info, in
|
|||
|
||||
delta = optimize_info_get_shift(info, pos);
|
||||
|
||||
if (context & OPT_CONTEXT_BOOLEAN) {
|
||||
if ((context & OPT_CONTEXT_BOOLEAN)
|
||||
&& !optimize_is_mutated(info, pos + delta)) {
|
||||
Scheme_Object *pred;
|
||||
pred = optimize_get_predicate(pos + delta, info);
|
||||
if (pred) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user