make compiler slightly smarter about 0-value letrec-values bindings
which corresponds to code generated from experession that are mixed with internal definitions
This commit is contained in:
parent
54216b5ced
commit
519d1ef8d1
|
@ -228,10 +228,11 @@ In the first case, the compiler likely does not know that
|
||||||
available.
|
available.
|
||||||
|
|
||||||
This caveat about @racket[letrec] also applies to definitions of
|
This caveat about @racket[letrec] also applies to definitions of
|
||||||
functions and constants within modules. A definition sequence in a
|
functions and constants as internal definitions or in modules. A
|
||||||
module body is analogous to a sequence of @racket[letrec] bindings,
|
definition sequence in a module body is analogous to a sequence of
|
||||||
and non-constant expressions in a module body can interfere with the
|
@racket[letrec] bindings, and non-constant expressions in a module
|
||||||
optimization of references to later bindings.
|
body can interfere with the optimization of references to later
|
||||||
|
bindings.
|
||||||
|
|
||||||
@; ----------------------------------------------------------------------
|
@; ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -3707,6 +3707,23 @@ static int get_convert_arg_count(Scheme_Object *lift)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Scheme_Object *drop_zero_value_return(Scheme_Object *expr)
|
||||||
|
{
|
||||||
|
if (SAME_TYPE(SCHEME_TYPE(expr), scheme_sequence_type)) {
|
||||||
|
if (((Scheme_Sequence *)expr)->count == 2) {
|
||||||
|
if (SAME_TYPE(SCHEME_TYPE(((Scheme_Sequence *)expr)->array[1]), scheme_application_type)) {
|
||||||
|
if (((Scheme_App_Rec *)((Scheme_Sequence *)expr)->array[1])->num_args == 0) {
|
||||||
|
if (SAME_OBJ(scheme_values_func, ((Scheme_App_Rec *)((Scheme_Sequence *)expr)->array[1])->args[0])) {
|
||||||
|
return ((Scheme_Sequence *)expr)->array[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Scheme_Object *
|
Scheme_Object *
|
||||||
scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
{
|
{
|
||||||
|
@ -3714,7 +3731,7 @@ scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
Scheme_Let_Header *head = (Scheme_Let_Header *)form;
|
Scheme_Let_Header *head = (Scheme_Let_Header *)form;
|
||||||
Scheme_Compiled_Let_Value *clv, *pre_body;
|
Scheme_Compiled_Let_Value *clv, *pre_body;
|
||||||
Scheme_Let_Value *lv, *last = NULL;
|
Scheme_Let_Value *lv, *last = NULL;
|
||||||
Scheme_Object *first = NULL, *body, *last_body = NULL;
|
Scheme_Object *first = NULL, *body, *last_body = NULL, *last_seq = NULL;
|
||||||
Scheme_Letrec *letrec;
|
Scheme_Letrec *letrec;
|
||||||
mzshort *skips, skips_fast[5];
|
mzshort *skips, skips_fast[5];
|
||||||
char *flonums, flonums_fast[5];
|
char *flonums, flonums_fast[5];
|
||||||
|
@ -4215,6 +4232,33 @@ scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
int j;
|
int j;
|
||||||
Scheme_Object *one_lifted;
|
Scheme_Object *one_lifted;
|
||||||
|
|
||||||
|
if (!clv->count)
|
||||||
|
expr = drop_zero_value_return(clv->value);
|
||||||
|
else
|
||||||
|
expr = NULL;
|
||||||
|
|
||||||
|
if (expr) {
|
||||||
|
/* changing a [() (begin expr (values))] clause,
|
||||||
|
which can be generated by internal-definition expansion,
|
||||||
|
into a `begin' */
|
||||||
|
expr = scheme_resolve_expr(expr, val_linfo);
|
||||||
|
expr = scheme_make_sequence_compilation(scheme_make_pair(expr,
|
||||||
|
scheme_make_pair(scheme_false,
|
||||||
|
scheme_null)),
|
||||||
|
0);
|
||||||
|
|
||||||
|
if (last)
|
||||||
|
last->body = expr;
|
||||||
|
else if (last_body)
|
||||||
|
SCHEME_CDR(last_body) = expr;
|
||||||
|
else if (last_seq)
|
||||||
|
((Scheme_Sequence *)last_seq)->array[1] = expr;
|
||||||
|
else
|
||||||
|
first = expr;
|
||||||
|
last = NULL;
|
||||||
|
last_body = NULL;
|
||||||
|
last_seq = expr;
|
||||||
|
} else {
|
||||||
expr = scheme_resolve_expr(clv->value, val_linfo);
|
expr = scheme_resolve_expr(clv->value, val_linfo);
|
||||||
|
|
||||||
lv = MALLOC_ONE_TAGGED(Scheme_Let_Value);
|
lv = MALLOC_ONE_TAGGED(Scheme_Let_Value);
|
||||||
|
@ -4222,10 +4266,13 @@ scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
last->body = (Scheme_Object *)lv;
|
last->body = (Scheme_Object *)lv;
|
||||||
else if (last_body)
|
else if (last_body)
|
||||||
SCHEME_CDR(last_body) = (Scheme_Object *)lv;
|
SCHEME_CDR(last_body) = (Scheme_Object *)lv;
|
||||||
|
else if (last_seq)
|
||||||
|
((Scheme_Sequence *)last_seq)->array[1] = (Scheme_Object *)lv;
|
||||||
else
|
else
|
||||||
first = (Scheme_Object *)lv;
|
first = (Scheme_Object *)lv;
|
||||||
last = lv;
|
last = lv;
|
||||||
last_body = NULL;
|
last_body = NULL;
|
||||||
|
last_seq = NULL;
|
||||||
|
|
||||||
lv->iso.so.type = scheme_let_value_type;
|
lv->iso.so.type = scheme_let_value_type;
|
||||||
lv->value = expr;
|
lv->value = expr;
|
||||||
|
@ -4250,10 +4297,13 @@ scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
boxenv = scheme_make_syntax_resolved(BOXENV_EXPD, pr);
|
boxenv = scheme_make_syntax_resolved(BOXENV_EXPD, pr);
|
||||||
if (last)
|
if (last)
|
||||||
last->body = boxenv;
|
last->body = boxenv;
|
||||||
|
else if (last_seq)
|
||||||
|
((Scheme_Sequence *)last_seq)->array[1] = boxenv;
|
||||||
else
|
else
|
||||||
SCHEME_CDR(last_body) = boxenv;
|
SCHEME_CDR(last_body) = boxenv;
|
||||||
last = NULL;
|
last = NULL;
|
||||||
last_body = pr;
|
last_body = pr;
|
||||||
|
last_seq = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* For regular let, delay the boxing until all RHSs are
|
/* For regular let, delay the boxing until all RHSs are
|
||||||
evaluated. */
|
evaluated. */
|
||||||
|
@ -4263,6 +4313,7 @@ scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
opos += clv->count;
|
opos += clv->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4283,12 +4334,16 @@ scheme_resolve_lets(Scheme_Object *form, Resolve_Info *info)
|
||||||
last->body = (Scheme_Object *)letrec;
|
last->body = (Scheme_Object *)letrec;
|
||||||
else if (last_body)
|
else if (last_body)
|
||||||
SCHEME_CDR(last_body) = (Scheme_Object *)letrec;
|
SCHEME_CDR(last_body) = (Scheme_Object *)letrec;
|
||||||
|
else if (last_seq)
|
||||||
|
((Scheme_Sequence *)last_seq)->array[1] = (Scheme_Object *)letrec;
|
||||||
else
|
else
|
||||||
first = (Scheme_Object *)letrec;
|
first = (Scheme_Object *)letrec;
|
||||||
} else if (last)
|
} else if (last)
|
||||||
last->body = body;
|
last->body = body;
|
||||||
else if (last_body)
|
else if (last_body)
|
||||||
SCHEME_CDR(last_body) = body;
|
SCHEME_CDR(last_body) = body;
|
||||||
|
else if (last_seq)
|
||||||
|
((Scheme_Sequence *)last_seq)->array[1] = (Scheme_Object *)body;
|
||||||
else
|
else
|
||||||
first = body;
|
first = body;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user