diff --git a/docs/Todo.md b/docs/Todo.md index 7df06bd1..6b09d7cb 100644 --- a/docs/Todo.md +++ b/docs/Todo.md @@ -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 diff --git a/examples/bugs.carp b/examples/bugs.carp index a21624ef..fb95f437 100644 --- a/examples/bugs.carp +++ b/examples/bugs.carp @@ -1,2 +1,6 @@ ;; This file contains examples of unsolved bugs +(defn main [] + (let [stuff [@"a" @"b" @"c"]] + (while true + (Array.delete stuff)))) diff --git a/src/ManageMemory.hs b/src/ManageMemory.hs index 95736f2a..93e4f023 100644 --- a/src/ManageMemory.hs +++ b/src/ManageMemory.hs @@ -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)