Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 7583226

Browse files
committed
Represent paths as Text.
1 parent be842df commit 7583226

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

semantic-core/src/Analysis/Concrete.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Data.Loc
2929
import qualified Data.Map as Map
3030
import Data.Monoid (Alt(..))
3131
import Data.Name
32-
import Data.Text (Text)
32+
import Data.Text (Text, unpack)
3333
import Prelude hiding (fail)
3434

3535
type Precise = Int
@@ -196,7 +196,7 @@ addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes }
196196
Unit -> "()"
197197
Bool b -> show b
198198
String s -> show s
199-
Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> p <> ":" <> showPos s <> "-" <> showPos e <> "]"
199+
Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> unpack p <> ":" <> showPos s <> "-" <> showPos e <> "]"
200200
Obj _ -> "{}"
201201
showPos (Pos l c) = show l <> ":" <> show c
202202
fromName (User s) = s

semantic-core/src/Analysis/Eval.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE FlexibleContexts, GeneralizedNewtypeDeriving, LambdaCase, RankNTypes, RecordWildCards #-}
1+
{-# LANGUAGE FlexibleContexts, GeneralizedNewtypeDeriving, LambdaCase, OverloadedStrings, RankNTypes, RecordWildCards #-}
22
module Analysis.Eval
33
( eval
44
, prog1
@@ -21,7 +21,7 @@ import Data.Functor
2121
import Data.Loc
2222
import Data.Maybe (fromJust)
2323
import Data.Name
24-
import Data.Text (Text, unpack)
24+
import Data.Text (Text)
2525
import GHC.Stack
2626
import Prelude hiding (fail)
2727

@@ -43,7 +43,7 @@ eval Analysis{..} eval = \case
4343
String s -> string s
4444
Load p -> do
4545
path <- eval p >>= asString
46-
lookupEnv' (Path (unpack path)) >>= deref' (Path (unpack path))
46+
lookupEnv' (Path path) >>= deref' (Path path)
4747
Edge e a -> ref a >>= edge e >> unit
4848
Frame -> frame
4949
a :. b -> do

semantic-core/src/Analysis/ImportGraph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import qualified Data.Set as Set
2525
import Data.Text (Text)
2626
import Prelude hiding (fail)
2727

28-
type ImportGraph = Map.Map FilePath (Set.Set FilePath)
28+
type ImportGraph = Map.Map Text (Set.Set Text)
2929

3030
data Value = Value
3131
{ valueSemi :: Semi

semantic-core/src/Data/Core/Parser.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Data.Core
1414
import Data.Name
1515
import Data.Semigroup
1616
import Data.String
17+
import Data.Text (pack)
1718
import qualified Text.Parser.Token as Token
1819
import qualified Text.Parser.Token.Highlight as Highlight
1920
import Text.Trifecta hiding (ident)
@@ -94,7 +95,7 @@ lvalue = choice
9495
name :: (TokenParsing m, Monad m) => m Name
9596
name = choice [regular, strpath] <?> "name" where
9697
regular = User <$> identifier
97-
strpath = Path <$> between (symbolic '"') (symbolic '"') (some $ noneOf "\"")
98+
strpath = Path . pack <$> between (symbolic '"') (symbolic '"') (some $ noneOf "\"")
9899

99100
lit :: (TokenParsing m, Monad m) => m Core
100101
lit = let x `given` n = x <$ reserved n in choice
@@ -112,4 +113,3 @@ lambda = Lam <$ lambduh <*> name <* arrow <*> core <?> "lambda" where
112113

113114
ident :: (Monad m, TokenParsing m) => m Core
114115
ident = Var <$> name <?> "identifier"
115-

semantic-core/src/Data/Loc.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ import Control.Effect.Error
1616
import Control.Effect.Fail
1717
import Control.Effect.Reader
1818
import Control.Effect.Sum
19+
import Data.Text (Text, pack)
1920
import Data.Text.Prettyprint.Doc (Pretty (..))
2021
import GHC.Stack
2122
import Prelude hiding (fail)
2223

2324
data Loc = Loc
24-
{ locPath :: !FilePath
25+
{ locPath :: !Text
2526
, locSpan :: {-# UNPACK #-} !Span
2627
}
2728
deriving (Eq, Ord, Show)
@@ -58,7 +59,7 @@ stackLoc cs = case getCallStack cs of
5859
_ -> Nothing
5960

6061
fromGHCSrcLoc :: SrcLoc -> Loc
61-
fromGHCSrcLoc SrcLoc{..} = Loc srcLocFile (Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol))
62+
fromGHCSrcLoc SrcLoc{..} = Loc (pack srcLocFile) (Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol))
6263

6364

6465
runFailWithLoc :: FailWithLocC m a -> m (Either (Loc, String) a)

semantic-core/src/Data/Name.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Control.Monad.IO.Class
2626
import qualified Data.Char as Char
2727
import Data.HashSet (HashSet)
2828
import qualified Data.HashSet as HashSet
29+
import Data.Text (Text)
2930
import Data.Text.Prettyprint.Doc (Pretty (..))
3031
import qualified Data.Text.Prettyprint.Doc as Pretty
3132

@@ -47,7 +48,7 @@ data Name
4748
-- This should be used for names which the user provided and which other code (other functions, other modules, other packages) could call, e.g. declaration names.
4849
| User User
4950
-- | A variable name represented as the path to a source file. Used for loading modules at a specific name.
50-
| Path FilePath
51+
| Path Text
5152
deriving (Eq, Ord, Show)
5253

5354
instance Pretty Name where

0 commit comments

Comments
 (0)