-
Notifications
You must be signed in to change notification settings - Fork 162
Add type role annotations to Signal and DSignal #1640
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
Prevents accidental, unsafe coerces
6ef8095
to
8160e11
Compare
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.
LGTM, do we also need a role annotation on BiSignal
's signal types?
I believe so! |
Good question, what are the inferred roles of |
In a similar vein, what about the |
Locally I get:
and for the sized types I get
|
Agreed. I'd like to put it a bit stronger; it's completely broken. E.g.,
Edit: Also, if this synthesizes, HDL simulation would yield different results. |
Even better, if it's completely broken we don't need to feel bad about changing it |
@alex-mckenna Could you extend/add a changelog for the other fixes too? :) |
25aa113
to
80f8d06
Compare
BiSignal also needs role annotations to prevent the natural number parameter from being treated as phantom. The natural number parameters of sized types are also made nominal: changing the size of a sized type should only be done explicitly using a well-defined resizing function (like resize#).
80f8d06
to
1db6eec
Compare
Reset and Enable have phantom types too
|
Or do they inherit the nominal from Signal? |
They should @leonschoorl, at least they did for |
I'll confirm now locally, but my understanding is that they go for the least restrictive option they can. So |
Yes:
|
I disagree here, for most types the behaviour you want is the inherited option. If I see a role annotation my first thought is this must differ from the inferred roles which won't be the case. Less is more |
Should this be backported to 1.2? |
Yeah, it's an API change, in theory you could use it responsibly I guess. I do think we should release 1.4 in a few weeks though. |
I wouldn't backport: this technically has the potential to break existing user code which uses |
@@ -156,6 +157,8 @@ import Clash.XException | |||
>>> let n = $$(fLit pi) :: SFixed 4 4 | |||
-} | |||
|
|||
type role Fixed representational nominal nominal |
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.
If this role annotation corresponds to the inferred role, could you remove it please.
@@ -69,6 +69,7 @@ operator that uses truncation introduces an additional error of /0.109375/: | |||
{-# LANGUAGE FlexibleContexts #-} | |||
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |||
{-# LANGUAGE MultiParamTypeClasses #-} | |||
{-# LANGUAGE RoleAnnotations #-} |
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.
Don't forget to remove this if you decide to remove the role annotation for Fixed
Type roles now feature in documentation, with the types in Clash.Sized.* now recommending the use of the Resize class to change the width of the type in a well-defined way.
Prevents accidental, unsafe coerces