Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Sync libasr from LFortran #2319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ RUN(NAME enum_06 LABELS cpython llvm c)
RUN(NAME enum_07 IMPORT_PATH ..
LABELS cpython llvm c)
RUN(NAME union_01 LABELS cpython llvm c)
RUN(NAME union_02 LABELS cpython llvm c)
RUN(NAME union_02 LABELS cpython llvm c NOFAST)
Copy link
Collaborator Author

@czgdp1807 czgdp1807 Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fast mode, this test silently works incorrectly on main branch as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? How can it silently work? Is our cmake flaky? If so, that's an urgent bug to fix.

Copy link
Collaborator Author

@czgdp1807 czgdp1807 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With main branch,

(lp) 14:17:37:~/lpython_project/lpython % lpython integration_tests/union_02.py --fast
0 1.00000000000000000e+00
2 7.00000000000000000e+00
5 1.30000000000000000e+01 3.04899892523928701e-314
(lp) 14:17:55:~/lpython_project/lpython % lpython integration_tests/union_02.py       
0 1.00000000000000000e+00
2 7.00000000000000000e+00
5 1.30000000000000000e+01 8.00000000000000000e+00

You can clearly see the difference in the last value of third line. --fast should have given assertion error in main branch but it didn't. So, clearly its passing silently in main branch as well. In my libasr_sync_06 this failure just shows up as an assertion error, something which should have happened in main branch only. I will fix it later, after getting this PR merged. The problem AFAIK is with LLVM generated code. --fast with LLVM removes assert statements (they were present in the ASR after applying all the passes).

Is our cmake flaky? If so, that's an urgent bug to fix.

I don't think that's the problem.

RUN(NAME union_03 LABELS cpython llvm c)
RUN(NAME union_04 IMPORT_PATH ..
LABELS cpython llvm c)
Expand Down
9 changes: 6 additions & 3 deletions src/libasr/ASR.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ abi -- External ABI

stmt
= Allocate(alloc_arg* args, expr? stat, expr? errmsg, expr? source)
| ReAlloc(alloc_arg* args)
| Assign(int label, identifier variable)
| Assignment(expr target, expr value, stmt? overloaded)
| Associate(expr target, expr value)
Expand All @@ -193,7 +194,7 @@ stmt
| If(expr test, stmt* body, stmt* orelse)
| IfArithmetic(expr test, int lt_label, int eq_label, int gt_label)
| Print(expr? fmt, expr* values, expr? separator, expr? end)
| FileOpen(int label, expr? newunit, expr? filename, expr? status)
| FileOpen(int label, expr? newunit, expr? filename, expr? status, expr? form)
| FileClose(int label, expr? unit, expr? iostat, expr? iomsg, expr? err, expr? status)
| FileRead(int label, expr? unit, expr? fmt, expr? iomsg, expr? iostat, expr? id, expr* values)
| FileBackspace(int label, expr? unit, expr? iostat, expr? err)
Expand Down Expand Up @@ -221,6 +222,8 @@ stmt
| SelectType(expr selector, type_stmt* body, stmt* default)
| CPtrToPointer(expr cptr, expr ptr, expr? shape, expr? lower_bounds)
| BlockCall(int label, symbol m)
| SetInsert(expr a, expr ele)
| SetRemove(expr a, expr ele)
| ListInsert(expr a, expr pos, expr ele)
| ListRemove(expr a, expr ele)
| ListClear(expr a)
Expand Down Expand Up @@ -261,6 +264,7 @@ expr
| RealUnaryMinus(expr arg, ttype type, expr? value)
| RealCompare(expr left, cmpop op, expr right, ttype type, expr? value)
| RealBinOp(expr left, binop op, expr right, ttype type, expr? value)
| RealCopySign(expr target, expr source, ttype type, expr? value)
| ComplexConstant(float re, float im, ttype type)
| ComplexUnaryMinus(expr arg, ttype type, expr? value)
| ComplexCompare(expr left, cmpop op, expr right, ttype type, expr? value)
Expand Down Expand Up @@ -311,10 +315,8 @@ expr
| ArrayBound(expr v, expr? dim, ttype type, arraybound bound,
expr? value)
| ArrayTranspose(expr matrix, ttype type, expr? value)
| ArrayMatMul(expr matrix_a, expr matrix_b, ttype type, expr? value)
| ArrayPack(expr array, expr mask, expr? vector, ttype type, expr? value)
| ArrayReshape(expr array, expr shape, ttype type, expr? value)
| ArrayMaxloc(expr array, expr? dim, expr? mask, expr? kind, expr? back, ttype type, expr? value)
| ArrayAll(expr mask, expr? dim, ttype type, expr? value)

