on master help sign in
Support inline specs inside specialize pragmas
commitacc77002e44e9bf9fb04e909b2ea63599d93ee0f authorUtku Demir <me@utdemir.com> dateWed 14 Aug 2019, 11:49 (7 years ago) parent0cf6d65
3 files changed+13−9
data/examples/declaration/signature/specialize/specialize-out.hs+2−2 data/examples/declaration/signature/specialize/specialize.hs+2−2 src/Ormolu/Printer/Meat/Declaration/Signature.hs+9−5
data/examples/declaration/signature/specialize/specialize-out.hs+2−2
@@ -1,9 +1,9 @@
11foo :: Num a => a -> a
22foo = id
33{-# SPECIALIZE foo :: Int -> Int #-}
4−{-# SPECIALIZE foo :: Float -> Float #-}
4+{-# SPECIALIZE INLINE foo :: Float -> Float #-}
55
6−{-# SPECIALIZE [2] bar :: Int -> Int #-}
6+{-# SPECIALIZE NOINLINE [2] bar :: Int -> Int #-}
77bar :: Num a => a -> a
88bar = id
99
data/examples/declaration/signature/specialize/specialize.hs+2−2
@@ -2,9 +2,9 @@ foo :: Num a => a -> a
22foo = id
33
44{-# SPECIALIZE foo :: Int -> Int #-}
5−{-# SPECIALIZE foo :: Float -> Float #-}
5+{-# SPECIALIZE INLINE foo :: Float -> Float #-}
66
7−{-# SPECIALIZE [2] bar :: Int -> Int #-}
7+{-# SPECIALIZE NOINLINE [2] bar :: Int -> Int #-}
88
99bar :: Num a => a -> a
1010bar = id
src/Ormolu/Printer/Meat/Declaration/Signature.hs+9−5
@@ -97,11 +97,7 @@ p_inlineSig
9797 -> InlinePragma -- ^ Inline pragma specification
9898 -> R ()
9999p_inlineSig name InlinePragma {..} = pragmaBraces $ do
100− txt $ case inl_inline of
101− Inline -> "INLINE "
102− Inlinable -> "INLINEABLE "
103− NoInline -> "NOINLINE "
104− NoUserInline -> notImplemented "NoUserInline"
100+ p_inlineSpec inl_inline
105101 case inl_rule of
106102 ConLike -> txt "CONLIKE "
107103 FunLike -> return ()
@@ -117,6 +113,7 @@ p_specSig
117113p_specSig name ts InlinePragma {..} = pragmaBraces $ do
118114 txt "SPECIALIZE"
119115 space
116+ p_inlineSpec inl_inline
120117 p_activation inl_act
121118 when (visibleActivation inl_act) space
122119 p_rdrName name
@@ -125,6 +122,13 @@ p_specSig name ts InlinePragma {..} = pragmaBraces $ do
125122 txt ":: "
126123 sep (comma >> breakpoint) (located' p_hsType . hsib_body) ts
127124
125+p_inlineSpec :: InlineSpec -> R ()
126+p_inlineSpec = txt . \case
127+ Inline -> "INLINE "
128+ Inlinable -> "INLINEABLE "
129+ NoInline -> "NOINLINE "
130+ NoUserInline -> ""
131+
128132p_activation :: Activation -> R ()
129133p_activation = \case
130134 NeverActive -> return ()