-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
[WIP] Use fully qualified class/interface name for TypeInfo_Class.name & mangled name for TypeInfo_Struct.name #11450
Conversation
[Just checking how bad the breakage would be.] |
I don't expect much breakage. While I agree this is the proper fix, it can result in huge strings for pretty rare use cases. We have avoided emitting similar long strings with the back references in the mangling. To be pedantic, the same change should be made for TypeInfo_Interface and TypieInfo_Struct (the latter would probably expose the long string issue). Maybe we could switch to using the mangled name, but that would really be a breaking change. |
I expected at least some, but it's looking pretty good.
I'm not too fond of long strings either. If switching to the mangled name, we'd definitely need to demangle it for the exception/backtrace string. |
Could you leave |
That's what I've done in ldc-developers/ldc#3517 (restricted to MSVC targets and Throwables only for now). |
I have built the phobos unittest.exe with a few variations for Win64:
Given that the name in struct typeinfo is not used by the runtime for dynamic typing as for classes and interfaces, and assuming that long chains of template instantiations are less likely for the latter two, I'd be fine with using |
It is used for things like |
Thx for the numbers, Rainer. I expected a bigger overhead, as we've seen old mangled names > 64k before you've implemented the backrefs (and I expect the FQN to be only slightly shorter than those old mangles).
Grepping for |
I appreciate it's not going to include the worst case scenarios but in the phobos unittests above adding struct FQN only adds 0.5% to the size of the binary - that's not bad. If it's worst case size that matters most then storing the mangle alongside the name as you're already doing on Windows in LDC is going to win eventually, at the cost of slightly inflated binaries for "normal" cases. To me the mangle makes sense as the thing to compare since it is designed to be a unique identifier in the first place. |
So what is it to be then? My first choice would be storing the mangle only and demangling on-the-fly on demand (e.g., when printing an exception), but as Still using the almost-fully-qualified name for structs would IMO be inconsistent and, as pointed out, be a potential problem for |
I.e., also fully qualify template arguments, to make these names truly unique per class/interface declaration.
To make them truly unique while preventing possibly very long human- readable fully-qualified names. `TypeInfo_Struct.toString()` returns this string; this change is expected to be the main user-visible effect.
Okay, implemented as proposed above, and it looks like we could get away without demangling in |
I like this approach, although I do think druntime to should be updated to demangle |
import dmd.root.outbuffer : OutBuffer; | ||
import dmd.dmangle : mangleToBuffer; | ||
OutBuffer nameBuf; | ||
mangleToBuffer(sd, &nameBuf); |
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.
Isn't the mangled name already available in tc.deco
?
I agree. It might even make sense to rename the |
Yeah, I wouldn't be too fond of an extra slice as cache inside TypeInfo_Struct - it would also prevent garbage collection if it's only used once. The GC required for demangling is actually my main concern - e.g., the druntime integration tests fail due to |
I was rather thinking of a global AA |
Hmm, a global AA would probably come with sync overhead for thread-safety...
Yeah right. |
Could be thread-local, too. But if you are allocating, you are using possibly blocking operations anyway. |
I rather tend to a slice in TypeInfo_Struct then, that's simple and fast to check/set. But how is one supposed to overcome the compiler/druntime coupling in this case here upstream without a druntime git submodule? I really don't want to prepare druntime for an upcoming compiler change, supporting both old and new |
Superseded by #12928. |
No description provided.