From 1ec15d5b8fdb7a09d405c79af748bd3b1be4d85e Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 3 Mar 2024 10:54:24 +0530 Subject: [PATCH 01/18] Implement `append`, `remove`, `reverse`, `pop`, `clear` and `insert` --- src/libasr/pass/intrinsic_function_registry.h | 15 ++++++----- src/lpython/semantics/python_attribute_eval.h | 26 +++++++++++++++++-- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 2fca01651d..f1d50a7733 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2520,12 +2520,15 @@ namespace ListIndex { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args <= 4, "Call to list.index must have at most four arguments", x.base.base.loc, diagnostics); - ASRUtils::require_impl(ASR::is_a(*ASRUtils::expr_type(x.m_args[0])) && - ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]))), - "First argument to list.index must be of list type and " - "second argument must be of same type as list elemental type", - x.base.base.loc, diagnostics); + ASR::ttype_t *list_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])) + : ASRUtils::expr_type(x.m_args[0]); + ASRUtils::require_impl(ASR::is_a(*list_type)) && + ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), + ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]))), + "First argument to list.index must be of list type and " + "second argument must be of same type as list elemental type", + x.base.base.loc, diagnostics); if(x.n_args >= 3) { ASRUtils::require_impl( ASR::is_a(*ASRUtils::expr_type(x.m_args[2])), diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 1aab45b379..7cc6944fdc 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -67,7 +67,9 @@ struct AttributeHandler { ASR::asr_t* get_attribute(ASR::expr_t *e, std::string attr_name, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - ASR::ttype_t *type = ASRUtils::expr_type(e); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(e)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(e)) + : ASRUtils::expr_type(e); std::string class_name = get_type_name(type); if (class_name == "") { throw SemanticError("Type name is not implemented yet.", loc); @@ -124,6 +126,9 @@ struct AttributeHandler { static ASR::asr_t* eval_list_append(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + throw SemanticError("cannot append element to a const list", loc); + } if (args.size() != 1) { throw SemanticError("append() takes exactly one argument", loc); @@ -148,6 +153,9 @@ struct AttributeHandler { static ASR::asr_t* eval_list_remove(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + throw SemanticError("cannot remove element from a const list", loc); + } if (args.size() != 1) { throw SemanticError("remove() takes exactly one argument", loc); @@ -176,7 +184,9 @@ struct AttributeHandler { throw SemanticError("count() takes exactly one argument", loc); } - ASR::ttype_t *type = ASRUtils::expr_type(s); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(e)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(e)) + : ASRUtils::expr_type(e); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); if (!ASRUtils::check_equal_type(ele_type, list_type)) { @@ -211,6 +221,9 @@ struct AttributeHandler { static ASR::asr_t* eval_list_reverse(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &/*diag*/) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + throw SemanticError("cannot reverse a const list", loc); + } Vec args_with_list; args_with_list.reserve(al, args.size() + 1); args_with_list.push_back(al, s); @@ -225,6 +238,9 @@ struct AttributeHandler { static ASR::asr_t* eval_list_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &/*diag*/) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + throw SemanticError("cannot pop element from a const list", loc); + } Vec args_with_list; args_with_list.reserve(al, args.size() + 1); args_with_list.push_back(al, s); @@ -239,6 +255,9 @@ struct AttributeHandler { static ASR::asr_t* eval_list_insert(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + throw SemanticError("cannot insert element in a const list", loc); + } if (args.size() != 2) { throw SemanticError("insert() takes exactly two arguments", loc); @@ -270,6 +289,9 @@ struct AttributeHandler { static ASR::asr_t* eval_list_clear(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics & diag) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + throw SemanticError("cannot clear elements from a const list", loc); + } if (args.size() != 0) { diag.add(diag::Diagnostic( "Incorrect number of arguments in 'clear', it accepts no argument", From 46975a289ffdea3cea3b7ab883da25a6c8c6f7db Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 3 Mar 2024 13:41:57 +0530 Subject: [PATCH 02/18] Implement `count` and `index` --- src/libasr/codegen/asr_to_llvm.cpp | 8 ++++++-- src/libasr/pass/intrinsic_function_registry.h | 10 ++++++---- src/lpython/semantics/python_attribute_eval.h | 8 ++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index d5af2946f7..eb6f5c83f4 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1729,7 +1729,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListCount(const ASR::ListCount_t& x) { - ASR::ttype_t* asr_el_type = ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_arg)); + ASR::ttype_t *asr_el_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_arg)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_arg))) + : ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_arg)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_arg); @@ -1744,7 +1746,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void generate_ListIndex(ASR::expr_t* m_arg, ASR::expr_t* m_ele, ASR::expr_t* m_start=nullptr, ASR::expr_t* m_end=nullptr) { - ASR::ttype_t* asr_el_type = ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg)); + ASR::ttype_t *asr_el_type = ASRUtils::type_to_str(ASRUtils::expr_type(m_arg)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg))) + : ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*m_arg); diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index f1d50a7733..becbbdfd86 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2523,9 +2523,9 @@ static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Di ASR::ttype_t *list_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "list const" ? ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])) : ASRUtils::expr_type(x.m_args[0]); - ASRUtils::require_impl(ASR::is_a(*list_type)) && + ASRUtils::require_impl(ASR::is_a(*list_type) && ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]))), + ASRUtils::get_contained_type(list_type)), "First argument to list.index must be of list type and " "second argument must be of same type as list elemental type", x.base.base.loc, diagnostics); @@ -2558,9 +2558,11 @@ static inline ASR::asr_t* create_ListIndex(Allocator& al, const Location& loc, const std::function err) { int64_t overload_id = 0; ASR::expr_t* list_expr = args[0]; - ASR::ttype_t *type = ASRUtils::expr_type(list_expr); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(list_expr)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(list_expr)) + : ASRUtils::expr_type(list_expr); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; - ASR::ttype_t *ele_type = ASRUtils::expr_type(args[1]); + ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); if (!ASRUtils::check_equal_type(ele_type, list_type)) { std::string fnd = ASRUtils::get_type_code(ele_type); std::string org = ASRUtils::get_type_code(list_type); diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 7cc6944fdc..17d3c18b71 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -184,11 +184,11 @@ struct AttributeHandler { throw SemanticError("count() takes exactly one argument", loc); } - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(e)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(e)) - : ASRUtils::expr_type(e); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(s)) + : ASRUtils::expr_type(s); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; - ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); + ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); if (!ASRUtils::check_equal_type(ele_type, list_type)) { std::string fnd = ASRUtils::type_to_str_python(ele_type); std::string org = ASRUtils::type_to_str_python(list_type); From e8789f5affa0e7d9ad0865c8102c2ba056e73fc4 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Mar 2024 09:59:35 +0530 Subject: [PATCH 03/18] Improve checking for `Const` type --- src/libasr/codegen/asr_to_llvm.cpp | 8 ++++---- src/libasr/pass/intrinsic_function_registry.h | 8 ++++---- src/lpython/semantics/python_attribute_eval.h | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index eb6f5c83f4..d389028431 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1729,8 +1729,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListCount(const ASR::ListCount_t& x) { - ASR::ttype_t *asr_el_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_arg)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_arg))) + ASR::ttype_t *asr_el_type = ASR::is_a(*ASRUtils::expr_type(x.m_arg)) + ? ASRUtils::get_contained_type(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_arg))) : ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_arg)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; @@ -1746,8 +1746,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void generate_ListIndex(ASR::expr_t* m_arg, ASR::expr_t* m_ele, ASR::expr_t* m_start=nullptr, ASR::expr_t* m_end=nullptr) { - ASR::ttype_t *asr_el_type = ASRUtils::type_to_str(ASRUtils::expr_type(m_arg)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg))) + ASR::ttype_t *asr_el_type = ASR::is_a(*ASRUtils::expr_type(m_arg)) + ? ASRUtils::get_contained_type(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))) : ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index becbbdfd86..a1bb3eb1eb 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2520,8 +2520,8 @@ namespace ListIndex { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args <= 4, "Call to list.index must have at most four arguments", x.base.base.loc, diagnostics); - ASR::ttype_t *list_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])) + ASR::ttype_t *list_type = ASR::is_a(*ASRUtils::expr_type(x.m_args[0])) + ? ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_args[0])) : ASRUtils::expr_type(x.m_args[0]); ASRUtils::require_impl(ASR::is_a(*list_type) && ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), @@ -2558,8 +2558,8 @@ static inline ASR::asr_t* create_ListIndex(Allocator& al, const Location& loc, const std::function err) { int64_t overload_id = 0; ASR::expr_t* list_expr = args[0]; - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(list_expr)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(list_expr)) + ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(list_expr)) + ? ASRUtils::type_get_past_const(ASRUtils::expr_type(list_expr)) : ASRUtils::expr_type(list_expr); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 17d3c18b71..e9cbec7b90 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -67,8 +67,8 @@ struct AttributeHandler { ASR::asr_t* get_attribute(ASR::expr_t *e, std::string attr_name, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(e)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(e)) + ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(e)) + ? ASRUtils::type_get_past_const(ASRUtils::expr_type(e)) : ASRUtils::expr_type(e); std::string class_name = get_type_name(type); if (class_name == "") { @@ -126,7 +126,7 @@ struct AttributeHandler { static ASR::asr_t* eval_list_append(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot append element to a const list", loc); } if (args.size() != 1) { @@ -153,7 +153,7 @@ struct AttributeHandler { static ASR::asr_t* eval_list_remove(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot remove element from a const list", loc); } if (args.size() != 1) { @@ -184,8 +184,8 @@ struct AttributeHandler { throw SemanticError("count() takes exactly one argument", loc); } - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(s)) + ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(s)) + ? ASRUtils::type_get_past_const(ASRUtils::expr_type(s)) : ASRUtils::expr_type(s); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); @@ -221,7 +221,7 @@ struct AttributeHandler { static ASR::asr_t* eval_list_reverse(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &/*diag*/) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot reverse a const list", loc); } Vec args_with_list; @@ -238,7 +238,7 @@ struct AttributeHandler { static ASR::asr_t* eval_list_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &/*diag*/) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot pop element from a const list", loc); } Vec args_with_list; @@ -255,7 +255,7 @@ struct AttributeHandler { static ASR::asr_t* eval_list_insert(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot insert element in a const list", loc); } if (args.size() != 2) { @@ -289,7 +289,7 @@ struct AttributeHandler { static ASR::asr_t* eval_list_clear(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics & diag) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "list const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot clear elements from a const list", loc); } if (args.size() != 0) { From d4d0952fe55e71f94cca083771a805f7d1584e77 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Mar 2024 15:22:16 +0530 Subject: [PATCH 04/18] Simplify type checking for `Const` --- src/libasr/codegen/asr_to_llvm.cpp | 8 ++------ src/libasr/pass/intrinsic_function_registry.h | 8 ++------ src/lpython/semantics/python_attribute_eval.h | 8 ++------ 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index d389028431..1e1560339a 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1729,9 +1729,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListCount(const ASR::ListCount_t& x) { - ASR::ttype_t *asr_el_type = ASR::is_a(*ASRUtils::expr_type(x.m_arg)) - ? ASRUtils::get_contained_type(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_arg))) - : ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_arg)); + ASR::ttype_t *asr_el_type = ASRUtils::get_contained_type(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_arg))); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_arg); @@ -1746,9 +1744,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor void generate_ListIndex(ASR::expr_t* m_arg, ASR::expr_t* m_ele, ASR::expr_t* m_start=nullptr, ASR::expr_t* m_end=nullptr) { - ASR::ttype_t *asr_el_type = ASR::is_a(*ASRUtils::expr_type(m_arg)) - ? ASRUtils::get_contained_type(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))) - : ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg)); + ASR::ttype_t *asr_el_type = ASRUtils::get_contained_type(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*m_arg); diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index a1bb3eb1eb..7adb0fd07f 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2520,9 +2520,7 @@ namespace ListIndex { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args <= 4, "Call to list.index must have at most four arguments", x.base.base.loc, diagnostics); - ASR::ttype_t *list_type = ASR::is_a(*ASRUtils::expr_type(x.m_args[0])) - ? ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_args[0])) - : ASRUtils::expr_type(x.m_args[0]); + ASR::ttype_t *list_type = ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_args[0])); ASRUtils::require_impl(ASR::is_a(*list_type) && ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), ASRUtils::get_contained_type(list_type)), @@ -2558,9 +2556,7 @@ static inline ASR::asr_t* create_ListIndex(Allocator& al, const Location& loc, const std::function err) { int64_t overload_id = 0; ASR::expr_t* list_expr = args[0]; - ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(list_expr)) - ? ASRUtils::type_get_past_const(ASRUtils::expr_type(list_expr)) - : ASRUtils::expr_type(list_expr); + ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(list_expr)); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); if (!ASRUtils::check_equal_type(ele_type, list_type)) { diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index e9cbec7b90..2b2e64a2ec 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -67,9 +67,7 @@ struct AttributeHandler { ASR::asr_t* get_attribute(ASR::expr_t *e, std::string attr_name, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(e)) - ? ASRUtils::type_get_past_const(ASRUtils::expr_type(e)) - : ASRUtils::expr_type(e); + ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(e)); std::string class_name = get_type_name(type); if (class_name == "") { throw SemanticError("Type name is not implemented yet.", loc); @@ -184,9 +182,7 @@ struct AttributeHandler { throw SemanticError("count() takes exactly one argument", loc); } - ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(s)) - ? ASRUtils::type_get_past_const(ASRUtils::expr_type(s)) - : ASRUtils::expr_type(s); + ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(s)); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); if (!ASRUtils::check_equal_type(ele_type, list_type)) { From aba1177cdee664fd8e48f2103ac1b31c340d3b66 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sat, 9 Mar 2024 20:39:40 +0530 Subject: [PATCH 05/18] Update test references --- .../asr-test_list_count-4b42498.json | 10 +- .../asr-test_list_count-4b42498.stdout | 117 ++++++++++++++++++ 2 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 tests/reference/asr-test_list_count-4b42498.stdout diff --git a/tests/reference/asr-test_list_count-4b42498.json b/tests/reference/asr-test_list_count-4b42498.json index f4864b55fb..e81357ef04 100644 --- a/tests/reference/asr-test_list_count-4b42498.json +++ b/tests/reference/asr-test_list_count-4b42498.json @@ -5,9 +5,9 @@ "infile_hash": "01975bd7c4bba02fd811de536b218167da99b532fa955b7bf8339779", "outfile": null, "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "asr-test_list_count-4b42498.stderr", - "stderr_hash": "f26efcc623b68ca43ef871eb01c8e3cbd1ae464baaa491c6e4969696", - "returncode": 2 + "stdout": "asr-test_list_count-4b42498.stdout", + "stdout_hash": "ebd75d7827b11fc01b497b61de99801051d36fe38fb2353a83eac7fa", + "stderr": null, + "stderr_hash": null, + "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/asr-test_list_count-4b42498.stdout b/tests/reference/asr-test_list_count-4b42498.stdout new file mode 100644 index 0000000000..f78bcd64b9 --- /dev/null +++ b/tests/reference/asr-test_list_count-4b42498.stdout @@ -0,0 +1,117 @@ +(TranslationUnit + (SymbolTable + 1 + { + __main__: + (Module + (SymbolTable + 2 + { + test_list_count_error: + (Function + (SymbolTable + 3 + { + __lcompilers_dummy: + (Variable + 3 + __lcompilers_dummy + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ), + a: + (Variable + 3 + a + [] + Local + () + () + Default + (List + (Integer 4) + ) + () + Source + Public + Required + .false. + ) + }) + test_list_count_error + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + .false. + ) + [] + [] + [(= + (Var 3 a) + (ListConstant + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4))] + (List + (Integer 4) + ) + ) + () + ) + (= + (Var 3 __lcompilers_dummy) + (ListCount + (Var 3 a) + (RealConstant + 1.000000 + (Real 8) + ) + (Integer 4) + () + ) + () + )] + () + Public + .false. + .false. + () + ) + }) + __main__ + [] + .false. + .false. + ), + main_program: + (Program + (SymbolTable + 4 + { + + }) + main_program + [] + [] + ) + }) + [] +) From 3798cbc702125bc7caa24876906336d86c209d9a Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 09:07:57 +0530 Subject: [PATCH 06/18] Add tests --- integration_tests/test_list_const.py | 15 +++++++++++++++ tests/errors/test_list_const.py | 12 ++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 integration_tests/test_list_const.py create mode 100644 tests/errors/test_list_const.py diff --git a/integration_tests/test_list_const.py b/integration_tests/test_list_const.py new file mode 100644 index 0000000000..b9eb7e5423 --- /dev/null +++ b/integration_tests/test_list_const.py @@ -0,0 +1,15 @@ +from lpython import i32, i64, f32, f64, dict, list, tuple, str, Const, c64 + + +def test_list_const(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + assert CONST_INTEGER_LIST.count(1) == 2 + assert CONST_INTEGER_LIST.index(1) == 0 + + CONST_STRING_LIST: Const[list[str]] = ["ALPHA", "BETA", "RELEASE"] + assert CONST_STRING_LIST.count("ALPHA") == 1 + assert CONST_STRING_LIST.index("RELEASE") == 2 + + +test_list_const() diff --git a/tests/errors/test_list_const.py b/tests/errors/test_list_const.py new file mode 100644 index 0000000000..d17a63aebc --- /dev/null +++ b/tests/errors/test_list_const.py @@ -0,0 +1,12 @@ +def test_list_const(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.append(6) + CONST_INTEGER_LIST.insert(3, 8) + CONST_INTEGER_LIST.reverse() + CONST_INTEGER_LIST.pop() + CONST_INTEGER_LIST.pop(0) + CONST_INTEGER_LIST.clear() + CONST_INTEGER_LIST.remove(1) + + From 4d191dd363b1a5779c4d4977a8373841aba9e3fb Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 09:10:40 +0530 Subject: [PATCH 07/18] Update test --- tests/errors/test_list_const.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/errors/test_list_const.py b/tests/errors/test_list_const.py index d17a63aebc..330f303cef 100644 --- a/tests/errors/test_list_const.py +++ b/tests/errors/test_list_const.py @@ -1,3 +1,5 @@ +from lpython import i32, list, Const + def test_list_const(): CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] @@ -9,4 +11,4 @@ def test_list_const(): CONST_INTEGER_LIST.clear() CONST_INTEGER_LIST.remove(1) - +test_list_const() From 3549a5dcbb53d87b9a0030ff87f1b63c7bddca65 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 13:01:21 +0530 Subject: [PATCH 08/18] Update error test references --- .../asr-test_list_const-4ffce80.json | 13 + .../asr-test_list_const-4ffce80.stdout | 270 ++++++++++++++++++ .../asr-test_list_const-7b77194.json | 13 + .../asr-test_list_const-7b77194.stderr | 5 + tests/tests.toml | 8 + 5 files changed, 309 insertions(+) create mode 100644 tests/reference/asr-test_list_const-4ffce80.json create mode 100644 tests/reference/asr-test_list_const-4ffce80.stdout create mode 100644 tests/reference/asr-test_list_const-7b77194.json create mode 100644 tests/reference/asr-test_list_const-7b77194.stderr diff --git a/tests/reference/asr-test_list_const-4ffce80.json b/tests/reference/asr-test_list_const-4ffce80.json new file mode 100644 index 0000000000..d707248f23 --- /dev/null +++ b/tests/reference/asr-test_list_const-4ffce80.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_list_const-4ffce80", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_list_const.py", + "infile_hash": "f2918a01e7e8a190f97d10ae208627d34944ee9d57aa98e01a239d1d", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_list_const-4ffce80.stdout", + "stdout_hash": "1f4d504cea56850fcaa47eac751b413ce6644e36da970c1a1ad26289", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_list_const-4ffce80.stdout b/tests/reference/asr-test_list_const-4ffce80.stdout new file mode 100644 index 0000000000..d57c133ec6 --- /dev/null +++ b/tests/reference/asr-test_list_const-4ffce80.stdout @@ -0,0 +1,270 @@ +(TranslationUnit + (SymbolTable + 1 + { + __main__: + (Module + (SymbolTable + 2 + { + __main__global_stmts: + (Function + (SymbolTable + 4 + { + + }) + __main__global_stmts + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + .false. + ) + [test_list_const] + [] + [(SubroutineCall + 2 test_list_const + () + [] + () + )] + () + Public + .false. + .false. + () + ), + test_list_const: + (Function + (SymbolTable + 3 + { + CONST_INTEGER_LIST: + (Variable + 3 + CONST_INTEGER_LIST + [] + Local + (ListConstant + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4)) + (IntegerConstant 4 (Integer 4)) + (IntegerConstant 5 (Integer 4)) + (IntegerConstant 1 (Integer 4))] + (List + (Integer 4) + ) + ) + (ListConstant + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4)) + (IntegerConstant 4 (Integer 4)) + (IntegerConstant 5 (Integer 4)) + (IntegerConstant 1 (Integer 4))] + (List + (Integer 4) + ) + ) + Parameter + (Const + (List + (Integer 4) + ) + ) + () + Source + Public + Required + .false. + ), + CONST_STRING_LIST: + (Variable + 3 + CONST_STRING_LIST + [] + Local + (ListConstant + [(StringConstant + "ALPHA" + (Character 1 5 ()) + ) + (StringConstant + "BETA" + (Character 1 4 ()) + ) + (StringConstant + "RELEASE" + (Character 1 7 ()) + )] + (List + (Character 1 5 ()) + ) + ) + (ListConstant + [(StringConstant + "ALPHA" + (Character 1 5 ()) + ) + (StringConstant + "BETA" + (Character 1 4 ()) + ) + (StringConstant + "RELEASE" + (Character 1 7 ()) + )] + (List + (Character 1 5 ()) + ) + ) + Parameter + (Const + (List + (Character 1 -2 ()) + ) + ) + () + Source + Public + Required + .false. + ) + }) + test_list_const + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + .false. + ) + [] + [] + [(Assert + (IntegerCompare + (ListCount + (Var 3 CONST_INTEGER_LIST) + (IntegerConstant 1 (Integer 4)) + (Integer 4) + () + ) + Eq + (IntegerConstant 2 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (IntegerCompare + (IntrinsicScalarFunction + ListIndex + [(Var 3 CONST_INTEGER_LIST) + (IntegerConstant 1 (Integer 4))] + 0 + (Integer 4) + () + ) + Eq + (IntegerConstant 0 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (IntegerCompare + (ListCount + (Var 3 CONST_STRING_LIST) + (StringConstant + "ALPHA" + (Character 1 5 ()) + ) + (Integer 4) + () + ) + Eq + (IntegerConstant 1 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (IntegerCompare + (IntrinsicScalarFunction + ListIndex + [(Var 3 CONST_STRING_LIST) + (StringConstant + "RELEASE" + (Character 1 7 ()) + )] + 0 + (Integer 4) + () + ) + Eq + (IntegerConstant 2 (Integer 4)) + (Logical 4) + () + ) + () + )] + () + Public + .false. + .false. + () + ) + }) + __main__ + [] + .false. + .false. + ), + main_program: + (Program + (SymbolTable + 5 + { + __main__global_stmts: + (ExternalSymbol + 5 + __main__global_stmts + 2 __main__global_stmts + __main__ + [] + __main__global_stmts + Public + ) + }) + main_program + [__main__] + [(SubroutineCall + 5 __main__global_stmts + 2 __main__global_stmts + [] + () + )] + ) + }) + [] +) diff --git a/tests/reference/asr-test_list_const-7b77194.json b/tests/reference/asr-test_list_const-7b77194.json new file mode 100644 index 0000000000..6eea12bb5f --- /dev/null +++ b/tests/reference/asr-test_list_const-7b77194.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_list_const-7b77194", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_list_const.py", + "infile_hash": "794f98a9e575bf64082d76c78f2466bf023c8b3f9432fdf3ec8fe866", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_list_const-7b77194.stderr", + "stderr_hash": "d18d6fde09df77a8af0b7b1f15e05aeb6b02e79c62ab97c5af79305d", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_list_const-7b77194.stderr b/tests/reference/asr-test_list_const-7b77194.stderr new file mode 100644 index 0000000000..8aaf7efa45 --- /dev/null +++ b/tests/reference/asr-test_list_const-7b77194.stderr @@ -0,0 +1,5 @@ +semantic error: cannot append element to a const list + --> tests/errors/test_list_const.py:6:5 + | +6 | CONST_INTEGER_LIST.append(6) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/tests.toml b/tests/tests.toml index ea687ca0b0..a43ca76444 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -488,6 +488,10 @@ asr = true filename = "../integration_tests/global_syms_01.py" asr = true +[[test]] +filename = "../integration_tests/test_list_const.py" +asr = true + [[test]] filename = "cast.py" asr = true @@ -828,6 +832,10 @@ asr = true filename = "errors/test_list_slicing.py" asr = true +[[test]] +filename = "errors/test_list_const.py" +asr = true + [[test]] filename = "errors/test_annassign_01.py" asr = true From cf327c24941747c6b26e5b642c11140ceaa65ef1 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 13:18:24 +0530 Subject: [PATCH 09/18] Update error test references --- .../reference/runtime-test_list_const-0ca4829.json | 13 +++++++++++++ .../runtime-test_list_const-0ca4829.stderr | 5 +++++ tests/tests.toml | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/reference/runtime-test_list_const-0ca4829.json create mode 100644 tests/reference/runtime-test_list_const-0ca4829.stderr diff --git a/tests/reference/runtime-test_list_const-0ca4829.json b/tests/reference/runtime-test_list_const-0ca4829.json new file mode 100644 index 0000000000..ff13081949 --- /dev/null +++ b/tests/reference/runtime-test_list_const-0ca4829.json @@ -0,0 +1,13 @@ +{ + "basename": "runtime-test_list_const-0ca4829", + "cmd": "lpython {infile}", + "infile": "tests/errors/test_list_const.py", + "infile_hash": "794f98a9e575bf64082d76c78f2466bf023c8b3f9432fdf3ec8fe866", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "runtime-test_list_const-0ca4829.stderr", + "stderr_hash": "be9de860495ffefe5254883bbf042bf04f698ea68e76516dc98fdbff", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/runtime-test_list_const-0ca4829.stderr b/tests/reference/runtime-test_list_const-0ca4829.stderr new file mode 100644 index 0000000000..8c393dce1a --- /dev/null +++ b/tests/reference/runtime-test_list_const-0ca4829.stderr @@ -0,0 +1,5 @@ +semantic error: cannot append element to a const list + --> tests/errors/test_list_const.py:6:5 + | +6 | CONST_INTEGER_LIST.append(6) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  diff --git a/tests/tests.toml b/tests/tests.toml index a43ca76444..dcff3d18f3 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -834,7 +834,7 @@ asr = true [[test]] filename = "errors/test_list_const.py" -asr = true +run = true [[test]] filename = "errors/test_annassign_01.py" From 842bf4ce674c4c052bfbe87d694f1da55dd6d0f2 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Sun, 10 Mar 2024 14:03:27 +0530 Subject: [PATCH 10/18] Update tests/tests.toml Co-authored-by: Shaikh Ubaid --- tests/tests.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests.toml b/tests/tests.toml index dcff3d18f3..a43ca76444 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -834,7 +834,7 @@ asr = true [[test]] filename = "errors/test_list_const.py" -run = true +asr = true [[test]] filename = "errors/test_annassign_01.py" From 6841437891ef0be576b58620bf92cd4c7432fb31 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 15:02:10 +0530 Subject: [PATCH 11/18] Tests: Update tests and test references --- integration_tests/CMakeLists.txt | 1 + ...{test_list_const.py => test_const_list.py} | 6 ++--- tests/errors/test_const_list_append.py | 10 +++++++ tests/errors/test_const_list_clear.py | 10 +++++++ tests/errors/test_const_list_insert.py | 10 +++++++ tests/errors/test_const_list_pop.py | 10 +++++++ tests/errors/test_const_list_remove.py | 10 +++++++ tests/errors/test_const_list_reverse.py | 10 +++++++ tests/errors/test_list_const.py | 14 ---------- .../asr-test_const_list_append-ada1ade.json | 13 ++++++++++ .../asr-test_const_list_append-ada1ade.stderr | 5 ++++ .../asr-test_const_list_clear-33bfae7.json | 13 ++++++++++ .../asr-test_const_list_clear-33bfae7.stderr | 5 ++++ .../asr-test_const_list_insert-4c81295.json | 13 ++++++++++ .../asr-test_const_list_insert-4c81295.stderr | 5 ++++ .../asr-test_const_list_pop-568b207.json | 13 ++++++++++ .../asr-test_const_list_pop-568b207.stderr | 5 ++++ .../asr-test_const_list_remove-c5deb20.json | 13 ++++++++++ .../asr-test_const_list_remove-c5deb20.stderr | 5 ++++ .../asr-test_const_list_reverse-2df1a6f.json | 13 ++++++++++ ...asr-test_const_list_reverse-2df1a6f.stderr | 5 ++++ tests/tests.toml | 26 +++++++++++++++---- 22 files changed, 193 insertions(+), 22 deletions(-) rename integration_tests/{test_list_const.py => test_const_list.py} (73%) create mode 100644 tests/errors/test_const_list_append.py create mode 100644 tests/errors/test_const_list_clear.py create mode 100644 tests/errors/test_const_list_insert.py create mode 100644 tests/errors/test_const_list_pop.py create mode 100644 tests/errors/test_const_list_remove.py create mode 100644 tests/errors/test_const_list_reverse.py delete mode 100644 tests/errors/test_list_const.py create mode 100644 tests/reference/asr-test_const_list_append-ada1ade.json create mode 100644 tests/reference/asr-test_const_list_append-ada1ade.stderr create mode 100644 tests/reference/asr-test_const_list_clear-33bfae7.json create mode 100644 tests/reference/asr-test_const_list_clear-33bfae7.stderr create mode 100644 tests/reference/asr-test_const_list_insert-4c81295.json create mode 100644 tests/reference/asr-test_const_list_insert-4c81295.stderr create mode 100644 tests/reference/asr-test_const_list_pop-568b207.json create mode 100644 tests/reference/asr-test_const_list_pop-568b207.stderr create mode 100644 tests/reference/asr-test_const_list_remove-c5deb20.json create mode 100644 tests/reference/asr-test_const_list_remove-c5deb20.stderr create mode 100644 tests/reference/asr-test_const_list_reverse-2df1a6f.json create mode 100644 tests/reference/asr-test_const_list_reverse-2df1a6f.stderr diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 44b703eaeb..c5a16e1498 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -551,6 +551,7 @@ RUN(NAME test_list_pop3 LABELS cpython llvm) RUN(NAME test_list_compare LABELS cpython llvm) RUN(NAME test_list_concat LABELS cpython llvm c NOFAST) RUN(NAME test_list_reserve LABELS cpython llvm) +RUN(NAME test_const_list LABELS cpython llvm c) RUN(NAME test_tuple_01 LABELS cpython llvm c) RUN(NAME test_tuple_02 LABELS cpython llvm c NOFAST) RUN(NAME test_tuple_03 LABELS cpython llvm c) diff --git a/integration_tests/test_list_const.py b/integration_tests/test_const_list.py similarity index 73% rename from integration_tests/test_list_const.py rename to integration_tests/test_const_list.py index b9eb7e5423..2b5100832c 100644 --- a/integration_tests/test_list_const.py +++ b/integration_tests/test_const_list.py @@ -1,7 +1,7 @@ -from lpython import i32, i64, f32, f64, dict, list, tuple, str, Const, c64 +from lpython import i32, list, str, Const -def test_list_const(): +def test_const_list(): CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] assert CONST_INTEGER_LIST.count(1) == 2 @@ -12,4 +12,4 @@ def test_list_const(): assert CONST_STRING_LIST.index("RELEASE") == 2 -test_list_const() +test_const_list() diff --git a/tests/errors/test_const_list_append.py b/tests/errors/test_const_list_append.py new file mode 100644 index 0000000000..c0c8e50e43 --- /dev/null +++ b/tests/errors/test_const_list_append.py @@ -0,0 +1,10 @@ +from lpython import i32, list, Const + + +def test_const_list_append(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.append(6) + + +test_const_list_append() diff --git a/tests/errors/test_const_list_clear.py b/tests/errors/test_const_list_clear.py new file mode 100644 index 0000000000..e233606f10 --- /dev/null +++ b/tests/errors/test_const_list_clear.py @@ -0,0 +1,10 @@ +from lpython import i32, list, Const + + +def test_const_list_clear(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.clear() + + +test_const_list_clear() diff --git a/tests/errors/test_const_list_insert.py b/tests/errors/test_const_list_insert.py new file mode 100644 index 0000000000..72f8b51e55 --- /dev/null +++ b/tests/errors/test_const_list_insert.py @@ -0,0 +1,10 @@ +from lpython import i32, list, Const + + +def test_const_list_insert(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.insert(3, 8) + + +test_const_list_insert() diff --git a/tests/errors/test_const_list_pop.py b/tests/errors/test_const_list_pop.py new file mode 100644 index 0000000000..fa405a7bc6 --- /dev/null +++ b/tests/errors/test_const_list_pop.py @@ -0,0 +1,10 @@ +from lpython import i32, list, Const + + +def test_const_list_pop(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.pop() + + +test_const_list_pop() diff --git a/tests/errors/test_const_list_remove.py b/tests/errors/test_const_list_remove.py new file mode 100644 index 0000000000..6073eef00c --- /dev/null +++ b/tests/errors/test_const_list_remove.py @@ -0,0 +1,10 @@ +from lpython import i32, list, Const + + +def test_const_list_remove(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.remove(1) + + +test_const_list_remove() diff --git a/tests/errors/test_const_list_reverse.py b/tests/errors/test_const_list_reverse.py new file mode 100644 index 0000000000..f1436b04ac --- /dev/null +++ b/tests/errors/test_const_list_reverse.py @@ -0,0 +1,10 @@ +from lpython import i32, list, Const + + +def test_const_list_reverse(): + CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + + CONST_INTEGER_LIST.reverse() + + +test_const_list_reverse() \ No newline at end of file diff --git a/tests/errors/test_list_const.py b/tests/errors/test_list_const.py deleted file mode 100644 index 330f303cef..0000000000 --- a/tests/errors/test_list_const.py +++ /dev/null @@ -1,14 +0,0 @@ -from lpython import i32, list, Const - -def test_list_const(): - CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] - - CONST_INTEGER_LIST.append(6) - CONST_INTEGER_LIST.insert(3, 8) - CONST_INTEGER_LIST.reverse() - CONST_INTEGER_LIST.pop() - CONST_INTEGER_LIST.pop(0) - CONST_INTEGER_LIST.clear() - CONST_INTEGER_LIST.remove(1) - -test_list_const() diff --git a/tests/reference/asr-test_const_list_append-ada1ade.json b/tests/reference/asr-test_const_list_append-ada1ade.json new file mode 100644 index 0000000000..484830324d --- /dev/null +++ b/tests/reference/asr-test_const_list_append-ada1ade.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_list_append-ada1ade", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_list_append.py", + "infile_hash": "1f8e9cdfaf24139c23d0a063fcce8c1765b0349500874c946c2a5bda", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_list_append-ada1ade.stderr", + "stderr_hash": "84fe0a7a75edd73700bce92d3e43cdc85e7f3c58f0047f53fb4412ad", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_list_append-ada1ade.stderr b/tests/reference/asr-test_const_list_append-ada1ade.stderr new file mode 100644 index 0000000000..08b7bf6c6b --- /dev/null +++ b/tests/reference/asr-test_const_list_append-ada1ade.stderr @@ -0,0 +1,5 @@ +semantic error: cannot append element to a const list + --> tests/errors/test_const_list_append.py:7:5 + | +7 | CONST_INTEGER_LIST.append(6) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_const_list_clear-33bfae7.json b/tests/reference/asr-test_const_list_clear-33bfae7.json new file mode 100644 index 0000000000..a4ac6699f7 --- /dev/null +++ b/tests/reference/asr-test_const_list_clear-33bfae7.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_list_clear-33bfae7", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_list_clear.py", + "infile_hash": "df04c8c3b9063bbbe0a24443f962c70732fecef59a7418cd7d5182af", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_list_clear-33bfae7.stderr", + "stderr_hash": "5c0c698319211c447c76e3309a027ee068dffded22d87bb3024cedf9", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_list_clear-33bfae7.stderr b/tests/reference/asr-test_const_list_clear-33bfae7.stderr new file mode 100644 index 0000000000..89fc62b51a --- /dev/null +++ b/tests/reference/asr-test_const_list_clear-33bfae7.stderr @@ -0,0 +1,5 @@ +semantic error: cannot clear elements from a const list + --> tests/errors/test_const_list_clear.py:7:5 + | +7 | CONST_INTEGER_LIST.clear() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_const_list_insert-4c81295.json b/tests/reference/asr-test_const_list_insert-4c81295.json new file mode 100644 index 0000000000..6113030e62 --- /dev/null +++ b/tests/reference/asr-test_const_list_insert-4c81295.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_list_insert-4c81295", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_list_insert.py", + "infile_hash": "d4a31ff954a49f096c46e38118ab88ac8821d5d691f1ada9ab323828", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_list_insert-4c81295.stderr", + "stderr_hash": "148e2a44028dd423007236ebf7a2c393fcefa4e8c12aad565f1c87fe", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_list_insert-4c81295.stderr b/tests/reference/asr-test_const_list_insert-4c81295.stderr new file mode 100644 index 0000000000..0a416adfd3 --- /dev/null +++ b/tests/reference/asr-test_const_list_insert-4c81295.stderr @@ -0,0 +1,5 @@ +semantic error: cannot insert element in a const list + --> tests/errors/test_const_list_insert.py:7:5 + | +7 | CONST_INTEGER_LIST.insert(3, 8) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_const_list_pop-568b207.json b/tests/reference/asr-test_const_list_pop-568b207.json new file mode 100644 index 0000000000..eb4e398c99 --- /dev/null +++ b/tests/reference/asr-test_const_list_pop-568b207.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_list_pop-568b207", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_list_pop.py", + "infile_hash": "e6cae5dc10a6a3505b3227d8492f32859f5baef086c143b1afcacdbf", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_list_pop-568b207.stderr", + "stderr_hash": "32d57cbb983509ca6c54bc0812c9a74b3c1886ecc94e635c5011c378", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_list_pop-568b207.stderr b/tests/reference/asr-test_const_list_pop-568b207.stderr new file mode 100644 index 0000000000..ad22224de1 --- /dev/null +++ b/tests/reference/asr-test_const_list_pop-568b207.stderr @@ -0,0 +1,5 @@ +semantic error: cannot pop element from a const list + --> tests/errors/test_const_list_pop.py:7:5 + | +7 | CONST_INTEGER_LIST.pop() + | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_const_list_remove-c5deb20.json b/tests/reference/asr-test_const_list_remove-c5deb20.json new file mode 100644 index 0000000000..4abd87a66b --- /dev/null +++ b/tests/reference/asr-test_const_list_remove-c5deb20.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_list_remove-c5deb20", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_list_remove.py", + "infile_hash": "e2bfdbf86ced2fae5e85037b6ea8479c1b73ab9b11b21c259739f8c1", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_list_remove-c5deb20.stderr", + "stderr_hash": "3529d822548d9327dbd0eab32aebc7b4a0da518cc0a6c2356e65c7b8", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_list_remove-c5deb20.stderr b/tests/reference/asr-test_const_list_remove-c5deb20.stderr new file mode 100644 index 0000000000..cdc585f4fc --- /dev/null +++ b/tests/reference/asr-test_const_list_remove-c5deb20.stderr @@ -0,0 +1,5 @@ +semantic error: cannot remove element from a const list + --> tests/errors/test_const_list_remove.py:7:5 + | +7 | CONST_INTEGER_LIST.remove(1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_const_list_reverse-2df1a6f.json b/tests/reference/asr-test_const_list_reverse-2df1a6f.json new file mode 100644 index 0000000000..b463e10677 --- /dev/null +++ b/tests/reference/asr-test_const_list_reverse-2df1a6f.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_list_reverse-2df1a6f", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_list_reverse.py", + "infile_hash": "b49f332d26356501f60c0342b86303deb62cd13621a821f3f2bc30c9", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_list_reverse-2df1a6f.stderr", + "stderr_hash": "78d4df28bbde66600867165e7c4d2b7e56874ba0f459052f8ab1b7fc", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_list_reverse-2df1a6f.stderr b/tests/reference/asr-test_const_list_reverse-2df1a6f.stderr new file mode 100644 index 0000000000..f49888969e --- /dev/null +++ b/tests/reference/asr-test_const_list_reverse-2df1a6f.stderr @@ -0,0 +1,5 @@ +semantic error: cannot reverse a const list + --> tests/errors/test_const_list_reverse.py:7:5 + | +7 | CONST_INTEGER_LIST.reverse() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/tests.toml b/tests/tests.toml index a43ca76444..bc1a4d6fcb 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -488,10 +488,6 @@ asr = true filename = "../integration_tests/global_syms_01.py" asr = true -[[test]] -filename = "../integration_tests/test_list_const.py" -asr = true - [[test]] filename = "cast.py" asr = true @@ -833,7 +829,27 @@ filename = "errors/test_list_slicing.py" asr = true [[test]] -filename = "errors/test_list_const.py" +filename = "errors/test_const_list_append.py" +asr = true + +[[test]] +filename = "errors/test_const_list_clear.py" +asr = true + +[[test]] +filename = "errors/test_const_list_insert.py" +asr = true + +[[test]] +filename = "errors/test_const_list_pop.py" +asr = true + +[[test]] +filename = "errors/test_const_list_reverse.py" +asr = true + +[[test]] +filename = "errors/test_const_list_remove.py" asr = true [[test]] From 0b9b94fd9dffad08adaec9f13a3bf7bc47f9e769 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sun, 10 Mar 2024 16:08:41 +0530 Subject: [PATCH 12/18] LLVM: Fix const list declaration --- src/libasr/codegen/asr_to_llvm.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 1e1560339a..8032a9f956 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -3514,7 +3514,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } if( init_expr != nullptr && - !ASR::is_a(*v->m_type)) { + !is_list) { target_var = ptr; tmp = nullptr; if (v->m_value != nullptr) { @@ -3590,7 +3590,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor throw CodeGenError("Unsupported len value in ASR"); } } else if (is_list) { - ASR::List_t* asr_list = ASR::down_cast(v->m_type); + ASR::List_t* asr_list = ASR::down_cast( + ASRUtils::type_get_past_const(v->m_type)); std::string type_code = ASRUtils::get_type_code(asr_list->m_type); list_api->list_init(type_code, ptr, *module); } From dd87ac8be8f24d789769a79e82bc65867e638ca8 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sun, 10 Mar 2024 16:22:06 +0530 Subject: [PATCH 13/18] Fix type for type checking --- src/libasr/pass/intrinsic_function_registry.h | 2 +- src/lpython/semantics/python_attribute_eval.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 7adb0fd07f..9a467fe45f 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2558,7 +2558,7 @@ static inline ASR::asr_t* create_ListIndex(Allocator& al, const Location& loc, ASR::expr_t* list_expr = args[0]; ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(list_expr)); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; - ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); + ASR::ttype_t *ele_type = ASRUtils::expr_type(args[1]); if (!ASRUtils::check_equal_type(ele_type, list_type)) { std::string fnd = ASRUtils::get_type_code(ele_type); std::string org = ASRUtils::get_type_code(list_type); diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 2b2e64a2ec..5c80074e01 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -184,7 +184,7 @@ struct AttributeHandler { } ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(s)); ASR::ttype_t *list_type = ASR::down_cast(type)->m_type; - ASR::ttype_t *ele_type = ASRUtils::get_contained_type(list_type); + ASR::ttype_t *ele_type = ASRUtils::expr_type(args[0]); if (!ASRUtils::check_equal_type(ele_type, list_type)) { std::string fnd = ASRUtils::type_to_str_python(ele_type); std::string org = ASRUtils::type_to_str_python(list_type); From fdf6cb380e876e3bdbd2e96a7acb72f9425aa8ce Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sun, 10 Mar 2024 16:22:24 +0530 Subject: [PATCH 14/18] Add print statements in test --- integration_tests/test_const_list.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration_tests/test_const_list.py b/integration_tests/test_const_list.py index 2b5100832c..482d2f3fc1 100644 --- a/integration_tests/test_const_list.py +++ b/integration_tests/test_const_list.py @@ -4,10 +4,14 @@ def test_const_list(): CONST_INTEGER_LIST: Const[list[i32]] = [1, 2, 3, 4, 5, 1] + print(CONST_INTEGER_LIST.count(1)) + print(CONST_INTEGER_LIST.index(1)) assert CONST_INTEGER_LIST.count(1) == 2 assert CONST_INTEGER_LIST.index(1) == 0 CONST_STRING_LIST: Const[list[str]] = ["ALPHA", "BETA", "RELEASE"] + print(CONST_STRING_LIST.count("ALPHA")) + print(CONST_STRING_LIST.index("RELEASE")) assert CONST_STRING_LIST.count("ALPHA") == 1 assert CONST_STRING_LIST.index("RELEASE") == 2 From d2029999896d827d6208cd67a5b1b62edd00a8bf Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sun, 10 Mar 2024 16:28:45 +0530 Subject: [PATCH 15/18] TEST: Update reference tests --- .../asr-test_list_const-4ffce80.json | 13 - .../asr-test_list_const-4ffce80.stdout | 270 ------------------ .../asr-test_list_const-7b77194.json | 13 - .../asr-test_list_const-7b77194.stderr | 5 - .../asr-test_list_count-4b42498.json | 10 +- .../asr-test_list_count-4b42498.stdout | 117 -------- .../runtime-test_list_const-0ca4829.json | 13 - .../runtime-test_list_const-0ca4829.stderr | 5 - 8 files changed, 5 insertions(+), 441 deletions(-) delete mode 100644 tests/reference/asr-test_list_const-4ffce80.json delete mode 100644 tests/reference/asr-test_list_const-4ffce80.stdout delete mode 100644 tests/reference/asr-test_list_const-7b77194.json delete mode 100644 tests/reference/asr-test_list_const-7b77194.stderr delete mode 100644 tests/reference/asr-test_list_count-4b42498.stdout delete mode 100644 tests/reference/runtime-test_list_const-0ca4829.json delete mode 100644 tests/reference/runtime-test_list_const-0ca4829.stderr diff --git a/tests/reference/asr-test_list_const-4ffce80.json b/tests/reference/asr-test_list_const-4ffce80.json deleted file mode 100644 index d707248f23..0000000000 --- a/tests/reference/asr-test_list_const-4ffce80.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "asr-test_list_const-4ffce80", - "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", - "infile": "tests/../integration_tests/test_list_const.py", - "infile_hash": "f2918a01e7e8a190f97d10ae208627d34944ee9d57aa98e01a239d1d", - "outfile": null, - "outfile_hash": null, - "stdout": "asr-test_list_const-4ffce80.stdout", - "stdout_hash": "1f4d504cea56850fcaa47eac751b413ce6644e36da970c1a1ad26289", - "stderr": null, - "stderr_hash": null, - "returncode": 0 -} \ No newline at end of file diff --git a/tests/reference/asr-test_list_const-4ffce80.stdout b/tests/reference/asr-test_list_const-4ffce80.stdout deleted file mode 100644 index d57c133ec6..0000000000 --- a/tests/reference/asr-test_list_const-4ffce80.stdout +++ /dev/null @@ -1,270 +0,0 @@ -(TranslationUnit - (SymbolTable - 1 - { - __main__: - (Module - (SymbolTable - 2 - { - __main__global_stmts: - (Function - (SymbolTable - 4 - { - - }) - __main__global_stmts - (FunctionType - [] - () - Source - Implementation - () - .false. - .false. - .false. - .false. - .false. - [] - .false. - ) - [test_list_const] - [] - [(SubroutineCall - 2 test_list_const - () - [] - () - )] - () - Public - .false. - .false. - () - ), - test_list_const: - (Function - (SymbolTable - 3 - { - CONST_INTEGER_LIST: - (Variable - 3 - CONST_INTEGER_LIST - [] - Local - (ListConstant - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4)) - (IntegerConstant 4 (Integer 4)) - (IntegerConstant 5 (Integer 4)) - (IntegerConstant 1 (Integer 4))] - (List - (Integer 4) - ) - ) - (ListConstant - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4)) - (IntegerConstant 4 (Integer 4)) - (IntegerConstant 5 (Integer 4)) - (IntegerConstant 1 (Integer 4))] - (List - (Integer 4) - ) - ) - Parameter - (Const - (List - (Integer 4) - ) - ) - () - Source - Public - Required - .false. - ), - CONST_STRING_LIST: - (Variable - 3 - CONST_STRING_LIST - [] - Local - (ListConstant - [(StringConstant - "ALPHA" - (Character 1 5 ()) - ) - (StringConstant - "BETA" - (Character 1 4 ()) - ) - (StringConstant - "RELEASE" - (Character 1 7 ()) - )] - (List - (Character 1 5 ()) - ) - ) - (ListConstant - [(StringConstant - "ALPHA" - (Character 1 5 ()) - ) - (StringConstant - "BETA" - (Character 1 4 ()) - ) - (StringConstant - "RELEASE" - (Character 1 7 ()) - )] - (List - (Character 1 5 ()) - ) - ) - Parameter - (Const - (List - (Character 1 -2 ()) - ) - ) - () - Source - Public - Required - .false. - ) - }) - test_list_const - (FunctionType - [] - () - Source - Implementation - () - .false. - .false. - .false. - .false. - .false. - [] - .false. - ) - [] - [] - [(Assert - (IntegerCompare - (ListCount - (Var 3 CONST_INTEGER_LIST) - (IntegerConstant 1 (Integer 4)) - (Integer 4) - () - ) - Eq - (IntegerConstant 2 (Integer 4)) - (Logical 4) - () - ) - () - ) - (Assert - (IntegerCompare - (IntrinsicScalarFunction - ListIndex - [(Var 3 CONST_INTEGER_LIST) - (IntegerConstant 1 (Integer 4))] - 0 - (Integer 4) - () - ) - Eq - (IntegerConstant 0 (Integer 4)) - (Logical 4) - () - ) - () - ) - (Assert - (IntegerCompare - (ListCount - (Var 3 CONST_STRING_LIST) - (StringConstant - "ALPHA" - (Character 1 5 ()) - ) - (Integer 4) - () - ) - Eq - (IntegerConstant 1 (Integer 4)) - (Logical 4) - () - ) - () - ) - (Assert - (IntegerCompare - (IntrinsicScalarFunction - ListIndex - [(Var 3 CONST_STRING_LIST) - (StringConstant - "RELEASE" - (Character 1 7 ()) - )] - 0 - (Integer 4) - () - ) - Eq - (IntegerConstant 2 (Integer 4)) - (Logical 4) - () - ) - () - )] - () - Public - .false. - .false. - () - ) - }) - __main__ - [] - .false. - .false. - ), - main_program: - (Program - (SymbolTable - 5 - { - __main__global_stmts: - (ExternalSymbol - 5 - __main__global_stmts - 2 __main__global_stmts - __main__ - [] - __main__global_stmts - Public - ) - }) - main_program - [__main__] - [(SubroutineCall - 5 __main__global_stmts - 2 __main__global_stmts - [] - () - )] - ) - }) - [] -) diff --git a/tests/reference/asr-test_list_const-7b77194.json b/tests/reference/asr-test_list_const-7b77194.json deleted file mode 100644 index 6eea12bb5f..0000000000 --- a/tests/reference/asr-test_list_const-7b77194.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "asr-test_list_const-7b77194", - "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", - "infile": "tests/errors/test_list_const.py", - "infile_hash": "794f98a9e575bf64082d76c78f2466bf023c8b3f9432fdf3ec8fe866", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "asr-test_list_const-7b77194.stderr", - "stderr_hash": "d18d6fde09df77a8af0b7b1f15e05aeb6b02e79c62ab97c5af79305d", - "returncode": 2 -} \ No newline at end of file diff --git a/tests/reference/asr-test_list_const-7b77194.stderr b/tests/reference/asr-test_list_const-7b77194.stderr deleted file mode 100644 index 8aaf7efa45..0000000000 --- a/tests/reference/asr-test_list_const-7b77194.stderr +++ /dev/null @@ -1,5 +0,0 @@ -semantic error: cannot append element to a const list - --> tests/errors/test_list_const.py:6:5 - | -6 | CONST_INTEGER_LIST.append(6) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/reference/asr-test_list_count-4b42498.json b/tests/reference/asr-test_list_count-4b42498.json index e81357ef04..f4864b55fb 100644 --- a/tests/reference/asr-test_list_count-4b42498.json +++ b/tests/reference/asr-test_list_count-4b42498.json @@ -5,9 +5,9 @@ "infile_hash": "01975bd7c4bba02fd811de536b218167da99b532fa955b7bf8339779", "outfile": null, "outfile_hash": null, - "stdout": "asr-test_list_count-4b42498.stdout", - "stdout_hash": "ebd75d7827b11fc01b497b61de99801051d36fe38fb2353a83eac7fa", - "stderr": null, - "stderr_hash": null, - "returncode": 0 + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_list_count-4b42498.stderr", + "stderr_hash": "f26efcc623b68ca43ef871eb01c8e3cbd1ae464baaa491c6e4969696", + "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_list_count-4b42498.stdout b/tests/reference/asr-test_list_count-4b42498.stdout deleted file mode 100644 index f78bcd64b9..0000000000 --- a/tests/reference/asr-test_list_count-4b42498.stdout +++ /dev/null @@ -1,117 +0,0 @@ -(TranslationUnit - (SymbolTable - 1 - { - __main__: - (Module - (SymbolTable - 2 - { - test_list_count_error: - (Function - (SymbolTable - 3 - { - __lcompilers_dummy: - (Variable - 3 - __lcompilers_dummy - [] - Local - () - () - Default - (Integer 4) - () - Source - Public - Required - .false. - ), - a: - (Variable - 3 - a - [] - Local - () - () - Default - (List - (Integer 4) - ) - () - Source - Public - Required - .false. - ) - }) - test_list_count_error - (FunctionType - [] - () - Source - Implementation - () - .false. - .false. - .false. - .false. - .false. - [] - .false. - ) - [] - [] - [(= - (Var 3 a) - (ListConstant - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4))] - (List - (Integer 4) - ) - ) - () - ) - (= - (Var 3 __lcompilers_dummy) - (ListCount - (Var 3 a) - (RealConstant - 1.000000 - (Real 8) - ) - (Integer 4) - () - ) - () - )] - () - Public - .false. - .false. - () - ) - }) - __main__ - [] - .false. - .false. - ), - main_program: - (Program - (SymbolTable - 4 - { - - }) - main_program - [] - [] - ) - }) - [] -) diff --git a/tests/reference/runtime-test_list_const-0ca4829.json b/tests/reference/runtime-test_list_const-0ca4829.json deleted file mode 100644 index ff13081949..0000000000 --- a/tests/reference/runtime-test_list_const-0ca4829.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "runtime-test_list_const-0ca4829", - "cmd": "lpython {infile}", - "infile": "tests/errors/test_list_const.py", - "infile_hash": "794f98a9e575bf64082d76c78f2466bf023c8b3f9432fdf3ec8fe866", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "runtime-test_list_const-0ca4829.stderr", - "stderr_hash": "be9de860495ffefe5254883bbf042bf04f698ea68e76516dc98fdbff", - "returncode": 2 -} \ No newline at end of file diff --git a/tests/reference/runtime-test_list_const-0ca4829.stderr b/tests/reference/runtime-test_list_const-0ca4829.stderr deleted file mode 100644 index 8c393dce1a..0000000000 --- a/tests/reference/runtime-test_list_const-0ca4829.stderr +++ /dev/null @@ -1,5 +0,0 @@ -semantic error: cannot append element to a const list - --> tests/errors/test_list_const.py:6:5 - | -6 | CONST_INTEGER_LIST.append(6) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  From a605f6c50ecfb7f59ac2d624cfa9126c98a26cb6 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sun, 10 Mar 2024 16:30:53 +0530 Subject: [PATCH 16/18] TEST: Remove C flag as ListCount() yet to be supported --- 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 c5a16e1498..a396205a23 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -551,7 +551,7 @@ RUN(NAME test_list_pop3 LABELS cpython llvm) RUN(NAME test_list_compare LABELS cpython llvm) RUN(NAME test_list_concat LABELS cpython llvm c NOFAST) RUN(NAME test_list_reserve LABELS cpython llvm) -RUN(NAME test_const_list LABELS cpython llvm c) +RUN(NAME test_const_list LABELS cpython llvm) RUN(NAME test_tuple_01 LABELS cpython llvm c) RUN(NAME test_tuple_02 LABELS cpython llvm c NOFAST) RUN(NAME test_tuple_03 LABELS cpython llvm c) From 66c288f8d22740f4b78cf9c300cd3d3aeee4f35b Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Sun, 10 Mar 2024 16:38:11 +0530 Subject: [PATCH 17/18] Remove list, str import --- integration_tests/test_const_list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/test_const_list.py b/integration_tests/test_const_list.py index 482d2f3fc1..4f0a568251 100644 --- a/integration_tests/test_const_list.py +++ b/integration_tests/test_const_list.py @@ -1,4 +1,4 @@ -from lpython import i32, list, str, Const +from lpython import i32, Const def test_const_list(): From c5d556f187fa4768791d2647c226ddc266bedd65 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 17:59:11 +0530 Subject: [PATCH 18/18] Fix formatting changes --- src/libasr/pass/intrinsic_function_registry.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 9a467fe45f..340d61b999 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2522,11 +2522,11 @@ static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Di x.base.base.loc, diagnostics); ASR::ttype_t *list_type = ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_args[0])); ASRUtils::require_impl(ASR::is_a(*list_type) && - ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), - ASRUtils::get_contained_type(list_type)), - "First argument to list.index must be of list type and " - "second argument must be of same type as list elemental type", - x.base.base.loc, diagnostics); + ASRUtils::check_equal_type(ASRUtils::expr_type(x.m_args[1]), + ASRUtils::get_contained_type(list_type)), + "First argument to list.index must be of list type and " + "second argument must be of same type as list elemental type", + x.base.base.loc, diagnostics); if(x.n_args >= 3) { ASRUtils::require_impl( ASR::is_a(*ASRUtils::expr_type(x.m_args[2])),