diff --git a/src/Data/Abstract/Heap.hs b/src/Data/Abstract/Heap.hs index a0f0fde32..9e39cd745 100644 --- a/src/Data/Abstract/Heap.hs +++ b/src/Data/Abstract/Heap.hs @@ -16,6 +16,7 @@ module Data.Abstract.Heap , pathDeclaration , lookupFrameAddress , lookupDeclaration + , isHeapEmpty ) where import Data.Abstract.Live @@ -104,6 +105,13 @@ fillFrame address slots heap = heapSize :: Heap scope address value -> Int heapSize = Map.size . heap +isHeapEmpty :: (Eq address, Eq value) => Heap scope address value -> Bool +isHeapEmpty h@Heap{..} = isJust currentFrame && + (heapSize h) == 1 && + (toEmptyFrame <$> Map.elems heap) == [ Frame () mempty mempty ] + where + toEmptyFrame Frame{..} = Frame () (Map.mapKeysMonotonic (const ()) <$> links) slots + -- -- | A map of addresses onto cells holding their values. -- newtype Heap address address value = Heap { unHeap :: Monoidal.Map address (Set value) } -- deriving (Eq, Foldable, Lower, Monoid, Ord, Semigroup) diff --git a/test/Analysis/TypeScript/Spec.hs b/test/Analysis/TypeScript/Spec.hs index 8c3ae0106..0d09079c5 100644 --- a/test/Analysis/TypeScript/Spec.hs +++ b/test/Analysis/TypeScript/Spec.hs @@ -73,7 +73,7 @@ spec config = parallel $ do it "side effect only imports" $ do (_, res) <- evaluate ["main2.ts", "a.ts", "foo.ts"] case ModuleTable.lookup "main2.ts" <$> res of - Right (Just (Module _ (_, (heap, _)) :| [])) -> heap `shouldBe` lowerBound + Right (Just (Module _ (_, (heap, _)) :| [])) -> heap `shouldSatisfy` Heap.isHeapEmpty other -> expectationFailure (show other) it "fails exporting symbols not defined in the module" $ do