Skip to content

Commit ca5c308

Browse files
committed
Improve error message when a synthesized method or noinline function uses a type lacking a Bit or SplitPorts instance
1 parent 0dbb7fa commit ca5c308

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

src/comp/ContextErrors.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,17 @@ handleCtxRedPrimPort pos (vp, reduced_ps) userty =
462462
-- --------------------
463463

464464
handleCtxRedWrapField:: Position -> (VPred, [VPred]) -> FString -> Type -> EMsg
465-
handleCtxRedWrapField pos (vp, reduced_ps) name userty =
466-
(pos, EBadIfcType (getFString name)
467-
"This method uses types that are not in the Bits or SplitPorts typeclasses.")
465+
handleCtxRedWrapField pos (vp, reduced_ps) name userty =
466+
(pos, EBadIfcType Nothing $
467+
"The interface method `" ++ getFString name ++
468+
"' uses type(s) that are not in the Bits or SplitPorts typeclasses: " ++
469+
intercalate ", " (concatMap bitsPredType reduced_ps)
470+
)
471+
where
472+
bitsPredType :: VPred -> [String]
473+
bitsPredType (VPred _ (PredWithPositions (IsIn (Class { name=(CTypeclass cid) }) [t, _]) _))
474+
| cid == idBits = [pfpString t]
475+
bitsPredType _ = []
468476

469477

470478
-- ========================================================================

src/comp/Error.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ data ErrMsg =
805805
| EPolyField
806806
| ENotKNum String
807807
| EBadGenArg String
808-
| EBadIfcType String String
808+
| EBadIfcType (Maybe String) String
809809
| EBadForeignIfcType String
810810
| ENoTypeSign String
811811
| EStmtContext String
@@ -2120,9 +2120,12 @@ getErrorText (ENotKNum t) =
21202120
(Type 41, empty, s2par ("Only size polymorphism allowed in code generation: " ++ t))
21212121
getErrorText (EBadGenArg i) =
21222122
(Type 42, empty, s2par ("Bad argument in code generation: " ++ ishow i))
2123-
getErrorText (EBadIfcType mod msg) =
2123+
getErrorText (EBadIfcType (Just mod) msg) =
21242124
(Type 43, empty,
21252125
s2par ("Cannot synthesize " ++ quote mod ++ ": " ++ msg))
2126+
getErrorText (EBadIfcType Nothing msg) =
2127+
(Type 43, empty,
2128+
s2par ("Cannot synthesize this module or function: " ++ msg))
21262129
getErrorText (ENoTypeSign e) =
21272130
(Type 44, empty, s2par ("Missing or bad type signature for a module: " ++ e))
21282131
getErrorText (EStmtContext c) =

src/comp/GenWrap.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ chkType def ty =
430430
Right ((_:_) :=> _) ->
431431
let ctx = if isClassic() then "context" else "proviso"
432432
msg = "It has a " ++ ctx ++ "."
433-
in bad (getPosition def, EBadIfcType (pfpString defId) msg)
433+
in bad (getPosition def, EBadIfcType (Just $ pfpString defId) msg)
434434
Right ([] :=> t) ->
435435
do
436436
if not (null (tv t))
437437
then let msg = "Its interface is polymorphic."
438-
in bad (getPosition def, EBadIfcType (pfpString defId) msg)
438+
in bad (getPosition def, EBadIfcType (Just $ pfpString defId) msg)
439439
else
440440
do
441441
--traceM ("chkType: " ++ pfpReadable (t, getArrows t))
@@ -447,7 +447,7 @@ chkType def ty =
447447
(f:_) -> let msg = "Its interface has a polymorphic field " ++
448448
quote (pfpString f) ++ "."
449449
in bad (getPosition def,
450-
EBadIfcType (pfpString defId) msg)
450+
EBadIfcType (Just $ pfpString defId) msg)
451451
[] ->
452452
do
453453
----traceM ("chkType 2: " ++ pfpReadable (chkInterface tr))
@@ -461,10 +461,10 @@ chkType def ty =
461461
quote (pfpString t) ++
462462
" is not an interface."
463463
in bad (getPosition def,
464-
EBadIfcType (pfpString defId) msg)
464+
EBadIfcType (Just $ pfpString defId) msg)
465465
_ -> let msg = "It is not a module."
466466
in bad (getPosition def,
467-
EBadIfcType (pfpString defId) msg)
467+
EBadIfcType (Just $ pfpString defId) msg)
468468

469469
-- Return a list of names of any fields which are polymorphic,
470470
-- if the given type is an interface; otherwise return an empty list.

src/comp/IExpand.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5227,7 +5227,7 @@ reportNonSynthTypeInMethod modId methId methExpr =
52275227
let str = "The interface method " ++ quote (pfpString methId) ++
52285228
" uses type " ++ quote (pfpString v) ++
52295229
" which is not in the Bits class."
5230-
in (modPos, EBadIfcType modName str)
5230+
in (modPos, EBadIfcType (Just modName) str)
52315231
in case (getNonSynthTypes methExpr) of
52325232
[] -> -- this shouldn't happen
52335233
(modPos, EPolyField)
@@ -5247,7 +5247,7 @@ reportNonSynthTypeInModuleArg modId modExpr =
52475247
let str = "A parameter of the module uses the type " ++
52485248
quote (pfpString v) ++
52495249
" which is not in the Bits class."
5250-
in (modPos, EBadIfcType modName str)
5250+
in (modPos, EBadIfcType (Just modName) str)
52515251
in case (getNonSynthTypes modExpr) of
52525252
[] -> internalError
52535253
("IExpand: unexplained module with type parameter: " ++

testsuite/bsc.verilog/noinline/NoInline_ArgNotInBits.bsv.bsc-vcomp-out.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Error: Unknown position: (T0031)
77
The proviso was implied by expressions at the following positions:
88
"NoInline_ArgNotInBits.bsv", line 4, column 15
99
Error: "NoInline_ArgNotInBits.bsv", line 4, column 15: (T0043)
10-
Cannot synthesize `fnNoInline_ArgNotInBits': This method uses types that are
11-
not in the Bits or SplitPorts typeclasses.
10+
Cannot synthesize this module or function: The interface method
11+
`fnNoInline_ArgNotInBits' uses type(s) that are not in the Bits or
12+
SplitPorts typeclasses: NoInline_ArgNotInBits::L

testsuite/bsc.verilog/noinline/NoInline_ResNotInBits.bsv.bsc-vcomp-out.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Error: Unknown position: (T0031)
77
The proviso was implied by expressions at the following positions:
88
"NoInline_ResNotInBits.bsv", line 4, column 12
99
Error: "NoInline_ResNotInBits.bsv", line 4, column 12: (T0043)
10-
Cannot synthesize `fnNoInline_ResNotInBits': This method uses types that are
11-
not in the Bits or SplitPorts typeclasses.
10+
Cannot synthesize this module or function: The interface method
11+
`fnNoInline_ResNotInBits' uses type(s) that are not in the Bits or
12+
SplitPorts typeclasses: NoInline_ResNotInBits::L
1213
Error: "NoInline_ResNotInBits.bsv", line 4, column 12: (T0029)
1314
Signature mismatch (given too general):
1415
given:

0 commit comments

Comments
 (0)