From 20966688a6c36720063764439d1b344c8d55233c Mon Sep 17 00:00:00 2001 From: Lukasz Czajka Date: Wed, 18 Dec 2024 12:44:15 +0100 Subject: [PATCH] Make all top-level definitions mutually recursive --- .../FromParsed/Analysis/Scoping.hs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs index 077216e433..8d9212699a 100644 --- a/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs +++ b/src/Juvix/Compiler/Concrete/Translation/FromParsed/Analysis/Scoping.hs @@ -1262,9 +1262,10 @@ checkTypeSig TypeSig {..} = do checkFunctionDef :: forall r. (Members '[HighlightBuilder, Reader ScopeParameters, Error ScoperError, State Scope, State ScoperState, InfoTableBuilder, Reader InfoTable, NameIdGen, Reader PackageId, State ScoperSyntax, Reader BindingStrategy] r) => + Bool -> FunctionDef 'Parsed -> Sem r (FunctionDef 'Scoped) -checkFunctionDef fdef@FunctionDef {..} = do +checkFunctionDef isTop fdef@FunctionDef {..} = do let FunctionLhs {..} = _functionDefLhs sigDoc' <- mapM checkJudoc _functionDefDoc (sig', sigBody') <- withLocalScope $ do @@ -1276,7 +1277,7 @@ checkFunctionDef fdef@FunctionDef {..} = do FunctionDefName name -> do name' <- if - | P.isFunctionLike fdef -> getReservedDefinitionSymbol name + | isTop || P.isFunctionLike fdef -> getReservedDefinitionSymbol name | otherwise -> reserveFunctionSymbol (fdef ^. functionDefLhs) return FunctionDefNameScoped @@ -1634,7 +1635,7 @@ checkModuleBody body = do body' <- fmap flattenSections . syntaxBlock - $ checkSections (mkSections body) + $ checkSections True (mkSections body) exported <- get >>= exportScope return (exported, body') where @@ -1672,9 +1673,10 @@ checkModuleBody body = do checkSections :: forall r. (Members '[HighlightBuilder, Error ScoperError, Reader ScopeParameters, State Scope, State ScoperState, InfoTableBuilder, Reader InfoTable, NameIdGen, State ScoperSyntax, Reader PackageId] r) => + Bool -> StatementSections 'Parsed -> Sem r (StatementSections 'Scoped) -checkSections sec = topBindings helper +checkSections isTop sec = topBindings helper where helper :: forall r'. @@ -1780,7 +1782,9 @@ checkSections sec = topBindings helper reserveDefinition :: Definition 'Parsed -> Sem r' (Maybe (Module 'Parsed 'ModuleLocal)) reserveDefinition = \case DefinitionSyntax s -> resolveSyntaxDef s $> Nothing - DefinitionFunctionDef d -> reserveFunctionLikeSymbol d >> return Nothing + DefinitionFunctionDef d + | isTop -> reserveFunctionSymbol (d ^. functionDefLhs) >> return Nothing + | otherwise -> reserveFunctionLikeSymbol d >> return Nothing DefinitionDeriving d -> reserveDerivingSymbol d >> return Nothing DefinitionAxiom d -> reserveAxiomSymbol d >> return Nothing DefinitionProjectionDef d -> reserveProjectionSymbol d >> return Nothing @@ -1836,7 +1840,7 @@ checkSections sec = topBindings helper goDefinition :: Definition 'Parsed -> Sem r' (Definition 'Scoped) goDefinition = \case DefinitionSyntax s -> DefinitionSyntax <$> checkSyntaxDef s - DefinitionFunctionDef d -> DefinitionFunctionDef <$> checkFunctionDef d + DefinitionFunctionDef d -> DefinitionFunctionDef <$> checkFunctionDef isTop d DefinitionDeriving d -> DefinitionDeriving <$> checkDeriving d DefinitionAxiom d -> DefinitionAxiom <$> checkAxiomDef d DefinitionInductive d -> DefinitionInductive <$> checkInductiveDef d @@ -2344,7 +2348,7 @@ checkLetStatements :: checkLetStatements = ignoreSyntax . fmap fromSections - . checkSections + . checkSections False . mkLetSections . toList where @@ -3034,7 +3038,7 @@ checkNamedArgumentFunctionDef :: NamedArgumentFunctionDef 'Parsed -> Sem r (NamedArgumentFunctionDef 'Scoped) checkNamedArgumentFunctionDef NamedArgumentFunctionDef {..} = do - def <- localBindings . ignoreSyntax $ checkFunctionDef _namedArgumentFunctionDef + def <- localBindings . ignoreSyntax $ checkFunctionDef False _namedArgumentFunctionDef return NamedArgumentFunctionDef { _namedArgumentFunctionDef = def