Skip to content

Commit

Permalink
Fix names in Core (#2843)
Browse files Browse the repository at this point in the history
* Closes #2733
  • Loading branch information
lukaszcz authored Jun 19, 2024
1 parent 235d88f commit 33d5650
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/Juvix/Compiler/Core/Data/Module.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ getInfoMain Module {..} =
<|> _moduleImportsTable ^. infoMain

identName :: Module -> Symbol -> Text
identName m = identName' (computeCombinedInfoTable m)
identName md sym = lookupIdentifierInfo md sym ^. identifierName

typeName :: Module -> Symbol -> Text
typeName m = typeName' (computeCombinedInfoTable m)
typeName md sym = lookupInductiveInfo md sym ^. inductiveName

constrName :: Module -> Tag -> Text
constrName md tag = lookupConstructorInfo md tag ^. constructorName

identNames :: Module -> HashSet Text
identNames m = identNames' (computeCombinedInfoTable m)
Expand Down
22 changes: 20 additions & 2 deletions src/Juvix/Compiler/Core/Transformation/DisambiguateNames.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ disambiguateNodeNames' disambiguate md = dmapL go
mkVar (setInfoName (BL.lookup _varIndex bl ^. binderName) _varInfo) _varIndex
NIdt Ident {..} ->
mkIdent (setInfoName (identName md _identSymbol) _identInfo) _identSymbol
NCtr Constr {..} ->
mkConstr (setInfoName (constrName md _constrTag) _constrInfo) _constrTag _constrArgs
NLam lam ->
NLam (over lambdaBinder (over binderName (disambiguate bl)) lam)
NLet lt ->
Expand All @@ -35,7 +37,18 @@ disambiguateNodeNames' disambiguate md = dmapL go
where
vs = toList (lt ^. letRecValues)
NCase c ->
NCase (over caseBranches (map (over caseBranchBinders (disambiguateBinders bl))) c)
NCase
( over
caseBranches
( map
( \br ->
over caseBranchInfo (setInfoName (constrName md (br ^. caseBranchTag)))
. over caseBranchBinders (disambiguateBinders bl)
$ br
)
)
c
)
NMatch m ->
NMatch (over matchBranches (map (over matchBranchPatterns (NonEmpty.fromList . snd . disambiguatePatterns bl . toList))) m)
NTyp TypeConstr {..} ->
Expand Down Expand Up @@ -64,7 +77,12 @@ disambiguateNodeNames' disambiguate md = dmapL go
where
b' = over binderName (disambiguate bl) (c ^. patternConstrBinder)
(bl', args') = disambiguatePatterns (BL.cons b' bl) (c ^. patternConstrArgs)
pat' = PatConstr $ set patternConstrBinder b' $ set patternConstrArgs args' c
pat' =
PatConstr
. set patternConstrBinder b'
. set patternConstrArgs args'
. over patternConstrInfo (setInfoName (constrName md (c ^. patternConstrTag)))
$ c

disambiguateNodeNames :: Module -> Node -> Node
disambiguateNodeNames md = disambiguateNodeNames' disambiguate md
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Compiler/Internal/Data/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ varFromHole h =
_nameFixity = Nothing
}
where
pp = "" <> prettyText (h ^. holeId)
pp :: Text = ""

varFromWildcard :: (Members '[NameIdGen] r) => Wildcard -> Sem r VarName
varFromWildcard w = do
_nameId <- freshNameId
let _nameText :: Text = "" <> prettyText _nameId
let _nameText :: Text = ""
_nameKind = KNameLocal
_nameKindPretty = KNameLocal
_namePretty = _nameText
Expand Down
6 changes: 3 additions & 3 deletions src/Juvix/Compiler/Internal/Translation/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,16 @@ goFunctionDef FunctionDef {..} = do
argToPattern arg@SigArg {..} = do
let _patternArgIsImplicit = _sigArgImplicit
_patternArgName :: Maybe Internal.Name = Nothing
noName = goWidlcard (Wildcard (getLoc arg))
goWidlcard w = do
noName = goWildcard (Wildcard (getLoc arg))
goWildcard w = do
_patternArgPattern <- Internal.PatternVariable <$> varFromWildcard w
return Internal.PatternArg {..}
mk :: Concrete.Argument 'Scoped -> Sem r Internal.PatternArg
mk = \case
Concrete.ArgumentSymbol s ->
let _patternArgPattern = Internal.PatternVariable (goSymbol s)
in return Internal.PatternArg {..}
Concrete.ArgumentWildcard w -> goWidlcard w
Concrete.ArgumentWildcard w -> goWildcard w
maybe (pure <$> noName) (mapM mk) (nonEmpty _sigArgNames)

goInductiveParameters ::
Expand Down

0 comments on commit 33d5650

Please sign in to comment.