Skip to content

Commit d492753

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Fix shadowed variable in faiss/impl/simd_result_handlers.h (#3960)
Summary: Pull Request resolved: #3960 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: meyering Differential Revision: D64398709 fbshipit-source-id: b10e44b40aa1d3e21aeb5112eb93fb63d64d4118
1 parent c93d1fd commit d492753

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

faiss/impl/simd_result_handlers.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,10 @@ struct HeapHandler : ResultHandlerCompare<C, with_id_map> {
368368
auto real_idx = this->adjust_id(b, j);
369369
lt_mask -= 1 << j;
370370
if (this->sel->is_member(real_idx)) {
371-
T dis = d32tab[j];
372-
if (C::cmp(heap_dis[0], dis)) {
371+
T dis_2 = d32tab[j];
372+
if (C::cmp(heap_dis[0], dis_2)) {
373373
heap_replace_top<C>(
374-
k, heap_dis, heap_ids, dis, real_idx);
374+
k, heap_dis, heap_ids, dis_2, real_idx);
375375
}
376376
}
377377
}
@@ -380,10 +380,10 @@ struct HeapHandler : ResultHandlerCompare<C, with_id_map> {
380380
// find first non-zero
381381
int j = __builtin_ctz(lt_mask);
382382
lt_mask -= 1 << j;
383-
T dis = d32tab[j];
384-
if (C::cmp(heap_dis[0], dis)) {
383+
T dis_2 = d32tab[j];
384+
if (C::cmp(heap_dis[0], dis_2)) {
385385
int64_t idx = this->adjust_id(b, j);
386-
heap_replace_top<C>(k, heap_dis, heap_ids, dis, idx);
386+
heap_replace_top<C>(k, heap_dis, heap_ids, dis_2, idx);
387387
}
388388
}
389389
}
@@ -480,17 +480,17 @@ struct ReservoirHandler : ResultHandlerCompare<C, with_id_map> {
480480
auto real_idx = this->adjust_id(b, j);
481481
lt_mask -= 1 << j;
482482
if (this->sel->is_member(real_idx)) {
483-
T dis = d32tab[j];
484-
res.add(dis, real_idx);
483+
T dis_2 = d32tab[j];
484+
res.add(dis_2, real_idx);
485485
}
486486
}
487487
} else {
488488
while (lt_mask) {
489489
// find first non-zero
490490
int j = __builtin_ctz(lt_mask);
491491
lt_mask -= 1 << j;
492-
T dis = d32tab[j];
493-
res.add(dis, this->adjust_id(b, j));
492+
T dis_2 = d32tab[j];
493+
res.add(dis_2, this->adjust_id(b, j));
494494
}
495495
}
496496
}
@@ -719,10 +719,10 @@ void dispatch_SIMDResultHandler_fixedCW(
719719
Types... args) {
720720
if (auto resh = dynamic_cast<SingleResultHandler<C, W>*>(&res)) {
721721
consumer.template f<SingleResultHandler<C, W>>(*resh, args...);
722-
} else if (auto resh = dynamic_cast<HeapHandler<C, W>*>(&res)) {
723-
consumer.template f<HeapHandler<C, W>>(*resh, args...);
724-
} else if (auto resh = dynamic_cast<ReservoirHandler<C, W>*>(&res)) {
725-
consumer.template f<ReservoirHandler<C, W>>(*resh, args...);
722+
} else if (auto resh_2 = dynamic_cast<HeapHandler<C, W>*>(&res)) {
723+
consumer.template f<HeapHandler<C, W>>(*resh_2, args...);
724+
} else if (auto resh_2 = dynamic_cast<ReservoirHandler<C, W>*>(&res)) {
725+
consumer.template f<ReservoirHandler<C, W>>(*resh_2, args...);
726726
} else { // generic handler -- will not be inlined
727727
FAISS_THROW_IF_NOT_FMT(
728728
simd_result_handlers_accept_virtual,
@@ -752,8 +752,8 @@ void dispatch_SIMDResultHandler(
752752
if (res.sizeof_ids == 0) {
753753
if (auto resh = dynamic_cast<StoreResultHandler*>(&res)) {
754754
consumer.template f<StoreResultHandler>(*resh, args...);
755-
} else if (auto resh = dynamic_cast<DummyResultHandler*>(&res)) {
756-
consumer.template f<DummyResultHandler>(*resh, args...);
755+
} else if (auto resh_2 = dynamic_cast<DummyResultHandler*>(&res)) {
756+
consumer.template f<DummyResultHandler>(*resh_2, args...);
757757
} else { // generic path
758758
FAISS_THROW_IF_NOT_FMT(
759759
simd_result_handlers_accept_virtual,

0 commit comments

Comments
 (0)