Skip to content

Commit 90782f9

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in gloo/gatherv.cc
Summary: Our upcoming compiler upgrade will require us not to have shadowed variables. Such variables have a _high_ bug rate and reduce readability, so we would like to avoid them even if the compiler was not forcing us to do so. This codemod attempts to fix an instance of a shadowed variable. Please review with care: if it's failed the result will be a silent bug. **What's a shadowed variable?** Shadowed variables are variables in an inner scope with the same name as another variable in an outer scope. Having the same name for both variables might be semantically correct, but it can make the code confusing to read! It can also hide subtle bugs. This diff fixes such an issue by renaming the variable. - If you approve of this diff, please use the "Accept & Ship" button :-) Reviewed By: dmm-fb Differential Revision: D52959097 fbshipit-source-id: f9f99a8943e1d83e9ee18f17e6a6c0b752a15b24
1 parent f5ad225 commit 90782f9

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

gloo/gatherv.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
namespace gloo {
1818

19-
void GathervOptions::setElementSize(size_t elementSize) {
19+
void GathervOptions::setElementSize(size_t elementSize_2) {
2020
if (this->elementSize == 0) {
21-
this->elementSize = elementSize;
21+
this->elementSize = elementSize_2;
2222
} else {
2323
GLOO_ENFORCE_EQ(
24-
elementSize,
24+
elementSize_2,
2525
this->elementSize,
2626
"Element size does not match existing value. ",
2727
"Please double check that the input and output types match.");
@@ -30,30 +30,30 @@ void GathervOptions::setElementSize(size_t elementSize) {
3030

3131
void GathervOptions::setInput(
3232
std::unique_ptr<transport::UnboundBuffer> buf,
33-
size_t elementSize) {
34-
this->setElementSize(elementSize);
33+
size_t elementSize_2) {
34+
this->setElementSize(elementSize_2);
3535
this->in = std::move(buf);
3636
}
3737

3838
void GathervOptions::setInput(
3939
void* ptr,
4040
size_t elements,
41-
size_t elementSize) {
42-
this->setElementSize(elementSize);
43-
this->in = context->createUnboundBuffer(ptr, elements * elementSize);
41+
size_t elementSize_2) {
42+
this->setElementSize(elementSize_2);
43+
this->in = context->createUnboundBuffer(ptr, elements * elementSize_2);
4444
}
4545

4646
void GathervOptions::setOutput(
4747
std::unique_ptr<transport::UnboundBuffer> buf,
48-
std::vector<size_t> elementsPerRank,
49-
size_t elementSize) {
48+
std::vector<size_t> elementsPerRank_2,
49+
size_t elementSize_2) {
5050
const auto totalElements =
5151
std::accumulate(
52-
elementsPerRank.begin(), elementsPerRank.end(), size_t(0));
53-
this->setElementSize(elementSize);
54-
GLOO_ENFORCE_EQ(elementsPerRank.size(), context->size);
55-
this->elementsPerRank = std::move(elementsPerRank);
56-
GLOO_ENFORCE_EQ(totalElements * elementSize, buf->size);
52+
elementsPerRank_2.begin(), elementsPerRank_2.end(), size_t(0));
53+
this->setElementSize(elementSize_2);
54+
GLOO_ENFORCE_EQ(elementsPerRank_2.size(), context->size);
55+
this->elementsPerRank = std::move(elementsPerRank_2);
56+
GLOO_ENFORCE_EQ(totalElements * elementSize_2, buf->size);
5757
this->out = std::move(buf);
5858
}
5959

0 commit comments

Comments
 (0)