Skip to content

Commit dfeacbc

Browse files
kmr-srbhThirumalai-Shaktivelubaidsk
authored
Add support for item access from Const data-structures (#2579)
* Add support for accessing items from data-structures within `Const` * Update type checking logic for `Const dict` Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com> * Minor formatting change Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com> * Handle negative indices for `const list` and minor formatting changes * Add tests * Update test references * Heavily simplify handling `const` * Tests: Add compile time test * Remove calls to `type_get_past_const()` * Tests: Update test references * Remove extra newline Co-authored-by: Shaikh Ubaid <shaikhubaid769@gmail.com> * Delete tests/reference/asr-test_const_access-82a9a24.json * Delete tests/reference/asr-test_const_access-82a9a24.stdout * Delete tests/reference/asr-test_const_str_access-59ff543.stderr * Delete tests/reference/asr-test_const_tuple_access-0d4c6df.json * Delete tests/reference/asr-test_const_tuple_access-0d4c6df.stderr * Delete tests/reference/asr-test_const_str_access-59ff543.json * Formatting changes * Tests: Add test to CMakeLists and update error references * Update asr_to_llvm.cpp * Undo formatting changes * Undo formatting changes * Revert throwing error for `Const` annotated tuples and strings * Tests: Remove error references * Remove redundant visitor * Undo moving `index` --------- Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com> Co-authored-by: Shaikh Ubaid <shaikhubaid769@gmail.com>
1 parent a74d529 commit dfeacbc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ RUN(NAME test_list_compare LABELS cpython llvm llvm_jit)
556556
RUN(NAME test_list_concat LABELS cpython llvm llvm_jit c NOFAST)
557557
RUN(NAME test_list_reserve LABELS cpython llvm llvm_jit)
558558
RUN(NAME test_const_list LABELS cpython llvm llvm_jit)
559+
RUN(NAME test_const_access LABELS cpython llvm llvm_jit)
559560
RUN(NAME test_tuple_01 LABELS cpython llvm llvm_jit c)
560561
RUN(NAME test_tuple_02 LABELS cpython llvm llvm_jit c NOFAST)
561562
RUN(NAME test_tuple_03 LABELS cpython llvm llvm_jit c)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from lpython import i32, Const
2+
3+
CONST_LIST: Const[list[i32]] = [1, 2, 3, 4, 5]
4+
CONST_DICTIONARY: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3}
5+
6+
assert CONST_LIST[0] == 1
7+
assert CONST_LIST[-2] == 4
8+
9+
assert CONST_DICTIONARY["a"] == 1

0 commit comments

Comments
 (0)