From 136a9661d2a20f1a6ec8b29176ecac474000b5cc Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 6 May 2018 16:35:04 -0400 Subject: [PATCH] Split the LoadError handling out into a separate function. --- src/Analysis/Abstract/ImportGraph.hs | 21 ++++++++++++++------- src/Semantic/Graph.hs | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Analysis/Abstract/ImportGraph.hs b/src/Analysis/Abstract/ImportGraph.hs index a15574020..33b794825 100644 --- a/src/Analysis/Abstract/ImportGraph.hs +++ b/src/Analysis/Abstract/ImportGraph.hs @@ -3,6 +3,7 @@ module Analysis.Abstract.ImportGraph ( ImportGraph(..) , renderImportGraph , graphingTerms +, graphingLoadErrors , graphingModules , importGraphing ) where @@ -54,12 +55,10 @@ style = (defaultStyle vertexName) edgeAttributes Variable{} Module{} = [ "color" := "blue" ] edgeAttributes _ _ = [] -graphingTerms :: forall location term value effects syntax ann a - . ( Element Syntax.Identifier syntax +graphingTerms :: ( Element Syntax.Identifier syntax , Members '[ Reader (Environment (Located location) value) , Reader ModuleInfo , Reader PackageInfo - , Resumable (LoadError term) , State (Environment (Located location) value) , State (ImportGraph term) ] effects @@ -73,10 +72,18 @@ graphingTerms recur term@(In _ syntax) = do moduleInclusion (Variable (unName name)) variableDefinition name _ -> pure () - resume - @(LoadError term) - (recur term) - (\ (LoadError name) -> moduleInclusion (Module (BC.pack name)) *> pure []) + (recur term) + +graphingLoadErrors :: forall location term value effects a + . Members '[ Reader ModuleInfo + , Resumable (LoadError term) + , State (ImportGraph term) + ] effects + => SubtermAlgebra (Base term) term (Evaluator location term value effects a) + -> SubtermAlgebra (Base term) term (Evaluator location term value effects a) +graphingLoadErrors recur term = resume @(LoadError term) + (recur term) + (\ (LoadError name) -> moduleInclusion (Module (BC.pack name)) *> pure []) graphingModules :: Members '[ Reader ModuleInfo , Reader PackageInfo diff --git a/src/Semantic/Graph.hs b/src/Semantic/Graph.hs index 26b698197..1e8304791 100644 --- a/src/Semantic/Graph.hs +++ b/src/Semantic/Graph.hs @@ -108,7 +108,7 @@ graphImports :: ( Show ann ) => Package (Term (Sum syntax) ann) -> Eff effs (ImportGraph (Term (Sum syntax) ann)) -graphImports package = analyze importGraphAnalysis (evaluatePackageWith graphingModules graphingTerms package) >>= extractGraph +graphImports package = analyze importGraphAnalysis (evaluatePackageWith graphingModules (graphingLoadErrors . graphingTerms) package) >>= extractGraph where extractGraph result = case result of (Right (Right ((_, graph), _)), _) -> pure graph