cs: fix encuoraged and cross-module inlining of set!

When an inlined `set!` mutates a variable that's bound in the inlined
function, the `set!` target was not updated to refer to the inlined
binding.

Closes #3817
This commit is contained in:
Matthew Flatt 2021-05-06 07:02:22 -06:00
parent 849d66adaa
commit 180983fb4b
3 changed files with 22 additions and 5 deletions

View File

@ -7132,6 +7132,21 @@
(f (+ 6.0 (one)) (+ 6.0 (one))))) (f (+ 6.0 (one)) (+ 6.0 (one)))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Regression test to checking inlingin with `set!`:
(module check-inline-of-set!-expression racket/base
(require racket/performance-hint)
(begin-encourage-inline
(define (f x)
(let ([y 0])
(set! y (+ y x))
y)))
(define result (list (f 1) (f 2)))
(provide result))
(test '(1 2) dynamic-require ''check-inline-of-set!-expression 'result)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(report-errs) (report-errs)

View File

@ -12722,10 +12722,12 @@
(values id_1 rhs_0))))))) (values id_1 rhs_0)))))))
(case-lambda (case-lambda
((id_0 rhs_0) ((id_0 rhs_0)
(list (let ((app_0
'set! (clone-expr id_0 env_0 mutated_0)))
id_0 (list
(clone-expr rhs_0 env_0 mutated_0))) 'set!
app_0
(clone-expr rhs_0 env_0 mutated_0))))
(args (args
(raise-binding-result-arity-error 2 args)))) (raise-binding-result-arity-error 2 args))))
(if (if (eq? '|#%variable-reference| hd_0) (if (if (eq? '|#%variable-reference| hd_0)

View File

@ -207,7 +207,7 @@
[`(begin-unsafe ,exps ...) [`(begin-unsafe ,exps ...)
`(begin-unsafe . ,(clone-body exps env mutated))] `(begin-unsafe . ,(clone-body exps env mutated))]
[`(set! ,id ,rhs) [`(set! ,id ,rhs)
`(set! ,id ,(clone-expr rhs env mutated))] `(set! ,(clone-expr id env mutated) ,(clone-expr rhs env mutated))]
[`(#%variable-reference) v] [`(#%variable-reference) v]
[`(#%variable-reference ,id) [`(#%variable-reference ,id)
`(#%variable-reference ,(clone-expr id env mutated))] `(#%variable-reference ,(clone-expr id env mutated))]