-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix literal rendering of Index values #2816
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FIXED: Clash hanging when rendering `Index n` literals, for large values of `n` [#2813](https://github.com/clash-lang/clash-compiler/issues/2813) | ||
FIXED: Render overflowed Index literals as errors | ||
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||||||||||
{-| | ||||||||||||||
Copyright : (C) 2015-2016, University of Twente, | ||||||||||||||
2017-2018, Google Inc., | ||||||||||||||
2021-2023, QBayLogic B.V., | ||||||||||||||
2021-2024, QBayLogic B.V., | ||||||||||||||
2022 , Google Inc. | ||||||||||||||
License : BSD2 (see the file LICENSE) | ||||||||||||||
Maintainer : QBayLogic B.V. <[email protected]> | ||||||||||||||
|
@@ -65,7 +65,7 @@ import Clash.Netlist.Types hiding (intWidth, usages, | |||||||||||||
import Clash.Netlist.Util | ||||||||||||||
import Clash.Signal.Internal (ActiveEdge (..)) | ||||||||||||||
import Clash.Util | ||||||||||||||
(SrcSpan, noSrcSpan, curLoc, makeCached, indexNote) | ||||||||||||||
(SrcSpan, clogBase, noSrcSpan, curLoc, makeCached, indexNote) | ||||||||||||||
import Clash.Util.Graph (reverseTopSort) | ||||||||||||||
|
||||||||||||||
-- | State for the 'Clash.Backend.SystemVerilog.SystemVerilogM' monad: | ||||||||||||||
|
@@ -1228,7 +1228,9 @@ expr_ _ (BlackBoxE pNm _ _ _ _ bbCtx _) | |||||||||||||
expr_ _ (BlackBoxE pNm _ _ _ _ bbCtx _) | ||||||||||||||
| pNm == "Clash.Sized.Internal.Index.fromInteger#" | ||||||||||||||
, [Literal _ (NumLit n), Literal _ i] <- extractLiterals bbCtx | ||||||||||||||
= exprLitSV (Just (Index (fromInteger n),fromInteger n)) i | ||||||||||||||
, Just k <- clogBase 2 n | ||||||||||||||
, let k' = max 1 k | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When would I feel like that only happens for types like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was basically copying what the VHDL backend does: clash-compiler/clash-lib/src/Clash/Backend/VHDL.hs Lines 1767 to 1772 in 3b755b9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I think you're right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That code was added in version 0.6.15 6b365dc#diff-d636015ead3ec91b11144d7f18c90be9133810ab83457b3649a91e046cfae73fR647 Which might be from a time before we elided 0-bit values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah probably. I had seen that, at least in simple cases clash, removes You want me to take out the |
||||||||||||||
= exprLitSV (Just (Index (fromInteger n),k')) i | ||||||||||||||
|
||||||||||||||
expr_ b (BlackBoxE _ libs imps inc bs bbCtx b') = | ||||||||||||||
parenIf (b || b') (Ap (renderBlackBox libs imps inc bs bbCtx <*> pure 0)) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Maybe that's not good either, but I worry people might not understand what "render as an error" means. I'd also like to emphasise that we're talking about HDL here for clarity.