-
Notifications
You must be signed in to change notification settings - Fork 164
Add BitPack instance for Index 0
#2784
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
Conversation
martijnbastiaan
left a comment
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.
Review together with @DigitalBrains1
Nice, this would get rid of a lot of unwanted 1 <= n constraints.
Add this fact to the typelits plugins.
I doubt reasoning about type families is in-scope for the plugins, but you might want to take that up with the maintainers :-).
I think we should change the cover letter's motivation to be something along the lines of "this aligns clash-the-compiler's thoughts on Index 0 with BitPack (Index 0)".
A changelog is needed, but that's also in the TODOs.
Other than that LGTUs.
|
It seems to still need something more though: Full messageExperienced with GHC 9.6.6. [edit] |
|
It's because of the new |
8510fbd to
2714056
Compare
|
I understand the desire to get rid of that But lets say someone is (accidentally) calling |
I don't think that this is the right way to look at it. Consider the following example: topEntity ::
HiddenClockResetEnable System =>
Signal System (Index 0)
topEntity = pure $ unpack @(Index 0) $ resize (0 :: BitVector 1)If that description is turned into Verilog with I agree that the user might end up with a run time error in simulation, if trying to inspect what comes out of applying Note that the type system never was intended to prevent us from this, in the same way as it cannot prevent us from ever having a look at the contents of |
2714056 to
0103c88
Compare
0103c88 to
8f922b8
Compare
DigitalBrains1
left a comment
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.
This isn't a full review yet; I'll wait until you have it working.
But browsing a bit I did notice you expanded the scope of the PR a lot. You've removed a lot of Index n, 1 <= n constraints even if they don't involve BitPack. If you want to address different cases of Index bounds as well, I think it's better treated in a new PR because it'll require some good thought.
For instance, you're removing the 1 <= n from the resetGlitchFilter functions, but now it is just completely broken:
>>> printX $ sampleN 10 $ unsafeFromReset $ resetGlitchFilter d2 systemClockGen resetGen
[True,True,True,True,True,False,False,False,False,False]
>>> printX $ sampleN 10 $ unsafeFromReset $ resetGlitchFilter d0 systemClockGen resetGen
[True,True,True,True,undefined,undefined,undefined,undefined,undefined,undefined]
Thanks for the quick feedback. I primarily was interested in observing which code may change and just wanted to get some feedback from CI. Unfortunately, there won't be any reasonable feedback without also hiding the warnings currently blocking #3061. I'll definitely have a closer look on all the introduced changes again. |
8f922b8 to
44ee96e
Compare
ccce472 to
90080f1
Compare
|
I have some comments but have not yet finished the review, please bear with me. |
DigitalBrains1
left a comment
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.
Thanks for all the work needed to get rid of these pesky constraints!
I have a few comments where I think the difference between Index 1 and Index 0 needs to be considered.
Also, in the first reply in this PR, Martijn wrote:
I think we should change the cover letter's motivation to be something along the lines of "this aligns clash-the-compiler's thoughts on
Index 0withBitPack (Index 0)".
I think the PR cover letter would be improved with that consideration included.
clash-lib/prims/commonverilog/Clash_Sized_Internal_Index.primitives.yaml
Outdated
Show resolved
Hide resolved
clash-lib/prims/commonverilog/Clash_Sized_Internal_Index.primitives.yaml
Outdated
Show resolved
Hide resolved
clash-lib/prims/vhdl/Clash_Sized_Internal_Index.primitives.yaml
Outdated
Show resolved
Hide resolved
clash-lib/prims/vhdl/Clash_Sized_Internal_Index.primitives.yaml
Outdated
Show resolved
Hide resolved
clash-prelude/src/Clash/Class/NumConvert/Internal/MaybeNumConvert.hs
Outdated
Show resolved
Hide resolved
90080f1 to
3400303
Compare
3400303 to
aa93ae4
Compare
2176900 to
aa93ae4
Compare
|
Oops, I really did not expect my git to choose your branch to push to when I executed the command It probably had something to do with a gaffe in setting up that branch, sorry. Anyway, on peter/add-bitpack-for-index-zero I added a commit to have I added a [edit] |
martijnbastiaan
left a comment
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.
I think this is right, though I do feel nervous about making this change. It's right on that border where it's seemingly easy to make a change, but also easy to mess up.
.. so what are we waiting for! ✔️
8901161 to
76b3bf1
Compare
|
@DigitalBrains1 Are you also satisfied with the updates regarding your requested changes then? |
DigitalBrains1
left a comment
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.
Well, almost! I am satisfied with the changes. But I noticed a few last things. First of all, your rebase didn't completely work out: you forgot a 1 <= n! I'd also like to suggest some small changes to the changelog entries.
Note: that is you forgot a 1 <= n. It is not you forgot a 1 <= n!, which holds for all natural numbers 😉.
clash-prelude/src/Clash/Class/NumConvert/Internal/MaybeNumConvert.hs
Outdated
Show resolved
Hide resolved
|
I'm sorry to restart the discussion again, but I got on the wrong track in the
The logic being that accepting And it looks like we've found real issues for Am I misunderstanding this discussion so badly, or are we making a mistake here? Edit: Not saying that I'm against pragmatic choices, to be clear. But I can't shake the feeling that the same issues that showed there is a need for |
Nice catch. Thanks for the hint. I applied your suggestions.
I totally agree. Isn't this exactly what has been implemented by this PR? |
unpack 0 :: Index 0returns an Well, it doesn't actually return a value. It returns |
|
I thought I'd run it through On this branch: So on |
ce171b2 to
8d442b3
Compare
is an unfortunate coincidence, because Hence, yes, in the context of REPL simulation you can create a bogous value of I consider it the same as topEntity :: Int -> ()
topEntity = undefinedcreating an error in simulation, while still describing and being generated to be perfectly valid HDL. |
Could you please elaborate what you mean? Are you saying the Clash user shouldn't have done that? That would not really be a strong argument to allow it. We want to minimise user surprises, and if that means imposing a few unnecessary |
I say that it is impossible to create any wrong hardware this way, because the Clash model still protects you from breaking things after HDL generation. The only case, where you can observe a difference is in simulation, if returning an topEntity :: HiddenClockResetEnable System => Signal System Bool -> Signal System Bool
topEntity = mealy (\i b -> (if b then i + 1 else i, b)) (undefined :: Index 0)In other words, we only give the user a foot gun for the specific case, where he wants to read some The current situation however, instead imposing that |
|
Being forced to write bogus shouldInit :: Index n -> Bool
shouldInit 0 = True
shouldInit _ = False(The idea is you iterate over all elements of something and you need something to fire whenever you restarted the iteration).
That doesn't sound correct. For one, my function above returns a |
|
Are we going to merge this now or not? My patience already reached its limits, noting that this PR already is open for more than 1.5 years now. If you still wanna discuss your concerns, then please do so in week one or two after opening the PR and not 1.5 years later. |
|
The delay is absolutely not due to the reviewers, which you seem to imply. I'm sorry you're fed up with it, but I'm also sorry you seem to lay blame for that on people who were not the cause. What has changed is that the review pointed out several issues with just removing It definitely would be an enormous shame and enormous waste of work if this were not merged, I will grant you that. It'd suck big time. But if the PR is not an improvement for our users when all things are considered, that could still be the best outcome. |
|
We have introduced XExceptions in the past #2563 in order to get rid of |
|
That PR seems to use Should we perhaps make |
|
The PR still introduced a run-time exception by dropping a |
What we do in this PR creates the opportunity for users to write code that causes Because the way I see it, the other PR only either
(Of course it's not fully irrelevant, because you might want to use the functions merely in simulation, outside your design itself. But it's a completely different story than this. I'm not saying we're wrong to merge this PR, I just think the other PR is no argument either in favour of or against this PR, it's just a different situation that has no bearing on this PR.) [edit] |
There never was any intention that would imply such allegation. I am just tiered of running into similar appearing discussions over and over again with individual opinions about the "dos and don'ts" swapping back and forth all the time. My question simply was about "What do you like to see as the outcome?", because if we don't even agree on the outcome, then it doesn't make any sense to further put effort into changing the code. I opened this PR, because multiple users at QBayLogic reported to be restricted by the I first want confirmation now, whether maintainers agree with this update or not, where agreement also means for me to not raise any further arguments against the update, which is merely counter-productive. Before agreeing on the outcome, I don't see why I should put any more effort into further touching this PR. |
|
I agree @kleinreact i will merge this PR |
This PR gets rid of the additional
1 <= nconstraint for theBitPackinstance ofIndex n, which aligns clash-the-compiler's thoughts onIndex 0withBitPack (Index 0).Background:
Index 0andVoidare empty types → isomorphic to the empty setIndex 1and()are singleton types → isomorphic to a singleton setHence, we only need to question ourselves: how many bits do you need to distinguish between different elements of these types / sets? In both cases the answer clearly is: 0. Thus,
BitSize (Index 0) = 0.From another perspective: Clash generates valid HDL for
Index 0and the number of bits required by the generated HDL is zero as well. Hence, there is no reason to hide this fact in the type system for this particular case.Requires:
Still TODO: