From a4255b37212399aa34fbe6aaebfe90b4cacdfe7d Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 25 Apr 2024 21:56:28 +0530 Subject: [PATCH 1/8] Fix symbolic pass for handling `IntrinsicElementalFunction` in `print()` --- src/libasr/pass/replace_symbolic.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 6e4aa5a7d2..567b5a686f 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -816,6 +816,8 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor(*val)) { ASR::Cast_t* cast_t = ASR::down_cast(val); From 5647cd5d77eba120dea15416675ce8ac4993d99e Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 25 Apr 2024 22:22:56 +0530 Subject: [PATCH 2/8] Tests: Add tests and update references --- integration_tests/CMakeLists.txt | 1 + .../test_intrinsic_function_mixed_print.py | 16 ++++++++++++++++ src/libasr/pass/replace_symbolic.cpp | 7 ++++--- ...intrinsic_function_mixed_print-a862825.json | 13 +++++++++++++ ...trinsic_function_mixed_print-a862825.stdout | 5 +++++ ...ime-test_list_item_mixed_print-a3fd49f.json | 2 +- ...e-test_list_item_mixed_print-a3fd49f.stdout | 18 +++++++++--------- tests/tests.toml | 4 ++++ 8 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 integration_tests/test_intrinsic_function_mixed_print.py create mode 100644 tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json create mode 100644 tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index d73d3520a3..682f8ed929 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -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 c NOFAST) # CPython and LLVM RUN(NAME const_01 LABELS cpython llvm llvm_jit c wasm) diff --git a/integration_tests/test_intrinsic_function_mixed_print.py b/integration_tests/test_intrinsic_function_mixed_print.py new file mode 100644 index 0000000000..81c66eaba9 --- /dev/null +++ b/integration_tests/test_intrinsic_function_mixed_print.py @@ -0,0 +1,16 @@ +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()) + print("1 is located at:", my_list.index(1)) + my_list.append(2) + print("2 is present", my_list.count(2), "times") + + # 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")) + +test_intrinsic_function_mixed_print() \ No newline at end of file diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 567b5a686f..c5deea5d93 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -849,9 +849,10 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor tmp_vec; diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json new file mode 100644 index 0000000000..d270b1b66f --- /dev/null +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json @@ -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": "15d9508261f2a05b2146780770d5d3cf25e6304568a497b4d7ab2e05", + "outfile": null, + "outfile_hash": null, + "stdout": "runtime-test_intrinsic_function_mixed_print-a862825.stdout", + "stdout_hash": "47e103dce40a4e7ab41c684afd71ae9565407a5631585fd58d6d18a4", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout new file mode 100644 index 0000000000..e68f63c060 --- /dev/null +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout @@ -0,0 +1,5 @@ +5 +0 +2 is present 2 times +['second', 'third', 'first'] +Value of 'third': 3 diff --git a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json index fde8aee79c..0ffe8e0828 100644 --- a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json +++ b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "runtime-test_list_item_mixed_print-a3fd49f.stdout", - "stdout_hash": "9d9a68fea29f11320efb0764ce38ed3d4090f64457b0f1eb10251a2b", + "stdout_hash": "baf7e613ab31bccc17acba1d6541e4da35dbb133e202ba5d0ebf0408", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout index a3f624820b..6f34ef5735 100644 --- a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout +++ b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout @@ -1,14 +1,14 @@ Hello -This isLPython -1 2 3 ... 3 4 5 -The first element is: 1 -The middle element is: 3 -3.14000000000000012e+00 * 2 = 6.28000000000000025e+00 +LPython +1 2 3 3 4 5 +1 +3 +3.14000000000000012e+00 6.28000000000000025e+00 Total: 9.41999999999999993e+00 -(1, 2, 3) is a tuple, but 1 is a number. +1 123 1 # 2 # 3 # 4 # 5 # -List 0 : [1, 2] -List 1 : [3, 4] -List 2 : [5, 6] +[1, 2] +[3, 4] +[5, 6] diff --git a/tests/tests.toml b/tests/tests.toml index 1f4706fd79..3e6589aef1 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -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 From 98383c62f8cc22ac92856a6661bd00392644807e Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 26 Apr 2024 07:44:45 +0530 Subject: [PATCH 3/8] Fix mistakenly commented out lines --- src/libasr/pass/replace_symbolic.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index c5deea5d93..52e84d783e 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -850,9 +850,9 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor tmp_vec; From 325600e9b14d6b55cdde82b3ce911c403f245346 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 26 Apr 2024 07:51:22 +0530 Subject: [PATCH 4/8] Tests: Add testcase and update references --- integration_tests/test_intrinsic_function_mixed_print.py | 1 + .../runtime-test_intrinsic_function_mixed_print-a862825.json | 4 ++-- ...runtime-test_intrinsic_function_mixed_print-a862825.stdout | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integration_tests/test_intrinsic_function_mixed_print.py b/integration_tests/test_intrinsic_function_mixed_print.py index 81c66eaba9..5689b85f79 100644 --- a/integration_tests/test_intrinsic_function_mixed_print.py +++ b/integration_tests/test_intrinsic_function_mixed_print.py @@ -7,6 +7,7 @@ def test_intrinsic_function_mixed_print(): print("1 is located at:", my_list.index(1)) my_list.append(2) print("2 is present", my_list.count(2), "times") + print(my_list.pop(), my_list) # dict and dict methods my_dict: dict[str, i32] = {"first": 1, "second": 2, "third": 3} diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json index d270b1b66f..1e9f7cb048 100644 --- a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json @@ -2,11 +2,11 @@ "basename": "runtime-test_intrinsic_function_mixed_print-a862825", "cmd": "lpython {infile}", "infile": "tests/../integration_tests/test_intrinsic_function_mixed_print.py", - "infile_hash": "15d9508261f2a05b2146780770d5d3cf25e6304568a497b4d7ab2e05", + "infile_hash": "eb30139022c49be86015547192341d98c3b05e74da74e17dc621bef3", "outfile": null, "outfile_hash": null, "stdout": "runtime-test_intrinsic_function_mixed_print-a862825.stdout", - "stdout_hash": "47e103dce40a4e7ab41c684afd71ae9565407a5631585fd58d6d18a4", + "stdout_hash": "523cab9cb106dd6e41fbabc12f303d93a8c042fc0c733db3d9204739", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout index e68f63c060..c9add59b7c 100644 --- a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout @@ -1,5 +1,6 @@ 5 0 2 is present 2 times +2 ['second', 'third', 'first'] Value of 'third': 3 From 07a9957101d4187202d36d19a97d34d2f3b4fb8d Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 26 Apr 2024 08:15:51 +0530 Subject: [PATCH 5/8] Tests: Update references --- ...intrinsic_function_mixed_print-a862825.json | 2 +- ...trinsic_function_mixed_print-a862825.stdout | 8 ++++---- ...ime-test_list_item_mixed_print-a3fd49f.json | 2 +- ...e-test_list_item_mixed_print-a3fd49f.stdout | 18 +++++++++--------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json index 1e9f7cb048..93b5ac8972 100644 --- a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "runtime-test_intrinsic_function_mixed_print-a862825.stdout", - "stdout_hash": "523cab9cb106dd6e41fbabc12f303d93a8c042fc0c733db3d9204739", + "stdout_hash": "a8d2083be043accf4ebe8c6a3e8a2427d492323b12d0c041ba79f10e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout index c9add59b7c..f0a5fb0724 100644 --- a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.stdout @@ -1,6 +1,6 @@ -5 -0 +Popped element: 5 +1 is located at: 0 2 is present 2 times -2 -['second', 'third', 'first'] +2 [1, 2, 3, 4] +Keys: ['second', 'third', 'first'] Value of 'third': 3 diff --git a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json index 0ffe8e0828..fde8aee79c 100644 --- a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json +++ b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "runtime-test_list_item_mixed_print-a3fd49f.stdout", - "stdout_hash": "baf7e613ab31bccc17acba1d6541e4da35dbb133e202ba5d0ebf0408", + "stdout_hash": "9d9a68fea29f11320efb0764ce38ed3d4090f64457b0f1eb10251a2b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout index 6f34ef5735..a3f624820b 100644 --- a/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout +++ b/tests/reference/runtime-test_list_item_mixed_print-a3fd49f.stdout @@ -1,14 +1,14 @@ Hello -LPython -1 2 3 3 4 5 -1 -3 -3.14000000000000012e+00 6.28000000000000025e+00 +This isLPython +1 2 3 ... 3 4 5 +The first element is: 1 +The middle element is: 3 +3.14000000000000012e+00 * 2 = 6.28000000000000025e+00 Total: 9.41999999999999993e+00 -1 +(1, 2, 3) is a tuple, but 1 is a number. 123 1 # 2 # 3 # 4 # 5 # -[1, 2] -[3, 4] -[5, 6] +List 0 : [1, 2] +List 1 : [3, 4] +List 2 : [5, 6] From 5ac67be2d2f5c66af627e2daddf9decc3f4a1eb0 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Fri, 26 Apr 2024 10:06:15 +0530 Subject: [PATCH 6/8] Style changes --- src/libasr/pass/replace_symbolic.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libasr/pass/replace_symbolic.cpp b/src/libasr/pass/replace_symbolic.cpp index 52e84d783e..567b5a686f 100644 --- a/src/libasr/pass/replace_symbolic.cpp +++ b/src/libasr/pass/replace_symbolic.cpp @@ -849,8 +849,7 @@ class ReplaceSymbolicVisitor : public PassUtils::PassVisitor Date: Sat, 27 Apr 2024 10:42:46 +0530 Subject: [PATCH 7/8] Remove C backend --- integration_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 682f8ed929..93da87d7ef 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -469,7 +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 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) From 1e157422d18488158986a530d73bb8efdd441c20 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sat, 27 Apr 2024 13:59:34 +0530 Subject: [PATCH 8/8] Tests: Add asserts and update test reference --- integration_tests/test_intrinsic_function_mixed_print.py | 8 ++++++++ ...ntime-test_intrinsic_function_mixed_print-a862825.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/integration_tests/test_intrinsic_function_mixed_print.py b/integration_tests/test_intrinsic_function_mixed_print.py index 5689b85f79..8c5ee2f32d 100644 --- a/integration_tests/test_intrinsic_function_mixed_print.py +++ b/integration_tests/test_intrinsic_function_mixed_print.py @@ -4,14 +4,22 @@ 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() \ No newline at end of file diff --git a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json index 93b5ac8972..4a4b853c8e 100644 --- a/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json +++ b/tests/reference/runtime-test_intrinsic_function_mixed_print-a862825.json @@ -2,7 +2,7 @@ "basename": "runtime-test_intrinsic_function_mixed_print-a862825", "cmd": "lpython {infile}", "infile": "tests/../integration_tests/test_intrinsic_function_mixed_print.py", - "infile_hash": "eb30139022c49be86015547192341d98c3b05e74da74e17dc621bef3", + "infile_hash": "b0f779598e5d9868d183f1032fb3f87c131fedacf7848aaed6c4d238", "outfile": null, "outfile_hash": null, "stdout": "runtime-test_intrinsic_function_mixed_print-a862825.stdout",