Skip to content

Commit

Permalink
changes for review
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Mar 17, 2023
1 parent a80b29c commit 778dfbf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
23 changes: 11 additions & 12 deletions src/Juvix/Compiler/Core/Transformation/CheckGeb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ checkGeb tab =
NLam Lambda {..}
| isDynamic (_lambdaBinder ^. binderType) ->
throw (dynamicTypeError node (_lambdaBinder ^. binderLocation))
NPi (Pi {..})
NPi Pi {..}
| isTypeConstr tab (_piBinder ^. binderType) ->
throw
CoreError
Expand Down Expand Up @@ -68,17 +68,16 @@ checkGeb tab =
_ -> return node

checkNoRecursion :: Sem r ()
checkNoRecursion =
if
| isCyclic (createIdentDependencyInfo tab) ->
throw
CoreError
{ _coreErrorMsg = "recursion not supported for the GEB target",
_coreErrorNode = Nothing,
_coreErrorLoc = defaultLoc
}
| otherwise ->
return ()
checkNoRecursion
| isCyclic (createIdentDependencyInfo tab) =
throw
CoreError
{ _coreErrorMsg = "recursion not supported for the GEB target",
_coreErrorNode = Nothing,
_coreErrorLoc = defaultLoc
}
| otherwise =
return ()

dynamicTypeError :: Node -> Maybe Location -> CoreError
dynamicTypeError node loc =
Expand Down
22 changes: 2 additions & 20 deletions src/Juvix/Data/DependencyInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Juvix.Data.DependencyInfo where
import Data.Graph qualified as Graph
import Data.HashMap.Strict qualified as HashMap
import Data.HashSet qualified as HashSet
import GHC.Arr (Array, indices, (!))
import Juvix.Prelude.Base

-- DependencyInfo is polymorphic to anticipate future use with other identifier
Expand Down Expand Up @@ -57,22 +56,5 @@ isReachable depInfo n = HashSet.member n (depInfo ^. depInfoReachable)
buildSCCs :: Ord n => DependencyInfo n -> [SCC n]
buildSCCs = Graph.stronglyConnComp . (^. depInfoEdgeList)

isCyclic :: DependencyInfo n -> Bool
isCyclic DependencyInfo {..} =
run $ evalState (mempty :: HashSet Int) $ or <$> mapM (go _depInfoGraph mempty) (indices _depInfoGraph)
where
go :: Member (State (HashSet Int)) r => Array Int [Int] -> HashSet Int -> Int -> Sem r Bool
go graph vars v
| HashSet.member v vars = return True
| otherwise = do
s <- get
if
| HashSet.member v s ->
return False
| otherwise -> do
put (HashSet.insert v s)
let vars' = HashSet.insert v vars
foldr
((\v' acc -> go graph vars' v' >>= \b -> acc <&> (||) b))
(return False)
(graph ! v)
isCyclic :: Ord n => DependencyInfo n -> Bool
isCyclic = any (\case CyclicSCC _ -> True; _ -> False) . buildSCCs

0 comments on commit 778dfbf

Please sign in to comment.