From 329f7b5401befa3ecd63dc37acf33b127e38400e Mon Sep 17 00:00:00 2001 From: Ana Pantilie Date: Fri, 7 Jun 2024 15:24:06 +0300 Subject: [PATCH] Revert "Add Data.AssocMap fix" This reverts commit c4e88bd01e43603d1c8727aa294620c50775e3ac. --- ...ScriptContextEqualityTerm-20.budget.golden | 4 +-- plutus-tx/src/PlutusTx/AssocMap.hs | 4 +++ plutus-tx/src/PlutusTx/Data/AssocMap.hs | 31 +------------------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/plutus-benchmark/script-contexts/test/9.6/checkScriptContextEqualityTerm-20.budget.golden b/plutus-benchmark/script-contexts/test/9.6/checkScriptContextEqualityTerm-20.budget.golden index ac4b9e4cb36..26c4a590569 100644 --- a/plutus-benchmark/script-contexts/test/9.6/checkScriptContextEqualityTerm-20.budget.golden +++ b/plutus-benchmark/script-contexts/test/9.6/checkScriptContextEqualityTerm-20.budget.golden @@ -1,2 +1,2 @@ -({cpu: 205618894 -| mem: 1216678}) \ No newline at end of file +({cpu: 201521366 +| mem: 1194270}) \ No newline at end of file diff --git a/plutus-tx/src/PlutusTx/AssocMap.hs b/plutus-tx/src/PlutusTx/AssocMap.hs index 3fc21ccd906..37ebb73cc4e 100644 --- a/plutus-tx/src/PlutusTx/AssocMap.hs +++ b/plutus-tx/src/PlutusTx/AssocMap.hs @@ -74,6 +74,10 @@ newtype Map k v = Map {unMap :: [(k, v)]} deriving stock (Generic, Haskell.Show, Data, TH.Lift) deriving newtype (NFData) +instance (Eq k, Eq v) => Eq (Map k v) where + Map m1 == m2 = + List.all (\(k, v) -> lookup k m2 == Just v) m1 + instance (Haskell.Eq k, Haskell.Eq v) => Haskell.Eq (Map k v) where Map m1 == Map m2 = Haskell.all (\(k, v) -> Haskell.lookup k m2 Haskell.== Just v) m1 diff --git a/plutus-tx/src/PlutusTx/Data/AssocMap.hs b/plutus-tx/src/PlutusTx/Data/AssocMap.hs index 63aacbef0f7..48712bd3274 100644 --- a/plutus-tx/src/PlutusTx/Data/AssocMap.hs +++ b/plutus-tx/src/PlutusTx/Data/AssocMap.hs @@ -57,24 +57,7 @@ this implementation provides slow lookup and update operations because it is bas on a list representation. -} newtype Map k a = Map (BI.BuiltinList (BI.BuiltinPair BuiltinData BuiltinData)) - deriving stock (Haskell.Show) - -instance (Haskell.Eq k, Haskell.Eq v) => Haskell.Eq (Map k v) where - m1 == m2@(Map m2') = - size m1 == size m2 - && all' (\(P.pairToPair -> (k, v)) -> lookup' k m2' Haskell.== Just v) m1 - where - all' p (Map m) = go m - where - go xs = - P.matchList - xs - (\() -> True) - ( \hd tl -> - if p hd - then go tl - else False - ) + deriving stock (Haskell.Eq, Haskell.Show) instance P.ToData (Map k a) where {-# INLINEABLE toBuiltinData #-} @@ -88,18 +71,6 @@ instance P.UnsafeFromData (Map k a) where {-# INLINABLE unsafeFromBuiltinData #-} unsafeFromBuiltinData = Map . BI.unsafeDataAsMap -{-# INLINEABLE size #-} -size :: forall k a. Map k a -> Integer -size (Map m) = go m - where - go l = - P.matchList - l - (\() -> 0) - ( \_ tl -> - 1 + go tl - ) - {-# INLINEABLE lookup #-} -- | Look up the value corresponding to the key. -- If the `Map` is not well-defined, the result is the value associated with