Skip to content

Commit

Permalink
Actually fixed simplifier ticks exhausted by avoding redundancy
Browse files Browse the repository at this point in the history
At ZuriHac ben explained me how this could have been caused by the case analysis. Turns out the we three redundant recursion steps (3 different case branches to `fill`). By removing the redundant code and reducing this to only one branch, the case analysis will not hit the limit anymore.

The INLINEABLE fix previously likely just stopped GHC from inlining it altogether.
  • Loading branch information
mpscholten committed Jun 8, 2024
1 parent 25207e0 commit 9dc3b9f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions IHP/Controller/Param.hs
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,16 @@ instance (FillParams rest record
, HasField "meta" record ModelSupport.MetaBag
, SetField "meta" record ModelSupport.MetaBag
) => FillParams (fieldName:rest) record where
fill !record = do
let name :: ByteString = cs $! (symbolVal (Proxy @fieldName))
case paramOrError name of
Right !(value :: fieldType) -> fill @rest (setField @fieldName value record)
Left ParamCouldNotBeParsedException { parserError } -> fill @rest (attachFailure (Proxy @fieldName) (cs parserError) record)
Left ParamNotFoundException {} -> fill @rest record
{-# INLINABLE fill #-}
fill !record =
let
name :: ByteString = cs $! (symbolVal (Proxy @fieldName))
record' = case paramOrError name of
Right !(value :: fieldType) -> setField @fieldName value record
Left ParamCouldNotBeParsedException { parserError } -> attachFailure (Proxy @fieldName) (cs parserError) record
Left ParamNotFoundException {} -> record
in
fill @rest record'
{-# INLINE fill #-}

ifValid :: (HasField "meta" model ModelSupport.MetaBag) => (Either model model -> IO r) -> model -> IO r
ifValid branch model = branch $! if ModelSupport.isValid model
Expand Down

0 comments on commit 9dc3b9f

Please sign in to comment.