Mark errors in expression when a wrong type is detected during optimization

This enables further reductions,
for example (begin (car x) (unbox x) z)  => (begin (car x) (unbox x))
This commit is contained in:
Gustavo Massaccesi 2015-01-01 16:13:25 -03:00 committed by Matthew Flatt
parent 34c2c2ebdd
commit 6d8ba1fd67
2 changed files with 11 additions and 4 deletions

View File

@ -1356,7 +1356,10 @@
'(lambda ()
(let ([y (random)])
(begin0 y (set! y 5)))))
(test-comp '(lambda (w) (car w) (mcar w))
'(lambda (w) (begin (car w) (mcar w) (random))))
; test for unary aplications
(test-comp -1
'(- 1))

View File

@ -2840,7 +2840,8 @@ static void check_known2(Optimize_Info *info, Scheme_App2_Rec *app,
Scheme_Object *rand, int id_offset,
const char *who, Scheme_Object *expect_pred, Scheme_Object *unsafe)
/* Replace the rator with an unsafe version if we know that it's ok. Alternatively,
the rator implies a check, so add type information for subsequent expressions. */
the rator implies a check, so add type information for subsequent expressions.
If the rand has alredy a different type, mark that this will generate an error. */
{
if (IS_NAMED_PRIM(app->rator, who)) {
if (SAME_TYPE(SCHEME_TYPE(rand), scheme_local_type)) {
@ -2853,8 +2854,11 @@ static void check_known2(Optimize_Info *info, Scheme_App2_Rec *app,
return;
pred = optimize_get_predicate(pos, info);
if (pred && SAME_OBJ(pred, expect_pred))
app->rator = unsafe;
if (pred)
if (SAME_OBJ(pred, expect_pred))
app->rator = unsafe;
else
info->escapes = 1;
else
add_type(info, pos, expect_pred);
}