diff --git a/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs b/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs index f236c5154c..23c93eabb9 100644 --- a/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs +++ b/src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs @@ -92,7 +92,7 @@ goModule m = case sing :: SModuleIsTop t of goPragmas :: Member (Reader Pragmas) r => Maybe ParsedPragmas -> Sem r Pragmas goPragmas p = do p' <- ask - return $ p' <> maybe mempty (^. withLocParam . withSourceValue) p + return $ p' <> p ^. _Just . withLocParam . withSourceValue goName :: S.Name -> Abstract.Name goName name = diff --git a/src/Juvix/Compiler/Concrete/Print/Base.hs b/src/Juvix/Compiler/Concrete/Print/Base.hs index 8b699b35c4..790949f134 100644 --- a/src/Juvix/Compiler/Concrete/Print/Base.hs +++ b/src/Juvix/Compiler/Concrete/Print/Base.hs @@ -60,8 +60,8 @@ instance SingI t => PrettyPrint (Module 'Scoped t) where ppCode Module {..} = do let moduleBody' = localIndent (ppCode _moduleBody) modulePath' = ppModulePathType _modulePath - moduleDoc' :: Sem r () = maybe (return ()) ppCode _moduleDoc - modulePragmas' :: Sem r () = maybe (return ()) ppCode _modulePragmas + moduleDoc' = whenJust _moduleDoc ppCode + modulePragmas' = whenJust _modulePragmas ppCode body' | null _moduleBody = ensureEmptyLine | otherwise = diff --git a/src/Juvix/Compiler/Concrete/Translation/FromSource.hs b/src/Juvix/Compiler/Concrete/Translation/FromSource.hs index a57e4179de..dd9e4db74e 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromSource.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromSource.hs @@ -180,7 +180,6 @@ stashPragmas = do pragmas <- withLoc parsePragmas P.lift (registerPragmas (getLoc pragmas)) P.lift (put (Just pragmas)) - return () where parsePragmas :: ParsecS r (WithSource Pragmas) parsePragmas = do diff --git a/src/Juvix/Compiler/Core/Transformation/UnrollRecursion.hs b/src/Juvix/Compiler/Core/Transformation/UnrollRecursion.hs index bfec100920..25a4668dd3 100644 --- a/src/Juvix/Compiler/Core/Transformation/UnrollRecursion.hs +++ b/src/Juvix/Compiler/Core/Transformation/UnrollRecursion.hs @@ -45,10 +45,8 @@ unrollRecursion tab = do computeUnrollLimit :: Member (Reader CoreOptions) r => Sem r Int computeUnrollLimit = do defaultUnrollLimit <- asks (^. optUnrollLimit) - let lims = mapMaybe go syms - if - | null lims -> return defaultUnrollLimit - | otherwise -> return $ minimum lims + let lims = nonEmpty (mapMaybe go syms) + return (maybe defaultUnrollLimit minimum1 lims) where go :: Symbol -> Maybe Int go sym = fmap (^. pragmaUnrollDepth) (ii ^. identifierPragmas . pragmasUnroll) diff --git a/src/Juvix/Data/Pragmas.hs b/src/Juvix/Data/Pragmas.hs index 6e56f0cd1f..4c317af0d7 100644 --- a/src/Juvix/Data/Pragmas.hs +++ b/src/Juvix/Data/Pragmas.hs @@ -1,8 +1,9 @@ module Juvix.Data.Pragmas where -import Data.Aeson.BetterErrors +import Data.Aeson.BetterErrors hiding ((<|>)) +import Data.Aeson.BetterErrors qualified as Aeson import Data.Yaml -import Juvix.Prelude.Base hiding ((<|>)) +import Juvix.Prelude.Base data PragmaInline = InlineNever @@ -42,12 +43,12 @@ instance FromJSON Pragmas where return Pragmas {..} parseInline :: Parse PragmaError PragmaInline - parseInline = parseInlineArgsNum <|> parseInlineBool + parseInline = parseInlineArgsNum Aeson.<|> parseInlineBool where parseInlineArgsNum :: Parse PragmaError PragmaInline parseInlineArgsNum = do _pragmaInlineArgsNum <- asIntegral - return $ InlinePartiallyApplied {..} + return InlinePartiallyApplied {..} parseInlineBool :: Parse PragmaError PragmaInline parseInlineBool = do @@ -61,20 +62,16 @@ instance FromJSON Pragmas where _pragmaUnrollDepth <- asIntegral return PragmaUnroll {..} --- The Semigroup `<>` is used to propagate pragmas from an enclosing context. +-- | The Semigroup `<>` is used to propagate pragmas from an enclosing context. -- For example, if `p1` are the pragmas declared for a module `M`, and `p2` the -- pragmas declared for a function `f` inside `M`, then the actual pragmas for -- `f` are `p1 <> p2`. instance Semigroup Pragmas where p1 <> p2 = Pragmas - { _pragmasInline = maybeSecond (p1 ^. pragmasInline) (p2 ^. pragmasInline), - _pragmasUnroll = maybeSecond (p2 ^. pragmasUnroll) (p1 ^. pragmasUnroll) + { _pragmasInline = p2 ^. pragmasInline <|> p1 ^. pragmasInline, + _pragmasUnroll = p1 ^. pragmasUnroll <|> p2 ^. pragmasUnroll } - where - maybeSecond :: Maybe a -> Maybe a -> Maybe a - maybeSecond x Nothing = x - maybeSecond _ x@Just {} = x instance Monoid Pragmas where mempty = diff --git a/src/Juvix/Parser/Lexer.hs b/src/Juvix/Parser/Lexer.hs index 8571a7feb9..33f03aaa37 100644 --- a/src/Juvix/Parser/Lexer.hs +++ b/src/Juvix/Parser/Lexer.hs @@ -38,6 +38,7 @@ hspace_ = void hspace spaceMsg :: String spaceMsg = "white space (only spaces and newlines allowed)" +-- | `special` is set when judoc comments or pragmas are supported space' :: forall e m. MonadParsec e Text m => Bool -> m (Maybe SpaceSpan) space' special = hidden $