@@ -1688,42 +1688,17 @@ static inline bool is_logical(ASR::ttype_t &x) {
16881688 type_get_past_pointer (&x))));
16891689}
16901690
1691- static inline bool is_generic (ASR::ttype_t &x) {
1692- switch (x.type ) {
1693- case ASR::ttypeType::List: {
1694- ASR::List_t *list_type = ASR::down_cast<ASR::List_t>(type_get_past_pointer (&x));
1695- return is_generic (*list_type->m_type );
1696- }
1697- case ASR::ttypeType::Array: {
1698- ASR::Array_t* array_t = ASR::down_cast<ASR::Array_t>(type_get_past_pointer (&x));
1699- return is_generic (*array_t ->m_type );
1700- }
1701- default : return ASR::is_a<ASR::TypeParameter_t>(*type_get_past_pointer (&x));
1702- }
1703- }
1704-
17051691static inline bool is_type_parameter (ASR::ttype_t &x) {
17061692 switch (x.type ) {
17071693 case ASR::ttypeType::List: {
17081694 ASR::List_t *list_type = ASR::down_cast<ASR::List_t>(type_get_past_pointer (&x));
17091695 return is_type_parameter (*list_type->m_type );
17101696 }
1711- default : return ASR::is_a<ASR::TypeParameter_t>(*type_get_past_pointer (&x));
1712- }
1713- }
1714-
1715- static inline bool is_template_function (ASR::symbol_t *x) {
1716- ASR::symbol_t * x2 = symbol_get_past_external (x);
1717- switch (x2->type ) {
1718- case ASR::symbolType::Function: {
1719- const SymbolTable* parent_symtab = symbol_parent_symtab (x2);
1720- if (ASR::is_a<ASR::symbol_t >(*parent_symtab->asr_owner )) {
1721- ASR::symbol_t * parent_sym = ASR::down_cast<ASR::symbol_t >(parent_symtab->asr_owner );
1722- return ASR::is_a<ASR::Template_t>(*parent_sym);
1723- }
1724- return false ;
1697+ case ASR::ttypeType::Array: {
1698+ ASR::Array_t *arr_type = ASR::down_cast<ASR::Array_t>(type_get_past_pointer (&x));
1699+ return is_type_parameter (*arr_type->m_type );
17251700 }
1726- default : return false ;
1701+ default : return ASR::is_a<ASR::TypeParameter_t>(* type_get_past_pointer (&x)) ;
17271702 }
17281703}
17291704
@@ -1742,20 +1717,19 @@ static inline bool is_generic_function(ASR::symbol_t *x) {
17421717 ASR::symbol_t * x2 = symbol_get_past_external (x);
17431718 switch (x2->type ) {
17441719 case ASR::symbolType::Function: {
1745- ASR::Function_t *func_sym = ASR::down_cast<ASR::Function_t>(x2);
1746- return (ASRUtils::get_FunctionType (func_sym)->n_type_params > 0 &&
1747- !ASRUtils::get_FunctionType (func_sym)->m_is_restriction );
1748- }
1749- default : return false ;
1750- }
1751- }
1752-
1753- static inline bool is_restriction_function (ASR::symbol_t *x) {
1754- ASR::symbol_t * x2 = symbol_get_past_external (x);
1755- switch (x2->type ) {
1756- case ASR::symbolType::Function: {
1757- ASR::Function_t *func_sym = ASR::down_cast<ASR::Function_t>(x2);
1758- return ASRUtils::get_FunctionType (func_sym)->m_is_restriction ;
1720+ if (is_requirement_function (x2)) {
1721+ return false ;
1722+ }
1723+ ASR::Function_t *func = ASR::down_cast<ASR::Function_t>(x2);
1724+ ASR::FunctionType_t *func_type
1725+ = ASR::down_cast<ASR::FunctionType_t>(func->m_function_signature );
1726+ for (size_t i=0 ; i<func_type->n_arg_types ; i++) {
1727+ if (is_type_parameter (*func_type->m_arg_types [i])) {
1728+ return true ;
1729+ }
1730+ }
1731+ return func_type->m_return_var_type
1732+ && is_type_parameter (*func_type->m_return_var_type );
17591733 }
17601734 default : return false ;
17611735 }
@@ -2110,7 +2084,7 @@ static inline ASR::ttype_t* duplicate_type(Allocator& al, const ASR::ttype_t* t,
21102084 return ASRUtils::TYPE (ASR::make_FunctionType_t (al, ft->base .base .loc ,
21112085 arg_types.p , arg_types.size (), ft->m_return_var_type , ft->m_abi ,
21122086 ft->m_deftype , ft->m_bindc_name , ft->m_elemental , ft->m_pure , ft->m_module , ft->m_inline ,
2113- ft->m_static , ft->m_type_params , ft-> n_type_params , ft-> m_restrictions , ft->n_restrictions ,
2087+ ft->m_static , ft->m_restrictions , ft->n_restrictions ,
21142088 ft->m_is_restriction ));
21152089 }
21162090 default : throw LCompilersException (" Not implemented " + std::to_string (t->type ));
@@ -3119,7 +3093,7 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
31193093 const Location &a_loc, ASR::expr_t ** a_args, size_t n_args,
31203094 ASR::expr_t * a_return_var, ASR::abiType a_abi, ASR::deftypeType a_deftype,
31213095 char * a_bindc_name, bool a_elemental, bool a_pure, bool a_module, bool a_inline,
3122- bool a_static, ASR:: ttype_t ** a_type_params, size_t n_type_params,
3096+ bool a_static,
31233097 ASR::symbol_t ** a_restrictions, size_t n_restrictions, bool a_is_restriction) {
31243098 Vec<ASR::ttype_t *> arg_types;
31253099 arg_types.reserve (al, n_args);
@@ -3141,7 +3115,7 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al,
31413115 return ASR::make_FunctionType_t (
31423116 al, a_loc, arg_types.p , arg_types.size (), return_var_type, a_abi, a_deftype,
31433117 a_bindc_name, a_elemental, a_pure, a_module, a_inline,
3144- a_static, a_type_params, n_type_params, a_restrictions, n_restrictions,
3118+ a_static, a_restrictions, n_restrictions,
31453119 a_is_restriction);
31463120}
31473121
@@ -3150,7 +3124,7 @@ inline ASR::asr_t* make_FunctionType_t_util(Allocator &al, const Location &a_loc
31503124 return ASRUtils::make_FunctionType_t_util (al, a_loc, a_args, n_args, a_return_var,
31513125 ft->m_abi , ft->m_deftype , ft->m_bindc_name , ft->m_elemental ,
31523126 ft->m_pure , ft->m_module , ft->m_inline , ft->m_static ,
3153- ft->m_type_params , ft-> n_type_params , ft-> m_restrictions ,
3127+ ft->m_restrictions ,
31543128 ft->n_restrictions , ft->m_is_restriction );
31553129}
31563130
@@ -3159,12 +3133,12 @@ inline ASR::asr_t* make_Function_t_util(Allocator& al, const Location& loc,
31593133 ASR::expr_t ** a_args, size_t n_args, ASR::stmt_t ** m_body, size_t n_body,
31603134 ASR::expr_t * m_return_var, ASR::abiType m_abi, ASR::accessType m_access,
31613135 ASR::deftypeType m_deftype, char * m_bindc_name, bool m_elemental, bool m_pure,
3162- bool m_module, bool m_inline, bool m_static, ASR:: ttype_t ** m_type_params, size_t n_type_params,
3136+ bool m_module, bool m_inline, bool m_static,
31633137 ASR::symbol_t ** m_restrictions, size_t n_restrictions, bool m_is_restriction,
31643138 bool m_deterministic, bool m_side_effect_free, char *m_c_header=nullptr ) {
31653139 ASR::ttype_t * func_type = ASRUtils::TYPE (ASRUtils::make_FunctionType_t_util (
31663140 al, loc, a_args, n_args, m_return_var, m_abi, m_deftype, m_bindc_name,
3167- m_elemental, m_pure, m_module, m_inline, m_static, m_type_params, n_type_params,
3141+ m_elemental, m_pure, m_module, m_inline, m_static,
31683142 m_restrictions, n_restrictions, m_is_restriction));
31693143 return ASR::make_Function_t (
31703144 al, loc, m_symtab, m_name, func_type, m_dependencies, n_dependencies,
@@ -3353,7 +3327,6 @@ class SymbolDuplicator {
33533327 function_type->m_abi , function->m_access , function_type->m_deftype ,
33543328 function_type->m_bindc_name , function_type->m_elemental , function_type->m_pure ,
33553329 function_type->m_module , function_type->m_inline , function_type->m_static ,
3356- function_type->m_type_params , function_type->n_type_params ,
33573330 function_type->m_restrictions , function_type->n_restrictions ,
33583331 function_type->m_is_restriction , function->m_deterministic ,
33593332 function->m_side_effect_free ));
0 commit comments