Forcing evaluation of some expressions to detect multiple uses of variable in while loops.

This commit is contained in:
Erik Svedäng 2017-10-18 21:22:32 +02:00
parent 6a310844d5
commit fb41915876
3 changed files with 8 additions and 3 deletions

View File

@ -3,7 +3,6 @@
## Critical Bugs
* Ensure 'Array.pop-back' is memory safe and shrinks the array properly.
* Can't define globals of with heap allocated types (String, structs, etc.)
* Looping over a block of code where an external array is endo-map:ed over.
* Arrays can contain references, this will lead to dangling pointers.
## Ugliness

View File

@ -1,2 +1,6 @@
;; This file contains examples of unsolved bugs
(defn main []
(let [stuff [@"a" @"b" @"c"]]
(while true
(Array.delete stuff))))

View File

@ -144,12 +144,14 @@ manageMemory typeEnv globalEnv root =
manage body
postDeleters <- get
-- Visit an extra time to simulate repeated use
_ <- visit expr
_ <- visit body
visitedExpr2 <- visit expr
visitedBody2 <- visit body
let diff = postDeleters Set.\\ preDeleters
put (postDeleters Set.\\ diff) -- Same as just pre deleters, right?!
return $ do okExpr <- visitedExpr
okBody <- visitedBody
okExpr2 <- visitedExpr2 -- This evaluates the second visit so that it actually produces the error
okBody2 <- visitedBody2 -- And this one too. Laziness FTW.
let newInfo = setDeletersOnInfo i diff
return (XObj (Lst (whileExpr : okExpr : okBody : [])) newInfo t)