Skip to content

Fix symbolic pass for handling IntrinsicElementalFunction in print() #2665

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

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 @@ -469,6 +469,7 @@ RUN(NAME print_list_tuple_01 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME print_list_tuple_02 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME print_list_tuple_03 LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_list_item_mixed_print LABELS cpython llvm llvm_jit c NOFAST)
RUN(NAME test_intrinsic_function_mixed_print LABELS cpython llvm llvm_jit NOFAST)

# CPython and LLVM
RUN(NAME const_01 LABELS cpython llvm llvm_jit c wasm)
Expand Down
25 changes: 25 additions & 0 deletions integration_tests/test_intrinsic_function_mixed_print.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from lpython import i32

def test_intrinsic_function_mixed_print():
# list and list methods
my_list: list[i32] = [1, 2, 3, 4, 5]
print("Popped element:", my_list.pop())
assert my_list == [1, 2, 3, 4]

print("1 is located at:", my_list.index(1))
assert my_list.index(1) == 0

my_list.append(2)
print("2 is present", my_list.count(2), "times")
assert my_list.count(2) == 2

print(my_list.pop(), my_list)
assert my_list == [1, 2, 3, 4]

# dict and dict methods
my_dict: dict[str, i32] = {"first": 1, "second": 2, "third": 3}
print("Keys:", my_dict.keys())
print("Value of 'third':", my_dict.pop("third"))
assert len(my_dict.keys()) == 2

test_intrinsic_function_mixed_print()
2 changes: 2 additions & 0 deletions src/libasr/pass/replace_symbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor<ReplaceSymbolicVisi
ASR::expr_t* function_call = process_attributes(x.base.base.loc, val);
print_tmp.push_back(function_call);
}
} else {
print_tmp.push_back(val);
}
} else if (ASR::is_a<ASR::Cast_t>(*val)) {
ASR::Cast_t* cast_t = ASR::down_cast<ASR::Cast_t>(val);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "runtime-test_intrinsic_function_mixed_print-a862825",
"cmd": "lpython {infile}",
"infile": "tests/../integration_tests/test_intrinsic_function_mixed_print.py",
"infile_hash": "b0f779598e5d9868d183f1032fb3f87c131fedacf7848aaed6c4d238",
"outfile": null,
"outfile_hash": null,
"stdout": "runtime-test_intrinsic_function_mixed_print-a862825.stdout",
"stdout_hash": "a8d2083be043accf4ebe8c6a3e8a2427d492323b12d0c041ba79f10e",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Popped element: 5
1 is located at: 0
2 is present 2 times
2 [1, 2, 3, 4]
Keys: ['second', 'third', 'first']
Value of 'third': 3
4 changes: 4 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ llvm = true
filename = "../integration_tests/test_list_item_mixed_print.py"
run = true

[[test]]
filename = "../integration_tests/test_intrinsic_function_mixed_print.py"
run = true

[[test]]
filename = "../integration_tests/generics_01.py"
asr = true
Expand Down