Fix instances of Reify and Reflect for lists of references.
facundominguez opened this issue · 0 comments
facundominguez commented
These instances used to work when reify j
produced a global reference of j
. But now, reify [j]
will delete the very local references that it is returning, and reflect [j]
will delete the input j
likely surprising the user.
Perhaps reify
and reflect
could be fixed by using local frames depending on how expensive they are.
instance Reify a => Reify [a] where
reify jobj = do
n <- getArrayLength jobj
forM [0..n-1] $ \i -> do
jx <- getObjectArrayElement jobj i
x <- reify jx
deleteLocalRef jx
return x
instance Reflect a => Reflect [a] where
reflect xs = do
let n = fromIntegral (length xs)
array <- newArray n :: IO (J ('Array (Interp a)))
forM_ (zip [0..n-1] xs) $ \(i, x) -> do
jx <- reflect x
setObjectArrayElement array i jx
deleteLocalRef jx
return array