Skip to content

Commit 46d49c0

Browse files
ansharlubiscertik
authored andcommitted
Removed type params from function type
1 parent d559090 commit 46d49c0

File tree

11 files changed

+47
-76
lines changed

11 files changed

+47
-76
lines changed

src/libasr/ASR.asdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ ttype
408408
| Array(ttype type, dimension* dims, array_physical_type physical_type)
409409
| FunctionType(ttype* arg_types, ttype? return_var_type,
410410
abi abi, deftype deftype, string? bindc_name, bool elemental,
411-
bool pure, bool module, bool inline, bool static, ttype* type_params,
411+
bool pure, bool module, bool inline, bool static,
412412
symbol* restrictions, bool is_restriction)
413413

414414
-- TODO: prefix the enumerators here, improve the names

src/libasr/asr_utils.h

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
17051691
static 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));

src/libasr/codegen/asr_to_wasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor<ASRToWASMVisitor> {
754754
nullptr, 0, nullptr, 0, x.m_body, x.n_body, nullptr,
755755
ASR::abiType::Source, ASR::accessType::Public,
756756
ASR::deftypeType::Implementation, nullptr, false, false, false, false, false,
757-
nullptr, 0, nullptr, 0, false, false, false);
757+
nullptr, 0, false, false, false);
758758
}
759759
this->visit_Function(*main_func);
760760
}

src/libasr/pass/global_stmts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void pass_wrap_global_stmts(Allocator &al,
123123
ASR::Public, ASR::Implementation,
124124
nullptr,
125125
false, false, false, false, false,
126-
nullptr, 0, nullptr, 0,
126+
nullptr, 0,
127127
false, false, false);
128128
std::string sym_name = fn_name;
129129
if (unit.m_global_scope->get_symbol(sym_name) != nullptr) {

src/libasr/pass/instantiate_template.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ class SymbolInstantiator : public ASR::BaseExprStmtDuplicator<SymbolInstantiator
189189
new_return_var_ref,
190190
func_abi, func_access, func_deftype, bindc_name,
191191
func_elemental, func_pure, func_module, ASRUtils::get_FunctionType(x)->m_inline,
192-
ASRUtils::get_FunctionType(x)->m_static, ASRUtils::get_FunctionType(x)->m_type_params,
193-
ASRUtils::get_FunctionType(x)->n_type_params, ASRUtils::get_FunctionType(x)->m_restrictions,
192+
ASRUtils::get_FunctionType(x)->m_static, ASRUtils::get_FunctionType(x)->m_restrictions,
194193
ASRUtils::get_FunctionType(x)->n_restrictions, false, false, false);
195194

196195
ASR::symbol_t *t = ASR::down_cast<ASR::symbol_t>(result);
@@ -337,7 +336,7 @@ class SymbolInstantiator : public ASR::BaseExprStmtDuplicator<SymbolInstantiator
337336
ASR::expr_t* dt = duplicate_expr(x->m_dt);
338337
if (ASRUtils::is_requirement_function(name)) {
339338
name = symbol_subs[call_name];
340-
} else if (ASRUtils::is_template_function(name)) {
339+
} else if (ASRUtils::is_generic_function(name)) {
341340
std::string nested_func_name = current_scope->get_unique_name("__asr_generic_" + call_name, false);
342341
ASR::symbol_t* name2 = ASRUtils::symbol_get_past_external(name);
343342
SymbolInstantiator nested_t(al, context_map, type_subs, symbol_subs, func_scope, template_scope, nested_func_name);
@@ -740,7 +739,7 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
740739
new_return_var_ref,
741740
func_abi, func_access, func_deftype, bindc_name,
742741
func_elemental, func_pure, func_module, ASRUtils::get_FunctionType(x)->m_inline,
743-
ASRUtils::get_FunctionType(x)->m_static, nullptr, 0, nullptr, 0, false, false, false);
742+
ASRUtils::get_FunctionType(x)->m_static, nullptr, 0, false, false, false);
744743

745744
ASR::symbol_t *t = ASR::down_cast<ASR::symbol_t>(result);
746745
func_scope->add_symbol(new_func_name, t);
@@ -836,7 +835,7 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
836835
ASR::ttype_t* type = substitute_type(x->m_type);
837836
ASR::expr_t* value = duplicate_expr(x->m_value);
838837
ASR::expr_t* dt = duplicate_expr(x->m_dt);
839-
if (ASRUtils::is_restriction_function(name)) {
838+
if (ASRUtils::is_requirement_function(name)) {
840839
name = rt_subs[call_name];
841840
} else if (ASRUtils::is_generic_function(name)) {
842841
std::string nested_func_name = current_scope->get_unique_name("__asr_generic_" + call_name, false);
@@ -863,7 +862,7 @@ class FunctionInstantiator : public ASR::BaseExprStmtDuplicator<FunctionInstanti
863862
args.push_back(al, new_arg);
864863
}
865864
ASR::expr_t* dt = duplicate_expr(x->m_dt);
866-
if (ASRUtils::is_restriction_function(name)) {
865+
if (ASRUtils::is_requirement_function(name)) {
867866
name = rt_subs[call_name];
868867
} else {
869868
std::string nested_func_name = current_scope->get_unique_name("__asr_generic_" + call_name, false);

src/libasr/pass/intrinsic_function_registry.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ class ASRBuilder {
206206
symtab, s2c(al, name), dep.p, dep.n, args.p, args.n, body.p, body.n, \
207207
return_var, ASR::abiType::abi, ASR::accessType::Public, \
208208
ASR::deftypeType::deftype, bindc_name, false, false, false, false, \
209-
false, nullptr, 0, nullptr, 0, false, false, false));
209+
false, nullptr, 0, false, false, false));
210210

