Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for in place sets and dictionaries in function calls #2778

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ RUN(NAME test_tuple_04 LABELS cpython llvm llvm_jit c)
RUN(NAME test_tuple_concat LABELS cpython llvm llvm_jit)
RUN(NAME test_tuple_nested LABELS cpython llvm llvm_jit)
RUN(NAME test_const_dict LABELS cpython llvm llvm_jit)
RUN(NAME test_params LABELS cpython llvm llvm_jit NOFAST)
RUN(NAME test_dict_01 LABELS cpython llvm llvm_jit c)
RUN(NAME test_dict_02 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_dict_03 LABELS cpython llvm llvm_jit NOFAST)
Expand Down
14 changes: 14 additions & 0 deletions integration_tests/test_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from lpython import i32

def takes_set(a: set[i32]) -> set[i32]:
return {1, 2, 3}

def takes_dict(a: dict[i32, i32]) -> dict[i32, i32]:
return {1:1, 2:2}

s: set[i32] = takes_set({1, 2})

assert len(s) == 3

w: dict[i32, i32] = takes_dict({1:1, 2:2})
assert len(w) == 2
12 changes: 11 additions & 1 deletion src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8859,6 +8859,14 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
target_type = llvm_utils->get_type_from_ttype_t_util(arg_type_, module.get());
break;
}
case (ASR::ttypeType::Dict): {
target_type = llvm_utils->get_type_from_ttype_t_util(arg_type_, module.get());
break;
}
case (ASR::ttypeType::Set): {
target_type = llvm_utils->get_type_from_ttype_t_util(arg_type_, module.get());
break;
}
default :
throw CodeGenError("Type " + ASRUtils::type_to_str(arg_type) + " not implemented yet.");
}
Expand Down Expand Up @@ -8913,7 +8921,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm::AllocaInst *target = builder0.CreateAlloca(
target_type, nullptr, "call_arg_value");
if( ASR::is_a<ASR::Tuple_t>(*arg_type) ||
ASR::is_a<ASR::List_t>(*arg_type) ) {
ASR::is_a<ASR::List_t>(*arg_type) ||
ASR::is_a<ASR::Set_t>(*arg_type) ||
ASR::is_a<ASR::Dict_t>(*arg_type)) {
llvm_utils->deepcopy(value, target, arg_type, module.get(), name2memidx);
} else {
builder->CreateStore(value, target);
Expand Down
Loading