From 4d833dad3c9746525fbbeb8300c332faab490950 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 3 Mar 2024 00:59:04 +0530 Subject: [PATCH 01/31] Implement attributes for `Const dict` --- src/libasr/codegen/asr_to_llvm.cpp | 28 ++++++++++--- src/libasr/pass/intrinsic_function_registry.h | 39 ++++++++++++------- src/lpython/semantics/python_attribute_eval.h | 9 ++++- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index d5af2946f7..1fb20427bd 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1523,8 +1523,15 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListItem(const ASR::ListItem_t& x) { - ASR::ttype_t* el_type = ASRUtils::get_contained_type( - ASRUtils::expr_type(x.m_a)); + /* Check whether the `list` is a `Const[list[data_type]]`: + - If true, set the list `el_type` to `data_type` by first going to `Const`, then `list`. + - If false, we have a normal list - `list[data_type]`, go to `list` and get `data_type`. + + We do the type checking through strings because `ASR::is_a` throws an error. + */ + ASR::ttype_t *el_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_a)) == "list const" + ? ASRUtils::get_contained_type(ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a))) + : ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_a); @@ -1540,8 +1547,16 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - ASR::Dict_t* dict_type = ASR::down_cast( - ASRUtils::expr_type(x.m_a)); + /* Check whether the `dict` is a `Const[dict[key_type, value_type]]`: + - If true, set the `dict_type` to `dict[key_type, value_type]' by going to `Const`. + - If false, we have a normal dict - `dict[key_type, value_type]`. + + We do the type checking through strings because `ASR::is_a` throws an error. + */ + ASR::Dict_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_a)) == "dict const" + ? ASR::down_cast(ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a))) + : ASR::down_cast(ASRUtils::expr_type(x.m_a)); + int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_a); @@ -1845,8 +1860,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t* dict_type = ASR::down_cast( - ASRUtils::expr_type(m_arg)); + ASR::Dict_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(m_arg)) == "dict const" + ? ASR::down_cast(ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg))) + : ASR::down_cast(ASRUtils::expr_type(m_arg)); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 2fca01651d..dbd6eb7c7a 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2744,14 +2744,17 @@ namespace DictKeys { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args == 1, "Call to dict.keys must have no argument", x.base.base.loc, diagnostics); - ASRUtils::require_impl(ASR::is_a(*ASRUtils::expr_type(x.m_args[0])), - "Argument to dict.keys must be of dict type", - x.base.base.loc, diagnostics); + ASR::ttype_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "dict 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(*dict_type), + "Argument to dict.keys must be of dict type", + x.base.base.loc, diagnostics); ASRUtils::require_impl(ASR::is_a(*x.m_type) && - ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]), 0)), - "Return type of dict.keys must be of list of dict key element type", - x.base.base.loc, diagnostics); + ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), + ASR::down_cast(dict_type)->m_key_type), + "Return type of dict.keys must be of list of dict key element type", + x.base.base.loc, diagnostics); } static inline ASR::expr_t *eval_dict_keys(Allocator &/*al*/, @@ -2766,9 +2769,10 @@ static inline ASR::asr_t* create_DictKeys(Allocator& al, const Location& loc, if (args.size() != 1) { err("Call to dict.keys must have no argument", loc); } - ASR::expr_t* dict_expr = args[0]; - ASR::ttype_t *type = ASRUtils::expr_type(dict_expr); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(dict_expr)) == "dict const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(dict_expr)) + : ASRUtils::expr_type(dict_expr); ASR::ttype_t *dict_keys_type = ASR::down_cast(type)->m_key_type; Vec arg_values; @@ -2790,14 +2794,17 @@ namespace DictValues { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args == 1, "Call to dict.values must have no argument", x.base.base.loc, diagnostics); - ASRUtils::require_impl(ASR::is_a(*ASRUtils::expr_type(x.m_args[0])), + ASR::ttype_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "dict 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(*dict_type), "Argument to dict.values must be of dict type", x.base.base.loc, diagnostics); ASRUtils::require_impl(ASR::is_a(*x.m_type) && - ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), - ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0]), 1)), - "Return type of dict.values must be of list of dict value element type", - x.base.base.loc, diagnostics); + ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), + ASRUtils::get_contained_type(ASR::down_cast(dict_type)->m_value_type, 1)), + "Return type of dict.values must be of list of dict value element type", + x.base.base.loc, diagnostics); } static inline ASR::expr_t *eval_dict_values(Allocator &/*al*/, @@ -2814,7 +2821,9 @@ static inline ASR::asr_t* create_DictValues(Allocator& al, const Location& loc, } ASR::expr_t* dict_expr = args[0]; - ASR::ttype_t *type = ASRUtils::expr_type(dict_expr); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(dict_expr)) == "dict const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(dict_expr)) + : ASRUtils::expr_type(dict_expr); ASR::ttype_t *dict_values_type = ASR::down_cast(type)->m_value_type; Vec arg_values; diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 1aab45b379..9336451466 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -68,7 +68,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 = ASRUtils::expr_type(e); - std::string class_name = get_type_name(type); + std::string class_name = ASRUtils::type_to_str(type) == "dict const" ? "dict" : get_type_name(type); if (class_name == "") { throw SemanticError("Type name is not implemented yet.", loc); } @@ -331,7 +331,9 @@ struct AttributeHandler { throw SemanticError("'get' takes atleast 1 and atmost 2 arguments", loc); } - ASR::ttype_t *type = ASRUtils::expr_type(s); + ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "dict const" + ? ASRUtils::get_contained_type(ASRUtils::expr_type(s)) + : ASRUtils::expr_type(s); ASR::ttype_t *key_type = ASR::down_cast(type)->m_key_type; ASR::ttype_t *value_type = ASR::down_cast(type)->m_value_type; if (args.size() == 2) { @@ -366,6 +368,9 @@ struct AttributeHandler { static ASR::asr_t* eval_dict_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { + if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "dict const") { + throw SemanticError("cannot pop elements from a const dict", loc); + } if (args.size() != 1) { throw SemanticError("'pop' takes only one argument for now", loc); } From 3d65739581852196145e56cabee896489fdd3966 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Sun, 3 Mar 2024 10:57:48 +0530 Subject: [PATCH 02/31] Remove duplicate changes --- src/libasr/codegen/asr_to_llvm.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 1fb20427bd..eab89c7133 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1523,15 +1523,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListItem(const ASR::ListItem_t& x) { - /* Check whether the `list` is a `Const[list[data_type]]`: - - If true, set the list `el_type` to `data_type` by first going to `Const`, then `list`. - - If false, we have a normal list - `list[data_type]`, go to `list` and get `data_type`. - - We do the type checking through strings because `ASR::is_a` throws an error. - */ - ASR::ttype_t *el_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_a)) == "list const" - ? ASRUtils::get_contained_type(ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a))) - : ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a)); + ASR::ttype_t *el_type = ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_a); From 7cd71dba363a0391ca5fb44b8da451bb00e3a6e1 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Mar 2024 09:27:55 +0530 Subject: [PATCH 03/31] Improve checking for `Const` types --- src/libasr/codegen/asr_to_llvm.cpp | 14 ++++---------- src/libasr/pass/intrinsic_function_registry.h | 16 ++++++++-------- src/lpython/semantics/python_attribute_eval.h | 8 ++++---- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index eab89c7133..9ac7c60d13 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1539,14 +1539,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - /* Check whether the `dict` is a `Const[dict[key_type, value_type]]`: - - If true, set the `dict_type` to `dict[key_type, value_type]' by going to `Const`. - - If false, we have a normal dict - `dict[key_type, value_type]`. - - We do the type checking through strings because `ASR::is_a` throws an error. - */ - ASR::Dict_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_a)) == "dict const" - ? ASR::down_cast(ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a))) + ASR::Dict_t *dict_type = ASR::is_a(*ASRUtils::expr_type(x.m_a)) + ? ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_a))) : ASR::down_cast(ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; @@ -1852,8 +1846,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(m_arg)) == "dict const" - ? ASR::down_cast(ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg))) + ASR::Dict_t *dict_type = ASR::is_a(*ASRUtils::expr_type(m_arg)) + ? ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))) : ASR::down_cast(ASRUtils::expr_type(m_arg)); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index dbd6eb7c7a..e538f85954 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2744,8 +2744,8 @@ namespace DictKeys { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args == 1, "Call to dict.keys must have no argument", x.base.base.loc, diagnostics); - ASR::ttype_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "dict const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])) + ASR::ttype_t *dict_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(*dict_type), "Argument to dict.keys must be of dict type", @@ -2770,8 +2770,8 @@ static inline ASR::asr_t* create_DictKeys(Allocator& al, const Location& loc, err("Call to dict.keys must have no argument", loc); } ASR::expr_t* dict_expr = args[0]; - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(dict_expr)) == "dict const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(dict_expr)) + ASR::ttype_t *type = ASR::is_a (*ASRUtils::expr_type(dict_expr)) + ? ASRUtils::type_get_past_const(ASRUtils::expr_type(dict_expr)) : ASRUtils::expr_type(dict_expr); ASR::ttype_t *dict_keys_type = ASR::down_cast(type)->m_key_type; @@ -2794,8 +2794,8 @@ namespace DictValues { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args == 1, "Call to dict.values must have no argument", x.base.base.loc, diagnostics); - ASR::ttype_t *dict_type = ASRUtils::type_to_str(ASRUtils::expr_type(x.m_args[0])) == "dict const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_args[0])) + ASR::ttype_t *dict_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(*dict_type), "Argument to dict.values must be of dict type", @@ -2821,8 +2821,8 @@ static inline ASR::asr_t* create_DictValues(Allocator& al, const Location& loc, } ASR::expr_t* dict_expr = args[0]; - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(dict_expr)) == "dict const" - ? ASRUtils::get_contained_type(ASRUtils::expr_type(dict_expr)) + ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(dict_expr)) + ? ASRUtils::type_get_past_const(ASRUtils::expr_type(dict_expr)) : ASRUtils::expr_type(dict_expr); ASR::ttype_t *dict_values_type = ASR::down_cast(type)->m_value_type; diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 9336451466..8397a42661 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -68,7 +68,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 = ASRUtils::expr_type(e); - std::string class_name = ASRUtils::type_to_str(type) == "dict const" ? "dict" : get_type_name(type); + std::string class_name = ASR::is_a(*type) ? "dict" : get_type_name(type); if (class_name == "") { throw SemanticError("Type name is not implemented yet.", loc); } @@ -331,8 +331,8 @@ struct AttributeHandler { throw SemanticError("'get' takes atleast 1 and atmost 2 arguments", loc); } - ASR::ttype_t *type = ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "dict 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 *key_type = ASR::down_cast(type)->m_key_type; ASR::ttype_t *value_type = ASR::down_cast(type)->m_value_type; @@ -368,7 +368,7 @@ struct AttributeHandler { static ASR::asr_t* eval_dict_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - if (ASRUtils::type_to_str(ASRUtils::expr_type(s)) == "dict const") { + if (ASR::is_a(*ASRUtils::expr_type(s))) { throw SemanticError("cannot pop elements from a const dict", loc); } if (args.size() != 1) { From 005fb72aee9a2f0506f145a5c461199c2cf8fb76 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Thu, 7 Mar 2024 18:59:09 +0530 Subject: [PATCH 04/31] Simplify type checking for `Const dict`. --- src/libasr/codegen/asr_to_llvm.cpp | 8 ++------ src/libasr/pass/intrinsic_function_registry.h | 12 +++--------- src/lpython/semantics/python_attribute_eval.h | 4 +--- 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 9ac7c60d13..7205bd9d66 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1539,9 +1539,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - ASR::Dict_t *dict_type = ASR::is_a(*ASRUtils::expr_type(x.m_a)) - ? ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_a))) - : ASR::down_cast(ASRUtils::expr_type(x.m_a)); + ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_a))); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; @@ -1846,9 +1844,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t *dict_type = ASR::is_a(*ASRUtils::expr_type(m_arg)) - ? ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))) - : ASR::down_cast(ASRUtils::expr_type(m_arg)); + ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index e538f85954..7df82e26da 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2744,9 +2744,7 @@ namespace DictKeys { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args == 1, "Call to dict.keys must have no argument", x.base.base.loc, diagnostics); - ASR::ttype_t *dict_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 *dict_type = ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_args[0])); ASRUtils::require_impl(ASR::is_a(*dict_type), "Argument to dict.keys must be of dict type", x.base.base.loc, diagnostics); @@ -2770,9 +2768,7 @@ static inline ASR::asr_t* create_DictKeys(Allocator& al, const Location& loc, err("Call to dict.keys must have no argument", loc); } ASR::expr_t* dict_expr = args[0]; - ASR::ttype_t *type = ASR::is_a (*ASRUtils::expr_type(dict_expr)) - ? ASRUtils::type_get_past_const(ASRUtils::expr_type(dict_expr)) - : ASRUtils::expr_type(dict_expr); + ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(dict_expr)); ASR::ttype_t *dict_keys_type = ASR::down_cast(type)->m_key_type; Vec arg_values; @@ -2821,9 +2817,7 @@ static inline ASR::asr_t* create_DictValues(Allocator& al, const Location& loc, } ASR::expr_t* dict_expr = args[0]; - ASR::ttype_t *type = ASR::is_a(*ASRUtils::expr_type(dict_expr)) - ? ASRUtils::type_get_past_const(ASRUtils::expr_type(dict_expr)) - : ASRUtils::expr_type(dict_expr); + ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(dict_expr)); ASR::ttype_t *dict_values_type = ASR::down_cast(type)->m_value_type; Vec arg_values; diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 8397a42661..1ca2522994 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -331,9 +331,7 @@ struct AttributeHandler { throw SemanticError("'get' takes atleast 1 and atmost 2 arguments", 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 *key_type = ASR::down_cast(type)->m_key_type; ASR::ttype_t *value_type = ASR::down_cast(type)->m_value_type; if (args.size() == 2) { From 161bd8e761d243a948aebf8a96f87bb697e3a45c Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 08:45:40 +0530 Subject: [PATCH 05/31] Add tests --- integration_tests/test_dict_const.py | 18 ++++++++++++++++++ tests/errors/test_dict_const.py | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 integration_tests/test_dict_const.py create mode 100644 tests/errors/test_dict_const.py diff --git a/integration_tests/test_dict_const.py b/integration_tests/test_dict_const.py new file mode 100644 index 0000000000..214b35e30c --- /dev/null +++ b/integration_tests/test_dict_const.py @@ -0,0 +1,18 @@ +from lpython import i32, f64, str, dict, Const + + +def test_dict_const(): + d_int: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} + + assert d_int.get("a") == 1 + assert d_int.keys() == ["c", "a", "b"] + assert d_int.values() == [3, 1, 2] + + d_float: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} + + assert d_float.get("a") == 1.0 + assert d_float.keys() == ["c", "a", "b"] + assert d_float.values() == [3.0, 1.0, 2.0] + + +test_dict_const() diff --git a/tests/errors/test_dict_const.py b/tests/errors/test_dict_const.py new file mode 100644 index 0000000000..be78d5d890 --- /dev/null +++ b/tests/errors/test_dict_const.py @@ -0,0 +1,6 @@ +from lpython import i32, f64, str, dict, Const + + +def test_dict_const(): + d: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} + print(d.pop("a")) From e75755b8229db33bc27e2bef944d30c83b21634b Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 08:49:46 +0530 Subject: [PATCH 06/31] Update test --- tests/errors/test_dict_const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/errors/test_dict_const.py b/tests/errors/test_dict_const.py index be78d5d890..71c4121736 100644 --- a/tests/errors/test_dict_const.py +++ b/tests/errors/test_dict_const.py @@ -4,3 +4,4 @@ def test_dict_const(): d: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} print(d.pop("a")) + i: i32 = d.pop("a") From 1a068c8210749a4f83c692cd4b32a358248745d4 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Sun, 10 Mar 2024 10:04:59 +0530 Subject: [PATCH 07/31] Update fetching attribute name logic Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com> --- src/lpython/semantics/python_attribute_eval.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 1ca2522994..6c42b1af92 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -68,7 +68,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 = ASRUtils::expr_type(e); - std::string class_name = ASR::is_a(*type) ? "dict" : get_type_name(type); + std::string class_name = get_type_name(ASRUtils::type_get_past_const(type)); if (class_name == "") { throw SemanticError("Type name is not implemented yet.", loc); } From 68524a4105191ba95ee8fb4197aee551b021a527 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 12:34:28 +0530 Subject: [PATCH 08/31] Update test references --- tests/reference/asr-test_dict_const-69479e2.json | 13 +++++++++++++ tests/reference/asr-test_dict_const-69479e2.stderr | 5 +++++ tests/reference/python-assert1-192ca6c.json | 2 +- tests/reference/python-assert1-192ca6c.stdout | 2 -- tests/reference/python-assign1-f87bafa.json | 2 +- tests/reference/python-assign1-f87bafa.stdout | 2 -- tests/reference/python-expr11-e6681c8.json | 2 +- tests/reference/python-expr11-e6681c8.stdout | 2 -- tests/reference/python-expr17-3b84714.json | 2 +- tests/reference/python-expr17-3b84714.stdout | 4 ---- tests/reference/python-expr2-6b69018.json | 2 +- tests/reference/python-expr2-6b69018.stdout | 2 -- tests/reference/python-expr4-161a0ec.json | 2 +- tests/reference/python-expr4-161a0ec.stdout | 3 +-- tests/reference/python-expr5-dee0e5c.json | 2 +- tests/reference/python-expr5-dee0e5c.stdout | 2 -- tests/reference/python-expr6-1a1d4fb.json | 2 +- tests/reference/python-expr6-1a1d4fb.stdout | 2 -- tests/tests.toml | 4 ++++ 19 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 tests/reference/asr-test_dict_const-69479e2.json create mode 100644 tests/reference/asr-test_dict_const-69479e2.stderr diff --git a/tests/reference/asr-test_dict_const-69479e2.json b/tests/reference/asr-test_dict_const-69479e2.json new file mode 100644 index 0000000000..ee62c8a1a2 --- /dev/null +++ b/tests/reference/asr-test_dict_const-69479e2.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_dict_const-69479e2", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_dict_const.py", + "infile_hash": "d1804e6783a3835037cc6ddbeb9aad238c016df351ce0049357b214e", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_dict_const-69479e2.stderr", + "stderr_hash": "2390df032f24f949ce0e7509961b69ab9347c4f35ee9d8e7a47ec4bc", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_dict_const-69479e2.stderr b/tests/reference/asr-test_dict_const-69479e2.stderr new file mode 100644 index 0000000000..b3269f240e --- /dev/null +++ b/tests/reference/asr-test_dict_const-69479e2.stderr @@ -0,0 +1,5 @@ +semantic error: Type name is not implemented yet. + --> tests/../integration_tests/test_dict_const.py:8:12 + | +8 | assert d_int.get("a") == 1 + | ^^^^^^^^^^^^^^ diff --git a/tests/reference/python-assert1-192ca6c.json b/tests/reference/python-assert1-192ca6c.json index ed9457882f..1db5a55ee7 100644 --- a/tests/reference/python-assert1-192ca6c.json +++ b/tests/reference/python-assert1-192ca6c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assert1-192ca6c.stdout", - "stdout_hash": "2120f9dd9a8d41e4d67cced7ceb14c4ded9d56335058f66b24cfe12e", + "stdout_hash": "0de7de97bd936f6a66e73ba9789e50ed968b66edce04acfcc168c6db", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assert1-192ca6c.stdout b/tests/reference/python-assert1-192ca6c.stdout index 77016e73f3..88a510476c 100644 --- a/tests/reference/python-assert1-192ca6c.stdout +++ b/tests/reference/python-assert1-192ca6c.stdout @@ -3,5 +3,3 @@ def test_assert(): a = 5 assert (a) == (5), "a is not 5" assert (a) != (10) - - diff --git a/tests/reference/python-assign1-f87bafa.json b/tests/reference/python-assign1-f87bafa.json index f4ce6903f8..ac0ac5afda 100644 --- a/tests/reference/python-assign1-f87bafa.json +++ b/tests/reference/python-assign1-f87bafa.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assign1-f87bafa.stdout", - "stdout_hash": "6fa5f5e1492cac718631d3c05d27ab2ddda15dd2e56cc37a1ce188b9", + "stdout_hash": "bd60a7791394a67503473530adb0369f2f12407e0108423397f3e4e4", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assign1-f87bafa.stdout b/tests/reference/python-assign1-f87bafa.stdout index caa7aaf2a6..e083f35a45 100644 --- a/tests/reference/python-assign1-f87bafa.stdout +++ b/tests/reference/python-assign1-f87bafa.stdout @@ -11,5 +11,3 @@ def test_augassign(): r = r / s a = "" a = a + "test" - - diff --git a/tests/reference/python-expr11-e6681c8.json b/tests/reference/python-expr11-e6681c8.json index 067b2c4518..9f40e4dc6d 100644 --- a/tests/reference/python-expr11-e6681c8.json +++ b/tests/reference/python-expr11-e6681c8.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr11-e6681c8.stdout", - "stdout_hash": "6ae1afc8767434e703cfd38bbdd22275c73effa90a5e86c5c09bab5b", + "stdout_hash": "425a18a0b44e596e166ce94fad47878623b4dd9b4d534419b7f18683", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr11-e6681c8.stdout b/tests/reference/python-expr11-e6681c8.stdout index da61c57b5a..a108676193 100644 --- a/tests/reference/python-expr11-e6681c8.stdout +++ b/tests/reference/python-expr11-e6681c8.stdout @@ -6,5 +6,3 @@ def test_StrOp_repeat(): s = "bb" * 4 s = "bb" * -(40) s = "a" * 3 * 3 - - diff --git a/tests/reference/python-expr17-3b84714.json b/tests/reference/python-expr17-3b84714.json index 11933a5b96..5ad1fd4c8d 100644 --- a/tests/reference/python-expr17-3b84714.json +++ b/tests/reference/python-expr17-3b84714.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr17-3b84714.stdout", - "stdout_hash": "c5754f71e1cd9a019d7289d5ccee634a42d75ac775b0e115eea48f03", + "stdout_hash": "9daa5ee66df347ea965190959be6eee3c070b52b38b0c9b52de04e2d", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr17-3b84714.stdout b/tests/reference/python-expr17-3b84714.stdout index 48b07875e4..d0f78d5ffe 100644 --- a/tests/reference/python-expr17-3b84714.stdout +++ b/tests/reference/python-expr17-3b84714.stdout @@ -8,7 +8,3 @@ def if_check(): print("positive value") else: print("zero") - - - - diff --git a/tests/reference/python-expr2-6b69018.json b/tests/reference/python-expr2-6b69018.json index 784e5f3e6f..07c3053bc1 100644 --- a/tests/reference/python-expr2-6b69018.json +++ b/tests/reference/python-expr2-6b69018.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr2-6b69018.stdout", - "stdout_hash": "849450cb39ead48c1935431e54d989370ecece8c711f34e4ca38fd2b", + "stdout_hash": "b9e6fef7e82bbf96d66869ae6fd739c46c8d20e5bafabb48a6a15fce", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr2-6b69018.stdout b/tests/reference/python-expr2-6b69018.stdout index 45bd2f5ccc..523311bbaa 100644 --- a/tests/reference/python-expr2-6b69018.stdout +++ b/tests/reference/python-expr2-6b69018.stdout @@ -9,5 +9,3 @@ def test_boolOp(): a = a and b == b a = a and b != b a = b or b - - diff --git a/tests/reference/python-expr4-161a0ec.json b/tests/reference/python-expr4-161a0ec.json index 9823faecf8..abc691f0c0 100644 --- a/tests/reference/python-expr4-161a0ec.json +++ b/tests/reference/python-expr4-161a0ec.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr4-161a0ec.stdout", - "stdout_hash": "1378e1d01da96646ba0d45dbc6f5d30f7956e1c874c558df95a9f733", + "stdout_hash": "6dbfa328171f15601ab250ddecda5d36beb85a4922a60f583c932d4a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr4-161a0ec.stdout b/tests/reference/python-expr4-161a0ec.stdout index a6a301dd99..81dfdff136 100644 --- a/tests/reference/python-expr4-161a0ec.stdout +++ b/tests/reference/python-expr4-161a0ec.stdout @@ -3,5 +3,4 @@ def test_del(): b: i32 a = 4 b = 20 - del a, b - + del a, b \ No newline at end of file diff --git a/tests/reference/python-expr5-dee0e5c.json b/tests/reference/python-expr5-dee0e5c.json index 5cf281a38d..1c3f9279d8 100644 --- a/tests/reference/python-expr5-dee0e5c.json +++ b/tests/reference/python-expr5-dee0e5c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr5-dee0e5c.stdout", - "stdout_hash": "cef56dbae8b4efd362ea96bcbdc080667fd46930c1d7cfbca92bbe8e", + "stdout_hash": "e4b6285bbd4e701c75f2abdeb7c21dc8b489f5c5ef848074c5ce1e3b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr5-dee0e5c.stdout b/tests/reference/python-expr5-dee0e5c.stdout index b63878db76..92fb4ec53b 100644 --- a/tests/reference/python-expr5-dee0e5c.stdout +++ b/tests/reference/python-expr5-dee0e5c.stdout @@ -3,5 +3,3 @@ def test_StrOp_concat(): s = "3" + "4" s = "a " + "test" s = "test" + "test" + "test" - - diff --git a/tests/reference/python-expr6-1a1d4fb.json b/tests/reference/python-expr6-1a1d4fb.json index f1eb23d77b..4637905e1c 100644 --- a/tests/reference/python-expr6-1a1d4fb.json +++ b/tests/reference/python-expr6-1a1d4fb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr6-1a1d4fb.stdout", - "stdout_hash": "f7e339254436fdf45988c26786265c1d00bfcc23c0c5419fc07c0e6c", + "stdout_hash": "36557786797da33792a4a672d4f5e5b0a6ced2c51e674c5ad9426d62", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr6-1a1d4fb.stdout b/tests/reference/python-expr6-1a1d4fb.stdout index ccb26aa61f..fe35320c4e 100644 --- a/tests/reference/python-expr6-1a1d4fb.stdout +++ b/tests/reference/python-expr6-1a1d4fb.stdout @@ -5,5 +5,3 @@ def test_ifexp(): a = 2 b = 6 if (a) == (2) else 8 c = True if (b) > (5) else False - - diff --git a/tests/tests.toml b/tests/tests.toml index 972c72bf91..5939ab860e 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -487,6 +487,10 @@ asr = true filename = "../integration_tests/global_syms_01.py" asr = true +[[test]] +filename = "../integration_tests/test_dict_const.py" +asr = true + [[test]] filename = "cast.py" asr = true From 6337279a8560e1b5959da7a84941900e3b236319 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Sun, 10 Mar 2024 12:47:57 +0530 Subject: [PATCH 09/31] Update fetching `dict_type` Co-authored-by: Thirumalai Shaktivel <74826228+Thirumalai-Shaktivel@users.noreply.github.com> --- src/libasr/pass/intrinsic_function_registry.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libasr/pass/intrinsic_function_registry.h b/src/libasr/pass/intrinsic_function_registry.h index 7df82e26da..2e4665d1b7 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2790,9 +2790,7 @@ namespace DictValues { static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Diagnostics& diagnostics) { ASRUtils::require_impl(x.n_args == 1, "Call to dict.values must have no argument", x.base.base.loc, diagnostics); - ASR::ttype_t *dict_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 *dict_type = ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_args[0])); ASRUtils::require_impl(ASR::is_a(*dict_type), "Argument to dict.values must be of dict type", x.base.base.loc, diagnostics); From c4225240fbbca9ef4e646241ee61b00ea732dbbd Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 12:52:51 +0530 Subject: [PATCH 10/31] Formatting changes --- src/libasr/codegen/asr_to_llvm.cpp | 3 ++- src/libasr/pass/intrinsic_function_registry.h | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 7205bd9d66..f38e958cd2 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1539,7 +1539,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_a))); + ASR::Dict_t *dict_type = ASR::down_cast( + ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_a))); 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 2e4665d1b7..afec53c6cc 100644 --- a/src/libasr/pass/intrinsic_function_registry.h +++ b/src/libasr/pass/intrinsic_function_registry.h @@ -2795,10 +2795,11 @@ static inline void verify_args(const ASR::IntrinsicScalarFunction_t& x, diag::Di "Argument to dict.values must be of dict type", x.base.base.loc, diagnostics); ASRUtils::require_impl(ASR::is_a(*x.m_type) && - ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), - ASRUtils::get_contained_type(ASR::down_cast(dict_type)->m_value_type, 1)), - "Return type of dict.values must be of list of dict value element type", - x.base.base.loc, diagnostics); + ASRUtils::check_equal_type(ASRUtils::get_contained_type(x.m_type), + ASRUtils::get_contained_type( + ASR::down_cast(dict_type)->m_value_type, 1)), + "Return type of dict.values must be of list of dict value element type", + x.base.base.loc, diagnostics); } static inline ASR::expr_t *eval_dict_values(Allocator &/*al*/, From a047e7169cad78bdb4452b249152b7e7062abc90 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 12:53:07 +0530 Subject: [PATCH 11/31] Update test references --- .../asr-test_dict_const-69479e2.json | 12 +- .../asr-test_dict_const-69479e2.stdout | 416 ++++++++++++++++++ tests/reference/python-assert1-192ca6c.json | 2 +- tests/reference/python-assert1-192ca6c.stdout | 2 + tests/reference/python-assign1-f87bafa.json | 2 +- tests/reference/python-assign1-f87bafa.stdout | 2 + tests/reference/python-expr11-e6681c8.json | 2 +- tests/reference/python-expr11-e6681c8.stdout | 2 + tests/reference/python-expr17-3b84714.json | 2 +- tests/reference/python-expr17-3b84714.stdout | 4 + tests/reference/python-expr2-6b69018.json | 2 +- tests/reference/python-expr2-6b69018.stdout | 2 + tests/reference/python-expr4-161a0ec.json | 2 +- tests/reference/python-expr4-161a0ec.stdout | 3 +- tests/reference/python-expr5-dee0e5c.json | 2 +- tests/reference/python-expr5-dee0e5c.stdout | 2 + tests/reference/python-expr6-1a1d4fb.json | 2 +- tests/reference/python-expr6-1a1d4fb.stdout | 2 + 18 files changed, 448 insertions(+), 15 deletions(-) create mode 100644 tests/reference/asr-test_dict_const-69479e2.stdout diff --git a/tests/reference/asr-test_dict_const-69479e2.json b/tests/reference/asr-test_dict_const-69479e2.json index ee62c8a1a2..b1e6e3b97d 100644 --- a/tests/reference/asr-test_dict_const-69479e2.json +++ b/tests/reference/asr-test_dict_const-69479e2.json @@ -2,12 +2,12 @@ "basename": "asr-test_dict_const-69479e2", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_dict_const.py", - "infile_hash": "d1804e6783a3835037cc6ddbeb9aad238c016df351ce0049357b214e", + "infile_hash": "61ca282635e2a28e2c7740f44cc8e1cc1af49988155e9f32b737cec3", "outfile": null, "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "asr-test_dict_const-69479e2.stderr", - "stderr_hash": "2390df032f24f949ce0e7509961b69ab9347c4f35ee9d8e7a47ec4bc", - "returncode": 2 + "stdout": "asr-test_dict_const-69479e2.stdout", + "stdout_hash": "9b7d2dc1e374e1a711a9b91edf78debb0b6f038b7e7f000769f57f96", + "stderr": null, + "stderr_hash": null, + "returncode": 0 } \ No newline at end of file diff --git a/tests/reference/asr-test_dict_const-69479e2.stdout b/tests/reference/asr-test_dict_const-69479e2.stdout new file mode 100644 index 0000000000..aa20030c5b --- /dev/null +++ b/tests/reference/asr-test_dict_const-69479e2.stdout @@ -0,0 +1,416 @@ +(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_dict_const] + [] + [(SubroutineCall + 2 test_dict_const + () + [] + () + )] + () + Public + .false. + .false. + () + ), + test_dict_const: + (Function + (SymbolTable + 3 + { + d_float: + (Variable + 3 + d_float + [] + Local + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 3.000000 + (Real 8) + )] + (Dict + (Character 1 1 ()) + (Real 8) + ) + ) + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 3.000000 + (Real 8) + )] + (Dict + (Character 1 1 ()) + (Real 8) + ) + ) + Parameter + (Const + (Dict + (Character 1 -2 ()) + (Real 8) + ) + ) + () + Source + Public + Required + .false. + ), + d_int: + (Variable + 3 + d_int + [] + Local + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4))] + (Dict + (Character 1 1 ()) + (Integer 4) + ) + ) + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4))] + (Dict + (Character 1 1 ()) + (Integer 4) + ) + ) + Parameter + (Const + (Dict + (Character 1 -2 ()) + (Integer 4) + ) + ) + () + Source + Public + Required + .false. + ) + }) + test_dict_const + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + .false. + ) + [] + [] + [(Assert + (IntegerCompare + (DictItem + (Var 3 d_int) + (StringConstant + "a" + (Character 1 1 ()) + ) + () + (Integer 4) + () + ) + Eq + (IntegerConstant 1 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictKeys + [(Var 3 d_int)] + 0 + (List + (Character 1 -2 ()) + ) + () + ) + Eq + (ListConstant + [(StringConstant + "c" + (Character 1 1 ()) + ) + (StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + )] + (List + (Character 1 1 ()) + ) + ) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictValues + [(Var 3 d_int)] + 0 + (List + (Integer 4) + ) + () + ) + Eq + (ListConstant + [(IntegerConstant 3 (Integer 4)) + (IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4))] + (List + (Integer 4) + ) + ) + (Logical 4) + () + ) + () + ) + (Assert + (RealCompare + (DictItem + (Var 3 d_float) + (StringConstant + "a" + (Character 1 1 ()) + ) + () + (Real 8) + () + ) + Eq + (RealConstant + 1.000000 + (Real 8) + ) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictKeys + [(Var 3 d_float)] + 0 + (List + (Character 1 -2 ()) + ) + () + ) + Eq + (ListConstant + [(StringConstant + "c" + (Character 1 1 ()) + ) + (StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + )] + (List + (Character 1 1 ()) + ) + ) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictValues + [(Var 3 d_float)] + 0 + (List + (Real 8) + ) + () + ) + Eq + (ListConstant + [(RealConstant + 3.000000 + (Real 8) + ) + (RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + )] + (List + (Real 8) + ) + ) + (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/python-assert1-192ca6c.json b/tests/reference/python-assert1-192ca6c.json index 1db5a55ee7..ed9457882f 100644 --- a/tests/reference/python-assert1-192ca6c.json +++ b/tests/reference/python-assert1-192ca6c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assert1-192ca6c.stdout", - "stdout_hash": "0de7de97bd936f6a66e73ba9789e50ed968b66edce04acfcc168c6db", + "stdout_hash": "2120f9dd9a8d41e4d67cced7ceb14c4ded9d56335058f66b24cfe12e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assert1-192ca6c.stdout b/tests/reference/python-assert1-192ca6c.stdout index 88a510476c..77016e73f3 100644 --- a/tests/reference/python-assert1-192ca6c.stdout +++ b/tests/reference/python-assert1-192ca6c.stdout @@ -3,3 +3,5 @@ def test_assert(): a = 5 assert (a) == (5), "a is not 5" assert (a) != (10) + + diff --git a/tests/reference/python-assign1-f87bafa.json b/tests/reference/python-assign1-f87bafa.json index ac0ac5afda..f4ce6903f8 100644 --- a/tests/reference/python-assign1-f87bafa.json +++ b/tests/reference/python-assign1-f87bafa.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-assign1-f87bafa.stdout", - "stdout_hash": "bd60a7791394a67503473530adb0369f2f12407e0108423397f3e4e4", + "stdout_hash": "6fa5f5e1492cac718631d3c05d27ab2ddda15dd2e56cc37a1ce188b9", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-assign1-f87bafa.stdout b/tests/reference/python-assign1-f87bafa.stdout index e083f35a45..caa7aaf2a6 100644 --- a/tests/reference/python-assign1-f87bafa.stdout +++ b/tests/reference/python-assign1-f87bafa.stdout @@ -11,3 +11,5 @@ def test_augassign(): r = r / s a = "" a = a + "test" + + diff --git a/tests/reference/python-expr11-e6681c8.json b/tests/reference/python-expr11-e6681c8.json index 9f40e4dc6d..067b2c4518 100644 --- a/tests/reference/python-expr11-e6681c8.json +++ b/tests/reference/python-expr11-e6681c8.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr11-e6681c8.stdout", - "stdout_hash": "425a18a0b44e596e166ce94fad47878623b4dd9b4d534419b7f18683", + "stdout_hash": "6ae1afc8767434e703cfd38bbdd22275c73effa90a5e86c5c09bab5b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr11-e6681c8.stdout b/tests/reference/python-expr11-e6681c8.stdout index a108676193..da61c57b5a 100644 --- a/tests/reference/python-expr11-e6681c8.stdout +++ b/tests/reference/python-expr11-e6681c8.stdout @@ -6,3 +6,5 @@ def test_StrOp_repeat(): s = "bb" * 4 s = "bb" * -(40) s = "a" * 3 * 3 + + diff --git a/tests/reference/python-expr17-3b84714.json b/tests/reference/python-expr17-3b84714.json index 5ad1fd4c8d..11933a5b96 100644 --- a/tests/reference/python-expr17-3b84714.json +++ b/tests/reference/python-expr17-3b84714.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr17-3b84714.stdout", - "stdout_hash": "9daa5ee66df347ea965190959be6eee3c070b52b38b0c9b52de04e2d", + "stdout_hash": "c5754f71e1cd9a019d7289d5ccee634a42d75ac775b0e115eea48f03", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr17-3b84714.stdout b/tests/reference/python-expr17-3b84714.stdout index d0f78d5ffe..48b07875e4 100644 --- a/tests/reference/python-expr17-3b84714.stdout +++ b/tests/reference/python-expr17-3b84714.stdout @@ -8,3 +8,7 @@ def if_check(): print("positive value") else: print("zero") + + + + diff --git a/tests/reference/python-expr2-6b69018.json b/tests/reference/python-expr2-6b69018.json index 07c3053bc1..784e5f3e6f 100644 --- a/tests/reference/python-expr2-6b69018.json +++ b/tests/reference/python-expr2-6b69018.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr2-6b69018.stdout", - "stdout_hash": "b9e6fef7e82bbf96d66869ae6fd739c46c8d20e5bafabb48a6a15fce", + "stdout_hash": "849450cb39ead48c1935431e54d989370ecece8c711f34e4ca38fd2b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr2-6b69018.stdout b/tests/reference/python-expr2-6b69018.stdout index 523311bbaa..45bd2f5ccc 100644 --- a/tests/reference/python-expr2-6b69018.stdout +++ b/tests/reference/python-expr2-6b69018.stdout @@ -9,3 +9,5 @@ def test_boolOp(): a = a and b == b a = a and b != b a = b or b + + diff --git a/tests/reference/python-expr4-161a0ec.json b/tests/reference/python-expr4-161a0ec.json index abc691f0c0..9823faecf8 100644 --- a/tests/reference/python-expr4-161a0ec.json +++ b/tests/reference/python-expr4-161a0ec.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr4-161a0ec.stdout", - "stdout_hash": "6dbfa328171f15601ab250ddecda5d36beb85a4922a60f583c932d4a", + "stdout_hash": "1378e1d01da96646ba0d45dbc6f5d30f7956e1c874c558df95a9f733", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr4-161a0ec.stdout b/tests/reference/python-expr4-161a0ec.stdout index 81dfdff136..a6a301dd99 100644 --- a/tests/reference/python-expr4-161a0ec.stdout +++ b/tests/reference/python-expr4-161a0ec.stdout @@ -3,4 +3,5 @@ def test_del(): b: i32 a = 4 b = 20 - del a, b \ No newline at end of file + del a, b + diff --git a/tests/reference/python-expr5-dee0e5c.json b/tests/reference/python-expr5-dee0e5c.json index 1c3f9279d8..5cf281a38d 100644 --- a/tests/reference/python-expr5-dee0e5c.json +++ b/tests/reference/python-expr5-dee0e5c.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr5-dee0e5c.stdout", - "stdout_hash": "e4b6285bbd4e701c75f2abdeb7c21dc8b489f5c5ef848074c5ce1e3b", + "stdout_hash": "cef56dbae8b4efd362ea96bcbdc080667fd46930c1d7cfbca92bbe8e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr5-dee0e5c.stdout b/tests/reference/python-expr5-dee0e5c.stdout index 92fb4ec53b..b63878db76 100644 --- a/tests/reference/python-expr5-dee0e5c.stdout +++ b/tests/reference/python-expr5-dee0e5c.stdout @@ -3,3 +3,5 @@ def test_StrOp_concat(): s = "3" + "4" s = "a " + "test" s = "test" + "test" + "test" + + diff --git a/tests/reference/python-expr6-1a1d4fb.json b/tests/reference/python-expr6-1a1d4fb.json index 4637905e1c..f1eb23d77b 100644 --- a/tests/reference/python-expr6-1a1d4fb.json +++ b/tests/reference/python-expr6-1a1d4fb.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "python-expr6-1a1d4fb.stdout", - "stdout_hash": "36557786797da33792a4a672d4f5e5b0a6ced2c51e674c5ad9426d62", + "stdout_hash": "f7e339254436fdf45988c26786265c1d00bfcc23c0c5419fc07c0e6c", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/python-expr6-1a1d4fb.stdout b/tests/reference/python-expr6-1a1d4fb.stdout index fe35320c4e..ccb26aa61f 100644 --- a/tests/reference/python-expr6-1a1d4fb.stdout +++ b/tests/reference/python-expr6-1a1d4fb.stdout @@ -5,3 +5,5 @@ def test_ifexp(): a = 2 b = 6 if (a) == (2) else 8 c = True if (b) > (5) else False + + From 99172277ea737ebc96c0707a50c1a81f5da76ea3 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 13:07:02 +0530 Subject: [PATCH 12/31] Update error test references --- integration_tests/test_dict_const.py | 16 +++++++-------- tests/errors/test_dict_const.py | 8 +++++--- .../asr-test_dict_const-69479e2.json | 4 ++-- .../asr-test_dict_const-69479e2.stdout | 20 +++++++++---------- .../runtime-test_dict_const-62054df.json | 13 ++++++++++++ .../runtime-test_dict_const-62054df.stderr | 5 +++++ tests/tests.toml | 4 ++++ 7 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 tests/reference/runtime-test_dict_const-62054df.json create mode 100644 tests/reference/runtime-test_dict_const-62054df.stderr diff --git a/integration_tests/test_dict_const.py b/integration_tests/test_dict_const.py index 214b35e30c..b8467e3a79 100644 --- a/integration_tests/test_dict_const.py +++ b/integration_tests/test_dict_const.py @@ -2,17 +2,17 @@ def test_dict_const(): - d_int: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} + CONST_DICTIONARY_INTEGR: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} - assert d_int.get("a") == 1 - assert d_int.keys() == ["c", "a", "b"] - assert d_int.values() == [3, 1, 2] + assert CONST_DICTIONARY_INTEGR.get("a") == 1 + assert CONST_DICTIONARY_INTEGR.keys() == ["c", "a", "b"] + assert CONST_DICTIONARY_INTEGR.values() == [3, 1, 2] - d_float: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} + CONST_DICTIONARY_FLOAT: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} - assert d_float.get("a") == 1.0 - assert d_float.keys() == ["c", "a", "b"] - assert d_float.values() == [3.0, 1.0, 2.0] + assert CONST_DICTIONARY_FLOAT.get("a") == 1.0 + assert CONST_DICTIONARY_FLOAT.keys() == ["c", "a", "b"] + assert CONST_DICTIONARY_FLOAT.values() == [3.0, 1.0, 2.0] test_dict_const() diff --git a/tests/errors/test_dict_const.py b/tests/errors/test_dict_const.py index 71c4121736..6515282bfe 100644 --- a/tests/errors/test_dict_const.py +++ b/tests/errors/test_dict_const.py @@ -2,6 +2,8 @@ def test_dict_const(): - d: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} - print(d.pop("a")) - i: i32 = d.pop("a") + CONST_DICTIONARY: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} + print(CONST_DICTIONARY.pop("a")) + i: i32 = CONST_DICTIONARY.pop("a") + +test_dict_const() diff --git a/tests/reference/asr-test_dict_const-69479e2.json b/tests/reference/asr-test_dict_const-69479e2.json index b1e6e3b97d..1404bf7f76 100644 --- a/tests/reference/asr-test_dict_const-69479e2.json +++ b/tests/reference/asr-test_dict_const-69479e2.json @@ -2,11 +2,11 @@ "basename": "asr-test_dict_const-69479e2", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_dict_const.py", - "infile_hash": "61ca282635e2a28e2c7740f44cc8e1cc1af49988155e9f32b737cec3", + "infile_hash": "e897020e0517d4a97b2f1cd2971ebf3686c0de832412160a0583e28d", "outfile": null, "outfile_hash": null, "stdout": "asr-test_dict_const-69479e2.stdout", - "stdout_hash": "9b7d2dc1e374e1a711a9b91edf78debb0b6f038b7e7f000769f57f96", + "stdout_hash": "072819f5feb77a8ba653fbd38c2f2b1345dbf5588e05e57a8c206cd4", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_dict_const-69479e2.stdout b/tests/reference/asr-test_dict_const-69479e2.stdout index aa20030c5b..4ec780e0ea 100644 --- a/tests/reference/asr-test_dict_const-69479e2.stdout +++ b/tests/reference/asr-test_dict_const-69479e2.stdout @@ -48,10 +48,10 @@ (SymbolTable 3 { - d_float: + CONST_DICTIONARY_FLOAT: (Variable 3 - d_float + CONST_DICTIONARY_FLOAT [] Local (DictConstant @@ -127,10 +127,10 @@ Required .false. ), - d_int: + CONST_DICTIONARY_INTEGR: (Variable 3 - d_int + CONST_DICTIONARY_INTEGR [] Local (DictConstant @@ -209,7 +209,7 @@ [(Assert (IntegerCompare (DictItem - (Var 3 d_int) + (Var 3 CONST_DICTIONARY_INTEGR) (StringConstant "a" (Character 1 1 ()) @@ -229,7 +229,7 @@ (ListCompare (IntrinsicScalarFunction DictKeys - [(Var 3 d_int)] + [(Var 3 CONST_DICTIONARY_INTEGR)] 0 (List (Character 1 -2 ()) @@ -263,7 +263,7 @@ (ListCompare (IntrinsicScalarFunction DictValues - [(Var 3 d_int)] + [(Var 3 CONST_DICTIONARY_INTEGR)] 0 (List (Integer 4) @@ -287,7 +287,7 @@ (Assert (RealCompare (DictItem - (Var 3 d_float) + (Var 3 CONST_DICTIONARY_FLOAT) (StringConstant "a" (Character 1 1 ()) @@ -310,7 +310,7 @@ (ListCompare (IntrinsicScalarFunction DictKeys - [(Var 3 d_float)] + [(Var 3 CONST_DICTIONARY_FLOAT)] 0 (List (Character 1 -2 ()) @@ -344,7 +344,7 @@ (ListCompare (IntrinsicScalarFunction DictValues - [(Var 3 d_float)] + [(Var 3 CONST_DICTIONARY_FLOAT)] 0 (List (Real 8) diff --git a/tests/reference/runtime-test_dict_const-62054df.json b/tests/reference/runtime-test_dict_const-62054df.json new file mode 100644 index 0000000000..8e7da3220f --- /dev/null +++ b/tests/reference/runtime-test_dict_const-62054df.json @@ -0,0 +1,13 @@ +{ + "basename": "runtime-test_dict_const-62054df", + "cmd": "lpython {infile}", + "infile": "tests/errors/test_dict_const.py", + "infile_hash": "6b1aa7e33c497b09cfd6db7a7897fe26dd98836d3d3d956018e9c211", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "runtime-test_dict_const-62054df.stderr", + "stderr_hash": "a9df181cfe48e863c8cfaac70f07ad18e1d5ee2c8b42fc10ac11eaad", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/runtime-test_dict_const-62054df.stderr b/tests/reference/runtime-test_dict_const-62054df.stderr new file mode 100644 index 0000000000..420ad7f106 --- /dev/null +++ b/tests/reference/runtime-test_dict_const-62054df.stderr @@ -0,0 +1,5 @@ +semantic error: cannot pop elements from a const dict + --> tests/errors/test_dict_const.py:6:11 + | +6 | print(CONST_DICTIONARY.pop("a")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^  diff --git a/tests/tests.toml b/tests/tests.toml index 5939ab860e..eabfaa9401 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -1031,6 +1031,10 @@ run = true filename = "errors/test_dict16.py" run = true +[[test]] +filename = "errors/test_dict_const.py" +run = true + [[test]] filename = "errors/test_zero_division.py" asr = true From 03d5998f7a5e0c65007ce3cd0d9b108018748f24 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Sun, 10 Mar 2024 15:11:08 +0530 Subject: [PATCH 13/31] Tests: Update test references --- ...{test_dict_const.py => test_const_dict.py} | 6 +- ...{test_dict_const.py => test_const_dict.py} | 6 +- .../asr-test_const_dict-151acad.json | 13 + .../asr-test_const_dict-151acad.stdout | 416 ++++++++++++++++++ .../asr-test_const_dict-59445d7.json | 13 + .../asr-test_const_dict-59445d7.stderr | 5 + tests/tests.toml | 6 +- 7 files changed, 456 insertions(+), 9 deletions(-) rename integration_tests/{test_dict_const.py => test_const_dict.py} (92%) rename tests/errors/{test_dict_const.py => test_const_dict.py} (66%) create mode 100644 tests/reference/asr-test_const_dict-151acad.json create mode 100644 tests/reference/asr-test_const_dict-151acad.stdout create mode 100644 tests/reference/asr-test_const_dict-59445d7.json create mode 100644 tests/reference/asr-test_const_dict-59445d7.stderr diff --git a/integration_tests/test_dict_const.py b/integration_tests/test_const_dict.py similarity index 92% rename from integration_tests/test_dict_const.py rename to integration_tests/test_const_dict.py index b8467e3a79..2a60352f77 100644 --- a/integration_tests/test_dict_const.py +++ b/integration_tests/test_const_dict.py @@ -1,7 +1,7 @@ from lpython import i32, f64, str, dict, Const -def test_dict_const(): +def test_const_dict(): CONST_DICTIONARY_INTEGR: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} assert CONST_DICTIONARY_INTEGR.get("a") == 1 @@ -9,10 +9,10 @@ def test_dict_const(): assert CONST_DICTIONARY_INTEGR.values() == [3, 1, 2] CONST_DICTIONARY_FLOAT: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} - + assert CONST_DICTIONARY_FLOAT.get("a") == 1.0 assert CONST_DICTIONARY_FLOAT.keys() == ["c", "a", "b"] assert CONST_DICTIONARY_FLOAT.values() == [3.0, 1.0, 2.0] -test_dict_const() +test_const_dict() diff --git a/tests/errors/test_dict_const.py b/tests/errors/test_const_dict.py similarity index 66% rename from tests/errors/test_dict_const.py rename to tests/errors/test_const_dict.py index 6515282bfe..020d204197 100644 --- a/tests/errors/test_dict_const.py +++ b/tests/errors/test_const_dict.py @@ -1,9 +1,9 @@ from lpython import i32, f64, str, dict, Const -def test_dict_const(): +def test_const_dict(): CONST_DICTIONARY: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} print(CONST_DICTIONARY.pop("a")) - i: i32 = CONST_DICTIONARY.pop("a") -test_dict_const() + +test_const_dict() diff --git a/tests/reference/asr-test_const_dict-151acad.json b/tests/reference/asr-test_const_dict-151acad.json new file mode 100644 index 0000000000..43529c3e53 --- /dev/null +++ b/tests/reference/asr-test_const_dict-151acad.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_dict-151acad", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/../integration_tests/test_const_dict.py", + "infile_hash": "6a8c7a08b3387c074e091719bcfa6b7fe526abbbcb5568e7b0623504", + "outfile": null, + "outfile_hash": null, + "stdout": "asr-test_const_dict-151acad.stdout", + "stdout_hash": "b6efc64f1e86923a360be2ad65c808cf00cf91c69f082db49935bc85", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_dict-151acad.stdout b/tests/reference/asr-test_const_dict-151acad.stdout new file mode 100644 index 0000000000..6cb57b8c0f --- /dev/null +++ b/tests/reference/asr-test_const_dict-151acad.stdout @@ -0,0 +1,416 @@ +(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_const_dict] + [] + [(SubroutineCall + 2 test_const_dict + () + [] + () + )] + () + Public + .false. + .false. + () + ), + test_const_dict: + (Function + (SymbolTable + 3 + { + CONST_DICTIONARY_FLOAT: + (Variable + 3 + CONST_DICTIONARY_FLOAT + [] + Local + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 3.000000 + (Real 8) + )] + (Dict + (Character 1 1 ()) + (Real 8) + ) + ) + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 3.000000 + (Real 8) + )] + (Dict + (Character 1 1 ()) + (Real 8) + ) + ) + Parameter + (Const + (Dict + (Character 1 -2 ()) + (Real 8) + ) + ) + () + Source + Public + Required + .false. + ), + CONST_DICTIONARY_INTEGR: + (Variable + 3 + CONST_DICTIONARY_INTEGR + [] + Local + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4))] + (Dict + (Character 1 1 ()) + (Integer 4) + ) + ) + (DictConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4))] + (Dict + (Character 1 1 ()) + (Integer 4) + ) + ) + Parameter + (Const + (Dict + (Character 1 -2 ()) + (Integer 4) + ) + ) + () + Source + Public + Required + .false. + ) + }) + test_const_dict + (FunctionType + [] + () + Source + Implementation + () + .false. + .false. + .false. + .false. + .false. + [] + .false. + ) + [] + [] + [(Assert + (IntegerCompare + (DictItem + (Var 3 CONST_DICTIONARY_INTEGR) + (StringConstant + "a" + (Character 1 1 ()) + ) + () + (Integer 4) + () + ) + Eq + (IntegerConstant 1 (Integer 4)) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictKeys + [(Var 3 CONST_DICTIONARY_INTEGR)] + 0 + (List + (Character 1 -2 ()) + ) + () + ) + Eq + (ListConstant + [(StringConstant + "c" + (Character 1 1 ()) + ) + (StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + )] + (List + (Character 1 1 ()) + ) + ) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictValues + [(Var 3 CONST_DICTIONARY_INTEGR)] + 0 + (List + (Integer 4) + ) + () + ) + Eq + (ListConstant + [(IntegerConstant 3 (Integer 4)) + (IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4))] + (List + (Integer 4) + ) + ) + (Logical 4) + () + ) + () + ) + (Assert + (RealCompare + (DictItem + (Var 3 CONST_DICTIONARY_FLOAT) + (StringConstant + "a" + (Character 1 1 ()) + ) + () + (Real 8) + () + ) + Eq + (RealConstant + 1.000000 + (Real 8) + ) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictKeys + [(Var 3 CONST_DICTIONARY_FLOAT)] + 0 + (List + (Character 1 -2 ()) + ) + () + ) + Eq + (ListConstant + [(StringConstant + "c" + (Character 1 1 ()) + ) + (StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + )] + (List + (Character 1 1 ()) + ) + ) + (Logical 4) + () + ) + () + ) + (Assert + (ListCompare + (IntrinsicScalarFunction + DictValues + [(Var 3 CONST_DICTIONARY_FLOAT)] + 0 + (List + (Real 8) + ) + () + ) + Eq + (ListConstant + [(RealConstant + 3.000000 + (Real 8) + ) + (RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + )] + (List + (Real 8) + ) + ) + (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_const_dict-59445d7.json b/tests/reference/asr-test_const_dict-59445d7.json new file mode 100644 index 0000000000..bf72d0a372 --- /dev/null +++ b/tests/reference/asr-test_const_dict-59445d7.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_dict-59445d7", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_dict.py", + "infile_hash": "86ebfc5e88bd38f880eca81c3a7456f33991135e335c13525acca172", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_dict-59445d7.stderr", + "stderr_hash": "1d3729d80a7895dd01baaf0905c6cc9ebadd7f7ce623f4ae5970e2b8", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_dict-59445d7.stderr b/tests/reference/asr-test_const_dict-59445d7.stderr new file mode 100644 index 0000000000..3b7757fec4 --- /dev/null +++ b/tests/reference/asr-test_const_dict-59445d7.stderr @@ -0,0 +1,5 @@ +semantic error: cannot pop elements from a const dict + --> tests/errors/test_const_dict.py:6:11 + | +6 | print(CONST_DICTIONARY.pop("a")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/tests.toml b/tests/tests.toml index eabfaa9401..ee30f207ca 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -488,7 +488,7 @@ filename = "../integration_tests/global_syms_01.py" asr = true [[test]] -filename = "../integration_tests/test_dict_const.py" +filename = "../integration_tests/test_const_dict.py" asr = true [[test]] @@ -1032,8 +1032,8 @@ filename = "errors/test_dict16.py" run = true [[test]] -filename = "errors/test_dict_const.py" -run = true +filename = "errors/test_const_dict.py" +asr = true [[test]] filename = "errors/test_zero_division.py" From 22009cd88ee27e3a0212170a00ae2843056b1d2b Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Mon, 11 Mar 2024 00:35:18 +0530 Subject: [PATCH 14/31] Tests: Add runtime tests and update test references --- integration_tests/CMakeLists.txt | 1 + integration_tests/test_const_dict.py | 2 +- tests/errors/test_const_dict.py | 2 +- tests/reference/asr-test_const_dict-151acad.json | 2 +- tests/reference/asr-test_const_dict-59445d7.json | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index a396205a23..0c02e55d52 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -571,6 +571,7 @@ RUN(NAME test_dict_10 LABELS cpython llvm c) RUN(NAME test_dict_11 LABELS cpython llvm c) RUN(NAME test_dict_12 LABELS cpython llvm c) RUN(NAME test_dict_13 LABELS cpython llvm c) +RUN(NAME test_const_dict LABELS cpython llvm c) RUN(NAME test_dict_bool LABELS cpython llvm) RUN(NAME test_dict_increment LABELS cpython llvm) RUN(NAME test_dict_keys_values LABELS cpython llvm) diff --git a/integration_tests/test_const_dict.py b/integration_tests/test_const_dict.py index 2a60352f77..906d2f5db5 100644 --- a/integration_tests/test_const_dict.py +++ b/integration_tests/test_const_dict.py @@ -1,4 +1,4 @@ -from lpython import i32, f64, str, dict, Const +from lpython import i32, f64, dict, Const def test_const_dict(): diff --git a/tests/errors/test_const_dict.py b/tests/errors/test_const_dict.py index 020d204197..7c0e33d33e 100644 --- a/tests/errors/test_const_dict.py +++ b/tests/errors/test_const_dict.py @@ -1,4 +1,4 @@ -from lpython import i32, f64, str, dict, Const +from lpython import i32, f64, dict, Const def test_const_dict(): diff --git a/tests/reference/asr-test_const_dict-151acad.json b/tests/reference/asr-test_const_dict-151acad.json index 43529c3e53..89b8138895 100644 --- a/tests/reference/asr-test_const_dict-151acad.json +++ b/tests/reference/asr-test_const_dict-151acad.json @@ -2,7 +2,7 @@ "basename": "asr-test_const_dict-151acad", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_const_dict.py", - "infile_hash": "6a8c7a08b3387c074e091719bcfa6b7fe526abbbcb5568e7b0623504", + "infile_hash": "6e547eaa2b0e4c4bef82a0b0071aa4fa5a94f91e0f1e8d1ab73e5014", "outfile": null, "outfile_hash": null, "stdout": "asr-test_const_dict-151acad.stdout", diff --git a/tests/reference/asr-test_const_dict-59445d7.json b/tests/reference/asr-test_const_dict-59445d7.json index bf72d0a372..69906db3c2 100644 --- a/tests/reference/asr-test_const_dict-59445d7.json +++ b/tests/reference/asr-test_const_dict-59445d7.json @@ -2,7 +2,7 @@ "basename": "asr-test_const_dict-59445d7", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/errors/test_const_dict.py", - "infile_hash": "86ebfc5e88bd38f880eca81c3a7456f33991135e335c13525acca172", + "infile_hash": "51130e98c759eb3cdbd50848e59879e4689d241c7a8674aa06a5b3c7", "outfile": null, "outfile_hash": null, "stdout": null, From 737acb4459bedfbcc3822b789101a8e73ec46bc1 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 1 May 2024 10:25:41 +0530 Subject: [PATCH 15/31] Remove checks on the absent `Const` node --- src/libasr/codegen/asr_to_llvm.cpp | 5 ++--- src/lpython/semantics/python_attribute_eval.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 62d5ae52f4..2e587ae6bd 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1540,8 +1540,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - ASR::Dict_t *dict_type = ASR::down_cast( - ASRUtils::type_get_past_const(ASRUtils::expr_type(x.m_a))); + ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; @@ -1846,7 +1845,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::type_get_past_const(ASRUtils::expr_type(m_arg))); + ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg))); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; diff --git a/src/lpython/semantics/python_attribute_eval.h b/src/lpython/semantics/python_attribute_eval.h index 17f479aa91..9b8386c611 100644 --- a/src/lpython/semantics/python_attribute_eval.h +++ b/src/lpython/semantics/python_attribute_eval.h @@ -358,7 +358,7 @@ struct AttributeHandler { throw SemanticError("'get' takes atleast 1 and atmost 2 arguments", loc); } - ASR::ttype_t *type = ASRUtils::type_get_past_const(ASRUtils::expr_type(s)); + ASR::ttype_t *type = ASRUtils::expr_type(s); ASR::ttype_t *key_type = ASR::down_cast(type)->m_key_type; ASR::ttype_t *value_type = ASR::down_cast(type)->m_value_type; if (args.size() == 2) { @@ -393,7 +393,7 @@ struct AttributeHandler { static ASR::asr_t* eval_dict_pop(ASR::expr_t *s, Allocator &al, const Location &loc, Vec &args, diag::Diagnostics &diag) { - if (ASR::is_a(*ASRUtils::expr_type(s))) { + if (ASRUtils::is_const(s)) { throw SemanticError("cannot pop elements from a const dict", loc); } if (args.size() != 1) { From 4a2942fbf5930e06f83c55e88bc05d4c303f407c Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 1 May 2024 10:33:36 +0530 Subject: [PATCH 16/31] Remove call to `get_contained_type()` --- src/libasr/codegen/asr_to_llvm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2e587ae6bd..2a7cf988f8 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1845,7 +1845,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::get_contained_type(ASRUtils::expr_type(m_arg))); + ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::expr_type(m_arg)); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; From 6f199800a6b6b9065e88e208ec3f310a03e48604 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 1 May 2024 10:35:03 +0530 Subject: [PATCH 17/31] Tests: Add tests and update references --- integration_tests/test_const_dict.py | 4 +- .../asr-test_const_dict-151acad.json | 4 +- .../asr-test_const_dict-151acad.stdout | 99 ++++++++++++++----- 3 files changed, 79 insertions(+), 28 deletions(-) diff --git a/integration_tests/test_const_dict.py b/integration_tests/test_const_dict.py index 906d2f5db5..2cab6db9bb 100644 --- a/integration_tests/test_const_dict.py +++ b/integration_tests/test_const_dict.py @@ -11,8 +11,8 @@ def test_const_dict(): CONST_DICTIONARY_FLOAT: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} assert CONST_DICTIONARY_FLOAT.get("a") == 1.0 - assert CONST_DICTIONARY_FLOAT.keys() == ["c", "a", "b"] - assert CONST_DICTIONARY_FLOAT.values() == [3.0, 1.0, 2.0] + assert CONST_DICTIONARY_FLOAT.keys() == ['a', 'b', 'c'] + assert CONST_DICTIONARY_FLOAT.values() == [1.0, 2.0, 3.0] test_const_dict() diff --git a/tests/reference/asr-test_const_dict-151acad.json b/tests/reference/asr-test_const_dict-151acad.json index 89b8138895..c8a9033f15 100644 --- a/tests/reference/asr-test_const_dict-151acad.json +++ b/tests/reference/asr-test_const_dict-151acad.json @@ -2,11 +2,11 @@ "basename": "asr-test_const_dict-151acad", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_const_dict.py", - "infile_hash": "6e547eaa2b0e4c4bef82a0b0071aa4fa5a94f91e0f1e8d1ab73e5014", + "infile_hash": "7588c95c118bf7ede1ec06b39b0478fa1184c202c449fcf354afa907", "outfile": null, "outfile_hash": null, "stdout": "asr-test_const_dict-151acad.stdout", - "stdout_hash": "b6efc64f1e86923a360be2ad65c808cf00cf91c69f082db49935bc85", + "stdout_hash": "c475b3d9b9bade94015ef852f949ef149e2e6035e8fddcd20b22ca69", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_const_dict-151acad.stdout b/tests/reference/asr-test_const_dict-151acad.stdout index 6cb57b8c0f..33bfa4bb28 100644 --- a/tests/reference/asr-test_const_dict-151acad.stdout +++ b/tests/reference/asr-test_const_dict-151acad.stdout @@ -115,11 +115,9 @@ ) ) Parameter - (Const - (Dict - (Character 1 -2 ()) - (Real 8) - ) + (Dict + (Character 1 -2 ()) + (Real 8) ) () Source @@ -176,11 +174,9 @@ ) ) Parameter - (Const - (Dict - (Character 1 -2 ()) - (Integer 4) - ) + (Dict + (Character 1 -2 ()) + (Integer 4) ) () Source @@ -227,14 +223,30 @@ ) (Assert (ListCompare - (IntrinsicScalarFunction + (IntrinsicElementalFunction DictKeys [(Var 3 CONST_DICTIONARY_INTEGR)] 0 (List (Character 1 -2 ()) ) - () + (ListConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + (List + (Character 1 -2 ()) + ) + ) ) Eq (ListConstant @@ -261,14 +273,21 @@ ) (Assert (ListCompare - (IntrinsicScalarFunction + (IntrinsicElementalFunction DictValues [(Var 3 CONST_DICTIONARY_INTEGR)] 0 (List (Integer 4) ) - () + (ListConstant + [(IntegerConstant 1 (Integer 4)) + (IntegerConstant 2 (Integer 4)) + (IntegerConstant 3 (Integer 4))] + (List + (Integer 4) + ) + ) ) Eq (ListConstant @@ -308,27 +327,43 @@ ) (Assert (ListCompare - (IntrinsicScalarFunction + (IntrinsicElementalFunction DictKeys [(Var 3 CONST_DICTIONARY_FLOAT)] 0 (List (Character 1 -2 ()) ) - () + (ListConstant + [(StringConstant + "a" + (Character 1 1 ()) + ) + (StringConstant + "b" + (Character 1 1 ()) + ) + (StringConstant + "c" + (Character 1 1 ()) + )] + (List + (Character 1 -2 ()) + ) + ) ) Eq (ListConstant [(StringConstant - "c" + "a" (Character 1 1 ()) ) (StringConstant - "a" + "b" (Character 1 1 ()) ) (StringConstant - "b" + "c" (Character 1 1 ()) )] (List @@ -342,27 +377,43 @@ ) (Assert (ListCompare - (IntrinsicScalarFunction + (IntrinsicElementalFunction DictValues [(Var 3 CONST_DICTIONARY_FLOAT)] 0 (List (Real 8) ) - () + (ListConstant + [(RealConstant + 1.000000 + (Real 8) + ) + (RealConstant + 2.000000 + (Real 8) + ) + (RealConstant + 3.000000 + (Real 8) + )] + (List + (Real 8) + ) + ) ) Eq (ListConstant [(RealConstant - 3.000000 + 1.000000 (Real 8) ) (RealConstant - 1.000000 + 2.000000 (Real 8) ) (RealConstant - 2.000000 + 3.000000 (Real 8) )] (List From 634011c0167b3c28f7d45b212604d8fb8ed2b85f Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 1 May 2024 18:30:43 +0530 Subject: [PATCH 18/31] Style changes --- src/libasr/codegen/asr_to_llvm.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2a7cf988f8..5c4ebe0d82 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1524,7 +1524,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListItem(const ASR::ListItem_t& x) { - ASR::ttype_t *el_type = ASRUtils::get_contained_type(ASRUtils::expr_type(x.m_a)); + ASR::ttype_t *el_type = ASRUtils::get_contained_type( + ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_a); @@ -1540,7 +1541,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::expr_type(x.m_a)); + ASR::Dict_t *dict_type = ASR::down_cast( + ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; @@ -1845,7 +1847,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t *dict_type = ASR::down_cast(ASRUtils::expr_type(m_arg)); + ASR::Dict_t *dict_type = ASR::down_cast( + ASRUtils::expr_type(m_arg)); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; From 85798514a03d32dc3ed1a9c04edd7047c82dd301 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 1 May 2024 18:31:19 +0530 Subject: [PATCH 19/31] Tests: Update tests and add to CMakeLists --- integration_tests/CMakeLists.txt | 2 ++ integration_tests/test_const_dict.py | 28 +++++++++++++++++----------- tests/tests.toml | 4 ---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 4ddd08c540..cf7b74c022 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -562,6 +562,8 @@ RUN(NAME test_tuple_03 LABELS cpython llvm llvm_jit c) 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_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) diff --git a/integration_tests/test_const_dict.py b/integration_tests/test_const_dict.py index 2cab6db9bb..e06578fc45 100644 --- a/integration_tests/test_const_dict.py +++ b/integration_tests/test_const_dict.py @@ -1,18 +1,24 @@ -from lpython import i32, f64, dict, Const +from lpython import i32, f64, Const +CONST_DICTIONARY_INTEGR: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} -def test_const_dict(): - CONST_DICTIONARY_INTEGR: Const[dict[str, i32]] = {"a": 1, "b": 2, "c": 3} +print(CONST_DICTIONARY_INTEGR.get("a")) +assert CONST_DICTIONARY_INTEGR.get("a") == 1 - assert CONST_DICTIONARY_INTEGR.get("a") == 1 - assert CONST_DICTIONARY_INTEGR.keys() == ["c", "a", "b"] - assert CONST_DICTIONARY_INTEGR.values() == [3, 1, 2] +print(CONST_DICTIONARY_INTEGR.keys()) +assert len(CONST_DICTIONARY_INTEGR.keys()) == 3 - CONST_DICTIONARY_FLOAT: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} +print(CONST_DICTIONARY_INTEGR.values()) +assert len(CONST_DICTIONARY_INTEGR.values()) == 3 - assert CONST_DICTIONARY_FLOAT.get("a") == 1.0 - assert CONST_DICTIONARY_FLOAT.keys() == ['a', 'b', 'c'] - assert CONST_DICTIONARY_FLOAT.values() == [1.0, 2.0, 3.0] +CONST_DICTIONARY_FLOAT: Const[dict[str, f64]] = {"a": 1.0, "b": 2.0, "c": 3.0} +print(CONST_DICTIONARY_FLOAT.get("a")) +assert CONST_DICTIONARY_FLOAT.get("a") == 1.0 + +print(CONST_DICTIONARY_FLOAT.keys()) +assert len(CONST_DICTIONARY_FLOAT.keys()) == 3 + +print(CONST_DICTIONARY_FLOAT.values()) +assert len(CONST_DICTIONARY_FLOAT.values()) == 3 -test_const_dict() diff --git a/tests/tests.toml b/tests/tests.toml index 8f5132d7bf..b106996999 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -497,10 +497,6 @@ asr = true filename = "../integration_tests/global_syms_01.py" asr = true -[[test]] -filename = "../integration_tests/test_const_dict.py" -asr = true - [[test]] filename = "cast.py" asr = true From 809fe8d55f5ed457f6ab55fc712b621bc704d0de Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:37:01 +0530 Subject: [PATCH 20/31] Delete tests/reference/asr-test_const_dict-151acad.json --- tests/reference/asr-test_const_dict-151acad.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/reference/asr-test_const_dict-151acad.json diff --git a/tests/reference/asr-test_const_dict-151acad.json b/tests/reference/asr-test_const_dict-151acad.json deleted file mode 100644 index c8a9033f15..0000000000 --- a/tests/reference/asr-test_const_dict-151acad.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "asr-test_const_dict-151acad", - "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", - "infile": "tests/../integration_tests/test_const_dict.py", - "infile_hash": "7588c95c118bf7ede1ec06b39b0478fa1184c202c449fcf354afa907", - "outfile": null, - "outfile_hash": null, - "stdout": "asr-test_const_dict-151acad.stdout", - "stdout_hash": "c475b3d9b9bade94015ef852f949ef149e2e6035e8fddcd20b22ca69", - "stderr": null, - "stderr_hash": null, - "returncode": 0 -} \ No newline at end of file From f0de6cf619a77a3c30bbcb9da6911bdec3bfa673 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:37:15 +0530 Subject: [PATCH 21/31] Delete tests/reference/asr-test_const_dict-151acad.stdout --- .../asr-test_const_dict-151acad.stdout | 467 ------------------ 1 file changed, 467 deletions(-) delete mode 100644 tests/reference/asr-test_const_dict-151acad.stdout diff --git a/tests/reference/asr-test_const_dict-151acad.stdout b/tests/reference/asr-test_const_dict-151acad.stdout deleted file mode 100644 index 33bfa4bb28..0000000000 --- a/tests/reference/asr-test_const_dict-151acad.stdout +++ /dev/null @@ -1,467 +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_const_dict] - [] - [(SubroutineCall - 2 test_const_dict - () - [] - () - )] - () - Public - .false. - .false. - () - ), - test_const_dict: - (Function - (SymbolTable - 3 - { - CONST_DICTIONARY_FLOAT: - (Variable - 3 - CONST_DICTIONARY_FLOAT - [] - Local - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - ) - (RealConstant - 3.000000 - (Real 8) - )] - (Dict - (Character 1 1 ()) - (Real 8) - ) - ) - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - ) - (RealConstant - 3.000000 - (Real 8) - )] - (Dict - (Character 1 1 ()) - (Real 8) - ) - ) - Parameter - (Dict - (Character 1 -2 ()) - (Real 8) - ) - () - Source - Public - Required - .false. - ), - CONST_DICTIONARY_INTEGR: - (Variable - 3 - CONST_DICTIONARY_INTEGR - [] - Local - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4))] - (Dict - (Character 1 1 ()) - (Integer 4) - ) - ) - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4))] - (Dict - (Character 1 1 ()) - (Integer 4) - ) - ) - Parameter - (Dict - (Character 1 -2 ()) - (Integer 4) - ) - () - Source - Public - Required - .false. - ) - }) - test_const_dict - (FunctionType - [] - () - Source - Implementation - () - .false. - .false. - .false. - .false. - .false. - [] - .false. - ) - [] - [] - [(Assert - (IntegerCompare - (DictItem - (Var 3 CONST_DICTIONARY_INTEGR) - (StringConstant - "a" - (Character 1 1 ()) - ) - () - (Integer 4) - () - ) - Eq - (IntegerConstant 1 (Integer 4)) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicElementalFunction - DictKeys - [(Var 3 CONST_DICTIONARY_INTEGR)] - 0 - (List - (Character 1 -2 ()) - ) - (ListConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - (List - (Character 1 -2 ()) - ) - ) - ) - Eq - (ListConstant - [(StringConstant - "c" - (Character 1 1 ()) - ) - (StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - )] - (List - (Character 1 1 ()) - ) - ) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicElementalFunction - DictValues - [(Var 3 CONST_DICTIONARY_INTEGR)] - 0 - (List - (Integer 4) - ) - (ListConstant - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4))] - (List - (Integer 4) - ) - ) - ) - Eq - (ListConstant - [(IntegerConstant 3 (Integer 4)) - (IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4))] - (List - (Integer 4) - ) - ) - (Logical 4) - () - ) - () - ) - (Assert - (RealCompare - (DictItem - (Var 3 CONST_DICTIONARY_FLOAT) - (StringConstant - "a" - (Character 1 1 ()) - ) - () - (Real 8) - () - ) - Eq - (RealConstant - 1.000000 - (Real 8) - ) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicElementalFunction - DictKeys - [(Var 3 CONST_DICTIONARY_FLOAT)] - 0 - (List - (Character 1 -2 ()) - ) - (ListConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - (List - (Character 1 -2 ()) - ) - ) - ) - Eq - (ListConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - (List - (Character 1 1 ()) - ) - ) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicElementalFunction - DictValues - [(Var 3 CONST_DICTIONARY_FLOAT)] - 0 - (List - (Real 8) - ) - (ListConstant - [(RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - ) - (RealConstant - 3.000000 - (Real 8) - )] - (List - (Real 8) - ) - ) - ) - Eq - (ListConstant - [(RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - ) - (RealConstant - 3.000000 - (Real 8) - )] - (List - (Real 8) - ) - ) - (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 - [] - () - )] - ) - }) - [] -) From 6c086e34ac2248bf83a6eaf8141deac84187cf73 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:37:37 +0530 Subject: [PATCH 22/31] Delete tests/reference/asr-test_const_dict-59445d7.json --- tests/reference/asr-test_const_dict-59445d7.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/reference/asr-test_const_dict-59445d7.json diff --git a/tests/reference/asr-test_const_dict-59445d7.json b/tests/reference/asr-test_const_dict-59445d7.json deleted file mode 100644 index 69906db3c2..0000000000 --- a/tests/reference/asr-test_const_dict-59445d7.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "asr-test_const_dict-59445d7", - "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", - "infile": "tests/errors/test_const_dict.py", - "infile_hash": "51130e98c759eb3cdbd50848e59879e4689d241c7a8674aa06a5b3c7", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "asr-test_const_dict-59445d7.stderr", - "stderr_hash": "1d3729d80a7895dd01baaf0905c6cc9ebadd7f7ce623f4ae5970e2b8", - "returncode": 2 -} \ No newline at end of file From 7e0a8c2791c77bc1dfd0035cf809eb7883545825 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:38:06 +0530 Subject: [PATCH 23/31] Delete tests/reference/asr-test_dict_const-69479e2.json --- tests/reference/asr-test_dict_const-69479e2.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/reference/asr-test_dict_const-69479e2.json diff --git a/tests/reference/asr-test_dict_const-69479e2.json b/tests/reference/asr-test_dict_const-69479e2.json deleted file mode 100644 index 1404bf7f76..0000000000 --- a/tests/reference/asr-test_dict_const-69479e2.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "asr-test_dict_const-69479e2", - "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", - "infile": "tests/../integration_tests/test_dict_const.py", - "infile_hash": "e897020e0517d4a97b2f1cd2971ebf3686c0de832412160a0583e28d", - "outfile": null, - "outfile_hash": null, - "stdout": "asr-test_dict_const-69479e2.stdout", - "stdout_hash": "072819f5feb77a8ba653fbd38c2f2b1345dbf5588e05e57a8c206cd4", - "stderr": null, - "stderr_hash": null, - "returncode": 0 -} \ No newline at end of file From e0c4d62ea2817f6980e46993aa60e3e4ccaa79cf Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:38:30 +0530 Subject: [PATCH 24/31] Delete tests/reference/asr-test_dict_const-69479e2.stderr --- tests/reference/asr-test_dict_const-69479e2.stderr | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tests/reference/asr-test_dict_const-69479e2.stderr diff --git a/tests/reference/asr-test_dict_const-69479e2.stderr b/tests/reference/asr-test_dict_const-69479e2.stderr deleted file mode 100644 index b3269f240e..0000000000 --- a/tests/reference/asr-test_dict_const-69479e2.stderr +++ /dev/null @@ -1,5 +0,0 @@ -semantic error: Type name is not implemented yet. - --> tests/../integration_tests/test_dict_const.py:8:12 - | -8 | assert d_int.get("a") == 1 - | ^^^^^^^^^^^^^^ From 3307acf3c7e79d61ac85bd5b595146f43efabd71 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:38:55 +0530 Subject: [PATCH 25/31] Delete tests/reference/asr-test_dict_const-69479e2.stdout --- .../asr-test_dict_const-69479e2.stdout | 416 ------------------ 1 file changed, 416 deletions(-) delete mode 100644 tests/reference/asr-test_dict_const-69479e2.stdout diff --git a/tests/reference/asr-test_dict_const-69479e2.stdout b/tests/reference/asr-test_dict_const-69479e2.stdout deleted file mode 100644 index 4ec780e0ea..0000000000 --- a/tests/reference/asr-test_dict_const-69479e2.stdout +++ /dev/null @@ -1,416 +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_dict_const] - [] - [(SubroutineCall - 2 test_dict_const - () - [] - () - )] - () - Public - .false. - .false. - () - ), - test_dict_const: - (Function - (SymbolTable - 3 - { - CONST_DICTIONARY_FLOAT: - (Variable - 3 - CONST_DICTIONARY_FLOAT - [] - Local - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - ) - (RealConstant - 3.000000 - (Real 8) - )] - (Dict - (Character 1 1 ()) - (Real 8) - ) - ) - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - ) - (RealConstant - 3.000000 - (Real 8) - )] - (Dict - (Character 1 1 ()) - (Real 8) - ) - ) - Parameter - (Const - (Dict - (Character 1 -2 ()) - (Real 8) - ) - ) - () - Source - Public - Required - .false. - ), - CONST_DICTIONARY_INTEGR: - (Variable - 3 - CONST_DICTIONARY_INTEGR - [] - Local - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4))] - (Dict - (Character 1 1 ()) - (Integer 4) - ) - ) - (DictConstant - [(StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - ) - (StringConstant - "c" - (Character 1 1 ()) - )] - [(IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4)) - (IntegerConstant 3 (Integer 4))] - (Dict - (Character 1 1 ()) - (Integer 4) - ) - ) - Parameter - (Const - (Dict - (Character 1 -2 ()) - (Integer 4) - ) - ) - () - Source - Public - Required - .false. - ) - }) - test_dict_const - (FunctionType - [] - () - Source - Implementation - () - .false. - .false. - .false. - .false. - .false. - [] - .false. - ) - [] - [] - [(Assert - (IntegerCompare - (DictItem - (Var 3 CONST_DICTIONARY_INTEGR) - (StringConstant - "a" - (Character 1 1 ()) - ) - () - (Integer 4) - () - ) - Eq - (IntegerConstant 1 (Integer 4)) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicScalarFunction - DictKeys - [(Var 3 CONST_DICTIONARY_INTEGR)] - 0 - (List - (Character 1 -2 ()) - ) - () - ) - Eq - (ListConstant - [(StringConstant - "c" - (Character 1 1 ()) - ) - (StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - )] - (List - (Character 1 1 ()) - ) - ) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicScalarFunction - DictValues - [(Var 3 CONST_DICTIONARY_INTEGR)] - 0 - (List - (Integer 4) - ) - () - ) - Eq - (ListConstant - [(IntegerConstant 3 (Integer 4)) - (IntegerConstant 1 (Integer 4)) - (IntegerConstant 2 (Integer 4))] - (List - (Integer 4) - ) - ) - (Logical 4) - () - ) - () - ) - (Assert - (RealCompare - (DictItem - (Var 3 CONST_DICTIONARY_FLOAT) - (StringConstant - "a" - (Character 1 1 ()) - ) - () - (Real 8) - () - ) - Eq - (RealConstant - 1.000000 - (Real 8) - ) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicScalarFunction - DictKeys - [(Var 3 CONST_DICTIONARY_FLOAT)] - 0 - (List - (Character 1 -2 ()) - ) - () - ) - Eq - (ListConstant - [(StringConstant - "c" - (Character 1 1 ()) - ) - (StringConstant - "a" - (Character 1 1 ()) - ) - (StringConstant - "b" - (Character 1 1 ()) - )] - (List - (Character 1 1 ()) - ) - ) - (Logical 4) - () - ) - () - ) - (Assert - (ListCompare - (IntrinsicScalarFunction - DictValues - [(Var 3 CONST_DICTIONARY_FLOAT)] - 0 - (List - (Real 8) - ) - () - ) - Eq - (ListConstant - [(RealConstant - 3.000000 - (Real 8) - ) - (RealConstant - 1.000000 - (Real 8) - ) - (RealConstant - 2.000000 - (Real 8) - )] - (List - (Real 8) - ) - ) - (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 - [] - () - )] - ) - }) - [] -) From aa6c24582eebd483a7be51b0f9e63435ef2a7289 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:39:23 +0530 Subject: [PATCH 26/31] Delete tests/reference/runtime-test_dict_const-62054df.json --- .../reference/runtime-test_dict_const-62054df.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/reference/runtime-test_dict_const-62054df.json diff --git a/tests/reference/runtime-test_dict_const-62054df.json b/tests/reference/runtime-test_dict_const-62054df.json deleted file mode 100644 index 8e7da3220f..0000000000 --- a/tests/reference/runtime-test_dict_const-62054df.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "basename": "runtime-test_dict_const-62054df", - "cmd": "lpython {infile}", - "infile": "tests/errors/test_dict_const.py", - "infile_hash": "6b1aa7e33c497b09cfd6db7a7897fe26dd98836d3d3d956018e9c211", - "outfile": null, - "outfile_hash": null, - "stdout": null, - "stdout_hash": null, - "stderr": "runtime-test_dict_const-62054df.stderr", - "stderr_hash": "a9df181cfe48e863c8cfaac70f07ad18e1d5ee2c8b42fc10ac11eaad", - "returncode": 2 -} \ No newline at end of file From cab3eea2e6db7d39586f3855f69b1cf1aa600eac Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:39:39 +0530 Subject: [PATCH 27/31] Delete tests/reference/runtime-test_dict_const-62054df.stderr --- tests/reference/runtime-test_dict_const-62054df.stderr | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tests/reference/runtime-test_dict_const-62054df.stderr diff --git a/tests/reference/runtime-test_dict_const-62054df.stderr b/tests/reference/runtime-test_dict_const-62054df.stderr deleted file mode 100644 index 420ad7f106..0000000000 --- a/tests/reference/runtime-test_dict_const-62054df.stderr +++ /dev/null @@ -1,5 +0,0 @@ -semantic error: cannot pop elements from a const dict - --> tests/errors/test_dict_const.py:6:11 - | -6 | print(CONST_DICTIONARY.pop("a")) - | ^^^^^^^^^^^^^^^^^^^^^^^^^  From c740e7074110e34ab525217269f9ab3c670391b4 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 18:39:51 +0530 Subject: [PATCH 28/31] Delete tests/reference/asr-test_const_dict-59445d7.stderr --- tests/reference/asr-test_const_dict-59445d7.stderr | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 tests/reference/asr-test_const_dict-59445d7.stderr diff --git a/tests/reference/asr-test_const_dict-59445d7.stderr b/tests/reference/asr-test_const_dict-59445d7.stderr deleted file mode 100644 index 3b7757fec4..0000000000 --- a/tests/reference/asr-test_const_dict-59445d7.stderr +++ /dev/null @@ -1,5 +0,0 @@ -semantic error: cannot pop elements from a const dict - --> tests/errors/test_const_dict.py:6:11 - | -6 | print(CONST_DICTIONARY.pop("a")) - | ^^^^^^^^^^^^^^^^^^^^^^^^^ From 9581a31544339b2ff11e2e093fa03f5bb52d6a04 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Date: Wed, 1 May 2024 18:40:47 +0530 Subject: [PATCH 29/31] Tests: Update error references --- tests/reference/asr-test_const_dict-59445d7.json | 13 +++++++++++++ tests/reference/asr-test_const_dict-59445d7.stderr | 5 +++++ 2 files changed, 18 insertions(+) create mode 100644 tests/reference/asr-test_const_dict-59445d7.json create mode 100644 tests/reference/asr-test_const_dict-59445d7.stderr diff --git a/tests/reference/asr-test_const_dict-59445d7.json b/tests/reference/asr-test_const_dict-59445d7.json new file mode 100644 index 0000000000..69906db3c2 --- /dev/null +++ b/tests/reference/asr-test_const_dict-59445d7.json @@ -0,0 +1,13 @@ +{ + "basename": "asr-test_const_dict-59445d7", + "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", + "infile": "tests/errors/test_const_dict.py", + "infile_hash": "51130e98c759eb3cdbd50848e59879e4689d241c7a8674aa06a5b3c7", + "outfile": null, + "outfile_hash": null, + "stdout": null, + "stdout_hash": null, + "stderr": "asr-test_const_dict-59445d7.stderr", + "stderr_hash": "1d3729d80a7895dd01baaf0905c6cc9ebadd7f7ce623f4ae5970e2b8", + "returncode": 2 +} \ No newline at end of file diff --git a/tests/reference/asr-test_const_dict-59445d7.stderr b/tests/reference/asr-test_const_dict-59445d7.stderr new file mode 100644 index 0000000000..3b7757fec4 --- /dev/null +++ b/tests/reference/asr-test_const_dict-59445d7.stderr @@ -0,0 +1,5 @@ +semantic error: cannot pop elements from a const dict + --> tests/errors/test_const_dict.py:6:11 + | +6 | print(CONST_DICTIONARY.pop("a")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ From 78e4205241081e9e61f53cb71d9ff3c9efd395c5 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 21:31:26 +0530 Subject: [PATCH 30/31] Undo formatting changes --- src/libasr/codegen/asr_to_llvm.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 5c4ebe0d82..f8b9d7e407 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -1524,7 +1524,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_ListItem(const ASR::ListItem_t& x) { - ASR::ttype_t *el_type = ASRUtils::get_contained_type( + ASR::ttype_t* el_type = ASRUtils::get_contained_type( ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; @@ -1541,9 +1541,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void visit_DictItem(const ASR::DictItem_t& x) { - ASR::Dict_t *dict_type = ASR::down_cast( - ASRUtils::expr_type(x.m_a)); - + ASR::Dict_t* dict_type = ASR::down_cast( + ASRUtils::expr_type(x.m_a)); int64_t ptr_loads_copy = ptr_loads; ptr_loads = 0; this->visit_expr(*x.m_a); @@ -1847,8 +1846,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } void generate_DictElems(ASR::expr_t* m_arg, bool key_or_value) { - ASR::Dict_t *dict_type = ASR::down_cast( - ASRUtils::expr_type(m_arg)); + ASR::Dict_t* dict_type = ASR::down_cast( + ASRUtils::expr_type(m_arg)); ASR::ttype_t* el_type = key_or_value == 0 ? dict_type->m_key_type : dict_type->m_value_type; From 891c001632d2131749653379d9b3b8e24d1e611e Mon Sep 17 00:00:00 2001 From: Saurabh Kumar <151380951+kmr-srbh@users.noreply.github.com> Date: Wed, 1 May 2024 21:46:59 +0530 Subject: [PATCH 31/31] Remove extra newline --- integration_tests/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index cf7b74c022..f2a6bbc995 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -562,8 +562,7 @@ RUN(NAME test_tuple_03 LABELS cpython llvm llvm_jit c) 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_const_dict LABELS cpython llvm llvm_jit) 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)