Skip to content

Commit

Permalink
Fix shadowed variable in gloo/alltoallv.cc
Browse files Browse the repository at this point in the history
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: D52959036

fbshipit-source-id: ce16eb7d7c260dd85cd2efb4012a94376bd3bd3f
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 24, 2024
1 parent 90782f9 commit 882d809
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions gloo/alltoallv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,75 +45,75 @@ void AlltoallvOptions::setElementSize(size_t elementSize_2) {
void AlltoallvOptions::setInput(
std::unique_ptr<transport::UnboundBuffer> buf,
std::vector<int64_t> elementsPerRank,
size_t elementSize) {
size_t elementSize_2) {
const auto totalElements = std::accumulate(
elementsPerRank.begin(), elementsPerRank.end(), size_t(0));
this->setElementSize(elementSize);
this->setElementSize(elementSize_2);
GLOO_ENFORCE_EQ(elementsPerRank.size(), context->size);
this->inOffsetPerRank.reserve(elementsPerRank.size());
this->inLengthPerRank.reserve(elementsPerRank.size());
splitOffsetsAndLengths(
elementsPerRank,
elementSize,
elementSize_2,
this->inOffsetPerRank,
this->inLengthPerRank);
GLOO_ENFORCE_EQ(totalElements * elementSize, buf->size);
GLOO_ENFORCE_EQ(totalElements * elementSize_2, buf->size);
this->in = std::move(buf);
}

void AlltoallvOptions::setInput(
void* ptr,
std::vector<int64_t> elementsPerRank,
size_t elementSize) {
size_t elementSize_2) {
const auto totalElements = std::accumulate(
elementsPerRank.begin(), elementsPerRank.end(), size_t(0));
this->setElementSize(elementSize);
this->setElementSize(elementSize_2);
GLOO_ENFORCE_EQ(elementsPerRank.size(), context->size);
this->inOffsetPerRank.reserve(elementsPerRank.size());
this->inLengthPerRank.reserve(elementsPerRank.size());
splitOffsetsAndLengths(
elementsPerRank,
elementSize,
elementSize_2,
this->inOffsetPerRank,
this->inLengthPerRank);
this->in = context->createUnboundBuffer(ptr, totalElements * elementSize);
this->in = context->createUnboundBuffer(ptr, totalElements * elementSize_2);
}

void AlltoallvOptions::setOutput(
std::unique_ptr<transport::UnboundBuffer> buf,
std::vector<int64_t> elementsPerRank,
size_t elementSize) {
size_t elementSize_2) {
const auto totalElements = std::accumulate(
elementsPerRank.begin(), elementsPerRank.end(), size_t(0));
this->setElementSize(elementSize);
this->setElementSize(elementSize_2);
GLOO_ENFORCE_EQ(elementsPerRank.size(), context->size);
this->outOffsetPerRank.reserve(elementsPerRank.size());
this->outLengthPerRank.reserve(elementsPerRank.size());
splitOffsetsAndLengths(
elementsPerRank,
elementSize,
elementSize_2,
this->outOffsetPerRank,
this->outLengthPerRank);
GLOO_ENFORCE_EQ(totalElements * elementSize, buf->size);
GLOO_ENFORCE_EQ(totalElements * elementSize_2, buf->size);
this->out = std::move(buf);
}

void AlltoallvOptions::setOutput(
void* ptr,
std::vector<int64_t> elementsPerRank,
size_t elementSize) {
size_t elementSize_2) {
const auto totalElements = std::accumulate(
elementsPerRank.begin(), elementsPerRank.end(), size_t(0));
this->setElementSize(elementSize);
this->setElementSize(elementSize_2);
GLOO_ENFORCE_EQ(elementsPerRank.size(), context->size);
this->outOffsetPerRank.reserve(elementsPerRank.size());
this->outLengthPerRank.reserve(elementsPerRank.size());
splitOffsetsAndLengths(
elementsPerRank,
elementSize,
elementSize_2,
this->outOffsetPerRank,
this->outLengthPerRank);
this->out = context->createUnboundBuffer(ptr, totalElements * elementSize);
this->out = context->createUnboundBuffer(ptr, totalElements * elementSize_2);
}

void alltoallv(AlltoallvOptions& opts) {
Expand Down

0 comments on commit 882d809

Please sign in to comment.