Skip to content

Commit

Permalink
Add potentially isolated nodes in dependency builder
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira authored and lukaszcz committed Sep 26, 2023
1 parent 74ddef2 commit c60a8a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Juvix/Compiler/Internal/Extra/DependencyBuilder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ addStartNode n = modify (HashSet.insert n)
addEdgeMay :: (Member (State DependencyGraph) r) => Maybe Name -> Name -> Sem r ()
addEdgeMay mn1 n2 = whenJust mn1 $ \n1 -> addEdge n1 n2

addNode :: (Member (State DependencyGraph) r) => Name -> Sem r ()
addNode n =
modify
( HashMap.alter
( \case
Just x -> Just x
Nothing -> Just (mempty :: HashSet Name)
)
n
)

addEdge :: (Member (State DependencyGraph) r) => Name -> Name -> Sem r ()
addEdge n1 n2 =
modify
Expand Down Expand Up @@ -179,6 +190,7 @@ goFunctionDefHelper ::
FunctionDef ->
Sem r ()
goFunctionDefHelper f = do
addNode (f ^. funDefName)
checkStartNode (f ^. funDefName)
when (f ^. funDefInstance) $
goInstance f
Expand Down
6 changes: 5 additions & 1 deletion src/Juvix/Compiler/Internal/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,13 @@ instance PrettyCode FunctionDef where
<?+> funDefName'
<+> kwColon
<+> funDefType'
<> line
<> hardline
<> vsep (toList clauses')

instance PrettyCode PreLetStatement where
ppCode = \case
PreLetFunctionDef f -> ppCode f

instance PrettyCode FunctionClause where
ppCode c = do
funName <- ppCode (c ^. clauseName)
Expand Down
2 changes: 2 additions & 0 deletions tests/positive/issue2373/Main.juvix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module Main;

import Stdlib.Data.Nat open;
import Stdlib.Data.Bool open;

main : Nat :=
let
y : Nat := 0;
x : _ := 0;
in x;

0 comments on commit c60a8a7

Please sign in to comment.