Skip to content

Commit ba12a37

Browse files
authored
Clash.Netlist: Clarify mkExpr error message (#2796)
This was previously rather misleading, suggesting that expressions were lambdas when they were not.
1 parent 15dc344 commit ba12a37

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

clash-lib/src/Clash/Netlist.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ mkExpr bbEasD declType bndr app =
830830
let hwTyA = case hwTys of
831831
hwTy:_ -> hwTy
832832
_ -> error ("internal error: unable to extract sufficient hwTys from: " <> show bndr)
833+
let invalid kind = throw (ClashException sp ($(curLoc) ++ "Not in normal form: " ++ kind ++ "\n\n" ++ showPpr app) Nothing)
833834
case appF of
834835
Data dc -> mkDcApplication declType hwTys bndr dc tmArgs
835836
Prim pInfo -> mkPrimitive False bbEasD declType bndr pInfo args tickDecls
@@ -839,9 +840,7 @@ mkExpr bbEasD declType bndr app =
839840
return (Noop, [])
840841
else do
841842
return (Identifier (Id.unsafeFromCoreId f) Nothing, [])
842-
| not (null tyArgs) ->
843-
throw (ClashException sp ($(curLoc) ++ "Not in normal form: "
844-
++ "Var-application with Type arguments:\n\n" ++ showPpr app) Nothing)
843+
| not (null tyArgs) -> invalid "Var-application with type arguments"
845844
| otherwise -> do
846845
argNm <- Id.suffix (netlistId1 id Id.unsafeFromCoreId bndr) "fun_arg"
847846
decls <- mkFunApp argNm f tmArgs tickDecls
@@ -862,12 +861,20 @@ mkExpr bbEasD declType bndr app =
862861
-- This net was already declared in the call to mkSelection
863862
return ( Identifier argNm Nothing
864863
, NetDecl' Nothing argNm hwTyA Nothing:decls)
864+
Case _ _ [] -> invalid "No case alternatives\n\n"
865865
Letrec binders body -> do
866866
netDecls <- concatMapM mkNetDecl binders
867867
decls <- concatMapM (uncurry (mkDeclarations' declType)) binders
868868
(bodyE,bodyDecls) <- mkExpr bbEasD declType bndr (mkApps (mkTicks body ticks) args)
869869
return (bodyE,netDecls ++ decls ++ bodyDecls)
870-
_ -> throw (ClashException sp ($(curLoc) ++ "Not in normal form: application of a Lambda-expression\n\n" ++ showPpr app) Nothing)
870+
Core.Literal _ -> invalid "application of literal"
871+
Let _ _ -> invalid "application of let"
872+
TyApp _ _ -> invalid "application of type application"
873+
Tick _ _ -> invalid "application of tick"
874+
Cast _ _ _ -> invalid "application of cast"
875+
Lam _ _ -> invalid "application of lambda"
876+
TyLam _ _ -> invalid "application of type lambda"
877+
App _ _ -> invalid "application of application"
871878

872879
-- | Generate an expression that projects a field out of a data-constructor.
873880
--

0 commit comments

Comments
 (0)