Skip to content
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

Fix names in Core #2843

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading