-
Notifications
You must be signed in to change notification settings - Fork 102
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
support ghc-9.10 #1367
support ghc-9.10 #1367
Changes from 4 commits
6a9e2ae
9396bff
8ade427
6098d80
128cbce
16e6af9
8074515
fd731a2
346bc88
750d74c
cf9c59b
8e5d9f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||
{-# LANGUAGE CPP #-} | ||||||
|
||||||
#if MIN_VERSION_base(4,20,0) | ||||||
{-# OPTIONS_GHC -Wno-x-partial #-} | ||||||
#endif | ||||||
|
||||||
|
||||||
-- | | ||||||
-- Module: unsafe.Data.Foldable.Unsafe | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-- Copyright: Copyright © 2024 Kadena LLC. | ||||||
-- License: MIT | ||||||
-- Maintainer: Pact Team | ||||||
-- Stability: experimental | ||||||
-- | ||||||
-- This module provides unsafe versions for all functions in "Data.Foldable" | ||||||
-- that are either partial or return a 'Maybe' value. | ||||||
-- | ||||||
module Data.Foldable.Unsafe | ||||||
( | ||||||
-- * Unsafe versions of partial functions | ||||||
unsafeMaximum | ||||||
, unsafeMaximumBy | ||||||
, unsafeMinimum | ||||||
, unsafeMinimumBy | ||||||
|
||||||
-- * Unsafe versions of functions that return 'Maybe' values | ||||||
, unsafeFind | ||||||
) where | ||||||
|
||||||
import Data.Foldable | ||||||
|
||||||
import GHC.Stack | ||||||
|
||||||
-- -------------------------------------------------------------------------- -- | ||||||
-- Unsafe versions of partial functions | ||||||
|
||||||
unsafeMaximum :: HasCallStack => Foldable t => Ord a => t a -> a | ||||||
unsafeMaximum = maximum | ||||||
|
||||||
unsafeMaximumBy :: HasCallStack => Foldable t => (a -> a -> Ordering) -> t a -> a | ||||||
unsafeMaximumBy = maximumBy | ||||||
|
||||||
unsafeMinimum :: HasCallStack => (Foldable t, Ord a) => t a -> a | ||||||
unsafeMinimum = minimum | ||||||
|
||||||
unsafeMinimumBy :: HasCallStack => Foldable t => (a -> a -> Ordering) -> t a -> a | ||||||
unsafeMinimumBy = minimumBy | ||||||
|
||||||
-- -------------------------------------------------------------------------- -- | ||||||
-- Unsafe versions of functions that return Maybe | ||||||
|
||||||
unsafeFind :: HasCallStack => Foldable t => (a -> Bool) -> t a -> a | ||||||
unsafeFind a b = case find a b of | ||||||
Nothing -> error "Data.List.Unsafe.unsafeFind: not found" | ||||||
Just x -> x | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
#if MIN_VERSION_base(4,20,0) | ||
{-# OPTIONS_GHC -Wno-x-partial #-} | ||
#endif | ||
|
||
-- | | ||
-- Module: Data.List.Unsafe | ||
-- Copyright: Copyright © 2024 Kadena LLC. | ||
-- License: MIT | ||
-- Maintainer: Pact Team | ||
-- Stability: experimental | ||
-- | ||
-- This module provides unsafe versions for all functions in "Data.List" that | ||
-- are either partial or return a 'Maybe' value. | ||
-- | ||
module Data.List.Unsafe | ||
( | ||
-- * Unsafe versions of partial functions | ||
unsafeHead | ||
, unsafeLast | ||
, unsafeTail | ||
, unsafeInit | ||
, unsafeIndex | ||
, unsafeGenericIndex | ||
|
||
-- * Unsafe versions of functions that return 'Maybe' values | ||
, unsafeUncons | ||
#if MIN_VERSION_base(4,19,0) | ||
, unsafeUnsnoc | ||
#endif | ||
, unsafeLookup | ||
, unsafeElemIndex | ||
, unsafeFindIndex | ||
, unsafeStripPrefix | ||
) where | ||
|
||
import Data.List | ||
|
||
import GHC.Stack | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Unsafe versions of partial functions | ||
|
||
unsafeHead :: HasCallStack => [a] -> a | ||
unsafeHead = head | ||
Check warning on line 46 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (ubuntu-20.04, 9.8, 3.12, true, -build-tool)
Check warning on line 46 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (9.8, 3.12, ubuntu-20.04, true, +build-tool)
Check warning on line 46 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (9.8, 3.12, ubuntu-22.04, true, +build-tool)
Check warning on line 46 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (9.8, 3.12, macos-14, true, +build-tool)
|
||
|
||
unsafeLast :: HasCallStack => [a] -> a | ||
unsafeLast = last | ||
|
||
unsafeTail :: HasCallStack => [a] -> [a] | ||
unsafeTail = tail | ||
Check warning on line 52 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (ubuntu-20.04, 9.8, 3.12, true, -build-tool)
Check warning on line 52 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (9.8, 3.12, ubuntu-20.04, true, +build-tool)
Check warning on line 52 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (9.8, 3.12, ubuntu-22.04, true, +build-tool)
Check warning on line 52 in lib/unsafe/src/Data/List/Unsafe.hs GitHub Actions / build (9.8, 3.12, macos-14, true, +build-tool)
|
||
|
||
unsafeInit :: HasCallStack => [a] -> [a] | ||
unsafeInit = init | ||
|
||
unsafeIndex :: HasCallStack => [a] -> Int -> a | ||
unsafeIndex = (!!) | ||
|
||
unsafeGenericIndex :: Integral i => [a] -> i -> a | ||
unsafeGenericIndex = genericIndex | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Unsafe versions of functions that return Maybe | ||
|
||
unsafeUncons :: HasCallStack => [a] -> (a, [a]) | ||
unsafeUncons a = case uncons a of | ||
Nothing -> error "Data.List.Unsafe.unsafeUncons: empty list" | ||
Just x -> x | ||
|
||
#if MIN_VERSION_base(4,19,0) | ||
unsafeUnsnoc :: [a] -> ([a], a) | ||
unsafeUnsnoc a = case unsnoc a of | ||
Nothing -> error "Data.List.Unsafe.unsafeUnsnoc: empty list" | ||
Just x -> x | ||
#endif | ||
|
||
unsafeLookup :: HasCallStack => Eq a => a -> [(a,b)] -> b | ||
unsafeLookup a b = case lookup a b of | ||
Nothing -> error "Data.List.Unsafe.unsafeLookup: not found" | ||
Just x -> x | ||
|
||
unsafeElemIndex :: Eq a => a -> [a] -> Int | ||
unsafeElemIndex a b = case elemIndex a b of | ||
Nothing -> error "Data.List.Unsafe.unsafeElemIndex: not found" | ||
Just x -> x | ||
|
||
unsafeFindIndex :: (a -> Bool) -> [a] -> Int | ||
unsafeFindIndex a b = case findIndex a b of | ||
Nothing -> error "Data.List.Unsafe.unsafeFindIndex: not found" | ||
Just x -> x | ||
|
||
unsafeStripPrefix :: Eq a => [a] -> [a] -> [a] | ||
unsafeStripPrefix a b = case stripPrefix a b of | ||
Nothing -> error "Data.List.Unsafe.unsafeStripPrefix: not found" | ||
Just x -> x | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
cabal-version: 2.2 | ||
cabal-version: 3.0 | ||
name: pact | ||
version: 4.12 | ||
-- ^ 4 digit is prerelease, 3- or 2-digit for prod release | ||
|
@@ -64,6 +64,22 @@ library pact-prettyprinter | |
, ansi-terminal >=0.4 | ||
, prettyprinter >= 1.7 | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Internal: unsafe functions from base | ||
-- | ||
-- This is to avoid cluttering production code with | ||
-- `{-# OPTIONS_GHC -Wno-x-partial #-}` pragmas with base >= 4.20 | ||
|
||
Comment on lines
+70
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not disable it package-wide? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that it's generally good to keep the scope of disabled warnings narrow. If it was possible to scope it to an individual functions, I would have preferred that -- in that case this library would probably not be necessary, because one could annotate each use case in the original code. |
||
library unsafe | ||
visibility: public | ||
hs-source-dirs: lib/unsafe/src | ||
rsoeldner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default-language: Haskell2010 | ||
exposed-modules: | ||
Data.Foldable.Unsafe | ||
Data.List.Unsafe | ||
build-depends: | ||
, base >= 4.5 && < 5 | ||
|
||
-- -------------------------------------------------------------------------- -- | ||
-- Pact library | ||
|
||
|
@@ -198,6 +214,7 @@ library | |
build-depends: | ||
-- internal | ||
, pact-prettyprinter | ||
, pact:unsafe | ||
|
||
-- external | ||
, Decimal >=0.4.2 | ||
|
@@ -236,7 +253,7 @@ library | |
, mod >=0.1.2 | ||
, mtl >=2.3 | ||
, pact-json >=0.1 | ||
, pact-time >=0.2 | ||
, pact-time >=0.3.0.1 | ||
, parsers >=0.12.4 | ||
, poly >=0.5.0 | ||
, primitive >=0.8 | ||
|
@@ -260,7 +277,6 @@ library | |
, utf8-string >=1.0.1.1 | ||
, vector >=0.11.0.0 | ||
, vector-algorithms >=0.7 | ||
, vector-space >=0.10.4 | ||
, wide-word >= 0.1 | ||
, yaml | ||
|
||
|
@@ -424,7 +440,6 @@ test-suite hspec | |
, attoparsec | ||
, base | ||
, base16-bytestring | ||
, base64-bytestring | ||
, binary | ||
, bound | ||
, bytestring | ||
|
@@ -445,7 +460,6 @@ test-suite hspec | |
, trifecta | ||
, unordered-containers | ||
, vector | ||
, wide-word >= 0.1 | ||
|
||
other-modules: | ||
Blake2Spec | ||
|
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.
The build with
+build-tool
still has a bunch of-Wx-partial
warnings.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.
@edmundnoble sorry, I missed your comments when I hit the merge button (from the GitHub phone app). I'll address your comments in a follow up PR.