summaryrefslogtreecommitdiff
path: root/source/Felix/Source.hs
diff options
context:
space:
mode:
Diffstat (limited to 'source/Felix/Source.hs')
-rw-r--r--source/Felix/Source.hs101
1 files changed, 13 insertions, 88 deletions
diff --git a/source/Felix/Source.hs b/source/Felix/Source.hs
index 64a88cd..68d596c 100644
--- a/source/Felix/Source.hs
+++ b/source/Felix/Source.hs
@@ -54,9 +54,6 @@ module Felix.Source
, attributeCanonicalSource
, resolveRoot
, resolveImport
- , SourceSelectionMeasurements(..)
- , resolveRootMeasured
- , resolveImportMeasured
, loadResolvedSource
, resolveAndLoadRoot
, resolveAndLoadImport
@@ -83,7 +80,7 @@ import Data.Map.Strict qualified as Map
import Data.Set qualified as Set
import Data.Text qualified as Text
import Data.Text.Encoding qualified as Encoding
-import Report.Location
+import Felix.Report.Location
( Location
, LocationRegistrationError(..)
, locationToText
@@ -816,55 +813,11 @@ resolveRoot
:: SourceMounts
-> RootRequest
-> IO (Either SourceError ResolvedSource)
-resolveRoot mounts request =
- fmap fst <$> resolveRootMeasured mounts request
-
--- | High-level operations used to select successful searched sources.
--- These are resolver operations, not operating-system syscall counts.
-data SourceSelectionMeasurements =
- SourceSelectionMeasurements
- { sourceSelectionCandidateProbeCount :: !Int
- , sourceSelectionCanonicalizationCount :: !Int
- , sourceSelectionTargetInspectionCount :: !Int
- }
- deriving stock (Show, Eq)
-
-instance Semigroup SourceSelectionMeasurements where
- left <> right =
- SourceSelectionMeasurements
- { sourceSelectionCandidateProbeCount =
- sourceSelectionCandidateProbeCount left
- + sourceSelectionCandidateProbeCount right
- , sourceSelectionCanonicalizationCount =
- sourceSelectionCanonicalizationCount left
- + sourceSelectionCanonicalizationCount right
- , sourceSelectionTargetInspectionCount =
- sourceSelectionTargetInspectionCount left
- + sourceSelectionTargetInspectionCount right
- }
-
-instance Monoid SourceSelectionMeasurements where
- mempty =
- SourceSelectionMeasurements
- { sourceSelectionCandidateProbeCount = 0
- , sourceSelectionCanonicalizationCount = 0
- , sourceSelectionTargetInspectionCount = 0
- }
-
-resolveRootMeasured
- :: SourceMounts
- -> RootRequest
- -> IO
- (Either
- SourceError
- (ResolvedSource, SourceSelectionMeasurements))
-resolveRootMeasured mounts = \case
+resolveRoot mounts = \case
SearchedRoot path ->
- resolveSearchedMeasured mounts (SearchedRootLookup path) path
+ resolveSearched mounts (SearchedRootLookup path) path
ExistingRoot canonical spelling ->
- pure
- ((\source -> (source, mempty))
- <$> attributeSelectedSource spelling mounts canonical)
+ pure (attributeSelectedSource spelling mounts canonical)
resolveImport
:: SourceMounts
@@ -872,47 +825,31 @@ resolveImport
-> ImportRef
-> IO (Either SourceError ResolvedSource)
resolveImport mounts importer reference =
- fmap fst
- <$> resolveImportMeasured mounts importer reference
-
-resolveImportMeasured
- :: SourceMounts
- -> ResolvedSource
- -> ImportRef
- -> IO
- (Either
- SourceError
- (ResolvedSource, SourceSelectionMeasurements))
-resolveImportMeasured mounts importer reference =
- resolveSearchedMeasured
+ resolveSearched
mounts
(ImportedSourceLookup importer reference)
(importPath reference)
-resolveSearchedMeasured
+resolveSearched
:: SourceMounts
-> SourceLookup
-> SafeRelativePath
- -> IO
- (Either
- SourceError
- (ResolvedSource, SourceSelectionMeasurements))
-resolveSearchedMeasured mounts lookupKind relative =
- choose 0 (sourceCandidates mounts relative)
+ -> IO (Either SourceError ResolvedSource)
+resolveSearched mounts lookupKind relative =
+ choose (sourceCandidates mounts relative)
where
candidates = sourceCandidates mounts relative
- choose _probeCount [] =
+ choose [] =
pure (Left (SourceNotFound lookupKind candidates))
- choose previousProbeCount (candidate : rest) = do
+ choose (candidate : rest) = do
let path = sourceCandidatePath candidate
- probeCount = previousProbeCount + 1
statusResult <- try (PosixFiles.getSymbolicLinkStatus path)
:: IO (Either IOException PosixFiles.FileStatus)
case statusResult of
Left err
| isDoesNotExistError err ->
- choose probeCount rest
+ choose rest
| otherwise ->
pure
(Left
@@ -921,19 +858,7 @@ resolveSearchedMeasured mounts lookupKind relative =
path
(Text.pack (displayException err))))
Right _status ->
- fmap
- (\source ->
- ( source
- , SourceSelectionMeasurements
- { sourceSelectionCandidateProbeCount =
- probeCount
- , sourceSelectionCanonicalizationCount =
- 1
- , sourceSelectionTargetInspectionCount =
- 1
- }
- ))
- <$> resolveCandidate mounts lookupKind candidate
+ resolveCandidate mounts lookupKind candidate
resolveCandidate
:: SourceMounts