on master help sign in
Support inline specs inside specialize pragmas
acc7700Utku Demir
data/examples/declaration/signature/specialize/specialize-out.hs+2−2
@@ -1,9 +1,9 @@
1foo :: Num a => a -> a
1foo :: Num a => a -> a
2foo = id
2foo = id
3{-# SPECIALIZE foo :: Int -> Int #-}
3{-# SPECIALIZE foo :: Int -> Int #-}
4−{-# SPECIALIZE foo :: Float -> Float #-}
4+{-# SPECIALIZE INLINE foo :: Float -> Float #-}
5
5
6−{-# SPECIALIZE [2] bar :: Int -> Int #-}
6+{-# SPECIALIZE NOINLINE [2] bar :: Int -> Int #-}
7bar :: Num a => a -> a
7bar :: Num a => a -> a
8bar = id
8bar = id
9
9
data/examples/declaration/signature/specialize/specialize.hs+2−2
@@ -2,9 +2,9 @@ foo :: Num a => a -> a
2foo = id
2foo = id
3
3
4{-# SPECIALIZE foo :: Int -> Int #-}
4{-# SPECIALIZE foo :: Int -> Int #-}
5−{-# SPECIALIZE foo :: Float -> Float #-}
5+{-# SPECIALIZE INLINE foo :: Float -> Float #-}
6
6
7−{-# SPECIALIZE [2] bar :: Int -> Int #-}
7+{-# SPECIALIZE NOINLINE [2] bar :: Int -> Int #-}
8
8
9bar :: Num a => a -> a
9bar :: Num a => a -> a
10bar = id
10bar = id
src/Ormolu/Printer/Meat/Declaration/Signature.hs+9−5
@@ -97,11 +97,7 @@ p_inlineSig
97 -> InlinePragma -- ^ Inline pragma specification
97 -> InlinePragma -- ^ Inline pragma specification
98 -> R ()
98 -> R ()
99p_inlineSig name InlinePragma {..} = pragmaBraces $ do
99p_inlineSig name InlinePragma {..} = pragmaBraces $ do
100− txt $ case inl_inline of
100+ p_inlineSpec inl_inline
101− Inline -> "INLINE "
102− Inlinable -> "INLINEABLE "
103− NoInline -> "NOINLINE "
104− NoUserInline -> notImplemented "NoUserInline"
105 case inl_rule of
101 case inl_rule of
106 ConLike -> txt "CONLIKE "
102 ConLike -> txt "CONLIKE "
107 FunLike -> return ()
103 FunLike -> return ()
@@ -117,6 +113,7 @@ p_specSig
117p_specSig name ts InlinePragma {..} = pragmaBraces $ do
113p_specSig name ts InlinePragma {..} = pragmaBraces $ do
118 txt "SPECIALIZE"
114 txt "SPECIALIZE"
119 space
115 space
116+ p_inlineSpec inl_inline
120 p_activation inl_act
117 p_activation inl_act
121 when (visibleActivation inl_act) space
118 when (visibleActivation inl_act) space
122 p_rdrName name
119 p_rdrName name
@@ -125,6 +122,13 @@ p_specSig name ts InlinePragma {..} = pragmaBraces $ do
125 txt ":: "
122 txt ":: "
126 sep (comma >> breakpoint) (located' p_hsType . hsib_body) ts
123 sep (comma >> breakpoint) (located' p_hsType . hsib_body) ts
127
124
125+p_inlineSpec :: InlineSpec -> R ()
126+p_inlineSpec = txt . \case
127+ Inline -> "INLINE "
128+ Inlinable -> "INLINEABLE "
129+ NoInline -> "NOINLINE "
130+ NoUserInline -> ""
131+
128p_activation :: Activation -> R ()
132p_activation :: Activation -> R ()
129p_activation = \case
133p_activation = \case
130 NeverActive -> return ()
134 NeverActive -> return ()