Skip to content
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

Use named tuple for std.array.byPair #5436

Merged
merged 2 commits into from
Dec 13, 2017
Merged

Conversation

John-Colvin
Copy link
Contributor

Not sure why it wasn't done this way originally

@DmitryOlshansky
Copy link
Member

Is a breaking change unfortunately

@John-Colvin
Copy link
Contributor Author

John-Colvin commented Jun 1, 2017

Any change to any return type is a breaking change*. If that's a blocker, then that's going to be a real source of stagnation...

*Actually, given D's powerful introspection, I'd wager a lot of PRs that people don't consider as breaking are strictly speaking breaking changes. Everything about the signature of a function can be introspected...

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT one of the reason behind using Voldemort types was that a library can change the type and implementation without the user needing to care about it.
In this case it's even still a tuple (just not anonymous anymore) and no explicit type is stated by the API, so I can't imagine that this will cause any breakage.

@DmitryOlshansky if you worry about, we could add a changelog entry (or Bugzilla issue) for this change, s.t. it's visible on the changelog.

std/array.d Outdated
import std.algorithm.iteration : map;

return aa.byKeyValue.map!(pair => tuple(pair.key, pair.value));
alias NamedTuple = Tuple!(Key, "key", Value, "value");
return aa.byKeyValue.map!(pair => NamedTuple(pair.key, pair.value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this could have also been simply:

return aa.byKeyValue.map!(pair => tuple!("key", "value")(pair.key, pair.value));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I always forget that the free function takes the names separately (which is funny because I worked a lot on that stuff getting Tuple.rename in)

@John-Colvin John-Colvin force-pushed the patch-10 branch 2 times, most recently from 98ee6cb to 86518eb Compare June 1, 2017 16:29
@quickfur
Copy link
Member

quickfur commented Jun 1, 2017

It wasn't done this way originally because of my negligence. Thanks for fixing it.

As for it being a breaking change, I disagree. The function is explicitly declared to return auto, meaning that the return type may change if the implementation changes. User code, therefore, should not be hard-coding the return type, but should be using typeof to obtain the correct type (e.g., if they wish to store it somewhere, like in a struct). If any code is hardcoding the return type to Tuple!(Key,Value), that code is technically wrong and ought to be broken.

@wilzbach
Copy link
Member

wilzbach commented Jun 7, 2017

Ping @DmitryOlshansky for responding to our feedback as expect for you comment there is nothing blocking a merge.

@DmitryOlshansky
Copy link
Member

DmitryOlshansky commented Jun 7, 2017 via email

@quickfur
Copy link
Member

Hmm you're right. This could be troublesome. Unless there was a way we could allow assignment to a Tuple with identical field types though not necessarily the same names. Might be tricky with the current implementation, though.

@John-Colvin
Copy link
Contributor Author

That wouldn't help when assigning to an array like in Dmitry's example would it?

@wilzbach
Copy link
Member

wilzbach commented Jul 2, 2017

Anyway you could merge it but add it to changelog as a breaking change it is.

I'm still for this as imho the implementation shouldn't really depend on this and showing a warning in the changelog should be good enough.
@quickfur @JackStouffer @ZombineDev - what's your take on this. Agree or veto?

@John-Colvin: could you please append an entry if other reviewers agree on this?

Copy link
Member

@JackStouffer JackStouffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is fine with an accompanying changelog entry

@JackStouffer
Copy link
Member

Let's move on with this. I'll add the changelog entry myself.

@wilzbach
Copy link
Member

@JackStouffer the error is due to the DUB registry being down:

Root package assert_writeln_magic references unknown package libdparse
posix.mak:625: recipe for target '.generated/assert_writeln_magic' failed

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @John-Colvin! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@wilzbach
Copy link
Member

@JackStouffer I rebased this PR to rekick DAutoTest and while I was at it, I added a changelog entry as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants