Skip to content

Commit

Permalink
Fix shadowed variable in faiss/impl/ResultHandler.h
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: algoriddle

Differential Revision: D52582910

fbshipit-source-id: 92ee06e819f15c411a3fee75a6c9e17fba96a7f3
  • Loading branch information
r-barnes authored and facebook-github-bot committed Jan 9, 2024
1 parent 42b6216 commit 0710cbd
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions faiss/impl/ResultHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ struct HeapResultHandler {
size_t i0, i1;

/// begin
void begin_multiple(size_t i0, size_t i1) {
this->i0 = i0;
this->i1 = i1;
for (size_t i = i0; i < i1; i++) {
void begin_multiple(size_t i0_2, size_t i1_2) {
this->i0 = i0_2;
this->i1 = i1_2;
for (size_t i = i0_2; i < i1_2; i++) {
heap_heapify<C>(k, heap_dis_tab + i * k, heap_ids_tab + i * k);
}
}
Expand Down Expand Up @@ -231,13 +231,13 @@ struct ReservoirResultHandler {
size_t i;

/// begin results for query # i
void begin(size_t i) {
void begin(size_t i_2) {
res1 = ReservoirTopN<C>(
hr.k,
hr.capacity,
reservoir_dis.data(),
reservoir_ids.data());
this->i = i;
this->i = i_2;
}

/// add one result for query i
Expand All @@ -264,18 +264,18 @@ struct ReservoirResultHandler {
std::vector<ReservoirTopN<C>> reservoirs;

/// begin
void begin_multiple(size_t i0, size_t i1) {
this->i0 = i0;
this->i1 = i1;
reservoir_dis.resize((i1 - i0) * capacity);
reservoir_ids.resize((i1 - i0) * capacity);
void begin_multiple(size_t i0_2, size_t i1_2) {
this->i0 = i0_2;
this->i1 = i1_2;
reservoir_dis.resize((i1_2 - i0_2) * capacity);
reservoir_ids.resize((i1_2 - i0_2) * capacity);
reservoirs.clear();
for (size_t i = i0; i < i1; i++) {
for (size_t i = i0_2; i < i1_2; i++) {
reservoirs.emplace_back(
k,
capacity,
reservoir_dis.data() + (i - i0) * capacity,
reservoir_ids.data() + (i - i0) * capacity);
reservoir_dis.data() + (i - i0_2) * capacity,
reservoir_ids.data() + (i - i0_2) * capacity);
}
}

Expand Down Expand Up @@ -363,9 +363,9 @@ struct RangeSearchResultHandler {
int pr = 0;

/// begin
void begin_multiple(size_t i0, size_t i1) {
this->i0 = i0;
this->i1 = i1;
void begin_multiple(size_t i0_2, size_t i1_2) {
this->i0 = i0_2;
this->i1 = i1_2;
}

/// add results for query i0..i1 and j0..j1
Expand Down Expand Up @@ -443,8 +443,8 @@ struct SingleBestResultHandler {
SingleResultHandler(SingleBestResultHandler& hr) : hr(hr) {}

/// begin results for query # i
void begin(const size_t current_idx) {
this->current_idx = current_idx;
void begin(const size_t current_idx_2) {
this->current_idx = current_idx_2;
min_dis = HUGE_VALF;
min_idx = -1;
}
Expand All @@ -467,19 +467,19 @@ struct SingleBestResultHandler {
size_t i0, i1;

/// begin
void begin_multiple(size_t i0, size_t i1) {
this->i0 = i0;
this->i1 = i1;
void begin_multiple(size_t i0_2, size_t i1_2) {
this->i0 = i0_2;
this->i1 = i1_2;

for (size_t i = i0; i < i1; i++) {
for (size_t i = i0_2; i < i1_2; i++) {
this->dis_tab[i] = HUGE_VALF;
}
}

/// add results for query i0..i1 and j0..j1
void add_results(size_t j0, size_t j1, const T* dis_tab) {
void add_results(size_t j0, size_t j1, const T* dis_tab_2) {
for (int64_t i = i0; i < i1; i++) {
const T* dis_tab_i = dis_tab + (j1 - j0) * (i - i0) - j0;
const T* dis_tab_i = dis_tab_2 + (j1 - j0) * (i - i0) - j0;

auto& min_distance = this->dis_tab[i];
auto& min_index = this->ids_tab[i];
Expand Down

0 comments on commit 0710cbd

Please sign in to comment.