-
Notifications
You must be signed in to change notification settings - Fork 148
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
Type synonyms with phantom parameters can lead to strange behaviors (E.g., compiler hang) #692
Comments
Yes, I would like for type synonyms with unused parameters to be illegal; but a reason why they are not is because it is used in the TLM packages (in the An example of phantom parameters in the TLM library is here. They look like this:
Where the macro is defined in
The typedef acts as a way of selecting out on of the parameters. For example, here:
which could be manually written out, since it's all still part of the library, but then in user code, you can also use it:
Some of these could be done away with by introducing a typeclass:
However, there are some places where this couldn't be used -- for example, the struct declaration of Or maybe there's a better way to write the TLM libraries that doesn't need any of this machinery. And maybe someone wants to argue that we don't need to fix the TLM libraries before fixing BSC. But it'd be great to figure out how we can move forward on fixing all of these known issues with type synonyms. And, yes, don't ever write new code that has phantom variables. The hanging behavior that you describe is new to me. I'd have to look into it, to see what's going on. |
I guess a possible fix for the TLM libraries would be to make these real data types and not type aliases. Anywhere that |
I am curious to see if anyone can repro the hanging behavior. It's interesting that it is possible to write code that is reliant on a feature that is so strongly discouraged. Is there a reason it is not supported? I could be way off base here, but it felt like a reasonable thing to try to do when I originally wrote the code that used it. I was surprised to find that it is (or should be) illegal. |
A type synonym is not a new type, it's just an alias, and you are allowed to use it interchangeably. If you define this:
You're allowed to pass values declared as type
So with your definition of
But then where is If (I guess, technically, the only thing that BSC needs to disallow is the definition of |
For example:
As written, compiling with
-g mkPhantomVecRegDut -verilog
this will generate two errors, and then hang the compiler.If you use the commented out interface (instead of the two type aliases), it will just give errors and not hang.
If you add the missing
Add k k__ n
proviso, it will give an error, and not hang.I talked it over with @nanavati, and he said that type synonyms with phantom parameters should just be an error flat out, and that since they are not being flagged as an error, the compiler is free to go off in the weeds and get stuck.
Should type synonyms with phantom parameters just be a fatal error?
The text was updated successfully, but these errors were encountered: