Skip to content

Commit b1bd67d

Browse files
authored
Merge of #2597
2 parents 98c8433 + 6752054 commit b1bd67d

File tree

17 files changed

+69
-66
lines changed

17 files changed

+69
-66
lines changed

src/swarm-engine/Swarm/Game/Step.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ stepCESK cesk = case cesk of
660660
Out _ s (FApp _ : _) -> badMachineState s "FApp of non-function"
661661
-- Start evaluating a record. If it's empty, we're done. Otherwise, focus
662662
-- on the first field and record the rest in a FRcd frame.
663-
In (TRcd m) e s k -> return $ case map (first lvVar) m of
663+
In (TRcd m) e s k -> return $ case map (first locVal) m of
664664
[] -> Out (VRcd M.empty) s k
665665
((x, t) : fs) -> In (fromMaybe (TVar x) t) e s (FRcd e [] x fs : k)
666666
-- When we finish evaluating the last field, return a record value.

src/swarm-lang/Swarm/Language/LSP/Hover.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ explain trm = case trm ^. sTerm of
238238
SRequirements {} -> pure "Query the requirements of a term."
239239
-- definition or bindings
240240
SLet ls isRecursive var mTypeAnn _ _ rhs _b -> pure $ explainDefinition ls isRecursive var (rhs ^. sType) mTypeAnn
241-
SLam (LV _s v) _mType _syn ->
241+
SLam (Loc _s v) _mType _syn ->
242242
pure $
243243
typeSignature v ty $
244244
"A lambda expression binding the variable " <> U.bquote v <> "."
245245
SBind mv _ _ _ rhs _cmds ->
246246
pure $
247-
typeSignature (maybe "__rhs" lvVar mv) (getInnerType $ rhs ^. sType) $
248-
"A monadic bind for commands" <> maybe "." (\(LV _s v) -> ", that binds variable " <> U.bquote v <> ".") mv
247+
typeSignature (maybe "__rhs" locVal mv) (getInnerType $ rhs ^. sType) $
248+
"A monadic bind for commands" <> maybe "." (\(Loc _s v) -> ", that binds variable " <> U.bquote v <> ".") mv
249249
-- composite types
250250
SPair {} ->
251251
Node
@@ -298,7 +298,7 @@ explainFunction s =
298298
]
299299

300300
explainDefinition :: ExplainableType ty => LetSyntax -> Bool -> LocVar -> ty -> Maybe RawPolytype -> Text
301-
explainDefinition ls isRecursive (LV _s var) ty maybeTypeAnnotation =
301+
explainDefinition ls isRecursive (Loc _s var) ty maybeTypeAnnotation =
302302
typeSignature var ty $
303303
T.unwords
304304
[ "A"

src/swarm-lang/Swarm/Language/LSP/VarUsage.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ instance Monoid Usage where
4444
mempty = Usage mempty mempty
4545

4646
toErrPos :: Text -> VarUsage -> Maybe (J.Range, Text)
47-
toErrPos code (VarUsage (LV loc v) scope) = do
47+
toErrPos code (VarUsage (Loc loc v) scope) = do
4848
-- A leading underscore will suppress the unused variable warning
4949
guard $ not $ "_" `T.isPrefixOf` v
5050
rangePair <- case loc of
@@ -78,12 +78,12 @@ checkOccurrences ::
7878
BindingType ->
7979
[Syntax] ->
8080
Usage
81-
checkOccurrences bindings lv@(LV loc v) declType childSyntaxes =
81+
checkOccurrences bindings lc@(Loc loc v) declType childSyntaxes =
8282
Usage childUsages $ missing <> deeperMissing
8383
where
8484
deeperBindings = M.insertWith (<>) v (pure loc) bindings
8585
Usage childUsages deeperMissing = mconcat $ map (getUsage deeperBindings) childSyntaxes
86-
missing = [VarUsage lv declType | lv `S.notMember` childUsages]
86+
missing = [VarUsage lc declType | lc `S.notMember` childUsages]
8787

8888
-- | Build up the bindings map as a function argument as
8989
-- we descend into the syntax tree.
@@ -97,7 +97,7 @@ getUsage bindings (CSyntax _pos t _comments) = case t of
9797
where
9898
myUsages = case M.lookup v bindings of
9999
Nothing -> mempty
100-
Just (loc :| _) -> S.singleton $ LV loc v
100+
Just (loc :| _) -> S.singleton $ Loc loc v
101101
SLam v _ s -> checkOccurrences bindings v Lambda [s]
102102
SApp s1 s2 -> getUsage bindings s1 <> getUsage bindings s2
103103
-- Warn on unused 'let' bindings...
@@ -110,7 +110,7 @@ getUsage bindings (CSyntax _pos t _comments) = case t of
110110
Just v -> checkOccurrences bindings v Bind [s1, s2]
111111
Nothing -> getUsage bindings s1 <> getUsage bindings s2
112112
SDelay s -> getUsage bindings s
113-
SRcd m -> foldMap (\(LV _ x, mt) -> maybe (getUsage bindings (STerm (TVar x))) (getUsage bindings) mt) m
113+
SRcd m -> foldMap (\(Loc _ x, mt) -> maybe (getUsage bindings (STerm (TVar x))) (getUsage bindings) mt) m
114114
SProj s _ -> getUsage bindings s
115115
SAnnotate s _ -> getUsage bindings s
116116
SSuspend s -> getUsage bindings s

src/swarm-lang/Swarm/Language/Parser/Lex.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ data IdentifierType = IDTyVar | IDTyName | IDTmVar
215215
-- | Parse an identifier together with its source location info.
216216
locIdentifier :: IdentifierType -> Parser LocVar
217217
locIdentifier idTy =
218-
uncurry LV <$> parseLocG ((lexeme . try) (p >>= check) <?> "variable name")
218+
uncurry Loc <$> parseLocG ((lexeme . try) (p >>= check) <?> "variable name")
219219
where
220220
p = (:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> char '_' <|> char '\'')
221221
check (into @Text -> t)
@@ -248,7 +248,7 @@ locTyName = (fmap . fmap) mkTDVar (locIdentifier IDTyName)
248248
-- alphanumeric characters and underscores, not starting with a
249249
-- digit. The Bool indicates whether we are parsing a type variable.
250250
identifier :: IdentifierType -> Parser Var
251-
identifier = fmap lvVar . locIdentifier
251+
identifier = fmap locVal . locIdentifier
252252

253253
-- | Parse a type variable, which must start with an underscore or
254254
-- lowercase letter and cannot be the lowercase version of a type

src/swarm-lang/Swarm/Language/Parser/Record.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Swarm.Language.Parser.Record (
1010

1111
import Swarm.Language.Parser.Core (Parser)
1212
import Swarm.Language.Parser.Lex (locTmVar, symbol)
13-
import Swarm.Language.Syntax.Loc (LocVar, lvVar)
13+
import Swarm.Language.Syntax.Loc (LocVar, locVal)
1414
import Swarm.Util (failT, findDup, squote)
1515
import Text.Megaparsec (sepBy)
1616

@@ -24,6 +24,6 @@ parseRecord :: Parser a -> Parser [(LocVar, a)]
2424
parseRecord p = (parseBinding `sepBy` symbol ",") >>= fromListUnique
2525
where
2626
parseBinding = (,) <$> locTmVar <*> p
27-
fromListUnique kvs = case findDup (map (lvVar . fst) kvs) of
27+
fromListUnique kvs = case findDup (map (locVal . fst) kvs) of
2828
Nothing -> pure kvs
2929
Just x -> failT ["duplicate field name", squote x, "in record literal"]

src/swarm-lang/Swarm/Language/Parser/Term.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ parseTermAtom2 =
8989
<*> (reserved "in" *> parseTerm)
9090
<|> do
9191
reserved "def"
92-
locVar@(LV _srcLoc nameText) <- locTmVar
92+
locVar@(Loc _srcLoc nameText) <- locTmVar
9393
mTy <- optional (symbol ":" *> parsePolytype)
9494
_ <- symbol "="
9595
body <- parseTerm
@@ -127,7 +127,7 @@ parseStock =
127127
-- | Construct an 'SLet', automatically filling in the Boolean field
128128
-- indicating whether it is recursive.
129129
sLet :: LetSyntax -> LocVar -> Maybe RawPolytype -> Syntax -> Syntax -> Term
130-
sLet ls x ty t1 = SLet ls (lvVar x `S.member` setOf freeVarsV t1) x ty Nothing mempty t1
130+
sLet ls x ty t1 = SLet ls (locVal x `S.member` setOf freeVarsV t1) x ty Nothing mempty t1
131131

132132
sNoop :: Syntax
133133
sNoop = STerm (TConst Noop)
@@ -159,7 +159,7 @@ parseTerm = sepEndBy1 parseStmt (symbol ";") >>= mkBindChain
159159

160160
mkBindChain :: [Stmt] -> Parser Syntax
161161
mkBindChain stmts = case last stmts of
162-
Binder x _ -> return $ foldr mkBind (STerm (TApp (TConst Pure) (TVar (lvVar x)))) stmts
162+
Binder x _ -> return $ foldr mkBind (STerm (TApp (TConst Pure) (TVar (locVal x)))) stmts
163163
BareTerm t -> return $ foldr mkBind t (init stmts)
164164
where
165165
mkBind (BareTerm t1) t2 = loc Nothing t1 t2 $ SBind Nothing Nothing Nothing Nothing t1 t2

src/swarm-lang/Swarm/Language/Parser/Type.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Swarm.Language.Parser.Lex (
3232
tyVar,
3333
)
3434
import Swarm.Language.Parser.Record (parseRecord)
35-
import Swarm.Language.Syntax.Loc (lvVar)
35+
import Swarm.Language.Syntax.Loc (locVal)
3636
import Swarm.Language.Types
3737
import Text.Megaparsec (choice, optional, some, (<|>))
3838

@@ -65,17 +65,19 @@ parseTypeMolecule =
6565
TyConApp <$> parseTyCon <*> many parseTypeAtom
6666
<|> parseTypeAtom
6767

68-
-- | A "type atom" consists of some atomic type snytax --- type
68+
-- | A "type atom" consists of some atomic type syntax --- type
6969
-- variables, things in brackets of some kind, or a lone type
7070
-- constructor.
7171
parseTypeAtom :: Parser Type
7272
parseTypeAtom =
7373
TyVar <$> tyVar
7474
<|> TyConApp <$> parseTyCon <*> pure []
7575
<|> TyDelay <$> braces parseType
76-
<|> TyRcd <$> brackets (M.fromList . (map . first) lvVar <$> parseRecord (symbol ":" *> parseType))
76+
<|> TyRcd <$> brackets (toRecFieldsMap <$> parseRecord (symbol ":" *> parseType))
7777
<|> tyRec <$> (reserved "rec" *> tyVar) <*> (symbol "." *> parseType)
7878
<|> parens parseType
79+
where
80+
toRecFieldsMap = M.fromList . map (first locVal)
7981

8082
-- | A type constructor.
8183
parseTyCon :: Parser TyCon

src/swarm-lang/Swarm/Language/Parser/Value.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ toValue = \case
6262
VKey <$> eitherToMaybe (MP.runParser parseKeyComboFull "" k)
6363
_ -> Nothing
6464
TPair t1 t2 -> VPair <$> toValue t1 <*> toValue t2
65-
TRcd m -> VRcd . M.fromList <$> traverse (traverse (>>= toValue) . first lvVar) m
65+
TRcd m -> VRcd . M.fromList <$> traverse (traverse (>>= toValue) . first locVal) m
6666
TParens t -> toValue t
6767
-- List the other cases explicitly, instead of a catch-all, so that
6868
-- we will get a warning if we ever add new constructors in the

src/swarm-lang/Swarm/Language/Pipeline.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ extractTCtx :: Syntax' ty -> TCtx
7777
extractTCtx (Syntax' _ t _ _) = extractTCtxTerm t
7878
where
7979
extractTCtxTerm = \case
80-
SLet _ _ (LV _ x) _ mty _ _ t2 -> maybe id (Ctx.addBinding x) mty (extractTCtx t2)
80+
SLet _ _ (Loc _ x) _ mty _ _ t2 -> maybe id (Ctx.addBinding x) mty (extractTCtx t2)
8181
SBind mx _ mty _ c1 c2 ->
8282
maybe
8383
id
8484
(uncurry Ctx.addBinding)
85-
((,) . lvVar <$> mx <*> mty)
85+
((,) . locVal <$> mx <*> mty)
8686
(extractTCtx c1 <> extractTCtx c2)
8787
SAnnotate t1 _ -> extractTCtx t1
8888
_ -> mempty
@@ -94,12 +94,12 @@ extractReqCtx :: Syntax' ty -> ReqCtx
9494
extractReqCtx (Syntax' _ t _ _) = extractReqCtxTerm t
9595
where
9696
extractReqCtxTerm = \case
97-
SLet _ _ (LV _ x) _ _ mreq _ t2 -> maybe id (Ctx.addBinding x) mreq (extractReqCtx t2)
97+
SLet _ _ (Loc _ x) _ _ mreq _ t2 -> maybe id (Ctx.addBinding x) mreq (extractReqCtx t2)
9898
SBind mx _ _ mreq c1 c2 ->
9999
maybe
100100
id
101101
(uncurry Ctx.addBinding)
102-
((,) . lvVar <$> mx <*> mreq)
102+
((,) . locVal <$> mx <*> mreq)
103103
(extractReqCtx c1 <> extractReqCtx c2)
104104
SAnnotate t1 _ -> extractReqCtx t1
105105
_ -> mempty

src/swarm-lang/Swarm/Language/Requirements/Analysis.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ requirements tdCtx ctx =
157157
TDelay t -> go t
158158
TRcd m -> add (singletonCap CRecord) *> forM_ m (go . expandEq)
159159
where
160-
expandEq (LV _ x, Nothing) = TVar x
160+
expandEq (Loc _ x, Nothing) = TVar x
161161
expandEq (_, Just t) = t
162162
TProj t _ -> add (singletonCap CRecord) *> go t
163163
-- A type ascription doesn't change requirements

0 commit comments

Comments
 (0)