| BitCast(expr source, expr mold, expr? size, ttype type, expr? value)
Expand Down Expand Up @@ -417,6 +419,7 @@ ttype
array_physical_type
= DescriptorArray
| PointerToDataArray
| UnboundedPointerToDataArray
| FixedSizeArray
| NumPyArray
| ISODescriptorArray
Expand Down
1 change: 1 addition & 0 deletions src/libasr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ set(SRC
string_utils.cpp
asr_scopes.cpp
modfile.cpp
pickle.cpp
serialization.cpp
utils2.cpp
)
Expand Down
2 changes: 1 addition & 1 deletion src/libasr/asdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def check(mod):

def parse(filename):
"""Parse ASDL from the given file and return a Module node describing it."""
with open(filename) as f:
with open(filename, encoding='utf8') as f:
parser = ASDLParser()
return parser.parse(f.read())

Expand Down
3 changes: 1 addition & 2 deletions src/libasr/asr_scopes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <libasr/asr_scopes.h>
#include <libasr/asr_utils.h>


std::string lcompilers_unique_ID;

namespace LCompilers {

template< typename T >
Expand Down Expand Up @@ -53,7 +53,6 @@ void SymbolTable::mark_all_variables_external(Allocator &al) {
}
}


ASR::symbol_t *SymbolTable::find_scoped_symbol(const std::string &name,
size_t n_scope_names, char **m_scope_names) {
const SymbolTable *s = this;
Expand Down
41 changes: 41 additions & 0 deletions src/libasr/asr_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,47 @@ ASR::symbol_t* import_class_procedure(Allocator &al, const Location& loc,
return original_sym;
}

ASR::asr_t* make_Binop_util(Allocator &al, const Location& loc, ASR::binopType binop,
ASR::expr_t* lexpr, ASR::expr_t* rexpr, ASR::ttype_t* ttype) {
switch (ttype->type) {
case ASR::ttypeType::Real: {
return ASR::make_RealBinOp_t(al, loc, lexpr, binop, rexpr,
ASRUtils::duplicate_type(al, ttype), nullptr);
}
case ASR::ttypeType::Integer: {
return ASR::make_IntegerBinOp_t(al, loc, lexpr, binop, rexpr,
ASRUtils::duplicate_type(al, ttype), nullptr);
}
case ASR::ttypeType::Complex: {
return ASR::make_ComplexBinOp_t(al, loc, lexpr, binop, rexpr,
ASRUtils::duplicate_type(al, ttype), nullptr);
}
default:
throw LCompilersException("Not implemented " + std::to_string(ttype->type));
}
}

ASR::asr_t* make_Cmpop_util(Allocator &al, const Location& loc, ASR::cmpopType cmpop,
ASR::expr_t* lexpr, ASR::expr_t* rexpr, ASR::ttype_t* ttype) {
ASR::ttype_t* expr_type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, 4));
switch (ttype->type) {
case ASR::ttypeType::Real: {
return ASR::make_RealCompare_t(al, loc, lexpr, cmpop, rexpr, expr_type, nullptr);
}
case ASR::ttypeType::Integer: {
return ASR::make_IntegerCompare_t(al, loc, lexpr, cmpop, rexpr, expr_type, nullptr);
}
case ASR::ttypeType::Complex: {
return ASR::make_ComplexCompare_t(al, loc, lexpr, cmpop, rexpr, expr_type, nullptr);
}
case ASR::ttypeType::Character: {
return ASR::make_StringCompare_t(al, loc, lexpr, cmpop, rexpr, expr_type, nullptr);
}
default:
throw LCompilersException("Not implemented " + std::to_string(ttype->type));
}
}

//Initialize pointer to zero so that it can be initialized in first call to get_instance
ASRUtils::LabelGenerator* ASRUtils::LabelGenerator::label_generator = nullptr;

Expand Down
Loading