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 21129: Make OnlyResult
store a value tuple instead of a static array of CommonType.
#7584
Fix issue 21129: Make OnlyResult
store a value tuple instead of a static array of CommonType.
#7584
Conversation
Thanks for your pull request and interest in making D better, @FeepingCreature! 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 references
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 + phobos#7584" |
Thanks. |
"Copying the range means copying all elements" seems pretty clear. Afaiu this is how |
This might cause other problems. Now, |
Yes but I mean, it's super awkward to fix that. I'd have to sort the tuple and keep a map of indexes to tuple indexes. |
No, that wouldn't solve it -- the types are different, not just in a different order. What I see as a possible problem is this: struct SomeStruct
{
typeof(only(1L, 1L) someRange;
}
// one place
auto s = SomeStruct(only(1L, 1L));
// some other place
auto s = SomeStruct(only(2L, 3)); Definitely contrived. I don't have an example in the wild. indeed the fact that buildkite passed completely suggests there isn't [m]any. But of course, buildkite didn't catch the problem that triggered this fix. I definitely have code that uses the Then of course, there's the matter of proliferation of templates. It's also a bit worse performing for opIndex. Hm.. just thought of this too -- if the implicit conversion is expensive or destructive, then it might break code which expects the conversion to only run once. Another contrived example. It seems like your original PR is fixing a one-off odd case, and this PR is fixing a one-off odd case, only to add more one-off odd cases. Is it worth considering to go back to the original mechanism, and fix the original one-off a different way? Like maybe using something like checking for each parameter if an implicit cast to Unqual!T is possible, and if so, use that for determining the common type? |
No. The original version did not match the description. The revised version still did not match the description. The implementation was just wrong both times, in ways that contradicted the explicit documentation. If I'd say just go for it. Template proliferation and minor index performance loss should not come at the expense of correctness. |
Perhaps a solution: Can we have the conversion take place at the call site? (i.e. Can you also add a testcase for the |
Wouldn't that break the static array example if the range is returned? |
Ah yes indeed you are completely right. Somehow I am treating |
ping |
@FeepingCreature Can you also add a testcase for the alias this type of "conversion" ? |
746d4ce
to
3efd77c
Compare
@JohanEngelen done. |
Technically, I think this should target stable. Is it worth holding up the beta for this? Was going to tag auto-merge. |
Yeah, it's sort of a regression, isn't it? Retargeting to stable. |
3efd77c
to
c5305a2
Compare
This isn't going to pass buildkite (due to the temporary difference between master and stable for phobos+no-autodecode), but auto-merge will give it priority on the testers. |
{ | ||
assert(!empty, "Attempting to fetch the front of an empty Only range"); | ||
return data[frontIndex]; | ||
return this[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.
This looks like an error?
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.
0 means frontIndex
in this context, see opIndex
implementation.
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.
Nevermind
This is triggering some kind of problem in phobos for the buildkite build:
Note, this is not what I was referring to above. This part should pass buildkite. |
That's unrelated to this PR. Note that it happens in |
I know. What concerns me is that it doesn't happen anywhere else (I haven't seen a massive buildkite failure like that in other PRs). It's a lovely error with no indication of what the compiler was doing when it tried to compile that. Possibly some combination of chain/only in some test or something is causing this, but I don't know why then it would pass all the autotesters, etc. |
This diagnostic was enabled recently in DMD and I've already removed that code in |
I wonder if it's possible buildkite got caught right in the middle of the switch to target the stable branch. Try a re-force-push? |
Maybe. I've retriggered Buildkite |
Didn't work. Maybe try a force push? or close and reopen? |
…t as a tuple, instead of a static array of CommonType. Remove the unittest that verifies that `OnlyResult` doesn't depend on argument order - since it now does. Add unittest for issue 21129.
c5305a2
to
8910911
Compare
Yes, that's a bug in Buildkite. When you change the target branch in GitHub without a new commit or force-push, then Buildkite doesn't update the base branch, i.e. It's a bit hard to workaround this as GitHub's API are rate-limited. |
Well, I'll be back in 12h. Good luck! ;) |
For static arrays,
only
used to store a reference to its caller. This was bad. I changed it (in #7253 ) to take its arguments by value, but I didn't realize the static array case - so it started storing a reference to its constructor parameters, which was more obviously bad, as it crashed (@system
) or failed to compile (@safe
).This PR changes
only
to store the tuple of arguments in the range and convert to the common type as late as possible.ping @JohanEngelen
Note that I test with
const(char)
as there seems to be a bug withCommonType
- it thinkschar[]
andstring
are best unified aschar[]
.