Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small style adjustments #2030

Merged
merged 7 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Abstract/Translation/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Compiler/Concrete/Print/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Concrete/Translation/FromSource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/Juvix/Compiler/Core/Transformation/UnrollRecursion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 8 additions & 11 deletions src/Juvix/Data/Pragmas.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions src/Juvix/Parser/Lexer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down