optimizer: treat known procedure bindings, etc., as #t for if
Closes PR 14526
This commit is contained in:
parent
5ad11c85e6
commit
ec96592702
|
@ -1158,6 +1158,36 @@
|
||||||
(a1)
|
(a1)
|
||||||
(a2))))
|
(a2))))
|
||||||
|
|
||||||
|
(test-comp '(lambda (y)
|
||||||
|
(let ([f (lambda (x) x)])
|
||||||
|
(if f
|
||||||
|
(+ y 1)
|
||||||
|
(- y 1))))
|
||||||
|
'(lambda (y)
|
||||||
|
(+ y 1)))
|
||||||
|
|
||||||
|
(test-comp '(module m racket/base
|
||||||
|
(define (f x) x)
|
||||||
|
(define (g y)
|
||||||
|
(if f
|
||||||
|
(+ y 1)
|
||||||
|
(- y 1))))
|
||||||
|
'(module m racket/base
|
||||||
|
(define (f x) x)
|
||||||
|
(define (g y)
|
||||||
|
(+ y 1))))
|
||||||
|
|
||||||
|
(test-comp '(module m racket/base
|
||||||
|
(struct p (x y) #:omit-define-syntaxes)
|
||||||
|
(define (g y)
|
||||||
|
(if p-x
|
||||||
|
(+ y 1)
|
||||||
|
(- y 1))))
|
||||||
|
'(module m racket/base
|
||||||
|
(struct p (x y) #:omit-define-syntaxes)
|
||||||
|
(define (g y)
|
||||||
|
(+ y 1))))
|
||||||
|
|
||||||
(test-comp '(values 10)
|
(test-comp '(values 10)
|
||||||
10)
|
10)
|
||||||
(test-comp '(let ([x (values 10)])
|
(test-comp '(let ([x (values 10)])
|
||||||
|
|
|
@ -6005,7 +6005,10 @@ Scheme_Object *scheme_optimize_expr(Scheme_Object *expr, Optimize_Info *info, in
|
||||||
case scheme_with_cont_mark_type:
|
case scheme_with_cont_mark_type:
|
||||||
return optimize_wcm(expr, info, context);
|
return optimize_wcm(expr, info, context);
|
||||||
case scheme_compiled_unclosed_procedure_type:
|
case scheme_compiled_unclosed_procedure_type:
|
||||||
return optimize_closure_compilation(expr, info, context);
|
if (context & OPT_CONTEXT_BOOLEAN)
|
||||||
|
return scheme_true;
|
||||||
|
else
|
||||||
|
return optimize_closure_compilation(expr, info, context);
|
||||||
case scheme_compiled_let_void_type:
|
case scheme_compiled_let_void_type:
|
||||||
return scheme_optimize_lets(expr, info, 0, context);
|
return scheme_optimize_lets(expr, info, 0, context);
|
||||||
case scheme_compiled_toplevel_type:
|
case scheme_compiled_toplevel_type:
|
||||||
|
@ -6025,6 +6028,9 @@ Scheme_Object *scheme_optimize_expr(Scheme_Object *expr, Optimize_Info *info, in
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c) {
|
if (c) {
|
||||||
|
if (context & OPT_CONTEXT_BOOLEAN)
|
||||||
|
return (SCHEME_FALSEP(c) ? scheme_false : scheme_true);
|
||||||
|
|
||||||
if (scheme_compiled_duplicate_ok(c, 0))
|
if (scheme_compiled_duplicate_ok(c, 0))
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
|
@ -6052,8 +6058,12 @@ Scheme_Object *scheme_optimize_expr(Scheme_Object *expr, Optimize_Info *info, in
|
||||||
optimize_info_used_top(info);
|
optimize_info_used_top(info);
|
||||||
return expr;
|
return expr;
|
||||||
case scheme_compiled_quote_syntax_type:
|
case scheme_compiled_quote_syntax_type:
|
||||||
info->size += 1;
|
if (context & OPT_CONTEXT_BOOLEAN)
|
||||||
optimize_info_used_top(info);
|
return scheme_true;
|
||||||
|
else {
|
||||||
|
info->size += 1;
|
||||||
|
optimize_info_used_top(info);
|
||||||
|
}
|
||||||
return expr;
|
return expr;
|
||||||
case scheme_variable_type:
|
case scheme_variable_type:
|
||||||
case scheme_module_variable_type:
|
case scheme_module_variable_type:
|
||||||
|
@ -6070,7 +6080,10 @@ Scheme_Object *scheme_optimize_expr(Scheme_Object *expr, Optimize_Info *info, in
|
||||||
case scheme_begin_for_syntax_type:
|
case scheme_begin_for_syntax_type:
|
||||||
return begin_for_syntax_optimize(expr, info, context);
|
return begin_for_syntax_optimize(expr, info, context);
|
||||||
case scheme_case_lambda_sequence_type:
|
case scheme_case_lambda_sequence_type:
|
||||||
return case_lambda_optimize(expr, info, context);
|
if (context & OPT_CONTEXT_BOOLEAN)
|
||||||
|
return scheme_true;
|
||||||
|
else
|
||||||
|
return case_lambda_optimize(expr, info, context);
|
||||||
case scheme_begin0_sequence_type:
|
case scheme_begin0_sequence_type:
|
||||||
return begin0_optimize(expr, info, context);
|
return begin0_optimize(expr, info, context);
|
||||||
case scheme_apply_values_type:
|
case scheme_apply_values_type:
|
||||||
|
@ -6943,11 +6956,13 @@ static Scheme_Object *do_optimize_info_lookup(Optimize_Info *info, int pos, int
|
||||||
if (single_use)
|
if (single_use)
|
||||||
*single_use = SCHEME_TRUEP(SCHEME_VEC_ELS(p)[3]);
|
*single_use = SCHEME_TRUEP(SCHEME_VEC_ELS(p)[3]);
|
||||||
if (SAME_TYPE(SCHEME_TYPE(n), scheme_compiled_unclosed_procedure_type)) {
|
if (SAME_TYPE(SCHEME_TYPE(n), scheme_compiled_unclosed_procedure_type)) {
|
||||||
|
if (context & OPT_CONTEXT_BOOLEAN) return scheme_true;
|
||||||
if (!closure_offset)
|
if (!closure_offset)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
*closure_offset = delta;
|
*closure_offset = delta;
|
||||||
} else if (SAME_TYPE(SCHEME_TYPE(n), scheme_case_lambda_sequence_type)) {
|
} else if (SAME_TYPE(SCHEME_TYPE(n), scheme_case_lambda_sequence_type)) {
|
||||||
|
if (context & OPT_CONTEXT_BOOLEAN) return scheme_true;
|
||||||
if (!closure_offset)
|
if (!closure_offset)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,12 +13,12 @@
|
||||||
consistently.)
|
consistently.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MZSCHEME_VERSION "6.0.1.10"
|
#define MZSCHEME_VERSION "6.0.1.11"
|
||||||
|
|
||||||
#define MZSCHEME_VERSION_X 6
|
#define MZSCHEME_VERSION_X 6
|
||||||
#define MZSCHEME_VERSION_Y 0
|
#define MZSCHEME_VERSION_Y 0
|
||||||
#define MZSCHEME_VERSION_Z 1
|
#define MZSCHEME_VERSION_Z 1
|
||||||
#define MZSCHEME_VERSION_W 10
|
#define MZSCHEME_VERSION_W 11
|
||||||
|
|
||||||
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
|
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
|
||||||
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)
|
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user