-
Notifications
You must be signed in to change notification settings - Fork 154
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
Clash error call: zipEqual: left list is longer
when using custom type proof
#2376
Comments
Looking at the log, the culprit is quite clearly the
which comes from: case oneLeCLog2n (Proxy @depth) of
Dict -> mealy go (T 0) i.e. the type of the case subject should be something of an equality constraint, but the unsafeCoerce gave us a |
To conclude this issue: this is really a PBKAC. The first type argument of oneLeCLog2n :: forall n . (2 <= n) => Proxy n -> Dict (1 <= CLog 2 n)
oneLeCLog2n Proxy = unsafeCoerce (Dict :: Dict (1 <= 1)) |
Or we could make caseCon a little more careful |
It seemed easy it to look at But on second thought this "fix" (silently) breaks other uses of unsafeCoerce, which used to work before. data AB a b = A a | B b
data CD = C Bool | D Int
topEntity :: Int
topEntity = case unsafeCoerce ab of
C _ -> 123
D i -> i
where
ab :: AB Bool Int
ab = B 4
|
We shouldn't try and detect this; We should handle coercions between |
I don't think it makes sense to change how
I think a better idea would be to improve the error here, since the main problem other than programmer error was Clash not actually telling us what was wrong directly. We can
We can then say that
Note that this is equality is possibly up to |
Better error messages aside, we may not want to do this when we don't have |
Linting this seems fine to me (we already do that with other invariants), but I don't see the point in tying it to |
We can't simply run this after a transformation: if
The coupling to
Having thought about this more, I don't think it should be a debug only check. If this check would fail, the core is just straight up wrong. I don't think there's much value in trying to generate hardware from a program which is known to be incorrect. If a transformation is wrong, better to know sooner. If the programmer is using Although to go back to the comment on cost not mattering since it's debug: even for debugging I would want such expensive checks to be optionally enabled because it would really slow down the debugging cycle for the programmer. This applies more for things like this where they likely happen infrequently since |
Sure, let's run it at the very start too. That shouldn't matter for performance given that it's a one time thing. Come to think of it, we should definitely do this:
I'm not really sure how this is relevant. Other transformations can introduce wrongly typed
I think this really comes down to: do you want to pay the cost of checking it? |
See: clash-lang/clash-compiler#2376 Co-authored-by: Martijn Bastiaan <[email protected]>
See: clash-lang/clash-compiler#2376 Co-authored-by: Martijn Bastiaan <[email protected]>
See: clash-lang/clash-compiler#2376 Co-authored-by: Martijn Bastiaan <[email protected]>
I just ran into this issue again, but this time via using some of the dictionaries of I agree that this is a PBKAC, but users easily get trapped into this issue by using libraries like |
The following:
causes:
In other examples Clash introduces free variables in
caseCon
(but I've yet to make a small reproducer for that).Printing the arguments given to
zipEqual
gives:Workaround: add
NOINLINE
tooneLeCLog2n
The text was updated successfully, but these errors were encountered: