-
-
Notifications
You must be signed in to change notification settings - Fork 610
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 Issue 12100 - __GENTYPE to generate ever different types #5633
Conversation
|
|
|
||
|
|
||
| /*********************************************************** | ||
| */ |
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.
Use existing comment style.
|
Thanks @9rnsr. |
|
You need to add test cases to check the new feature behavior. |
cd7ac2e to
03fbac3
Compare
|
It might be much simpler, and more flexible, to have COUNTER. COUNTER could then be used to generate unique types, unique identifiers, unique symbols, as required. |
|
The idea ends up horribly broken with separate compilation. Depending on the order of analysis, the 'same' declaration will be passed different numbers. If it's entirely internal then it will work, but with inlining and templates that's hard to guarantee. My preferred way is to use a struct, since these have stable but unique names. The downside is that you need to declare the struct yourself to get a unique name. |
|
@yebblies that's the exact reason I decided to use the mangled name of the instantiation scope instead of COUNTER. Do you have an example of where separate compilation will break this? |
|
@Biotronic In old days, the name of function literal and delegate literal ( |
|
@9rnsr That sounds a whole lot like what I'm doing here. Some examples of what to expect: |
|
I'm wondering if this could be done using a library function and CTFE rather than building it into the core language. |
|
Currently, no. That would require storing some information between calls to ctfeGensym(). The closest you get currently is the use of MODULE and LINE. That fails for at least these cases: The last example incidentally also shows a case where adding COLUMN wouldn't help. Without a way to transmit information between calls to ctfeGensym, I don't think this problem can be solved in a library. |
|
Yeah, I forgot about CTFE not allowing any global state. Lemme think about this some more. |
|
It seems that the entire benefit of implementing this unique compile-time string generation is to enable the hack workaround to make Typedefs behave as expected. Is that the only use-case? Because if so we should think about solving the |
|
@AndrejMitrovic It's useful for any auto-generated types that need to be unique. See this thread, for example: http://forum.dlang.org/post/yfeavyrdsqdchexmggih@forum.dlang.org |
|
Cool, thanks! So it seems there's precedent from other languages (lisp), that's good. |
|
@yebblies @WalterBright are we not allowed to use D hashmaps in the front-end? And actually I'm pretty sure there's a hashmap implementation somewhere in the source files as an alternative. It would simplify the code quite a bit here. |
|
Otherwise we shouldn't use an array for the lookup (slow lookups), there's a mix of |
|
@RazvanN7 we should probably close this for now |
Is there any alternative to produce this/similar behavior? |
This PR fixes https://issues.dlang.org/show_bug.cgi?id=12100 by adding the construct GENSYM, which creates a unique string intended for use with template default parameters for e.g. Typedef: