Skip to content

Commit 0864b75

Browse files
committed
Pass the current module name into handleContextReduction for better error message
1 parent bbcfc56 commit 0864b75

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/comp/ContextErrors.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import TCMisc
2121
import Unify
2222

2323
import FStringCompat (FString, mkFString, getFString)
24-
import Id(mkId)
24+
import Id(Id, mkId)
2525
import PreIds
2626
import CSyntax
2727
import Util(separate, concatMapM, quote, headOrErr, toMaybe, boolCompress)
@@ -39,8 +39,8 @@ import CType(typeclassId, isTNum, getTNum)
3939
-- a list of the contexts which failed to reduce, this function
4040
-- returns the list of error messages which should be reported
4141
--
42-
handleContextReduction :: Position -> [VPred] -> TI a
43-
handleContextReduction pos vps =
42+
handleContextReduction :: Maybe Id -> Position -> [VPred] -> TI a
43+
handleContextReduction mid pos vps =
4444
do
4545
-- We used to remove duplicates:
4646
-- let vps' = nubVPred vps
@@ -80,15 +80,15 @@ handleContextReduction pos vps =
8080
then vps_reduced_nicenames
8181
else is_mod_arrow_vps
8282

83-
emsgs <- mapM (handleContextReduction' pos) err_vps
83+
emsgs <- mapM (handleContextReduction' mid pos) err_vps
8484

8585
errs "handleContextReduction" emsgs
8686

8787
-- --------------------
8888

8989
-- This helper function takes one predicate at a time
90-
handleContextReduction' :: Position -> (VPred, [VPred]) -> TI EMsg
91-
handleContextReduction' pos
90+
handleContextReduction' :: Maybe Id -> Position -> (VPred, [VPred]) -> TI EMsg
91+
handleContextReduction' mid pos
9292
p@((VPred vpi (PredWithPositions (IsIn c@(Class { name=(CTypeclass cid) }) ts) _)), _)
9393
| cid == idBitwise =
9494
case ts of
@@ -167,15 +167,15 @@ handleContextReduction' pos
167167
"SizedLiteral instance contains wrong number of types")
168168
| cid == idWrapField =
169169
case ts of
170-
[TCon (TyStr name _), t, _] -> return $ handleCtxRedWrapField pos p name t
170+
[TCon (TyStr name _), t, _] -> return $ handleCtxRedWrapField mid pos p name t
171171
_ -> internalError("handleContextReduction': " ++
172172
"WrapField instance contains wrong number of types")
173173

174174
-- | cid == idLiteral =
175175
-- | cid == idRealLiteral =
176176
-- | cid == idStringLiteral =
177177

178-
handleContextReduction' pos p =
178+
handleContextReduction' mid pos p =
179179
return (defaultContextReductionErr pos p)
180180

181181
-- --------------------
@@ -461,9 +461,9 @@ handleCtxRedPrimPort pos (vp, reduced_ps) userty =
461461

462462
-- --------------------
463463

464-
handleCtxRedWrapField:: Position -> (VPred, [VPred]) -> FString -> Type -> EMsg
465-
handleCtxRedWrapField pos (vp, reduced_ps) name userty =
466-
(pos, EBadIfcType Nothing $
464+
handleCtxRedWrapField:: Maybe Id -> Position -> (VPred, [VPred]) -> FString -> Type -> EMsg
465+
handleCtxRedWrapField mid pos (vp, reduced_ps) name userty =
466+
(pos, EBadIfcType (fmap pfpString mid) $
467467
"The interface method `" ++ getFString name ++
468468
"' uses type(s) that are not in the Bits or SplitPorts typeclasses: " ++
469469
intercalate ", " (concatMap bitsPredType reduced_ps)
@@ -1036,7 +1036,7 @@ earlyContextReduction pos ps =
10361036
rs <- mapM try_pred ps
10371037
let err_preds = map fst (filter (not . snd) rs)
10381038
when (not (null err_preds)) $
1039-
handleContextReduction pos err_preds
1039+
handleContextReduction Nothing pos err_preds
10401040

10411041
-- ========================================================================
10421042

src/comp/TCheck.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,7 @@ tiExpl''' as0 i sc alts me (oqt@(oqs :=> ot), vts) = do
26392639
-- Were any contexts without variables left unsatisfied?
26402640
if not (null uds) then
26412641
-- Report reduction errors
2642-
handleContextReduction (getPosition i) uds
2642+
handleContextReduction (Just i) (getPosition i) uds
26432643
else
26442644
-- No ambiguous variables, so...
26452645
-- Produce the return values (deferred preds, CDefl)

src/comp/TypeCheck.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ tiOneDef :: CDefn -> TI CDefn
7272
tiOneDef d@(CValueSign (CDef i t s)) = do
7373
--trace ("TC " ++ ppReadable i) $ return ()
7474
(rs, ~(CLValueSign d' _)) <- tiExpl nullAssump (i, t, s, [])
75-
checkTopPreds d rs
75+
checkTopPreds (Just i) d rs
7676
s <- getSubst'
7777
clearSubst
7878
return (CValueSign (apSub s d'))
@@ -91,7 +91,7 @@ tiOneDef d@(Cclass incoh cps ik is fd fs) = do
9191
fqt' = CQType fps' fty
9292
(rs, ~(CLValueSign (CDefT _ _ _ fcs') _))
9393
<- tiExpl nullAssump (fid, fqt', fcs, [])
94-
checkTopPreds fid rs
94+
checkTopPreds (Just fid) fid rs
9595
clearSubst
9696
return (f { cf_default = fcs' })
9797
fs' <- mapM tiF fs
@@ -113,17 +113,17 @@ getSubst' = do
113113
if s == s then return s else internalError "TypeCheck.getSubst': s /= s (WTF!?)"
114114

115115
-- Any predicates at the top level should be reported as an error
116-
checkTopPreds :: (HasPosition a, PPrint a) => a -> [VPred] -> TI ()
117-
checkTopPreds _ [] = return ()
118-
checkTopPreds a ps = do
116+
checkTopPreds :: (HasPosition a, PPrint a) => Maybe Id -> a -> [VPred] -> TI ()
117+
checkTopPreds _ _ [] = return ()
118+
checkTopPreds mid a ps = do
119119
-- reduce the predicates as much as possible
120120
(ps', ls) <- satisfy [] ps
121121
if null ps' then
122122
-- they shouldn't reduce away completely
123123
internalError ("checkTopPreds " ++ ppReadable (a, ps))
124124
else do
125125
addExplPreds [] -- add en empty context
126-
handleContextReduction (getPosition a) ps'
126+
handleContextReduction mid (getPosition a) ps'
127127

128128
-- typecheck an expression as a top-level object
129129
-- returning any unsatisfied preds

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +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 this module or function: The interface method
10+
Cannot synthesize `module_fnNoInline_ArgNotInBits­': The interface method
1111
`fnNoInline_ArgNotInBits' uses type(s) that are not in the Bits or
1212
SplitPorts typeclasses: NoInline_ArgNotInBits::L

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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 this module or function: The interface method
10+
Cannot synthesize `module_fnNoInline_ResNotInBits­': The interface method
1111
`fnNoInline_ResNotInBits' uses type(s) that are not in the Bits or
1212
SplitPorts typeclasses: NoInline_ResNotInBits::L
1313
Error: "NoInline_ResNotInBits.bsv", line 4, column 12: (T0029)

0 commit comments

Comments
 (0)