Skip to content

Commit

Permalink
DEC: don't generate single-branch case-expressions
Browse files Browse the repository at this point in the history
Fixes #90
  • Loading branch information
christiaanb committed Oct 23, 2015
1 parent 3ba31de commit 9db4e8f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clash-lib/src/CLaSH/Normalize/DEC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Set.Lens as Lens

import Unbound.Generics.LocallyNameless (Bind, bind, embed, unbind,
import Unbound.Generics.LocallyNameless (Bind, bind, embed, fv, unbind,
unembed, unrec)
import qualified Unbound.Generics.LocallyNameless as Unbound

Expand Down Expand Up @@ -354,6 +354,13 @@ genCase ty dcM argTys = go
go (LB lb ct) =
Letrec (bind (Unbound.rec lb) (go ct))

go (Branch scrut [(p,ct)]) =
let ct' = go ct
alt = bind p ct'
in case Lens.setOf termFreeIds ct' == Lens.setOf fv alt of
True -> ct'
_ -> Case scrut ty [alt]

go (Branch scrut pats) =
Case scrut ty (map (\(p,ct) -> bind p (go ct)) pats)

Expand Down

0 comments on commit 9db4e8f

Please sign in to comment.