1- {-# LANGUAGE CPP, ConstraintKinds, Rank2Types, ScopedTypeVariables, TypeFamilies, TypeOperators #-}
2- {-# OPTIONS_GHC -Wno-missing-signatures -O0 #-}
1+ {-# LANGUAGE CPP, ConstraintKinds, PartialTypeSignatures, Rank2Types, ScopedTypeVariables, TypeFamilies,
2+ TypeOperators #-}
3+ {-# OPTIONS_GHC -Wno-missing-signatures -Wno-partial-type-signatures -O0 #-}
34module Semantic.Util
45 ( evalGoProject
56 , evalPHPProject
@@ -10,6 +11,7 @@ module Semantic.Util
1011 , mergeErrors
1112 , reassociate
1213 , parseFile
14+ , parseFileQuiet
1315 ) where
1416
1517import Prelude hiding (readFile )
@@ -30,6 +32,7 @@ import Data.Blob.IO
3032import Data.Graph (topologicalSort )
3133import qualified Data.Language as Language
3234import Data.List (uncons )
35+ import Data.Location
3336import Data.Project hiding (readFile )
3437import Data.Quieterm (Quieterm , quieterm )
3538import Data.Sum (weaken )
@@ -47,70 +50,11 @@ import Semantic.Task
4750import System.Exit (die )
4851import System.FilePath.Posix (takeDirectory )
4952
50- import Data.Location
51-
52- -- The type signatures in these functions are pretty gnarly, but these functions
53- -- are hit sufficiently often in the CLI and test suite so as to merit avoiding
54- -- the overhead of repeated type inference. If you have to hack on these functions,
55- -- it's recommended to remove all the type signatures and add them back when you
56- -- are done (type holes in GHCi will help here).
57-
58- justEvaluating :: Evaluator
59- term
60- Precise
61- (Value term Precise )
62- (ResumableC
63- (BaseError (ValueError term Precise ))
64- (ResumableC
65- (BaseError (AddressError Precise (Value term Precise )))
66- (ResumableC
67- (BaseError ResolutionError )
68- (ResumableC
69- (BaseError
70- (EvalError term Precise (Value term Precise )))
71- (ResumableC
72- (BaseError (HeapError Precise ))
73- (ResumableC
74- (BaseError (ScopeError Precise ))
75- (ResumableC
76- (BaseError
77- (UnspecializedError
78- Precise (Value term Precise )))
79- (ResumableC
80- (BaseError
81- (LoadError
82- Precise
83- (Value term Precise )))
84- (FreshC
85- (StateC
86- (ScopeGraph
87- Precise )
88- (StateC
89- (Heap
90- Precise
91- Precise
92- (Value
93- term
94- Precise ))
95- (TraceByPrintingC
96- (LiftC
97- IO )))))))))))))
98- result
99- -> IO
100- (Heap Precise Precise (Value term Precise ),
101- (ScopeGraph Precise ,
102- Either
103- (SomeError
104- (Sum
105- '[BaseError (ValueError term Precise ),
106- BaseError (AddressError Precise (Value term Precise )),
107- BaseError ResolutionError ,
108- BaseError (EvalError term Precise (Value term Precise )),
109- BaseError (HeapError Precise ),
110- BaseError (ScopeError Precise ),
111- BaseError (UnspecializedError Precise (Value term Precise )),
112- BaseError (LoadError Precise (Value term Precise ))]))
113- result ))
53+ justEvaluating :: Evaluator term Precise (Value term Precise ) _ result
54+ -> IO ( Heap Precise Precise (Value term Precise ),
55+ ( ScopeGraph Precise
56+ , Either (SomeError (Sum _ )) result )
57+ )
11458justEvaluating
11559 = runM
11660 . runEvaluator
@@ -128,75 +72,27 @@ justEvaluating
12872 . runAddressError
12973 . runValueError
13074
131- type FileEvaluator syntax =
75+ type FileEvaluator err syntax =
13276 [FilePath ]
13377 -> IO
134- (Heap
135- Precise
136- Precise
137- (Value
138- (Quieterm (Sum syntax ) Location ) Precise ),
139- (ScopeGraph Precise ,
140- Either
141- (SomeError
142- (Sum
143- '[BaseError
144- (ValueError
145- (Quieterm (Sum syntax ) Location )
146- Precise ),
147- BaseError
148- (AddressError
149- Precise
150- (Value
151- (Quieterm
152- (Sum syntax ) Location )
153- Precise )),
154- BaseError ResolutionError ,
155- BaseError
156- (EvalError
157- (Quieterm (Sum syntax ) Location )
158- Precise
159- (Value
160- (Quieterm
161- (Sum syntax ) Location )
162- Precise )),
163- BaseError (HeapError Precise ),
164- BaseError (ScopeError Precise ),
165- BaseError
166- (UnspecializedError
167- Precise
168- (Value
169- (Quieterm
170- (Sum syntax ) Location )
171- Precise )),
172- BaseError
173- (LoadError
174- Precise
175- (Value
176- (Quieterm
177- (Sum syntax ) Location )
178- Precise ))]))
179- (ModuleTable
180- (Module
181- (ModuleResult
182- Precise
183- (Value
184- (Quieterm (Sum syntax ) Location )
185- Precise ))))))
78+ ( Heap Precise Precise (Value (Quieterm (Sum syntax ) Location ) Precise ),
79+ ( ScopeGraph Precise
80+ , Either (SomeError (Sum err ))
81+ (ModuleTable (Module (ModuleResult Precise (Value (Quieterm (Sum syntax ) Location ) Precise ))))))
18682
187- evalGoProject :: FileEvaluator Language.Go.Assignment. Syntax
83+ evalGoProject :: FileEvaluator _ Language.Go.Assignment. Syntax
18884evalGoProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.Go ) goParser
18985
190- evalRubyProject :: FileEvaluator Language.Ruby.Assignment. Syntax
86+ evalRubyProject :: FileEvaluator _ Language.Ruby.Assignment. Syntax
19187evalRubyProject = justEvaluating <=< evaluateProject (Proxy @ 'Language.Ruby ) rubyParser
19288
193- evalPHPProject :: FileEvaluator Language.PHP.Assignment. Syntax
89+ evalPHPProject :: FileEvaluator _ Language.PHP.Assignment. Syntax
19490evalPHPProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.PHP ) phpParser
19591
196- evalPythonProject :: FileEvaluator Language.Python.Assignment. Syntax
197- evalPythonProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.Python ) pythonParser
92+ evalPythonProject :: FileEvaluator _ Language.Python.Assignment. Syntax
93+ evalPythonProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.Python ) pythonParser
19894
199- evalTypeScriptProject :: FileEvaluator Language.TypeScript.Assignment. Syntax
95+ evalTypeScriptProject :: FileEvaluator _ Language.TypeScript.Assignment. Syntax
20096evalTypeScriptProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.TypeScript ) typescriptParser
20197
20298evaluateProject proxy parser paths = withOptions debugOptions $ \ config logger statter ->
@@ -218,11 +114,13 @@ evaluateProject' session proxy parser paths = do
218114 (evaluate proxy (runDomainEffects (evalTerm withTermSpans)) modules)))))))
219115 either (die . displayException) pure res
220116
221- parseFile :: Parser term -> FilePath -> IO term
117+ parseFile , parseFileQuiet :: Parser term -> FilePath -> IO term
222118parseFile parser = runTask' . (parse parser <=< readBlob . fileForPath)
119+ parseFileQuiet parser = runTaskQuiet . (parse parser <=< readBlob . fileForPath)
223120
224- runTask' :: TaskEff a -> IO a
121+ runTask' , runTaskQuiet :: TaskEff a -> IO a
225122runTask' task = runTaskWithOptions debugOptions task >>= either (die . displayException) pure
123+ runTaskQuiet task = runTaskWithOptions defaultOptions task >>= either (die . displayException) pure
226124
227125mergeErrors :: Either (SomeError (Sum errs )) (Either (SomeError err ) result ) -> Either (SomeError (Sum (err ': errs ))) result
228126mergeErrors = either (\ (SomeError sum ) -> Left (SomeError (weaken sum ))) (either (\ (SomeError err) -> Left (SomeError (inject err))) Right )
0 commit comments