Skip to content

Commit f3389e6

Browse files
authored
Merge pull request #2778 from advikkabra/set-args
Add support for in place sets and dictionaries in function calls
2 parents 81e2b1e + 4d91f3c commit f3389e6

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ RUN(NAME test_tuple_04 LABELS cpython llvm llvm_jit c)
569569
RUN(NAME test_tuple_concat LABELS cpython llvm llvm_jit)
570570
RUN(NAME test_tuple_nested LABELS cpython llvm llvm_jit)
571571
RUN(NAME test_const_dict LABELS cpython llvm llvm_jit)
572+
RUN(NAME test_params LABELS cpython llvm llvm_jit NOFAST)
572573
RUN(NAME test_dict_01 LABELS cpython llvm llvm_jit c)
573574
RUN(NAME test_dict_02 LABELS cpython llvm llvm_jit c NOFAST)
574575
RUN(NAME test_dict_03 LABELS cpython llvm llvm_jit NOFAST)

integration_tests/test_params.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from lpython import i32
2+
3+
def takes_set(a: set[i32]) -> set[i32]:
4+
return {1, 2, 3}
5+
6+
def takes_dict(a: dict[i32, i32]) -> dict[i32, i32]:
7+
return {1:1, 2:2}
8+
9+
s: set[i32] = takes_set({1, 2})
10+
11+
assert len(s) == 3
12+
13+
w: dict[i32, i32] = takes_dict({1:1, 2:2})
14+
assert len(w) == 2

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8859,6 +8859,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
88598859
target_type = llvm_utils->get_type_from_ttype_t_util(arg_type_, module.get());
88608860
break;
88618861
}
8862+
case (ASR::ttypeType::Dict): {
8863+
target_type = llvm_utils->get_type_from_ttype_t_util(arg_type_, module.get());
8864+
break;
8865+
}
8866+
case (ASR::ttypeType::Set): {
8867+
target_type = llvm_utils->get_type_from_ttype_t_util(arg_type_, module.get());
8868+
break;
8869+
}
88628870
default :
88638871
throw CodeGenError("Type " + ASRUtils::type_to_str(arg_type) + " not implemented yet.");
88648872
}
@@ -8913,7 +8921,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
89138921
llvm::AllocaInst *target = builder0.CreateAlloca(
89148922
target_type, nullptr, "call_arg_value");
89158923
if( ASR::is_a<ASR::Tuple_t>(*arg_type) ||
8916-
ASR::is_a<ASR::List_t>(*arg_type) ) {
8924+
ASR::is_a<ASR::List_t>(*arg_type) ||
8925+
ASR::is_a<ASR::Set_t>(*arg_type) ||
8926+
ASR::is_a<ASR::Dict_t>(*arg_type)) {
89178927
llvm_utils->deepcopy(value, target, arg_type, module.get(), name2memidx);
89188928
} else {
89198929
builder->CreateStore(value, target);

0 commit comments

Comments
 (0)