Skip to content

Commit

Permalink
Properly scan imports inside local modules (#2165)
Browse files Browse the repository at this point in the history
- Closes #2163 

Nested imports where not scanned properly when building the Internal
InfoTable. That is no fixed
  • Loading branch information
janmasrovira committed Jun 2, 2023
1 parent e068980 commit 02e9f89
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Juvix/Compiler/Internal/Translation/FromAbstract.hs
Expand Up @@ -182,15 +182,26 @@ goDefinition = \case
Abstract.StatementAxiom a -> pure . PreAxiomDef <$> goAxiomDef a
Abstract.StatementImport {} -> return []

scanImports :: Abstract.ModuleBody -> [Abstract.TopModule]
scanImports (Abstract.ModuleBody stmts) = mconcatMap go stmts
where
go :: Abstract.Statement -> [Abstract.TopModule]
go = \case
Abstract.StatementLocalModule m -> scanImports (m ^. Abstract.moduleBody)
Abstract.StatementImport t -> [t]
Abstract.StatementInductive {} -> []
Abstract.StatementFunction {} -> []
Abstract.StatementAxiom {} -> []

goModuleBody ::
forall r.
Members '[Reader ExportsTable, Reader NameDependencyInfo, State TranslationState, NameIdGen] r =>
Abstract.ModuleBody ->
Sem r ModuleBody
goModuleBody (Abstract.ModuleBody stmts) = do
goModuleBody b@(Abstract.ModuleBody stmts) = do
preDefs <- concatMapM goDefinition stmts
sccs <- buildMutualBlocks preDefs
let imports :: [Abstract.TopModule] = [t | Abstract.StatementImport t <- stmts]
let imports :: [Abstract.TopModule] = scanImports b
statements' = map goSCC sccs
imports' <- map StatementInclude <$> mapMaybeM goImport imports
return
Expand Down Expand Up @@ -236,17 +247,6 @@ goImport m = do
}
)

-- goStatement ::
-- (Members '[Reader ExportsTable, State TranslationState, NameIdGen, Reader NameDependencyInfo] r) =>
-- Abstract.Statement ->
-- Sem r (Maybe Statement)
-- goStatement = \case
-- Abstract.StatementAxiom d -> Just . StatementAxiom <$> goAxiomDef d
-- Abstract.StatementFunction {} -> return Nothing
-- Abstract.StatementImport i -> fmap StatementInclude <$> goImport i
-- Abstract.StatementLocalModule m -> Just . StatementModule <$> goModule m
-- Abstract.StatementInductive i -> Just . StatementInductive <$> goInductiveDef i

goTypeIden :: Abstract.Iden -> Iden
goTypeIden = \case
Abstract.IdenFunction f -> IdenFunction (f ^. Abstract.functionRefName)
Expand Down
4 changes: 4 additions & 0 deletions test/Typecheck/Positive.hs
Expand Up @@ -225,6 +225,10 @@ tests =
"Mutual inference inside let"
$(mkRelDir ".")
$(mkRelFile "MutualLet.juvix"),
posTest
"import inside local module"
$(mkRelDir "issue2163")
$(mkRelFile "Main.juvix"),
posTest
"id application in type"
$(mkRelDir ".")
Expand Down
8 changes: 8 additions & 0 deletions tests/positive/issue2163/Main.juvix
@@ -0,0 +1,8 @@
module Main;

module B;
import Stdlib.Prelude open;

idNat : Nat -> Nat;
idNat x := x;
end;
4 changes: 4 additions & 0 deletions tests/positive/issue2163/juvix.yaml
@@ -0,0 +1,4 @@
dependencies:
- .juvix-build/stdlib/
name: issue2163
version: 0.0.0

0 comments on commit 02e9f89

Please sign in to comment.