Skip to content

Commit

Permalink
Factor defaultUnrollLimit (#1936)
Browse files Browse the repository at this point in the history
avoids repeating the constant 140 in several places
  • Loading branch information
janmasrovira authored Mar 28, 2023
1 parent 524e966 commit 46976cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
15 changes: 9 additions & 6 deletions app/GlobalOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data GlobalOptions = GlobalOptions
_globalNoPositivity :: Bool,
_globalNoCoverage :: Bool,
_globalNoStdlib :: Bool,
_globalUnrollLimit :: Word
_globalUnrollLimit :: Int
}
deriving stock (Eq, Show)

Expand Down Expand Up @@ -51,7 +51,7 @@ instance CanonicalProjection GlobalOptions Core.CoreOptions where
project GlobalOptions {..} =
Core.CoreOptions
{ Core._optCheckCoverage = not _globalNoCoverage,
Core._optUnrollLimit = fromIntegral _globalUnrollLimit
Core._optUnrollLimit = _globalUnrollLimit
}

defaultGlobalOptions :: GlobalOptions
Expand All @@ -67,7 +67,7 @@ defaultGlobalOptions =
_globalNoPositivity = False,
_globalNoCoverage = False,
_globalNoStdlib = False,
_globalUnrollLimit = 140
_globalUnrollLimit = defaultUnrollLimit
}

-- | Get a parser for global flags which can be hidden or not depending on
Expand Down Expand Up @@ -128,8 +128,11 @@ parseGlobalFlags = do
)
_globalUnrollLimit <-
option
naturalNumberOpt
(long "unroll" <> value 140 <> help "Recursion unrolling limit (default: 140)")
(fromIntegral <$> naturalNumberOpt)
( long "unroll"
<> value defaultUnrollLimit
<> help ("Recursion unrolling limit (default: " <> show defaultUnrollLimit <> ")")
)
return GlobalOptions {..}

parseBuildDir :: Mod OptionFields (SomeBase Dir) -> Parser (AppPath Dir)
Expand All @@ -152,6 +155,6 @@ entryPointFromGlobalOptions root mainFile opts =
_entryPointNoPositivity = opts ^. globalNoPositivity,
_entryPointNoCoverage = opts ^. globalNoCoverage,
_entryPointNoStdlib = opts ^. globalNoStdlib,
_entryPointUnrollLimit = fromIntegral $ opts ^. globalUnrollLimit,
_entryPointUnrollLimit = opts ^. globalUnrollLimit,
_entryPointGenericOptions = project opts
}
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defaultCoreOptions :: CoreOptions
defaultCoreOptions =
CoreOptions
{ _optCheckCoverage = True,
_optUnrollLimit = 140
_optUnrollLimit = defaultUnrollLimit
}

fromEntryPoint :: EntryPoint -> CoreOptions
Expand Down
5 changes: 4 additions & 1 deletion src/Juvix/Compiler/Pipeline/EntryPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ defaultEntryPoint root mainFile =
_entryPointGenericOptions = defaultGenericOptions,
_entryPointTarget = TargetCore,
_entryPointDebug = False,
_entryPointUnrollLimit = 140,
_entryPointUnrollLimit = defaultUnrollLimit,
_entryPointModulePaths = pure mainFile
}
where
buildDir = rootBuildDir root

defaultUnrollLimit :: Int
defaultUnrollLimit = 140

mainModulePath :: Lens' EntryPoint (Path Abs File)
mainModulePath = entryPointModulePaths . _head1

Expand Down

0 comments on commit 46976cd

Please sign in to comment.