From be82c27db3294cb88e33d54211175bb0b158da7f Mon Sep 17 00:00:00 2001 From: Gustavo Massaccesi Date: Mon, 4 Jan 2016 14:30:37 -0300 Subject: [PATCH] fix bug in shifting of types during inlining During inlining, the type information gathered in code that was inside the lambda is copied to the outer context. But the coordinates of the type information were shifted in the wrong direction, so the type was assigned to the wrong variable. This bug is difficult to trigger, so the test is convoluted. Merge to v6.4 --- .../tests/racket/optimize.rktl | 28 +++++++++++++++++-- racket/src/racket/src/optimize.c | 6 ++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/pkgs/racket-test-core/tests/racket/optimize.rktl b/pkgs/racket-test-core/tests/racket/optimize.rktl index 01ab2b1f16..df465a98f8 100644 --- a/pkgs/racket-test-core/tests/racket/optimize.rktl +++ b/pkgs/racket-test-core/tests/racket/optimize.rktl @@ -3629,6 +3629,30 @@ (set! f 0)) #f) +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Check that the type information is shifted in the +;; right direction while inlining. +;; The first example triggered a bug in 6.3. + +(test-comp '(let ([zz (lambda (x) (lambda (y) 0))]) + (lambda (a b c) + ((zz (let ([loop (lambda () 0)]) loop)) (car a)) + (list c (pair? c)))) + '(let ([zz (lambda (x) (lambda (y) 0))]) + (lambda (a b c) + ((zz (let ([loop (lambda () 0)]) loop)) (car a)) + (list c #t))) + #f) + +(test-comp '(let ([zz (lambda (x) (lambda (y) 0))]) + (lambda (a b c) + ((zz (let ([loop (lambda () 0)]) loop)) (car a)) + (list a (pair? a)))) + '(let ([zz (lambda (x) (lambda (y) 0))]) + (lambda (a b c) + ((zz (let ([loop (lambda () 0)]) loop)) (car a)) + (list a #t)))) + ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Check that the unused continuations are removed @@ -4179,9 +4203,9 @@ (test-values '(-100001.0t0 100001.0t0) tail))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Check for corect fixpoint calculation when lifting +;; Check for correct fixpoint calculation when lifting -;; This test is especilly fragile. It's a minimized(?) variant +;; This test is especially fragile. It's a minimized(?) variant ;; of PR 12910, where just enbought `with-continuation-mark's ;; are needed to thwart inlining, and enough functions are ;; present in the right order to require enough fixpoint diff --git a/racket/src/racket/src/optimize.c b/racket/src/racket/src/optimize.c index 3d700107e2..11cf2f1ac5 100644 --- a/racket/src/racket/src/optimize.c +++ b/racket/src/racket/src/optimize.c @@ -1959,7 +1959,7 @@ Scheme_Object *optimize_for_inline(Optimize_Info *info, Scheme_Object *le, int a id_offset, orig_le, prev); if (id_offset) { optimize_info_done(sub_info, NULL); - merge_types(sub_info, info, id_offset); + merge_types(sub_info, info, -id_offset); } return le; } else { @@ -5922,7 +5922,7 @@ scheme_optimize_lets(Scheme_Object *form, Optimize_Info *info, int for_inline, i info->single_result = sub_info->single_result; info->preserves_marks = sub_info->preserves_marks; optimize_info_done(sub_info, NULL); - merge_types(sub_info, info, 1); + merge_types(sub_info, info, -1); } return form; @@ -5948,7 +5948,7 @@ scheme_optimize_lets(Scheme_Object *form, Optimize_Info *info, int for_inline, i info->single_result = sub_info->single_result; info->preserves_marks = sub_info->preserves_marks; optimize_info_done(sub_info, NULL); - merge_types(sub_info, info, 1); + merge_types(sub_info, info, -1); return body; } }