From 933e3c14b581f1449b0b15c280daa25bfa8962dd Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sun, 28 Oct 2018 18:50:56 -0600 Subject: [PATCH] bytecode: fix "preserves marks" annotation w.r.t call/immediate-mark A function that uses `call-with-immediate-continuation-mark` in tail position should not be flagged as "preserves marks", because the JIT needs to bump the mark stack if the function is called in non-tail position. Closes #2333 --- .../tests/racket/optimize.rktl | 36 +++++++++++++++++++ racket/src/racket/src/optimize.c | 2 ++ 2 files changed, 38 insertions(+) diff --git a/pkgs/racket-test-core/tests/racket/optimize.rktl b/pkgs/racket-test-core/tests/racket/optimize.rktl index 78aede26e2..a862deec57 100644 --- a/pkgs/racket-test-core/tests/racket/optimize.rktl +++ b/pkgs/racket-test-core/tests/racket/optimize.rktl @@ -6371,4 +6371,40 @@ ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(module optimizes-to-with-immediate-continuation-mark-in-noninlined racket/base + (define (call/icm proc) + (call-with-immediate-continuation-mark + 'x + (lambda (v) + ;; The constant '(1 2 3) currently prevents inlining + (if (proc '(1 2 3)) + (proc v) + #f)))) + + (define (call/cm proc) + (if (zero? (random 1)) + (with-continuation-mark + 'x 'y + (proc)) + ;; disable inline: + '(3 4 5))) + + (define result + (let ([in? #f] + [result #f]) + (call/cm + (lambda () + (set! in? #t) + (call/icm + (lambda (v) + (set! result v))) + (set! in? #f))) + result)) + + (provide result)) + +(test #f dynamic-require ''optimizes-to-with-immediate-continuation-mark-in-noninlined 'result) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (report-errs) diff --git a/racket/src/racket/src/optimize.c b/racket/src/racket/src/optimize.c index b79e9a992d..150b5564bf 100644 --- a/racket/src/racket/src/optimize.c +++ b/racket/src/racket/src/optimize.c @@ -6539,6 +6539,8 @@ with_immed_mark_optimize(Scheme_Object *data, Optimize_Info *info, int context) wcm->val = val; SCHEME_CDR(wcm->body) = body; + info->preserves_marks = 0; + return data; }