-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for recursive inductive types in the GEB pipeline (#1909)
Currently, only recursion in functions is checked. This PR also adds some utilities (TypeDependencyInfo) that will be useful for issue #1907. --------- Co-authored-by: janmasrovira <janmasrovira@gmail.com>
- Loading branch information
1 parent
839093c
commit 906720c
Showing
3 changed files
with
56 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Juvix.Compiler.Core.Data.TypeDependencyInfo where | ||
|
||
import Data.HashMap.Strict qualified as HashMap | ||
import Data.HashSet qualified as HashSet | ||
import Juvix.Compiler.Core.Data.InfoTable | ||
import Juvix.Compiler.Core.Extra.Utils | ||
import Juvix.Compiler.Core.Language | ||
|
||
type TypeDependencyInfo = DependencyInfo Symbol | ||
|
||
createTypeDependencyInfo :: InfoTable -> TypeDependencyInfo | ||
createTypeDependencyInfo tab = createDependencyInfo graph startVertices | ||
where | ||
graph :: HashMap Symbol (HashSet Symbol) | ||
graph = | ||
HashSet.fromList . (^.. inductiveSymbols) | ||
<$> HashMap.filter (isNothing . (^. inductiveBuiltin)) (tab ^. infoInductives) | ||
|
||
constructorTypes :: SimpleFold ConstructorInfo Type | ||
constructorTypes = constructorType . to typeArgs . each | ||
|
||
inductiveSymbols :: SimpleFold InductiveInfo Symbol | ||
inductiveSymbols = inductiveConstructors . each . constructorTypes . nodeInductives | ||
|
||
startVertices :: HashSet Symbol | ||
startVertices = HashSet.fromList syms | ||
|
||
syms :: [Symbol] | ||
syms = map (^. inductiveSymbol) (HashMap.elems (tab ^. infoInductives)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters