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 static AA initialization #15744
Fix static AA initialization #15744
Conversation
Thanks for your pull request, @schveiguy! 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 "stable + dmd#15744" |
ping @dkorpel This is going to fail unittests, and I don't know why. I couldn't get it to pass on my local system with a |
runtime. We do this by storing the hash function in the Impl instead of using the passed-in TypeInfo for the key.
f20c0aa
to
0a4d80c
Compare
Is there a bugzilla? |
As this is a new unreleased feature, I am unsure if it's a bug or not. I'm hoping @dkorpel can shed some light. |
Hm... an issue with the current DMD tests, I'll investigate. |
{ | ||
assert(__ctfe, "makeAA Must only be called at compile time"); |
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.
Added this because I had to make this @trusted
. Note that we can pretty much ignore all attributes because this is CTFE only.
@@ -642,7 +642,8 @@ class TypeInfo | |||
*/ | |||
size_t getHash(scope const void* p) @trusted nothrow const | |||
{ | |||
return hashOf(p); | |||
// by default, do not assume anything about the type | |||
return 0; |
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.
Anyone have any idea why this would be bad? The default of hashing the pointer seems ludicrous to me -- the pointer comes from anywhere and is a consequence of having a runtime interface vs. a compile time one. It has nothing to do with item equality or hashing.
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.
It could be a bad performance regression, not sure if anyone actually relies on it though.
90dde8f
to
50ed660
Compare
OK, finally this is the thing that fails on my local system. If I move the static AA declaration outside the unittest, I get the error:
|
OK, I found a test that actually compiles and tests the change. unfortunately, it only works if I declare a global (this will be a different bug filed) instead of a static variable. So that's why I put in the version(unittest). If this turns green, I think it's good to go. |
What is this error with profilegc? What is the problem, and how do I fix it? EDIT: I figured it out, and added a readme to help future me or others understand the issues. |
version(unittest): | ||
struct Foo { | ||
ubyte x; | ||
double d; | ||
} | ||
int[Foo] utaa = [Foo(1, 2.0) : 5]; | ||
unittest { |
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.
version(unittest): | |
struct Foo { | |
ubyte x; | |
double d; | |
} | |
int[Foo] utaa = [Foo(1, 2.0) : 5]; | |
unittest { | |
unittest | |
{ | |
static struct Foo | |
{ | |
ubyte x; | |
double d; | |
} | |
static int[Foo] utaa = [Foo(1, 2.0) : 5]; |
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 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'll look into it
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.
needs a bigger block size.
02a05f2
to
702a63f
Compare
@ibuclaw if you can hold off until this is merged to do the big merge, that would be good. I expect this to turn green. |
You can always just set the base to stable. :-) |
Just ping me if you do it before this is merged. |
I'm just starting off a final point release of stable, should occupy a couple hours before freezing master for 2.106 beta |
FWIW, I can't target stable with this until master is merged into stable, because I need Dennis' changes to the newaa as a base. |
Waiting for merge to stable, then I will retarget stable. |
@schveiguy I've changed base of this PR to |
OK, if nobody reviews this, I guess just merge it in 48 hours? |
Static AA initialization (the yet unreleased feature, added in #15468) is broken for some cases of AA initialization.
The issue comes from
TypeInfo.getHash
not always behaving the same ashashOf
. The fix here is to add a delegate which does the hashing to theImpl
struct of the AA. Normal AA initialization at runtime copies the key'sTypeInfo.getHash
function, whereas when we initialize it using static AA initialization, we write our own function that always useshashOf
, making the hashing consistent.FWIW, this means some cases where the compiler passes in the key
TypeInfo
are not needed, though we still callopEquals
from the keyTypeInfo
. Possibly we can remove that usage by storing all the delegates needed upon creation.