mirror of
https://github.com/github/semantic.git
synced 2024-12-30 02:14:20 +03:00
Rephrase BadVariables as a resumingBadVariables handler.
This commit is contained in:
parent
b5c2cd6282
commit
8a8bfc05a3
@ -1,39 +1,21 @@
|
||||
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, TypeFamilies, TypeOperators, UndecidableInstances #-}
|
||||
{-# OPTIONS_GHC -Wno-redundant-constraints #-} -- For the Interpreter instance’s Evaluator constraint
|
||||
{-# LANGUAGE GADTs, TypeOperators #-}
|
||||
module Analysis.Abstract.BadVariables
|
||||
( BadVariables
|
||||
( resumingBadVariables
|
||||
) where
|
||||
|
||||
import Control.Abstract.Analysis
|
||||
import Control.Abstract.Evaluator
|
||||
import Data.Abstract.Evaluatable
|
||||
import Prologue
|
||||
|
||||
-- An analysis that resumes from evaluation errors and records the list of unresolved free variables.
|
||||
newtype BadVariables m (effects :: [* -> *]) a = BadVariables { runBadVariables :: m effects a }
|
||||
deriving (Alternative, Applicative, Functor, Effectful, Monad)
|
||||
|
||||
deriving instance Evaluator location term value m => Evaluator location term value (BadVariables m)
|
||||
deriving instance AnalyzeModule location term value inner outer m => AnalyzeModule location term value inner outer (BadVariables m)
|
||||
deriving instance AnalyzeTerm location term value inner outer m => AnalyzeTerm location term value inner outer (BadVariables m)
|
||||
|
||||
instance ( AbstractHole value
|
||||
, Evaluator location term value m
|
||||
, Interpreter m effects
|
||||
, Show value
|
||||
)
|
||||
=> Interpreter (BadVariables m) (Resumable (EvalError value) ': State [Name] ': effects) where
|
||||
type Result (BadVariables m) (Resumable (EvalError value) ': State [Name] ': effects) result = Result m effects (result, [Name])
|
||||
interpret
|
||||
= interpret
|
||||
. runBadVariables
|
||||
. raiseHandler
|
||||
( flip runState []
|
||||
. relay pure (\ (Resumable err) yield -> traceM ("EvalError" <> show err) *> case err of
|
||||
EnvironmentLookupError{} -> yield hole
|
||||
DefaultExportError{} -> yield ()
|
||||
ExportError{} -> yield ()
|
||||
IntegerFormatError{} -> yield 0
|
||||
FloatFormatError{} -> yield 0
|
||||
RationalFormatError{} -> yield 0
|
||||
FreeVariableError name -> modify' (name :) *> yield hole
|
||||
FreeVariablesError names -> modify' (names <>) *> yield (fromMaybeLast "unknown" names)))
|
||||
resumingBadVariables :: (AbstractHole value, Effectful m, Show value) => m (Resumable (EvalError value) ': State [Name] ': effects) a -> m effects (a, [Name])
|
||||
resumingBadVariables
|
||||
= handleState []
|
||||
. raiseHandler (relay pure (\ (Resumable err) yield -> traceM ("EvalError" <> show err) *> case err of
|
||||
EnvironmentLookupError{} -> yield hole
|
||||
DefaultExportError{} -> yield ()
|
||||
ExportError{} -> yield ()
|
||||
IntegerFormatError{} -> yield 0
|
||||
FloatFormatError{} -> yield 0
|
||||
RationalFormatError{} -> yield 0
|
||||
FreeVariableError name -> modify' (name :) *> yield hole
|
||||
FreeVariablesError names -> modify' (names <>) *> yield (fromMaybeLast "unknown" names)))
|
||||
|
Loading…
Reference in New Issue
Block a user