- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 656
use special enums for __c_long, etc. instead of special structs #8152
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
| Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#8152" | 
| How will the usage of this look like? | 
| I guess something like enum __c_long : long;
alias c_long = __c_long;
void foo(c_long c);
void bar() { foo(123); }I suggest adding special IDs  | 
| enum __c_long : long;
alias c_long = __c_long;
void foo(c_long a){};
void main()
{
   foo(3L);
}The above results in:  | 
| @WalterBright would you consider trying to get this working instead #7458? That is, adding support for  | 
| 
 It's completely antiethical to the way alias works. Aliases are internally instantly replaced with their aliased type all through the compiler. Enums are not, which is why doing special enums is a very small change. | 
| What's the advantage of using an enum instead of a struct? | 
| 
 That might be the case but it would be very convenient. | 
| 
 
 | 
| 
 You can add the enum declarations into the test file right now. This is currently done for the struct version in cppa.d. | 
d581138    to
    3daef90      
    Compare
  
    | Ok I added some tests to cppa.d | 
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.
Can you add a usage test as well that verifies that the implicit conversions work too.
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.
One thing that I don't think is handled here but probably will need to be in druntime are type properties. Wouldn't you need to declare enum members named init, max, min, etc... Unless there is special handling in the compiler that I'm not seeing here.
| else if (id == Id.__c_ulong) | ||
| t = TYulong; | ||
| else if (id == Id.__c_long_double) | ||
| t = TYdouble; | 
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 take it that tydouble is correct here, and that there is no long double ty.
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.
There is a TYdouble_alias, but it is used by the dmc++ front end to do name mangling. The code generator doesn't care - the dmd front end does the name mangling.
e8f903f    to
    22f61fc      
    Compare
  
    | version (CRuntime_Microsoft) | ||
| { | ||
| struct __c_long_double | ||
| version (PULL8152) | 
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.
What's the reasoning for the version statement? Will this test be run on a compiler that doesn't contain this change?
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.
Can't have two global declarations of __c_long, etc.
| 
 The  | 
The existing mechanism is in core.stdc.config, which uses a struct named __c_long. This change enables using an enum instead, which has some advantages:
Later we can do away with core.stdc.config entirely and just predefine these enums in the compiler.
The tests will be when core.stdc.config is redone using enums, which will be the egg (or the chicken?).