-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document unsafe operations of AssocMap
#5838
Conversation
Signed-off-by: Ana Pantilie <[email protected]>
Signed-off-by: Ana Pantilie <[email protected]>
Signed-off-by: Ana Pantilie <[email protected]>
Signed-off-by: Ana Pantilie <[email protected]>
plutus-tx/src/PlutusTx/AssocMap.hs
Outdated
-- have been checked to not contain duplicate pairs or duplicate keys, otherwise the 'Map' invariant | ||
-- will be broken. As usual, the "keys" are considered to be the first element of the pair. | ||
unsafeFromList :: [(k, v)] -> Map k v | ||
unsafeFromList = Map | ||
|
||
{-# INLINEABLE fromListSafe #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the other one is called unsafeFromList
, it's better to call this one safeFromList
.
plutus-tx/src/PlutusTx/AssocMap.hs
Outdated
fromList = Map | ||
{-# INLINEABLE unsafeFromList #-} | ||
-- | Unsafely create a 'Map' from a list of pairs. This should _only_ be applied to lists which | ||
-- have been checked to not contain duplicate pairs or duplicate keys, otherwise the 'Map' invariant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- "duplicate pairs or duplicate keys" - is it not enough to just say "duplicate keys"?
- It may not be obvious what "the 'Map' invariant will be broken" means. I think it's worth elaborating a bit.
@@ -53,15 +53,13 @@ import GHC.Generics (Generic) | |||
import Language.Haskell.TH.Syntax as TH (Lift) | |||
import Prettyprinter (Pretty (..)) | |||
|
|||
{- HLINT ignore "Use newtype instead of data" -} | |||
|
|||
-- See Note [Optimising Value]. | |||
-- | A 'Map' of key-value pairs. | |||
newtype Map k v = Map {unMap :: [(k, v)]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand the Haddock of the Map
type to summarize which operations are unsafe? Otherwise people may miss the Haddock on the instances.
Signed-off-by: Ana Pantilie <[email protected]>
Signed-off-by: Ana Pantilie <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
`fromList` was deprecated in `1.24.0.0` by IntersectMBO/plutus#5838
`fromList` was deprecated in `1.24.0.0` by IntersectMBO/plutus#5838
`fromList` was deprecated in `1.24.0.0` by IntersectMBO/plutus#5838
* Plutus 1.25.0.0 * Replace `fromList` with `unsafeFromList` `fromList` was deprecated in `1.24.0.0` by IntersectMBO/plutus#5838 * Bump patch versions --------- Co-authored-by: Lucsanszky <[email protected]> Co-authored-by: Lucsanszky <[email protected]>
Pre-submit checklist: