Skip to content
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 17419 - add __traits(getLinkage, s) to the the linkage of s… #6822

Merged
merged 1 commit into from
May 23, 2017

Conversation

WalterBright
Copy link
Member

…ymbol s

The use of name mangling in std.traits is slow, unreliable and brittle. Should be replaced with __traits(). This is a start.

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
17419 add __traits(getLinkage, s) to the the linkage of symbol s

return new ErrorExp();
}
string linkage;
switch (d.linkage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final switch ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.def is not represented

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is .def ?
give it a string representation, then.
Better then a halt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh default linkage.
This should be D linkage, no ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Member

@UplinkCoder UplinkCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it.

@wilzbach
Copy link
Member

Doesn't this need an accompanying PR to dlang.org for the doc change and probably a changelog entry as well?

case LINK.system: linkage = "System"; break;
default: assert(0);
}
auto se = new StringExp(e.loc, cast(char*)linkage.ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&linkage[0]

Copy link
Member

@UplinkCoder UplinkCoder May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also maybe use new StringExp(e.loc, cast(void*) &linkage[0], linkage.length ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the current version will call strlen inside of StringExp constructor.
which is probably negligible but still we don't need to throw the length information away.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth the extra complexity.

}
string linkage;
switch (d.linkage)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ... rather then using strings here we take the pointers to the identifiers out of the string table we already have ?
Id.{D, C, Windows ... }.string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't work because of C++ and Objective-C

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right.

extern (Objective-C) int fooobjc();
extern (System) int foos();

static assert(__traits(getLinkage, fooc) == "C");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this was to be food ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's c, not d

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the symbol food, is not referenced in this test.
while fooc is referenced twice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, my mistake

Copy link
Member

@UplinkCoder UplinkCoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe address the comments ?

static assert(__traits(getLinkage, fooc) == "C");
static assert(__traits(getLinkage, aliasc) == "C");

extern (C) int food();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be extern(D)

case LINK.windows: linkage = "Windows"; break;
case LINK.pascal: linkage = "Pascal"; break;
case LINK.objc: linkage = "Objective-C"; break;
case LINK.system: linkage = "System"; break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is uncovered ...
I guess system linkage is replaced earlier
should this be an ice then ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra complexity of duplicating other logic is not worth it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extern(System) is resolved when building the parsing tree. If anyone wants to fix that to defer until semantic, be my guest. However I suspect even then that is still before traits are evaluated.

case LINK.pascal: linkage = "Pascal"; break;
case LINK.objc: linkage = "Objective-C"; break;
case LINK.system: linkage = "System"; break;
default: assert(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider making this a proper ice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that's what asserts are for.

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants