Skip to content

Commit

Permalink
Make all top-level definitions mutually recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Dec 18, 2024
1 parent cb10fe3 commit 2096668
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2344,7 +2348,7 @@ checkLetStatements ::
checkLetStatements =
ignoreSyntax
. fmap fromSections
. checkSections
. checkSections False
. mkLetSections
. toList
where
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2096668

Please sign in to comment.