Skip to content

Commit bfd1067

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in gloo/allgatherv.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: D52959187 fbshipit-source-id: 17c366f00985dd2523f0fd029c280e984d64cc6d
1 parent b1ef59a commit bfd1067

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

gloo/allgatherv.cc

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

1717
namespace gloo {
1818

19-
void AllgathervOptions::setElementSize(size_t elementSize) {
19+
void AllgathervOptions::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,29 +30,29 @@ void AllgathervOptions::setElementSize(size_t elementSize) {
3030

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

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

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

0 commit comments

Comments
 (0)