211211
#define make_Function_Without_ReturnVar_t(name, symtab, dep, args, body, \
212212
abi, deftype, bindc_name) \
213213
ASR::down_cast<ASR::symbol_t>( ASRUtils::make_Function_t_util(al, loc, \
214214
symtab, s2c(al, name), dep.p, dep.n, args.p, args.n, body.p, body.n, \
215215
nullptr, ASR::abiType::abi, ASR::accessType::Public, \
216216
ASR::deftypeType::deftype, bindc_name, false, false, false, false, \
217-
false, nullptr, 0, nullptr, 0, false, false, false));
217+
false, nullptr, 0, false, false, false));
218218

219219
// Types -------------------------------------------------------------------
220220
#define int32 TYPE(ASR::make_Integer_t(al, loc, 4))

src/libasr/pass/pass_array_by_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class PassArrayByDataProcedureVisitor : public PassUtils::PassVisitor<PassArrayB
155155
return_var, x_func_type->m_abi, x->m_access, x_func_type->m_deftype,
156156
s2c(al, new_bindc_name), x_func_type->m_elemental,
157157
x_func_type->m_pure, x_func_type->m_module, x_func_type->m_inline,
158-
x_func_type->m_static, x_func_type->m_type_params, x_func_type->n_type_params,
158+
x_func_type->m_static,
159159
x_func_type->m_restrictions, x_func_type->n_restrictions, false, false, false);
160160
new_symbol = ASR::down_cast<ASR::symbol_t>(new_subrout);
161161
}

src/libasr/pass/pass_compare.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class CompareExprReplacer : public ASR::BaseExprReplacer<CompareExprReplacer>
227227
/* a_return_var */ result,
228228
ASR::abiType::Source,
229229
ASR::accessType::Public, ASR::deftypeType::Implementation,
230-
nullptr, false, false, false, false, false, nullptr, 0, nullptr, 0,
230+
nullptr, false, false, false, false, false, nullptr, 0,
231231
false, false, false);
232232
ASR::symbol_t *fn_sym = ASR::down_cast<ASR::symbol_t>(fn);
233233
global_scope->add_symbol(fn_name, fn_sym);
@@ -412,7 +412,7 @@ class CompareExprReplacer : public ASR::BaseExprReplacer<CompareExprReplacer>
412412
ASR::accessType::Public, ASR::deftypeType::Implementation,
413413
nullptr,
414414
false, false, false, false, false,
415-
nullptr, 0, nullptr, 0,
415+
nullptr, 0,
416416
false, false, false);
417417
ASR::symbol_t *fn_sym = ASR::down_cast<ASR::symbol_t>(fn);
418418
global_scope->add_symbol(fn_name, fn_sym);

src/libasr/pass/pass_list_expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class ListExprReplacer : public ASR::BaseExprReplacer<ListExprReplacer>
329329
ASR::accessType::Public, ASR::deftypeType::Implementation,
330330
nullptr,
331331
false, false, false, false, false,
332-
nullptr, 0, nullptr, 0,
332+
nullptr, 0,
333333
false, false, false);
334334
ASR::symbol_t *fn_sym = ASR::down_cast<ASR::symbol_t>(fn);
335335
global_scope->add_symbol(fn_name, fn_sym);
@@ -496,7 +496,7 @@ class ListExprReplacer : public ASR::BaseExprReplacer<ListExprReplacer>
496496
ASR::accessType::Public, ASR::deftypeType::Implementation,
497497
nullptr,
498498
false, false, false, false, false,
499-
nullptr, 0, nullptr, 0,
499+
nullptr, 0,
500500
false, false, false);
501501
ASR::symbol_t *fn_sym = ASR::down_cast<ASR::symbol_t>(fn);
502502
global_scope->add_symbol(fn_name, fn_sym);

src/libasr/pass/pass_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ namespace LCompilers {
743743
ASR::abiType::Source, ASR::accessType::Public,
744744
ASR::deftypeType::Implementation,
745745
nullptr, false, false, false, false, false,
746-
nullptr, 0, nullptr, 0, false, false, false);
746+
nullptr, 0, false, false, false);
747747
global_scope->add_symbol(vector_copy_name, ASR::down_cast<ASR::symbol_t>(vector_copy_asr));
748748
return ASR::down_cast<ASR::symbol_t>(vector_copy_asr);
749749
}

0 commit comments

Comments
 (0)