Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

Commit 149813a

Browse files
committed
cs: fix schemify bug with imported mutated variable
Closes racket#3998
1 parent 33ebd4f commit 149813a

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pkgs/racket-test-core/tests/racket/optimize.rktl

+19
Original file line numberDiff line numberDiff line change
@@ -7147,6 +7147,25 @@
71477147

71487148
(test '(1 2) dynamic-require ''check-inline-of-set!-expression 'result)
71497149

7150+
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7151+
;; Regression test for schemify cross-module inlining
7152+
7153+
(module modifies-its-exported-variable racket/base
7154+
(provide (all-defined-out))
7155+
(define X '())
7156+
(define (change-X!)
7157+
(set! X (cons 'shouldnt-be X))))
7158+
7159+
(module uses-imported-variable-before-modify racket/base
7160+
(require 'modifies-its-exported-variable)
7161+
(provide old-X)
7162+
(define old-X
7163+
(let ([copy-of-X X])
7164+
(change-X!)
7165+
copy-of-X)))
7166+
7167+
(test '() dynamic-require ''uses-imported-variable-before-modify 'old-X)
7168+
71507169
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
71517170

71527171
(report-errs)

racket/src/cs/schemified/schemify.scm

+3-1
Original file line numberDiff line numberDiff line change
@@ -14242,7 +14242,9 @@
1424214242
c2_0)))
1424314243
(if defn8_0
1424414244
a-known-constant
14245-
(known-copy rhs_0))))))))
14245+
(if (hash-ref imports12_0 u-rhs_0 #f)
14246+
a-known-constant
14247+
(known-copy rhs_0)))))))))
1424614248
(if (parameter-result?
1424714249
rhs_0
1424814250
prim-knowns11_0

racket/src/schemify/infer-known.rkt

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
(known-copy rhs)]
8181
[else known]))]
8282
[defn a-known-constant]
83+
[(hash-ref imports u-rhs #f)
84+
;; imported, but nothing known about it => could be mutable
85+
a-known-constant]
8386
[else (known-copy rhs)])]
8487
[(parameter-result? rhs prim-knowns knowns mutated)
8588
(known-procedure 3)]

0 commit comments

Comments
 (0)