1
1
mirror of https://github.com/github/semantic.git synced 2025-01-02 12:23:08 +03:00

Use upstream Resource effect.

This commit is contained in:
Patrick Thomson 2018-10-16 20:10:34 -04:00
parent ebda4bfaa1
commit d56badfb29
6 changed files with 4 additions and 41 deletions

View File

@ -189,7 +189,6 @@ library
, Semantic.Parse
, Semantic.REPL
, Semantic.Resolution
, Semantic.Resource
, Semantic.Task
, Semantic.Telemetry
, Semantic.Telemetry.AsyncQueue

View File

@ -9,6 +9,7 @@ import Prologue hiding (bracket)
import Control.Concurrent.Async
import qualified Control.Exception as Exc (bracket)
import Control.Monad.Effect
import Control.Monad.Effect.Resource
import Control.Monad.Effect.Trace
import Control.Monad.IO.Class
import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
@ -23,7 +24,6 @@ import Data.Location
import Data.Source
import Data.Span
import Data.Term
import Semantic.Resource
import Semantic.Timeout
import qualified TreeSitter.Language as TS

View File

@ -5,6 +5,7 @@ module Semantic.REPL
) where
import Control.Abstract hiding (Continue, List, string)
import Control.Monad.Effect.Resource
import Control.Monad.IO.Class
import Data.Abstract.Address.Precise as Precise
import Data.Abstract.Environment as Env
@ -31,7 +32,6 @@ import Semantic.Distribute
import Semantic.Graph
import Semantic.IO as IO
import Semantic.Resolution
import Semantic.Resource
import Semantic.Task hiding (Error)
import Semantic.Telemetry
import Semantic.Timeout

View File

@ -1,36 +0,0 @@
{-# LANGUAGE GADTs, TypeOperators, RankNTypes #-}
module Semantic.Resource
( Resource (..)
, bracket
, runResource
) where
import Control.Monad.Effect
import Control.Monad.IO.Class
import qualified Control.Exception as Exc
data Resource m output where
Resource :: m res -> (res -> m any) -> (res -> m output) -> Resource m output
instance PureEffect Resource
instance Effect Resource where
handleState c dist (Request (Resource fore aft go) k)
= Request (Resource (dist (fore <$ c)) (dist . fmap aft) (dist . fmap go)) (dist . fmap k)
bracket :: (Member Resource effs, Effectful m)
=> m effs res
-> (res -> m effs any)
-> (res -> m effs b)
-> m effs b
bracket fore aft go = send (Resource (lowerEff fore) (lowerEff . aft) (lowerEff . go))
runResource :: (Member (Lift IO) effects, PureEffects effects)
=> (forall x . Eff effects x -> IO x)
-> Eff (Resource ': effects) a
-> Eff effects a
runResource handler = interpret (\(Resource fore aft go)
-> liftIO (Exc.bracket
(handler (runResource handler fore))
(handler . runResource handler . aft)
(handler . runResource handler . go)))

View File

@ -61,6 +61,7 @@ import Control.Monad
import Control.Monad.Effect
import Control.Monad.Effect.Exception
import Control.Monad.Effect.Reader
import Control.Monad.Effect.Resource
import Control.Monad.Effect.Trace
import Data.Blob
import Data.Bool
@ -85,7 +86,6 @@ import Semantic.Distribute
import Semantic.Timeout
import qualified Semantic.IO as IO
import Semantic.Resolution
import Semantic.Resource
import Semantic.Telemetry
import Serializing.Format hiding (Options)
import System.Exit (die)

2
vendor/effects vendored

@ -1 +1 @@
Subproject commit 8ded4a64133ce77ddd2fc734f455753e62af0ad3
Subproject commit e7858dacce6fbb43e76a49e4dbeff1f1815aa290