Don't visit declarations and expression if there are no visitors for them

This commit is contained in:
Jeroen Engels 2021-10-27 08:08:07 +02:00
parent b71984aebb
commit 92aa1c0822

View File

@ -4331,27 +4331,47 @@ getFolderFromTraversal traversalAndFolder =
visitModuleForProjectRule : RunnableModuleVisitor moduleContext -> moduleContext -> ProjectModule -> ( List (Error {}), moduleContext )
visitModuleForProjectRule schema initialContext module_ =
let
declarationAndExpressionVisits : List (Node Declaration) -> ( List (Error {}), moduleContext ) -> ( List (Error {}), moduleContext )
declarationAndExpressionVisits =
if shouldVisitDeclarationsAndExpressions schema then
accumulateList
(visitDeclaration
schema.declarationVisitorsOnEnter
schema.declarationVisitorsOnExit
{ expressionVisitorsOnEnter = schema.expressionVisitorsOnEnter
, expressionVisitorsOnExit = schema.expressionVisitorsOnExit
, letDeclarationVisitorsOnEnter = schema.letDeclarationVisitorsOnEnter
, letDeclarationVisitorsOnExit = schema.letDeclarationVisitorsOnExit
, caseBranchVisitorsOnEnter = schema.caseBranchVisitorsOnEnter
, caseBranchVisitorsOnExit = schema.caseBranchVisitorsOnExit
}
)
else
\_ errorsAndContext -> errorsAndContext
in
( [], initialContext )
|> accumulateWithListOfVisitors schema.moduleDefinitionVisitors module_.ast.moduleDefinition
|> accumulateWithListOfVisitors schema.commentsVisitors module_.ast.comments
|> accumulateList (visitImport schema.importVisitors) module_.ast.imports
|> accumulateWithListOfVisitors schema.declarationListVisitors module_.ast.declarations
|> accumulateList
(visitDeclaration
schema.declarationVisitorsOnEnter
schema.declarationVisitorsOnExit
{ expressionVisitorsOnEnter = schema.expressionVisitorsOnEnter
, expressionVisitorsOnExit = schema.expressionVisitorsOnExit
, letDeclarationVisitorsOnEnter = schema.letDeclarationVisitorsOnEnter
, letDeclarationVisitorsOnExit = schema.letDeclarationVisitorsOnExit
, caseBranchVisitorsOnEnter = schema.caseBranchVisitorsOnEnter
, caseBranchVisitorsOnExit = schema.caseBranchVisitorsOnExit
}
)
module_.ast.declarations
|> declarationAndExpressionVisits module_.ast.declarations
|> (\( errors, moduleContext ) -> ( makeFinalEvaluation schema.finalEvaluationFns ( errors, moduleContext ), moduleContext ))
shouldVisitDeclarationsAndExpressions : RunnableModuleVisitor moduleContext -> Bool
shouldVisitDeclarationsAndExpressions schema =
not (List.isEmpty schema.declarationVisitorsOnEnter)
|| not (List.isEmpty schema.declarationVisitorsOnExit)
|| not (List.isEmpty schema.expressionVisitorsOnEnter)
|| not (List.isEmpty schema.expressionVisitorsOnExit)
|| not (List.isEmpty schema.letDeclarationVisitorsOnEnter)
|| not (List.isEmpty schema.letDeclarationVisitorsOnExit)
|| not (List.isEmpty schema.caseBranchVisitorsOnEnter)
|| not (List.isEmpty schema.caseBranchVisitorsOnExit)
type alias ExpressionRelatedVisitors moduleContext =
{ expressionVisitorsOnEnter : List (Visitor Expression moduleContext)
, expressionVisitorsOnExit : List (Visitor Expression moduleContext)