Skip to content

Commit

Permalink
Even more selective inlining to cut down on code size for user modules
Browse files Browse the repository at this point in the history
  • Loading branch information
KingoftheHomeless committed Aug 16, 2023
1 parent c09decd commit 3661edc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/Polysemy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,17 @@ subsume = subsume_
--
-- @since 1.3.0.0
subsumeUsing :: e r a. ElemOf e r -> Sem (e ': r) a -> Sem r a
subsumeUsing pr = transformSem' \hs ->
subsumeUsing pr = transformSem' (subsumeUsing' pr)
{-# INLINE subsumeUsing #-}

subsumeUsing' :: ElemOf e r
-> HandlerVector r rSem res -> HandlerVector (e ': r) rSem res
subsumeUsing' pr = \hs ->
let
AHandler !h = AHandler $ getHandler' hs pr
in
h `consHandler'` hs
{-# INLINE subsumeUsing #-}
{-# NOINLINE subsumeUsing' #-}

------------------------------------------------------------------------------
-- | Moves all uses of an effect @e@ within the argument computation
Expand Down Expand Up @@ -369,12 +374,18 @@ insertAt = transformSem $
--
-- @since 2.0.0.0
exposeUsing :: forall e r a. ElemOf e r -> Sem r a -> Sem (e ': r) a
exposeUsing pr = transformSem' \hs ->
exposeUsing pr = transformSem' (exposeUsing' pr)
{-# INLINE exposeUsing #-}

exposeUsing' :: ElemOf e r
-> HandlerVector (e ': r) rSem res -> HandlerVector r rSem res
exposeUsing' pr = \hs ->
let
AHandler !h = AHandler $ getHandler' hs Here
in
interceptHandler' pr h (dropHandlerVector (singList @'[_]) hs)
{-# INLINE exposeUsing #-}
{-# NOINLINE exposeUsing' #-}


------------------------------------------------------------------------------
-- | Variant of 'InterpreterFor' that takes a list of effects.
Expand Down
12 changes: 10 additions & 2 deletions src/Polysemy/Internal/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,18 @@ transformUsing
-> (forall r0 x. e1 (Sem r0) x -> e2 (Sem r0) x)
-> Sem (e1 ': r) a
-> Sem r a
transformUsing pr f = transformSem' \handlers ->
transformUsing pr f = transformSem' (transformUsing' pr f)
{-# INLINE transformUsing #-}

transformUsing'
:: forall e2 e1 r rSem res
. ElemOf e2 r
-> (forall r0 x. e1 (Sem r0) x -> e2 (Sem r0) x)
-> HandlerVector r rSem res -> HandlerVector (e1 ': r) rSem res
transformUsing' pr f = \handlers ->
let
AHandler !h = AHandler $ getHandler' handlers pr
AHandler h' = AHandler (h . rewriteWeaving f)
in
consHandler' h' handlers
{-# INLINEABLE transformUsing #-}
{-# INLINEABLE transformUsing' #-}

0 comments on commit 3661edc

Please sign in to comment.