From 9b3c3d279f82e5407f3ba218977533fc37ccbdd2 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 12:07:37 -0400 Subject: [PATCH 01/13] Remove Variable --- src/Language/Python/Assignment.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Language/Python/Assignment.hs b/src/Language/Python/Assignment.hs index 5f91b8290..c3711c54d 100644 --- a/src/Language/Python/Assignment.hs +++ b/src/Language/Python/Assignment.hs @@ -48,7 +48,6 @@ type Syntax = , Declaration.Comprehension , Declaration.Decorator , Declaration.Function - , Declaration.Variable , Expression.Plus , Expression.Minus , Expression.Times From e833ad4feffe55f0c0e1c3760a339ecf4566a284 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 12:59:29 -0400 Subject: [PATCH 02/13] add eval instance for sequence expression --- src/Data/Syntax/Expression.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index dd4c8c2f1..22cd317c3 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -284,7 +284,9 @@ instance Ord1 SequenceExpression where liftCompare = genericLiftCompare instance Show1 SequenceExpression where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for SequenceExpression -instance Evaluatable SequenceExpression +instance Evaluatable SequenceExpression where + eval (SequenceExpression a b) = + subtermValue a >> subtermRef b -- | Javascript void operator From 6aa043482d15c1c147342ec9cbfeb86b7c8f12ab Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 15:18:23 -0400 Subject: [PATCH 03/13] add eval instance for sequence expression --- src/Data/Syntax/Expression.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index 22cd317c3..5938523b0 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -288,7 +288,6 @@ instance Evaluatable SequenceExpression where eval (SequenceExpression a b) = subtermValue a >> subtermRef b - -- | Javascript void operator newtype Void a = Void { value :: a } deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1) From 29a49ca4fbe4165c6bcfae44d78937f1d93fc015 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 15:29:31 -0400 Subject: [PATCH 04/13] regenerate failing python tests --- .../corpus/comparison-operator.diffB-A.txt | 20 ++++++------ .../python/corpus/exec-statement.diffA-B.txt | 31 +++++++------------ .../python/corpus/exec-statement.diffB-A.txt | 23 +++++++------- test/fixtures/python/corpus/float.diffA-B.txt | 6 ++-- test/fixtures/python/corpus/float.diffB-A.txt | 4 +-- .../corpus/import-from-statement.diffA-B.txt | 4 +-- .../corpus/import-from-statement.diffB-A.txt | 4 +-- .../python/corpus/integer.diffA-B.txt | 4 +-- .../python/corpus/integer.diffB-A.txt | 2 +- .../fixtures/python/corpus/string.diffA-B.txt | 4 +-- .../fixtures/python/corpus/string.diffB-A.txt | 2 +- .../python/corpus/unary-operator.diffB-A.txt | 7 +++-- 12 files changed, 52 insertions(+), 59 deletions(-) diff --git a/test/fixtures/python/corpus/comparison-operator.diffB-A.txt b/test/fixtures/python/corpus/comparison-operator.diffB-A.txt index fcbfd6c3f..70bc5763c 100644 --- a/test/fixtures/python/corpus/comparison-operator.diffB-A.txt +++ b/test/fixtures/python/corpus/comparison-operator.diffB-A.txt @@ -15,10 +15,12 @@ {+(GreaterThan {+(Identifier)+} {+(Identifier)+})+} -{+(Not - {+(Equal - {+(Identifier)+} - {+(Identifier)+})+})+} + (Not + (Equal + { (Identifier) + ->(Identifier) } + { (Identifier) + ->(Identifier) })) {+(Member {+(Identifier)+} {+(Identifier)+})+} @@ -29,12 +31,10 @@ {+(Member {+(Identifier)+} {+(Identifier)+})+})+} - (Not - (Equal - { (Identifier) - ->(Identifier) } - { (Identifier) - ->(Identifier) })) +{+(Not + {+(Equal + {+(Identifier)+} + {+(Identifier)+})+})+} {-(Not {-(Member {-(Identifier)-} diff --git a/test/fixtures/python/corpus/exec-statement.diffA-B.txt b/test/fixtures/python/corpus/exec-statement.diffA-B.txt index f51260a9b..6646dda54 100644 --- a/test/fixtures/python/corpus/exec-statement.diffA-B.txt +++ b/test/fixtures/python/corpus/exec-statement.diffA-B.txt @@ -1,28 +1,21 @@ (Statements -{+(Call - {+(Identifier)+} - {+(TextElement)+} - {+(Identifier)+} - {+(Empty)+})+} -{+(Call - {+(Identifier)+} - {+(TextElement)+} - {+(Identifier)+} - {+(Identifier)+} - {+(Empty)+})+} (Call (Identifier) { (TextElement) ->(TextElement) } + {+(Identifier)+} (Empty)) -{-(Call - {-(Identifier)-} - {-(TextElement)-} + (Call + (Identifier) + (TextElement) + {+(Identifier)+} + {+(Identifier)+} {-(Null)-} - {-(Empty)-})-} -{-(Call - {-(Identifier)-} - {-(TextElement)-} + (Empty)) + (Call + (Identifier) + { (TextElement) + ->(TextElement) } {-(Identifier)-} {-(Identifier)-} - {-(Empty)-})-}) + (Empty))) diff --git a/test/fixtures/python/corpus/exec-statement.diffB-A.txt b/test/fixtures/python/corpus/exec-statement.diffB-A.txt index 278c9efaf..0d66e13b5 100644 --- a/test/fixtures/python/corpus/exec-statement.diffB-A.txt +++ b/test/fixtures/python/corpus/exec-statement.diffB-A.txt @@ -1,22 +1,21 @@ (Statements -{+(Call - {+(Identifier)+} - {+(TextElement)+} - {+(Empty)+})+} + (Call + (Identifier) + { (TextElement) + ->(TextElement) } + {-(Identifier)-} + (Empty)) (Call (Identifier) (TextElement) {+(Null)+} + {-(Identifier)-} {-(Identifier)-} (Empty)) (Call (Identifier) - (TextElement) + { (TextElement) + ->(TextElement) } {+(Identifier)+} - (Identifier) - {-(Identifier)-} - (Empty)) -{-(Call - {-(Identifier)-} - {-(TextElement)-} - {-(Empty)-})-}) + {+(Identifier)+} + (Empty))) diff --git a/test/fixtures/python/corpus/float.diffA-B.txt b/test/fixtures/python/corpus/float.diffA-B.txt index 625f9e866..5faf63430 100644 --- a/test/fixtures/python/corpus/float.diffA-B.txt +++ b/test/fixtures/python/corpus/float.diffA-B.txt @@ -6,14 +6,14 @@ ->(Float) } {+(Float)+} {+(Float)+} -{+(Float)+} -{+(Float)+} { (Float) ->(Float) } {+(Float)+} {+(Float)+} {+(Float)+} -{-(Float)-} +{ (Float) +->(Float) } +{+(Float)+} {-(Float)-} {-(Float)-} {-(Float)-} diff --git a/test/fixtures/python/corpus/float.diffB-A.txt b/test/fixtures/python/corpus/float.diffB-A.txt index 77fccee5f..9021595bb 100644 --- a/test/fixtures/python/corpus/float.diffB-A.txt +++ b/test/fixtures/python/corpus/float.diffB-A.txt @@ -12,8 +12,8 @@ {+(Float)+} {+(Float)+} {+(Float)+} -{ (Float) -->(Float) } +{+(Float)+} +{-(Float)-} {-(Float)-} {-(Float)-} {-(Float)-} diff --git a/test/fixtures/python/corpus/import-from-statement.diffA-B.txt b/test/fixtures/python/corpus/import-from-statement.diffA-B.txt index 707005652..169cb908b 100644 --- a/test/fixtures/python/corpus/import-from-statement.diffA-B.txt +++ b/test/fixtures/python/corpus/import-from-statement.diffA-B.txt @@ -3,10 +3,10 @@ {+(Import)+} {+(Import)+} {+(Import)+} -{ (Import) -->(Import) } +{+(Import)+} {+(Import)+} {-(Import)-} {-(Import)-} {-(Import)-} +{-(Import)-} {-(Import)-}) diff --git a/test/fixtures/python/corpus/import-from-statement.diffB-A.txt b/test/fixtures/python/corpus/import-from-statement.diffB-A.txt index 1df038db2..180b64aa4 100644 --- a/test/fixtures/python/corpus/import-from-statement.diffB-A.txt +++ b/test/fixtures/python/corpus/import-from-statement.diffB-A.txt @@ -1,7 +1,6 @@ (Statements {+(Import)+} -{ (Import) -->(Import) } +{+(Import)+} {+(Import)+} {+(Import)+} { (Import) @@ -9,4 +8,5 @@ {-(Import)-} {-(Import)-} {-(Import)-} +{-(Import)-} {-(Import)-}) diff --git a/test/fixtures/python/corpus/integer.diffA-B.txt b/test/fixtures/python/corpus/integer.diffA-B.txt index c436722d6..50bb9395b 100644 --- a/test/fixtures/python/corpus/integer.diffA-B.txt +++ b/test/fixtures/python/corpus/integer.diffA-B.txt @@ -8,6 +8,8 @@ {+(Integer)+} {+(Negate {+(Integer)+})+} +{ (Integer) +->(Integer) } {+(Integer)+} {+(Integer)+} {+(Integer)+} @@ -15,8 +17,6 @@ {+(Integer)+} {+(Integer)+} {+(Integer)+} -{+(Integer)+} -{-(Integer)-} {-(Integer)-} {-(Negate {-(Integer)-})-} diff --git a/test/fixtures/python/corpus/integer.diffB-A.txt b/test/fixtures/python/corpus/integer.diffB-A.txt index 50bb9395b..89167fb73 100644 --- a/test/fixtures/python/corpus/integer.diffB-A.txt +++ b/test/fixtures/python/corpus/integer.diffB-A.txt @@ -8,6 +8,7 @@ {+(Integer)+} {+(Negate {+(Integer)+})+} +{+(Integer)+} { (Integer) ->(Integer) } {+(Integer)+} @@ -16,7 +17,6 @@ {+(Integer)+} {+(Integer)+} {+(Integer)+} -{+(Integer)+} {-(Integer)-} {-(Negate {-(Integer)-})-} diff --git a/test/fixtures/python/corpus/string.diffA-B.txt b/test/fixtures/python/corpus/string.diffA-B.txt index b8c7007ec..53f220d04 100644 --- a/test/fixtures/python/corpus/string.diffA-B.txt +++ b/test/fixtures/python/corpus/string.diffA-B.txt @@ -1,12 +1,12 @@ (Statements {+(TextElement)+} (TextElement) -{+(TextElement)+} -{+(TextElement)+} { (TextElement) ->(TextElement) } {+(TextElement)+} {+(TextElement)+} +{+(TextElement)+} +{+(TextElement)+} {-(TextElement)-} {-(TextElement)-} {-(TextElement)-} diff --git a/test/fixtures/python/corpus/string.diffB-A.txt b/test/fixtures/python/corpus/string.diffB-A.txt index 2a50b5e11..608b34482 100644 --- a/test/fixtures/python/corpus/string.diffB-A.txt +++ b/test/fixtures/python/corpus/string.diffB-A.txt @@ -1,13 +1,13 @@ (Statements {-(TextElement)-} (TextElement) -{+(TextElement)+} { (TextElement) ->(TextElement) } {+(TextElement)+} {+(TextElement)+} {+(TextElement)+} {+(TextElement)+} +{+(TextElement)+} {-(TextElement)-} {-(TextElement)-} {-(TextElement)-} diff --git a/test/fixtures/python/corpus/unary-operator.diffB-A.txt b/test/fixtures/python/corpus/unary-operator.diffB-A.txt index a0086cd4b..00f0a0845 100644 --- a/test/fixtures/python/corpus/unary-operator.diffB-A.txt +++ b/test/fixtures/python/corpus/unary-operator.diffB-A.txt @@ -2,9 +2,10 @@ {+(Negate {+(Identifier)+})+} {+(Identifier)+} - (Complement - { (Identifier) - ->(Identifier) }) +{+(Complement + {+(Identifier)+})+} +{-(Complement + {-(Identifier)-})-} {-(Negate {-(Identifier)-})-} {-(Identifier)-}) From fd70377a8526d84aa396e14c0e9c49fb15dd210d Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 16:03:03 -0400 Subject: [PATCH 05/13] add sequence expression to typescript test spec --- test/Analysis/TypeScript/Spec.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/Analysis/TypeScript/Spec.hs b/test/Analysis/TypeScript/Spec.hs index b89b2b9c2..57c0a2edb 100644 --- a/test/Analysis/TypeScript/Spec.hs +++ b/test/Analysis/TypeScript/Spec.hs @@ -46,6 +46,15 @@ spec config = parallel $ do Right (Just (Module _ (_, addr) :| [])) -> heapLookupAll addr heap `shouldBe` Just [Value.Float (Number.Decimal 123.0)] other -> expectationFailure (show other) + it "evaluates sequence expressions" $ do + (_, (heap, res)) <- evaluate ["sequence-expression.ts"] + case ModuleTable.lookup "sequence-expression.ts" <$> res of + Right (Just (Module _ (env, addr) :| [])) -> do + Env.names env `shouldBe` [ "x" ] + (derefQName heap ("x" :| []) env) `shouldBe` Just (Value.Float (Number.Decimal 3.0)) + + other -> expectationFailure (show other) + where fixtures = "test/fixtures/typescript/analysis/" evaluate = evalTypeScriptProject . map (fixtures <>) From 7ee4bad1730b64f2bc6edaa254b0a0a134dfa993 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 16:08:20 -0400 Subject: [PATCH 06/13] add sequence expression to test spec Co-Authored-By: Josh Vera --- test/fixtures/typescript/analysis/sequence-expression.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/fixtures/typescript/analysis/sequence-expression.ts diff --git a/test/fixtures/typescript/analysis/sequence-expression.ts b/test/fixtures/typescript/analysis/sequence-expression.ts new file mode 100644 index 000000000..61a83571b --- /dev/null +++ b/test/fixtures/typescript/analysis/sequence-expression.ts @@ -0,0 +1 @@ +x = (2,3); From 49072fc3997e4ebd83d992378fb21243b8972386 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 16:24:44 -0400 Subject: [PATCH 07/13] add evaluatable instance for void Co-Authored-By: Josh Vera --- src/Data/Syntax/Expression.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index 5938523b0..d66248c0a 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -7,7 +7,8 @@ import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedF import Data.Fixed import Data.JSON.Fields import Diffing.Algorithm -import Prologue hiding (index, Member, This) +import Prologue hiding (index, Member, This, null) +import Prelude hiding (null) import Proto3.Suite.Class -- | Typical prefix function application, like `f(x)` in many languages, or `f x` in Haskell. @@ -297,8 +298,9 @@ instance Ord1 Void where liftCompare = genericLiftCompare instance Show1 Void where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for Void -instance Evaluatable Void - +instance Evaluatable Void where + eval (Void a) = + subtermValue a >> rvalBox null -- | Javascript typeof operator newtype Typeof a = Typeof { value :: a } From 75aa8f76622abedda0016dded6e4389923dbb1bb Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 16:41:29 -0400 Subject: [PATCH 08/13] add tests for void --- test/Analysis/TypeScript/Spec.hs | 5 +++++ test/fixtures/typescript/analysis/void.ts | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 test/fixtures/typescript/analysis/void.ts diff --git a/test/Analysis/TypeScript/Spec.hs b/test/Analysis/TypeScript/Spec.hs index 57c0a2edb..d8f6f125b 100644 --- a/test/Analysis/TypeScript/Spec.hs +++ b/test/Analysis/TypeScript/Spec.hs @@ -52,7 +52,12 @@ spec config = parallel $ do Right (Just (Module _ (env, addr) :| [])) -> do Env.names env `shouldBe` [ "x" ] (derefQName heap ("x" :| []) env) `shouldBe` Just (Value.Float (Number.Decimal 3.0)) + other -> expectationFailure (show other) + it "evaluates void expressions" $ do + (_, (heap, res)) <- evaluate ["void.ts"] + case ModuleTable.lookup "void.ts" <$> res of + Right (Just (Module _ (_, addr) :| [])) -> heapLookupAll addr heap `shouldBe` Just [Null] other -> expectationFailure (show other) where diff --git a/test/fixtures/typescript/analysis/void.ts b/test/fixtures/typescript/analysis/void.ts new file mode 100644 index 000000000..7ea66d6d5 --- /dev/null +++ b/test/fixtures/typescript/analysis/void.ts @@ -0,0 +1,5 @@ +function foo() { + return "hi"; +} + +void foo(); From a3c36b89efd80b311d2da8f063e3bd83de6d3c53 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Thu, 9 Aug 2018 17:55:59 -0400 Subject: [PATCH 09/13] add evaluatable instance and test for delete Co-Authored-By: Josh Vera --- src/Control/Abstract/Heap.hs | 9 ++++++++- src/Data/Abstract/Heap.hs | 3 +++ src/Data/Map/Monoidal.hs | 4 ++++ src/Data/Syntax/Expression.hs | 10 +++++++--- test/Analysis/TypeScript/Spec.hs | 9 +++++++++ test/fixtures/typescript/analysis/delete.ts | 2 ++ 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/typescript/analysis/delete.ts diff --git a/src/Control/Abstract/Heap.hs b/src/Control/Abstract/Heap.hs index 5b7d9ff17..3f1b5276e 100644 --- a/src/Control/Abstract/Heap.hs +++ b/src/Control/Abstract/Heap.hs @@ -8,6 +8,7 @@ module Control.Abstract.Heap , putHeap , box , alloc +, dealloc , deref , assign , letrec @@ -16,7 +17,7 @@ module Control.Abstract.Heap -- * Garbage collection , gc -- * Effects -, Allocator(..) +, Allocator , runAllocator , Deref(..) , runDeref @@ -71,6 +72,9 @@ box val = do alloc :: Member (Allocator address value) effects => Name -> Evaluator address value effects address alloc = sendAllocator . Alloc +dealloc :: Member (Allocator address value) effects => address -> Evaluator address value effects () +dealloc = sendAllocator . Delete + -- | Dereference the given address in the heap, or fail if the address is uninitialized. deref :: Member (Deref address value) effects => address -> Evaluator address value effects value deref = send . Deref @@ -162,6 +166,7 @@ data Allocator address value (m :: * -> *) return where Alloc :: Name -> Allocator address value m address Assign :: address -> value -> Allocator address value m () GC :: Live address -> Allocator address value m () + Delete :: address -> Allocator address value m () data Deref address value (m :: * -> *) return where Deref :: address -> Deref address value m value @@ -179,6 +184,7 @@ runAllocator = interpret $ \ eff -> case eff of Alloc name -> allocCell name Assign addr value -> modifyHeap (heapInsert addr value) GC roots -> modifyHeap (heapRestrict <*> reachable roots) + Delete addr -> modifyHeap (heapDelete addr) runDeref :: ( Derefable address effects , PureEffects effects @@ -198,6 +204,7 @@ instance Effect (Allocator address value) where handleState c dist (Request (Alloc name) k) = Request (Alloc name) (dist . (<$ c) . k) handleState c dist (Request (Assign addr value) k) = Request (Assign addr value) (dist . (<$ c) . k) handleState c dist (Request (GC roots) k) = Request (GC roots) (dist . (<$ c) . k) + handleState c dist (Request (Delete addr) k) = Request (Delete addr) (dist . (<$ c) . k) instance PureEffect (Deref address value) diff --git a/src/Data/Abstract/Heap.hs b/src/Data/Abstract/Heap.hs index 956be461f..03609b508 100644 --- a/src/Data/Abstract/Heap.hs +++ b/src/Data/Abstract/Heap.hs @@ -4,6 +4,7 @@ module Data.Abstract.Heap , heapLookup , heapLookupAll , heapInsert + , heapDelete , heapInit , heapSize , heapRestrict @@ -42,6 +43,8 @@ heapSize = Monoidal.size . unHeap heapRestrict :: Ord address => Heap address cell value -> Live address -> Heap address cell value heapRestrict (Heap m) roots = Heap (Monoidal.filterWithKey (\ address _ -> address `liveMember` roots) m) +heapDelete :: Ord address => address -> Heap address cell value -> Heap address cell value +heapDelete addr = Heap . (Monoidal.delete addr) . unHeap instance (Ord address, Reducer value (cell value)) => Reducer (address, value) (Heap address cell value) where unit = Heap . unit diff --git a/src/Data/Map/Monoidal.hs b/src/Data/Map/Monoidal.hs index 6fa553857..3711fd1b2 100644 --- a/src/Data/Map/Monoidal.hs +++ b/src/Data/Map/Monoidal.hs @@ -6,6 +6,7 @@ module Data.Map.Monoidal , singleton , size , insert +, delete , filterWithKey , pairs , keys @@ -35,6 +36,9 @@ size = Map.size . unMap insert :: Ord key => key -> value -> Map key value -> Map key value insert key value = Map . Map.insert key value . unMap +delete :: Ord key => key -> Map key value -> Map key value +delete key = Map . Map.delete key . unMap + filterWithKey :: (key -> value -> Bool) -> Map key value -> Map key value filterWithKey f = Map . Map.filterWithKey f . unMap diff --git a/src/Data/Syntax/Expression.hs b/src/Data/Syntax/Expression.hs index d66248c0a..705e684f7 100644 --- a/src/Data/Syntax/Expression.hs +++ b/src/Data/Syntax/Expression.hs @@ -6,7 +6,7 @@ import Data.Abstract.Evaluatable hiding (Member) import Data.Abstract.Number (liftIntegralFrac, liftReal, liftedExponent, liftedFloorDiv) import Data.Fixed import Data.JSON.Fields -import Diffing.Algorithm +import Diffing.Algorithm hiding (Delete) import Prologue hiding (index, Member, This, null) import Prelude hiding (null) import Proto3.Suite.Class @@ -273,8 +273,12 @@ instance Ord1 Delete where liftCompare = genericLiftCompare instance Show1 Delete where liftShowsPrec = genericLiftShowsPrec -- TODO: Implement Eval instance for Delete -instance Evaluatable Delete - +instance Evaluatable Delete where + eval (Delete a) = do + valueRef <- subtermRef a + addr <- address valueRef + dealloc addr + rvalBox unit -- | A sequence expression such as Javascript or C's comma operator. data SequenceExpression a = SequenceExpression { firstExpression :: !a, secondExpression :: !a } diff --git a/test/Analysis/TypeScript/Spec.hs b/test/Analysis/TypeScript/Spec.hs index d8f6f125b..b4f20090c 100644 --- a/test/Analysis/TypeScript/Spec.hs +++ b/test/Analysis/TypeScript/Spec.hs @@ -60,6 +60,15 @@ spec config = parallel $ do Right (Just (Module _ (_, addr) :| [])) -> heapLookupAll addr heap `shouldBe` Just [Null] other -> expectationFailure (show other) + it "evaluates delete" $ do + (_, (heap, res)) <- evaluate ["delete.ts"] + case ModuleTable.lookup "delete.ts" <$> res of + Right (Just (Module _ (env, addr) :| [])) -> do + heapLookupAll addr heap `shouldBe` Just [Unit] + (derefQName heap ("x" :| []) env) `shouldBe` Nothing + Env.names env `shouldBe` [ "x" ] + other -> expectationFailure (show other) + where fixtures = "test/fixtures/typescript/analysis/" evaluate = evalTypeScriptProject . map (fixtures <>) diff --git a/test/fixtures/typescript/analysis/delete.ts b/test/fixtures/typescript/analysis/delete.ts new file mode 100644 index 000000000..dd2b5d796 --- /dev/null +++ b/test/fixtures/typescript/analysis/delete.ts @@ -0,0 +1,2 @@ +x = 3; +delete x; From 2906e39b71937112d50b1e5ad29441668d238ee1 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Fri, 10 Aug 2018 16:57:53 -0400 Subject: [PATCH 10/13] remove redundant brackets --- src/Data/Abstract/Heap.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Abstract/Heap.hs b/src/Data/Abstract/Heap.hs index b07d9d73f..b602a8b87 100644 --- a/src/Data/Abstract/Heap.hs +++ b/src/Data/Abstract/Heap.hs @@ -44,7 +44,7 @@ heapRestrict :: Ord address => Heap address value -> Live address -> Heap addres heapRestrict (Heap m) roots = Heap (Monoidal.filterWithKey (\ address _ -> address `liveMember` roots) m) heapDelete :: Ord address => address -> Heap address cell value -> Heap address cell value -heapDelete addr = Heap . (Monoidal.delete addr) . unHeap +heapDelete addr = Heap . Monoidal.delete addr . unHeap instance (Ord address, Ord value) => Reducer (address, value) (Heap address value) where unit = Heap . unit From 054f5b4b36c1f26b28814e2a908f47668ba8f387 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Fri, 10 Aug 2018 17:41:46 -0400 Subject: [PATCH 11/13] fix heapDelete type signature --- src/Data/Abstract/Heap.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data/Abstract/Heap.hs b/src/Data/Abstract/Heap.hs index b602a8b87..740046f55 100644 --- a/src/Data/Abstract/Heap.hs +++ b/src/Data/Abstract/Heap.hs @@ -43,7 +43,7 @@ heapSize = Monoidal.size . unHeap heapRestrict :: Ord address => Heap address value -> Live address -> Heap address value heapRestrict (Heap m) roots = Heap (Monoidal.filterWithKey (\ address _ -> address `liveMember` roots) m) -heapDelete :: Ord address => address -> Heap address cell value -> Heap address cell value +heapDelete :: Ord address => address -> Heap address value -> Heap address value heapDelete addr = Heap . Monoidal.delete addr . unHeap instance (Ord address, Ord value) => Reducer (address, value) (Heap address value) where From b54f175ebfd72d804ed3b39176faee62b3b5b9ef Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Mon, 13 Aug 2018 10:20:13 -0400 Subject: [PATCH 12/13] update examples --- test/fixtures/ruby/corpus/unless.parseB.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/fixtures/ruby/corpus/unless.parseB.txt b/test/fixtures/ruby/corpus/unless.parseB.txt index 9662e1fab..e69de29bb 100644 --- a/test/fixtures/ruby/corpus/unless.parseB.txt +++ b/test/fixtures/ruby/corpus/unless.parseB.txt @@ -1,13 +0,0 @@ -(Statements - (If - (Not - (Send - (Identifier))) - (Statements) - (Empty)) - (If - (Not - (Send - (Identifier))) - (Statements) - (Empty))) From d107446abf3af43cb178bd8f7c6bc7dbf91fd4e1 Mon Sep 17 00:00:00 2001 From: Ayman Nadeem Date: Mon, 13 Aug 2018 10:43:44 -0400 Subject: [PATCH 13/13] re-generate ruby example --- test/fixtures/ruby/corpus/unless.parseB.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/fixtures/ruby/corpus/unless.parseB.txt b/test/fixtures/ruby/corpus/unless.parseB.txt index e69de29bb..9662e1fab 100644 --- a/test/fixtures/ruby/corpus/unless.parseB.txt +++ b/test/fixtures/ruby/corpus/unless.parseB.txt @@ -0,0 +1,13 @@ +(Statements + (If + (Not + (Send + (Identifier))) + (Statements) + (Empty)) + (If + (Not + (Send + (Identifier))) + (Statements) + (Empty)))