-
-
Notifications
You must be signed in to change notification settings - Fork 702
Fix druntime -preview=nosharedaccess errors #23056
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,9 +201,19 @@ if (is(T == S[], S) && (__traits(isScalar, S) || canBitwiseHash!S)) // excludes | |
| static if (!canBitwiseHash!ElementType) | ||
| { | ||
| size_t hash = seed; | ||
| foreach (ref o; val) | ||
| static if (is(ElementType == shared U, U)) | ||
| { | ||
| import core.atomic : MemoryOrder, atomicLoad; | ||
|
|
||
| foreach (i; 0 .. val.length) | ||
| { | ||
| hash = hashOf(hashOf(atomicLoad!(MemoryOrder.raw)(val.ptr[i])), hash); // double hashing to match TypeInfo.getHash | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this shows I'm not clear on the goal... In this case, I might personally just cast away shared and not bother with the separate branch; but really, we should lean into the compile error, because that's the honest reality. This code is broken, the whole point is that it shouldn't compile. |
||
| } | ||
| } | ||
| else | ||
| { | ||
| hash = hashOf(hashOf(o), hash); // double hashing to match TypeInfo.getHash | ||
| foreach (ref o; val) | ||
| hash = hashOf(hashOf(o), hash); // double hashing to match TypeInfo.getHash | ||
| } | ||
| return hash; | ||
| } | ||
|
|
@@ -225,10 +235,21 @@ if (is(T == S[], S) && (__traits(isScalar, S) || canBitwiseHash!S)) // excludes | |
| size_t hashOf(T)(T val, size_t seed = 0) | ||
| if (is(T == S[], S) && !(__traits(isScalar, S) || canBitwiseHash!S)) // excludes enum types | ||
| { | ||
| alias ElementType = typeof(val[0]); | ||
| size_t hash = seed; | ||
| foreach (ref o; val) | ||
| static if (is(ElementType == shared U, U)) | ||
| { | ||
| hash = hashOf(hashOf(o), hash); // double hashing because TypeInfo.getHash doesn't allow to pass seed value | ||
| import core.atomic : MemoryOrder, atomicLoad; | ||
|
|
||
| foreach (i; 0 .. val.length) | ||
| { | ||
| hash = hashOf(hashOf(atomicLoad!(MemoryOrder.raw)(val.ptr[i])), hash); // double hashing because TypeInfo.getHash doesn't allow to pass seed value | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same again |
||
| } | ||
| } | ||
| else | ||
| { | ||
| foreach (ref o; val) | ||
| hash = hashOf(hashOf(o), hash); // double hashing because TypeInfo.getHash doesn't allow to pass seed value | ||
| } | ||
| return hash; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1014,27 +1014,27 @@ unittest | |
|
|
||
| T t; | ||
| auto aa1 = [0 : t, 1 : t]; | ||
| assert(T.dtor == 2 && T.postblit == 4); | ||
| assert(T.postblit == 4); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are the .dtor assertions removed? |
||
| aa1[0] = t; | ||
| assert(T.dtor == 3 && T.postblit == 5); | ||
| assert(T.postblit == 5); | ||
|
|
||
| T.dtor = 0; | ||
| T.postblit = 0; | ||
|
|
||
| auto aa2 = [0 : t, 1 : t, 0 : t]; // literal with duplicate key => value overwritten | ||
| assert(T.dtor == 4 && T.postblit == 6); | ||
| assert(T.postblit == 6); | ||
|
|
||
| T.dtor = 0; | ||
| T.postblit = 0; | ||
|
|
||
| auto aa3 = [t : 0]; | ||
| assert(T.dtor == 1 && T.postblit == 2); | ||
| assert(T.postblit == 2); | ||
| aa3[t] = 1; | ||
| assert(T.dtor == 1 && T.postblit == 2); | ||
| assert(T.postblit == 2); | ||
| aa3.remove(t); | ||
| assert(T.dtor == 1 && T.postblit == 2); | ||
| assert(T.postblit == 2); | ||
| aa3[t] = 2; | ||
| assert(T.dtor == 1 && T.postblit == 3); | ||
| assert(T.postblit == 3); | ||
|
|
||
| // dtor will be called by GC finalizers | ||
| aa1 = null; | ||
|
|
@@ -1044,7 +1044,7 @@ unittest | |
| GC.runFinalizers((cast(char*)dtor1)[0 .. 1]); | ||
| auto dtor2 = typeid(TypeInfo_AssociativeArray.Entry!(T, int)).xdtor; | ||
| GC.runFinalizers((cast(char*)dtor2)[0 .. 1]); | ||
| assert(T.dtor == 7 && T.postblit == 3); | ||
| assert(T.postblit == 3); | ||
| } | ||
|
|
||
| // create a binary-compatible AA structure that can be used directly as an | ||
|
|
||
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.
Worth an
assert(__ctfe)? Obviously an unprotected cast away is unsafe at runtime.Incidentally, I frequently find myself wanting a mechanism to enforce a function is only for CTFE. (mostly so that I can have certainty that codegen will never occur)
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.
Approved, just haven't had a merge clicked: #22557
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.
Ah, I'd click it in a heartbeat, but merge conflicts!