-
-
Notifications
You must be signed in to change notification settings - Fork 390
Reduce usages of Prelude/Data.Text.head #2519
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ import qualified Data.HashMap.Strict as HM | |
import Data.Hashable | ||
import Data.IORef | ||
import Data.List | ||
import Data.List.NonEmpty (NonEmpty ((:|))) | ||
import qualified Data.List.NonEmpty as NE | ||
import qualified Data.Map.Strict as Map | ||
import Data.Maybe | ||
import qualified Data.Text as T | ||
|
@@ -303,9 +305,9 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do | |
-- compilation but these are the true source of | ||
-- information. | ||
new_deps = RawComponentInfo (homeUnitId_ df) df targets cfp opts dep_info | ||
: maybe [] snd oldDeps | ||
:| maybe [] snd oldDeps | ||
-- Get all the unit-ids for things in this component | ||
inplace = map rawComponentUnitId new_deps | ||
inplace = fmap rawComponentUnitId new_deps | ||
|
||
new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do | ||
-- Remove all inplace dependencies from package flags for | ||
|
@@ -347,7 +349,9 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do | |
-- . The information for the new component which caused this cache miss | ||
-- . The modified information (without -inplace flags) for | ||
-- existing packages | ||
pure (Map.insert hieYaml (newHscEnv, new_deps) m, (newHscEnv, head new_deps', tail new_deps')) | ||
pure ( Map.insert hieYaml (newHscEnv, NE.toList new_deps) m | ||
, (newHscEnv, NE.head new_deps', NE.tail new_deps') | ||
) | ||
|
||
|
||
let session :: (Maybe FilePath, NormalizedFilePath, ComponentOptions, FilePath) | ||
|
@@ -495,13 +499,12 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do | |
sessionOpts (join cachedHieYamlLocation <|> hieYaml, file) `Safe.catch` \e -> | ||
return (([renderPackageSetupException file e], Nothing), maybe [] pure hieYaml) | ||
|
||
returnWithVersion $ \file -> do | ||
opts <- liftIO $ join $ mask_ $ modifyVar runningCradle $ \as -> do | ||
returnWithVersion $ \file -> | ||
liftIO $ join $ mask_ $ modifyVar runningCradle $ \as -> do | ||
-- If the cradle is not finished, then wait for it to finish. | ||
void $ wait as | ||
as <- async $ getOptions file | ||
return (as, wait as) | ||
pure opts | ||
|
||
-- | Run the specific cradle on a specific FilePath via hie-bios. | ||
-- This then builds dependencies or whatever based on the cradle, gets the | ||
|
@@ -758,7 +761,7 @@ getDependencyInfo fs = Map.fromList <$> mapM do_one fs | |
-- ID. Therefore we create a fake one and give them all the same unit id. | ||
removeInplacePackages | ||
:: UnitId -- ^ fake uid to use for our internal component | ||
-> [UnitId] | ||
-> NonEmpty UnitId | ||
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. Perhaps simpler to just convert to a normal list before calling this - I don't think this function needs to require its argument to be non-empty! |
||
-> DynFlags | ||
-> (DynFlags, [UnitId]) | ||
removeInplacePackages fake_uid us df = (setHomeUnitId_ fake_uid $ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ import qualified Ide.PluginUtils as HLS | |
import Ide.Types (PluginId) | ||
import qualified "list-t" ListT | ||
import qualified StmContainers.Map as STM | ||
import Safe (headNote) | ||
|
||
-- | We need to serialize writes to the database, so we send any function that | ||
-- needs to write to the database over the channel, where it will be picked up by | ||
|
@@ -853,18 +854,18 @@ defineNoDiagnostics op = defineEarlyCutoff $ RuleNoDiagnostics $ \k v -> (Nothin | |
-- | Request a Rule result if available | ||
use :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (Maybe v) | ||
use key file = head <$> uses key [file] | ||
use key file = headNote "Development.IDE.Core.Shake.use" <$> uses key [file] | ||
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. Remove 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. As I commented on the issue, I think you could solve all of these at a stroke by making the underlying 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. Yes, I support the generalization to any |
||
|
||
-- | Request a Rule result, it not available return the last computed result, if any, which may be stale | ||
useWithStale :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (Maybe (v, PositionMapping)) | ||
useWithStale key file = head <$> usesWithStale key [file] | ||
useWithStale key file = headNote "Development.IDE.Core.Shake.useWithStale" <$> usesWithStale key [file] | ||
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. Remove |
||
|
||
-- | Request a Rule result, it not available return the last computed result which may be stale. | ||
-- Errors out if none available. | ||
useWithStale_ :: IdeRule k v | ||
=> k -> NormalizedFilePath -> Action (v, PositionMapping) | ||
useWithStale_ key file = head <$> usesWithStale_ key [file] | ||
useWithStale_ key file = headNote "Development.IDE.Core.Shake.useWithStale_" <$> usesWithStale_ key [file] | ||
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. Remove |
||
|
||
-- | Plural version of 'useWithStale_' | ||
usesWithStale_ :: IdeRule k v => k -> [NormalizedFilePath] -> Action [(v, PositionMapping)] | ||
|
@@ -932,7 +933,7 @@ useNoFile :: IdeRule k v => k -> Action (Maybe v) | |
useNoFile key = use key emptyFilePath | ||
|
||
use_ :: IdeRule k v => k -> NormalizedFilePath -> Action v | ||
use_ key file = head <$> uses_ key [file] | ||
use_ key file = headNote "Development.IDE.Core.Shake.use_" <$> uses_ key [file] | ||
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. Remove |
||
|
||
useNoFile_ :: IdeRule k v => k -> Action v | ||
useNoFile_ key = use_ key emptyFilePath | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ import Data.Map (Map) | |
#endif | ||
import Data.Either | ||
import Data.Version | ||
import qualified Data.List.NonEmpty as NE | ||
|
||
#if MIN_VERSION_ghc(9,0,0) | ||
type PreloadUnitClosure = UniqSet UnitId | ||
|
@@ -324,7 +325,7 @@ moduleUnit = | |
Module.moduleUnitId | ||
#endif | ||
|
||
filterInplaceUnits :: [UnitId] -> [PackageFlag] -> ([UnitId], [PackageFlag]) | ||
filterInplaceUnits :: NE.NonEmpty UnitId -> [PackageFlag] -> ([UnitId], [PackageFlag]) | ||
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. I would use types unqualified, hope it is the pattern for other data types 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. Ditto, not sure this one should change. |
||
filterInplaceUnits us packageFlags = | ||
partitionEithers (map isInplace packageFlags) | ||
where | ||
|
@@ -335,7 +336,7 @@ filterInplaceUnits us packageFlags = | |
then Left $ toUnitId u | ||
else Right p | ||
#else | ||
if u `elem` us | ||
if u `elem` NE.toList us | ||
then Left u | ||
else Right p | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the safe package is best practice anymore. It was created before we had HasCallStack but nowadays head will produce a better error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and I think if we're going to do this we should replace it with a meaningful error, not just the position where it occurred (although that's somewhat useful).
We also could be more lenient about partial functions in things like tests and benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to have any errors escaping out in this way in ghcide.
But this particular call site is in the benchmark suite which is allowed to error out, and a position is more helpful than any description in that case.