This repository was archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Pass Ormolu cradle flags & default-extensions #1589
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb6bd30
Cache CompilerOptions with Cradle
Avi-D-coder dd96dc7
Make Ormolu respect cradle GHC options & extensions
Avi-D-coder 3e039fc
Cache CompilerOptions on cradle initialization
Avi-D-coder 62c7326
Cache ComponentOptions from cradle init
Avi-D-coder d231602
Refactor & rename lookupComponentOptions
Avi-D-coder 2f25e37
Update ormolu stack builds
Avi-D-coder 1e92a3c
Remove cabal allow-newer ormolu
Avi-D-coder cdd8b53
Bump cabal ormolu version
Avi-D-coder 1ae19ae
Remove redundant imports
Avi-D-coder 0725e86
Add docs
Avi-D-coder 83d99ef
Update cabal Hackage index
Avi-D-coder 1ff3592
Fix grammar
Avi-D-coder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,24 +99,49 @@ data LookupCradleResult = ReuseCradle | LoadCradle CachedCradle | NewCradle File | |
-- via 'setCurrentCradle' before the Cradle can be cached via 'cacheCradle'. | ||
lookupCradle :: FilePath -> GhcModuleCache -> LookupCradleResult | ||
lookupCradle fp gmc = | ||
case currentCradle gmc of | ||
Just (dirs, _c) | (any (\d -> d `isPrefixOf` fp) dirs) -> ReuseCradle | ||
_ -> case T.match (cradleCache gmc) (B.pack fp) of | ||
Just (_k, c, _suf) -> LoadCradle c | ||
Nothing -> NewCradle fp | ||
|
||
data CachedCradle = CachedCradle BIOS.Cradle HscEnv | ||
lookupInCache fp gmc (const $ const ReuseCradle) LoadCradle $ NewCradle fp | ||
|
||
-- | Find the cradle wide 'ComponentOptions' that apply to a 'FilePath' | ||
lookupComponentOptions | ||
:: HasGhcModuleCache m => FilePath -> m (Maybe BIOS.ComponentOptions) | ||
lookupComponentOptions fp = do | ||
gmc <- getModuleCache | ||
return $ lookupInCache fp gmc (const Just) (Just . compOpts) Nothing | ||
|
||
lookupInCache | ||
:: FilePath | ||
-> GhcModuleCache | ||
-- | Called when file is in the current cradle | ||
-> (BIOS.Cradle -> BIOS.ComponentOptions -> a) | ||
-- | Called when file is a member of a cached cradle | ||
-> (CachedCradle -> a) | ||
-- | Default value to return is a cradle is not found | ||
Avi-D-coder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-> a | ||
-> a | ||
lookupInCache fp gmc cur cached def = case currentCradle gmc of | ||
Just (dirs, c, co) | any (`isPrefixOf` fp) dirs -> cur c co | ||
_ -> case T.match (cradleCache gmc) (B.pack fp) of | ||
Just (_k, c, _suf) -> cached c | ||
Nothing -> def | ||
|
||
-- | A 'Cradle', it's 'HscEnv' and 'ComponentOptions' | ||
data CachedCradle = CachedCradle | ||
{ ccradle :: BIOS.Cradle | ||
, hscEnv :: HscEnv | ||
, compOpts :: BIOS.ComponentOptions | ||
} | ||
Comment on lines
+128
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are already at it, could you extend documentation for this, too? |
||
|
||
instance Show CachedCradle where | ||
show (CachedCradle x _) = show x | ||
show (CachedCradle x _ _) = show x | ||
|
||
data GhcModuleCache = GhcModuleCache | ||
{ cradleCache :: !(T.Trie CachedCradle) | ||
-- ^ map from FilePath to cradles | ||
-- ^ map from FilePath to cradle and it's config. | ||
-- May not include currentCradle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not? The cradle cache should also contain current cradle, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea, I added this as a warning, because I had expected it to be in the cache. |
||
, uriCaches :: !UriCaches | ||
, currentCradle :: Maybe ([FilePath], BIOS.Cradle) | ||
-- ^ The current cradle and which FilePath's it is | ||
-- responsible for | ||
, currentCradle :: Maybe ([FilePath], BIOS.Cradle, BIOS.ComponentOptions) | ||
-- ^ The current cradle, it's config, | ||
-- and which FilePath's it is responsible for. | ||
} deriving (Show) | ||
|
||
-- --------------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.