Skip to content

Commit ed37542

Browse files
sheafBodigrim
authored andcommitted
Avoid redundant pattern warning in Resource.hsc
With GHC MR !8478, GHC is able to spot a redundant pattern match when RLIM_SAVED_CUR == RLIM_SAVED_MAX, which it wasn't able to detect before. So we use considerAccessible to avoid a pattern match check. This unfortunately means we must change the SafeHaskell status of that module to TrustWorth, as considerAccessible is from GHC.Exts, which isn't safe. Alternatives: - we can't perform the equality test RLIM_SAVED_CUR == RLIM_SAVED_MAX using CPP macros, because one of the values might expand out to have casts; - turning off pattern match warnings impacts warnings across the whole module, instead of the single affected function, - adding a dummy equation such as "id True" to the first pattern match would work, but seems more ad-hoc.
1 parent 7681b0e commit ed37542

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

System/Posix/Resource.hsc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE CApiFFI #-}
2-
{-# LANGUAGE Safe #-}
2+
{-# LANGUAGE Trustworthy #-}
3+
34
-----------------------------------------------------------------------------
45
-- |
56
-- Module : System.Posix.Resource
@@ -31,6 +32,9 @@ import Foreign.C
3132
import System.IO.Error ( ioeSetLocation )
3233
import GHC.IO.Exception ( unsupportedOperation )
3334
#endif
35+
#if __GLASGOW_HASKELL__ >= 905
36+
import GHC.Exts ( considerAccessible )
37+
#endif
3438

3539
-- -----------------------------------------------------------------------------
3640
-- Resource limits
@@ -115,12 +119,20 @@ unpackRLimit :: CRLim -> ResourceLimit
115119
unpackRLimit (#const RLIM_INFINITY) = ResourceLimitInfinity
116120
unpackRLimit other
117121
#if defined(RLIM_SAVED_MAX)
118-
| ((#const RLIM_SAVED_MAX) :: CRLim) /= (#const RLIM_INFINITY) &&
119-
other == (#const RLIM_SAVED_MAX) = ResourceLimitUnknown
122+
| ((#const RLIM_SAVED_MAX) :: CRLim) /= (#const RLIM_INFINITY)
123+
, other == (#const RLIM_SAVED_MAX)
124+
= ResourceLimitUnknown
120125
#endif
121126
#if defined(RLIM_SAVED_CUR)
122-
| ((#const RLIM_SAVED_CUR) :: CRLim) /= (#const RLIM_INFINITY) &&
123-
other == (#const RLIM_SAVED_CUR) = ResourceLimitUnknown
127+
| ((#const RLIM_SAVED_CUR) :: CRLim) /= (#const RLIM_INFINITY)
128+
, other == (#const RLIM_SAVED_CUR)
129+
#if __GLASGOW_HASKELL__ >= 905
130+
, considerAccessible
131+
#endif
132+
= ResourceLimitUnknown
133+
-- (*) This pattern match is redundant if RLIM_SAVED_MAX and RLIM_SAVED_CUR
134+
-- are both defined and are equal. This redundancy is only detected by GHC
135+
-- starting from version 9.5, so we use 'considerAccessible'.
124136
#endif
125137
| otherwise = ResourceLimit (fromIntegral other)
126138

0 commit comments

Comments
 (0)