-
-
Notifications
You must be signed in to change notification settings - Fork 420
TypeInfo_Struct: Switch to stored mangled name & demangle lazily (with per-thread cache) #3527
Conversation
Thanks for your pull request and interest in making D better, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. 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 run digger -- build "master + druntime#3527" |
Making the TypeInfo_Struct names truly unique and more compact at the same time. Requires dlang/druntime#3527.
8201c3c
to
1ce87d4
Compare
I've run the tests locally on Linux x64 with both dmd and druntime branches; all green (dmd/druntime/phobos) except for (apparently hanging) druntime integration subtest |
} | ||
unittest | ||
{ | ||
assert(typeid(void).toString == "void"); |
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.
TypeInfo.toString()
isn't pure anymore.
The test is trying to print the types of allocations while the GC lock is held: this deadlocks when accessing That also shows another subtle change: using |
This is a breaking change (although I was expecting quite more to be broken than just
While this certainly is a good thing, can you explain why is it necessary? Are you trying to solve some bigger problem with this? |
Cheers; worked around it for now by using
The AA shouldn't really matter, as |
@PetarKirov: I haven't found an existing issue yet, so filed a new one: https://issues.dlang.org/show_bug.cgi?id=22149 This is especially bad for classes (tackled later), where it can e.g. break EH with LDC on Windows (see ldc-developers/ldc#3517), and dynamic casting in general AFAIK. |
…ched equality semantics By storing the mangled name, making the TypeInfo_Struct names truly unique and more compact at the same time. Requires dlang/druntime#3527.
Testcase added to dlang/dmd#12928. |
Indeed, that's a quite severe. Thanks for the explanations and linking the LDC PR! |
…ched equality semantics By storing the mangled name, making the TypeInfo_Struct names truly unique and more compact at the same time. Requires dlang/druntime#3527.
c7782cd
to
24ab248
Compare
Fine with me, a log can be run through ddemangle if needed.
Noticed that too after commenting. An alternative could be to abort demangling if the passed buffer is too small and let the caller allocate a larger one. If only the demangler would not use exceptions (which it only needs for backward compatibilty with older ambiguous manglings IIRC). Changing the demangler would be another PR, though. |
Yeah, or passing some sink which is responsible for increasing the internal capacity as needed.
Yeah, I find it also very suboptimal as demangling is used for exception backtraces, and throws at that time aren't really to be expected.
Definitely. I've just seen that there are other 'beautiful' related hacks like Lines 1209 to 1210 in 3a9ede0
CI doesn't seem to really work with feature branches (same-named branches directly on the official dlang repos) to tackle compiler and druntime at the same time; both PRs currently include a temporary commit to make Cirrus CI use the correct branches at least. Those commits obviously need to be removed before merging. Restoring |
{ | ||
return hashOf(this.mangledName); | ||
} | ||
|
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.
TypeInfo.opCmp
uses toString()
too; I'm not convinced overriding it here to check for a TypeInfo_Struct
rhs and comparing the mangledName
instead is worth it.
…h per-thread cache) Making the TypeInfo_Struct names truly unique and more compact at the same time. Requires compiler support. Caching the demangled name in the instance itself isn't possible because `TypeInfo.toString()` is const. I had to remove its `pure` in order to cache the demangled name in a per-thread AA (and using `const void*` as key, as `const TypeInfo_Struct` leads to an infinite recursion...).
This is especially useful to make `typeid(<class ref>).toString()` pure again (e.g., used by unit-threaded's `shouldThrow`).
24ab248
to
9a30e97
Compare
… from the official dlang repo
I've made it work for Azure Pipelines now (one according commit in each PR; all Windows jobs are green); the druntime patch here is a bit of an ugly copy-pasta but does the job. So PRs originating from branches on the official dlang repos will try to use same-named branches for the other repos, and fall back to
Edit: Now (properly) working with Cirrus CI too and thus covering Windows/Linux/macOS/FreeBSD; the previous hack doesn't need to be removed anymore. |
…ing from the official dlang repo
We really should stop wasting everyone's time with the artificial split between dmd and druntime (and possibly phobos) and merge them in a mono repo. |
[Would be nice to have this land in 2.098; Walter has approved of the DMD PR.] |
@kinke It seems that the autotester is failing a couple of tests in dmd. Is this expected? |
@RazvanN7: Yes, these 2 DMD testsuite failures are expected if DMD and druntime aren't in sync. |
I'm gonna pull the trigger on these PRs. Let's hope everything will run smoothly. |
Hmm, unfortunately I don't have the right to merge this unless it passes all required tests. However, I have enough permissions to merge the dmd PR. Maybe I can do that and wait for this PR to be green? That will stall the entire pipeline. But I don't see any other way out of it. |
Can't you merge manually via git cmdline? Should I try to? |
Feel free to merge both PRs. (I apparently can't merge this one) |
@RazvanN7: I can't merge any one of these PRs either; looks like the GitHub branch protection rules even apply to manual pushes. So if you can indeed merge the DMD one, please go ahead. |
…otched equality semantics (#12928) * Fix Issue 22149 - TypeInfo_Struct names aren't unique, leading to botched equality semantics By storing the mangled name, making the TypeInfo_Struct names truly unique and more compact at the same time. Requires dlang/druntime#3527. * Fix Issue 22150 - TypeInfo_Class names aren't unique, leading to botched equality semantics By fully qualifying template arguments. * [temp] Cirrus CI: Use same-named druntime branch * Azure Pipelines: Try to use same-named druntime/Phobos branches for PRs originating from the official dlang repo * Cirrus CI: Try to use same-named druntime/Phobos branches for PRs originating from the official dlang repo
@kinke Merged it. |
…otched equality semantics (#12928) * Fix Issue 22149 - TypeInfo_Struct names aren't unique, leading to botched equality semantics By storing the mangled name, making the TypeInfo_Struct names truly unique and more compact at the same time. Requires dlang/druntime#3527. * Fix Issue 22150 - TypeInfo_Class names aren't unique, leading to botched equality semantics By fully qualifying template arguments. * [temp] Cirrus CI: Use same-named druntime branch * Azure Pipelines: Try to use same-named druntime/Phobos branches for PRs originating from the official dlang repo * Cirrus CI: Try to use same-named druntime/Phobos branches for PRs originating from the official dlang repo
…otched equality semantics (dlang#12928) * Fix Issue 22149 - TypeInfo_Struct names aren't unique, leading to botched equality semantics By storing the mangled name, making the TypeInfo_Struct names truly unique and more compact at the same time. Requires dlang/druntime#3527. * Fix Issue 22150 - TypeInfo_Class names aren't unique, leading to botched equality semantics By fully qualifying template arguments. * [temp] Cirrus CI: Use same-named druntime branch * Azure Pipelines: Try to use same-named druntime/Phobos branches for PRs originating from the official dlang repo * Cirrus CI: Try to use same-named druntime/Phobos branches for PRs originating from the official dlang repo
Making the
TypeInfo_Struct
names truly unique and more compact at the same time. Requires compiler support: dlang/dmd#12928Caching the demangled name in the instance itself isn't possible because
TypeInfo.toString()
isconst
. I had to remove itspure
in order to cache the demangled name in a per-thread AA (and usingconst void*
as key, asconst TypeInfo_Struct
leads to an infinite recursion...).