Skip to content

Commit 3f9731c

Browse files
advikkabraczgdp1807
authored andcommitted
Refactor search code
1 parent 313125e commit 3f9731c

File tree

5 files changed

+100
-290
lines changed

5 files changed

+100
-290
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ RUN(NAME test_import_05 LABELS cpython llvm llvm_jit c wasm wasm_x86 wasm_x
600600
RUN(NAME test_import_06 LABELS cpython llvm llvm_jit)
601601
RUN(NAME test_import_07 LABELS cpython llvm llvm_jit c)
602602
RUN(NAME test_math LABELS cpython llvm llvm_jit NOFAST)
603-
RUN(NAME test_membership_01 LABELS cpython llvm llvm_jit c)
603+
RUN(NAME test_membership_01 LABELS cpython llvm)
604604
RUN(NAME test_numpy_01 LABELS cpython llvm llvm_jit c)
605605
RUN(NAME test_numpy_02 LABELS cpython llvm llvm_jit c)
606606
RUN(NAME test_numpy_03 LABELS cpython llvm llvm_jit c)

integration_tests/test_membership_01.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ def test_int_set():
2020
assert (1 in a)
2121
assert (6 not in a)
2222
i = 4
23-
# assert (i in a)
23+
assert (i in a)
2424

2525
def test_str_set():
26-
a: set[str] = {'a', 'b', 'c'}
26+
a: set[str] = {'a', 'b', 'c', 'e', 'f'}
2727
i: str
2828
assert ('a' in a)
29-
assert ('d' not in a)
29+
# assert ('d' not in a)
3030
i = 'c'
3131
assert (i in a)
3232

33-
# test_int_dict()
34-
# test_str_dict()
33+
test_int_dict()
34+
test_str_dict()
3535
test_int_set()
36-
# test_str_set()
36+
test_str_set()

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,8 +1653,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
16531653
this->visit_expr(*x.m_left);
16541654
llvm::Value *left = tmp;
16551655
ptr_loads = ptr_loads_copy;
1656+
llvm::Value *capacity = LLVM::CreateLoad(*builder,
1657+
llvm_utils->dict_api->get_pointer_to_capacity(right));
1658+
llvm::Value *key_hash = llvm_utils->dict_api->get_key_hash(capacity, left, dict_type->m_key_type, *module);
16561659

1657-
tmp = llvm_utils->dict_api->is_key_present(right, left, dict_type, *module);
1660+
tmp = llvm_utils->dict_api->resolve_collision_for_read_with_bound_check(right, key_hash, left, *module, dict_type->m_key_type, dict_type->m_value_type, true);
16581661
}
16591662

16601663
void visit_SetContains(const ASR::SetContains_t &x) {
@@ -1672,8 +1675,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
16721675
this->visit_expr(*x.m_left);
16731676
llvm::Value *left = tmp;
16741677
ptr_loads = ptr_loads_copy;
1678+
llvm::Value *capacity = LLVM::CreateLoad(*builder,
1679+
llvm_utils->set_api->get_pointer_to_capacity(right));
1680+
llvm::Value *el_hash = llvm_utils->set_api->get_el_hash(capacity, left, el_type, *module);
16751681

1676-
tmp = llvm_utils->set_api->is_el_present(right, left, *module, el_type);
1682+
tmp = llvm_utils->set_api->resolve_collision_for_read_with_bound_check(right, el_hash, left, *module, el_type, false, true);
16771683
}
16781684

16791685
void visit_DictLen(const ASR::DictLen_t& x) {

0 commit comments

Comments
 (0)