cp0: repair move of non-tail into 'effect context

Kent noticed the bug, where `make-nontail` used `ignored` where it
should have used `effect`. Also, Kent points out that `make-nontail`
can skip the `$values` wrapped in `effect` contexts in unsafe mode.

original commit: edd9ba3d656f3bd712e5e235b77225f756397077
This commit is contained in:
Matthew Flatt 2020-05-23 06:30:02 -06:00
parent c5ee80bf0d
commit 75f287befd
2 changed files with 18 additions and 6 deletions

View File

@ -3042,6 +3042,13 @@
(not (equivalent-expansion?
(expand/optimize `(lambda (g) ,(mk `(g))))
'(lambda (g) (g))))
;; When moving into an ignored position, ensure single valued
;; in safe mode:
(equivalent-expansion?
(expand/optimize `(lambda (g) ,(mk `(g)) 0))
(if (= 3 (optimize-level))
'(lambda (g) (g) 0)
'(lambda (g) (#3%$value (g)) 0)))
;; Ditto, but in a nested procedure:
(not (equivalent-expansion?
(expand/optimize `(lambda () (lambda (g) ,(mk `(g)))))

View File

@ -853,12 +853,17 @@
(define make-nontail
(lambda (ctxt e)
(if (context-case ctxt
[(tail) (single-valued-without-inspecting-continuation? e)]
[(ignored) (single-valued? e)]
[else #t])
e
(build-primcall 3 '$value (list e)))))
(context-case ctxt
[(tail)
(if (single-valued-without-inspecting-continuation? e)
e
(build-primcall 3 '$value (list e)))]
;; An 'effect, 'ignored, 'value, or 'test position will not
;; have any attachment on the immediate continuation.
;; Also, an 'ignored, 'value, or 'test position will already
;; enforce a single result value
[(effect) (safe-single-value e)]
[else e])))
(define result-exp
(lambda (e)