on master help sign in
Merge pull request #147 from bgamari/master

[WIP] Various rule-robustness issues

commit28631f0a212dec18f976524ddeb7105adf6a9ff7 authorBryan O'Sullivan <bos@serpentine.com> dateTue 16 Aug 2016, 16:27 (10 years ago) parent7a0e002ffa9813
2 files changed+12−7
Data/Text.hs+10−7 Data/Text/Internal/Builder.hs+2
Data/Text.hs+10−7
@@ -238,6 +238,7 @@ import Data.ByteString (ByteString)
238238import qualified Data.Text.Lazy as L
239239import Data.Int (Int64)
240240#endif
241+import GHC.Base (eqInt, neInt, gtInt, geInt, ltInt, leInt)
241242#if __GLASGOW_HASKELL__ >= 708
242243import qualified GHC.Exts as Exts
243244#endif
@@ -571,7 +572,9 @@ isSingleton = S.isSingleton . stream
571572-- Subject to fusion.
572573length :: Text -> Int
573574length t = S.length (stream t)
574−{-# INLINE length #-}
575+{-# INLINE [0] length #-}
576+-- length needs to be phased after the compareN/length rules otherwise
577+-- it may inline before the rules have an opportunity to fire.
575578
576579-- | /O(n)/ Compare the count of characters in a 'Text' to a number.
577580-- Subject to fusion.
@@ -590,32 +593,32 @@ compareLength t n = S.compareLengthI (stream t) n
590593
591594{-# RULES
592595"TEXT ==N/length -> compareLength/==EQ" [~1] forall t n.
593− (==) (length t) n = compareLength t n == EQ
596+ eqInt (length t) n = compareLength t n == EQ
594597 #-}
595598
596599{-# RULES
597600"TEXT /=N/length -> compareLength//=EQ" [~1] forall t n.
598− (/=) (length t) n = compareLength t n /= EQ
601+ neInt (length t) n = compareLength t n /= EQ
599602 #-}
600603
601604{-# RULES
602605"TEXT <N/length -> compareLength/==LT" [~1] forall t n.
603− (<) (length t) n = compareLength t n == LT
606+ ltInt (length t) n = compareLength t n == LT
604607 #-}
605608
606609{-# RULES
607610"TEXT <=N/length -> compareLength//=GT" [~1] forall t n.
608− (<=) (length t) n = compareLength t n /= GT
611+ leInt (length t) n = compareLength t n /= GT
609612 #-}
610613
611614{-# RULES
612615"TEXT >N/length -> compareLength/==GT" [~1] forall t n.
613− (>) (length t) n = compareLength t n == GT
616+ gtInt (length t) n = compareLength t n == GT
614617 #-}
615618
616619{-# RULES
617620"TEXT >=N/length -> compareLength//=LT" [~1] forall t n.
618− (>=) (length t) n = compareLength t n /= LT
621+ geInt (length t) n = compareLength t n /= LT
619622 #-}
620623
621624-- -----------------------------------------------------------------------------
Data/Text/Internal/Builder.hs+2
@@ -242,6 +242,8 @@ flush = Builder $ \ k buf@(Buffer p o u l) ->
242242 !t = Text arr o u
243243 ts <- inlineInterleaveST (k b)
244244 return $! t : ts
245+{-# INLINE [1] flush #-}
246+-- defer inlining so that flush/flush rule may fire.
245247
246248------------------------------------------------------------------------
247249