1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 05:41:54 +03:00

Revert "Add a type family for the required effects."

This reverts commit cc352239fd94a6689ae3a03739b2feebbb7372ef.
This commit is contained in:
Rob Rix 2018-03-09 11:03:33 -05:00
parent 1fd764f05e
commit 0d040911eb
6 changed files with 16 additions and 25 deletions

View File

@ -79,7 +79,6 @@ instance ( Corecursive (TermFor m)
, Recursive (TermFor m)
)
=> MonadAnalysis (CachingAnalysis m) where
type EffectsRequiredFor (CachingAnalysis m) = CachingEffects (TermFor m) (ValueFor m) (EffectsRequiredFor m)
analyzeTerm e = do
c <- getConfiguration (embedSubterm e)
-- Convergence here is predicated upon an Eq instance, not α-equivalence

View File

@ -45,7 +45,6 @@ instance ( Corecursive (TermFor m)
, Recursive (TermFor m)
)
=> MonadAnalysis (DeadCodeAnalysis m) where
type EffectsRequiredFor (DeadCodeAnalysis m) = DeadCode (TermFor m) ': EffectsRequiredFor m
analyzeTerm term = do
revive (embedSubterm term)
liftAnalyze analyzeTerm term

View File

@ -21,26 +21,26 @@ import System.FilePath.Posix
evaluate :: forall value term
. ( Evaluatable (Base term)
, FreeVariables term
, MonadAddressable (LocationFor value) (Evaluating term value (EvaluatingEffects term value '[]))
, MonadValue value (Evaluating term value (EvaluatingEffects term value '[]))
, MonadAddressable (LocationFor value) (Evaluating term value '[])
, MonadValue value (Evaluating term value '[])
, Recursive term
)
=> term
-> Final (EvaluatingEffects term value '[]) value
evaluate = run @(Evaluating term value (EvaluatingEffects term value '[])) . evaluateModule
evaluate = run @(Evaluating term value '[]) . evaluateModule
-- | Evaluate terms and an entry point to a value.
evaluates :: forall value term
. ( Evaluatable (Base term)
, FreeVariables term
, MonadAddressable (LocationFor value) (Evaluating term value (EvaluatingEffects term value '[]))
, MonadValue value (Evaluating term value (EvaluatingEffects term value '[]))
, MonadAddressable (LocationFor value) (Evaluating term value '[])
, MonadValue value (Evaluating term value '[])
, Recursive term
)
=> [(Blob, term)] -- List of (blob, term) pairs that make up the program to be evaluated
-> (Blob, term) -- Entrypoint
-> Final (EvaluatingEffects term value '[]) value
evaluates pairs (_, t) = run @(Evaluating term value (EvaluatingEffects term value '[])) (withModules pairs (evaluateModule t))
evaluates pairs (_, t) = run @(Evaluating term value '[]) (withModules pairs (evaluateModule t))
-- | Run an action with the passed ('Blob', @term@) pairs available for imports.
withModules :: (MonadAnalysis m, MonadEvaluator m) => [(Blob, TermFor m)] -> m a -> m a
@ -48,13 +48,13 @@ withModules pairs = localModuleTable (const moduleTable)
where moduleTable = ModuleTable (Map.fromList (map (first (dropExtensions . blobPath)) pairs))
-- | An analysis evaluating @term@s to @value@s with a list of @effects@ using 'Evaluatable', and producing incremental results of type @a@.
newtype Evaluating term value effects a = Evaluating { runEvaluating :: Eff effects a }
newtype Evaluating term value effects a = Evaluating { runEvaluating :: Eff (EvaluatingEffects term value effects) a }
deriving (Applicative, Functor, Effectful, Monad)
deriving instance Member Fail effects => MonadFail (Evaluating term value effects)
deriving instance Member Fresh effects => MonadFresh (Evaluating term value effects)
deriving instance Member NonDetEff effects => Alternative (Evaluating term value effects)
deriving instance Member NonDetEff effects => MonadNonDet (Evaluating term value effects)
deriving instance Member Fail (EvaluatingEffects term value effects) => MonadFail (Evaluating term value effects)
deriving instance Member Fresh (EvaluatingEffects term value effects) => MonadFresh (Evaluating term value effects)
deriving instance Member NonDetEff (EvaluatingEffects term value effects) => Alternative (Evaluating term value effects)
deriving instance Member NonDetEff (EvaluatingEffects term value effects) => MonadNonDet (Evaluating term value effects)
type EvaluatingEffects term value effects
= Fail -- Failure with an error message
@ -65,7 +65,7 @@ type EvaluatingEffects term value effects
': State (ModuleTable value) -- Cache of evaluated modules
': effects
instance Members (EvaluatingEffects term value '[]) effects => MonadEvaluator (Evaluating term value effects) where
instance MonadEvaluator (Evaluating term value effects) where
type TermFor (Evaluating term value effects) = term
type ValueFor (Evaluating term value effects) = value
@ -86,11 +86,9 @@ instance Members (EvaluatingEffects term value '[]) effects => MonadEvaluator (E
instance ( Evaluatable (Base term)
, FreeVariables term
, Members (EvaluatingEffects term value '[]) effects
, MonadAddressable (LocationFor value) (Evaluating term value effects)
, MonadValue value (Evaluating term value effects)
, Recursive term
)
=> MonadAnalysis (Evaluating term value effects) where
type EffectsRequiredFor (Evaluating term value effects) = EvaluatingEffects term value '[]
analyzeTerm = eval

View File

@ -30,7 +30,6 @@ instance ( Corecursive (TermFor m)
, Reducer (ConfigurationFor (TermFor m) (ValueFor m)) (TraceFor trace m)
)
=> MonadAnalysis (TracingAnalysis trace m) where
type EffectsRequiredFor (TracingAnalysis trace m) = TracerFor trace m ': EffectsRequiredFor m
analyzeTerm term = do
config <- getConfiguration (embedSubterm term)
trace (Reducer.unit config)

View File

@ -1,4 +1,4 @@
{-# LANGUAGE DataKinds, KindSignatures, TypeFamilies #-}
{-# LANGUAGE TypeFamilies #-}
module Control.Abstract.Analysis
( MonadAnalysis(..)
, evaluateTerm
@ -21,8 +21,6 @@ import Prologue
--
-- This typeclass is left intentionally unconstrained to avoid circular dependencies between it and other typeclasses.
class (MonadEvaluator m, Recursive (TermFor m)) => MonadAnalysis m where
type EffectsRequiredFor m :: [* -> *]
-- | Analyze a term using the semantics of the current analysis. This should generally only be called by definitions of 'evaluateTerm' and 'analyzeTerm' in this or other instances.
analyzeTerm :: SubtermAlgebra (Base (TermFor m)) (TermFor m) (m (ValueFor m))

View File

@ -45,13 +45,11 @@ evaluateRubyFiles paths = do
-- Python
-- TODO: Can we phrase this type as something like (CachingAnalysis Evaluating Python.Term Type '[]) ?
typecheckPythonFile :: FilePath
-> IO (Final (EffectsRequiredFor (CachingAnalysis (Evaluating Python.Term Type (CachingEffects Python.Term Type '[])))) Type)
typecheckPythonFile path = run @(CachingAnalysis (Evaluating Python.Term Type (CachingEffects Python.Term Type (EvaluatingEffects Python.Term Type '[])))) . evaluateModule . snd <$> parseFile pythonParser path
typecheckPythonFile path = run @(CachingAnalysis (Evaluating Python.Term Type (CachingEffects Python.Term Type '[]))) . evaluateModule . snd <$> parseFile pythonParser path
tracePythonFile path = run @(TracingAnalysis [] (Evaluating Python.Term PythonValue (Tracer [] Python.Term PythonValue ': (EvaluatingEffects Python.Term PythonValue '[])))) . evaluateModule . snd <$> parseFile pythonParser path
tracePythonFile path = run @(TracingAnalysis [] (Evaluating Python.Term PythonValue '[Tracer [] Python.Term PythonValue])) . evaluateModule . snd <$> parseFile pythonParser path
type PythonTracer = TracingAnalysis [] (Evaluating Python.Term PythonValue (DeadCode Python.Term ': Tracer [] Python.Term PythonValue ': (EvaluatingEffects Python.Term PythonValue '[])))
type PythonTracer = TracingAnalysis [] (Evaluating Python.Term PythonValue '[DeadCode Python.Term, Tracer [] Python.Term PythonValue])
evaluateDeadTracePythonFile path = run @(DeadCodeAnalysis PythonTracer) . evaluateModule . snd <$> parseFile pythonParser path