Skip to content
Open
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
53 changes: 51 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ jobs:

- uses: hendrikmuhs/ccache-action@main
with:
variant: sccache
key: ${{ github.job }}-${{ matrix.os }}

- name: Build Linux
shell: bash -l {0}
run: |
./build0.sh
export CXXFLAGS="-Werror"
cmake . -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DWITH_LLVM=yes \
Expand All @@ -292,8 +294,55 @@ jobs:
-DWITH_RUNTIME_STACKTRACE=yes \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
-DCMAKE_INSTALL_PREFIX=`pwd`/inst \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache

cmake --build . -j16 --target install

- name: Test Linux
shell: bash -l {0}
run: |
ctest
./run_tests.py -s
cd integration_tests
./run_tests.py -b llvm c
./run_tests.py -b llvm c -f

release:
name: Check Release build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: mamba-org/setup-micromamba@v1
with:
environment-file: ci/environment.yml
create-args: >-
python=3.10
bison=3.4

- uses: hendrikmuhs/ccache-action@main
with:
variant: sccache
key: ${{ github.job }}-${{ matrix.os }}

- name: Build Linux
shell: bash -l {0}
run: |
./build0.sh
export CXXFLAGS="-Werror"
cmake . -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_LLVM=yes \
-DLFORTRAN_BUILD_ALL=yes \
-DWITH_STACKTRACE=no \
-DWITH_RUNTIME_STACKTRACE=yes \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
-DCMAKE_INSTALL_PREFIX=`pwd`/inst \
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache

cmake --build . -j16 --target install

Expand Down
6 changes: 6 additions & 0 deletions build0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ python src/libasr/wasm_instructions_visitor.py
(cd src/lpython/parser && re2c -W -b tokenizer.re -o tokenizer.cpp)
(cd src/lpython/parser && bison -Wall -d -r all parser.yy)

python -c "file = 'src/lpython/parser/parser.tab.cc'
with open(file, 'r') as f: text = f.read()
with open(file, 'w') as f:
f.write('[[maybe_unused]] int yynerrs'.join(text.split('int yynerrs')))
"

grep -n "'" src/lpython/parser/parser.yy && echo "Single quote not allowed" && exit 1
echo "OK"
32 changes: 15 additions & 17 deletions src/libasr/codegen/llvm_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,7 @@ namespace LCompilers {

if( type == nullptr ) {
type = get_type_from_ttype_t_util(v_type->m_type, module, arg_m_abi)->getPointerTo();
}
}
if( type != nullptr ) {
}
if( type != nullptr ) {
break;
} break;
}
case ASR::array_physical_typeType::FixedSizeArray: {
type = llvm::ArrayType::get(get_el_type(v_type->m_type, module),
Expand Down Expand Up @@ -1485,7 +1480,8 @@ namespace LCompilers {
break;
}
default: {
// can exit with error
throw LCompilersException("LLVMUtils::is_ineq_by_value unsupported overload_id " +
std::to_string(overload_id));
}
}
return builder->CreateCmp(pred, left, right);
Expand All @@ -1509,7 +1505,8 @@ namespace LCompilers {
break;
}
default: {
// can exit with error
throw LCompilersException("LLVMUtils::is_ineq_by_value unsupported overload_id " +
std::to_string(overload_id));
}
}
return builder->CreateCmp(pred, left, right);
Expand Down Expand Up @@ -1556,7 +1553,8 @@ namespace LCompilers {
break;
}
default: {
// can exit with error
throw LCompilersException("LLVMUtils::is_ineq_by_value unsupported overload_id " +
std::to_string(overload_id));
}
}
cond = builder->CreateAnd(cond, builder->CreateCmp(pred, l, r));
Expand Down Expand Up @@ -4431,21 +4429,21 @@ namespace LCompilers {
ASR::ttype_t* int32_type) {
/**
* Equivalent in C++
*
*
* equality_holds = 1;
* inequality_holds = 0;
* i = 0;
*
*
* while( i < a_len && i < b_len && equality_holds ) {
* equality_holds &= (a[i] == b[i]);
* inequality_holds |= (a[i] op b[i]);
* i++;
* }
*
*
* if( (i == a_len || i == b_len) && equality_holds ) {
* inequality_holds = a_len op b_len;
* }
*
*
*/

llvm::AllocaInst *equality_holds = builder->CreateAlloca(
Expand Down Expand Up @@ -4670,21 +4668,21 @@ namespace LCompilers {
llvm::Module& module, int8_t overload_id) {
/**
* Equivalent in C++
*
*
* equality_holds = 1;
* inequality_holds = 0;
* i = 0;
*
*
* // owing to compile-time access of indices,
* // loop is unrolled into multiple if statements
* while( i < a_len && equality_holds ) {
* inequality_holds |= (a[i] op b[i]);
* equality_holds &= (a[i] == b[i]);
* i++;
* }
*
*
* return inequality_holds;
*
*
*/

llvm::AllocaInst *equality_holds = builder->CreateAlloca(
Expand Down
8 changes: 4 additions & 4 deletions src/libasr/runtime/lfortran_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,15 +1372,15 @@ LFORTRAN_API void _lfortran_read_int32(int32_t *p, int32_t unit_num)
if (unit_num == -1) {
// Read from stdin
FILE *fp = fdopen(0, "r+");
fread(p, sizeof(int32_t), 1, fp);
(void)fread(p, sizeof(int32_t), 1, fp);
fclose(fp);
return;
}
if (!unit_to_file[unit_num]) {
printf("No file found with given unit\n");
exit(1);
}
fread(p, sizeof(int32_t), 1, unit_to_file[unit_num]);
(void)fread(p, sizeof(int32_t), 1, unit_to_file[unit_num]);
}

LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
Expand All @@ -1389,7 +1389,7 @@ LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
// Read from stdin
*p = (char*)malloc(16);
FILE *fp = fdopen(0, "r+");
fread(*p, sizeof(char), 16, fp);
(void)fread(*p, sizeof(char), 16, fp);
fclose(fp);
return;
}
Expand All @@ -1398,7 +1398,7 @@ LFORTRAN_API void _lfortran_read_char(char **p, int32_t unit_num)
exit(1);
}
*p = (char*)malloc(16);
fread(*p, sizeof(char), 16, unit_to_file[unit_num]);
(void)fread(*p, sizeof(char), 16, unit_to_file[unit_num]);
}

LFORTRAN_API char* _lpython_read(int64_t fd, int64_t n)
Expand Down
2 changes: 1 addition & 1 deletion src/lpython/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Result<LPython::AST::ast_t*> parse_python_file(Allocator &al,
const std::string &infile,
diag::Diagnostics &diagnostics,
uint32_t prev_loc,
bool new_parser) {
[[maybe_unused]] bool new_parser) {
LPython::AST::ast_t* ast;
// We will be using the new parser from now on
new_parser = true;
Expand Down
20 changes: 12 additions & 8 deletions src/lpython/semantics/python_ast_to_asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
this->visit_expr(*exprs[i]);
ASR::expr_t* expr = nullptr;
ASR::call_arg_t arg;
arg.loc.first = -1;
arg.loc.last = -1;
if (tmp) {
expr = ASRUtils::EXPR(tmp);
arg.loc = expr->base.loc;
Expand Down Expand Up @@ -1009,7 +1011,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {

ASR::ttype_t* get_type_from_var_annotation(std::string var_annotation,
const Location& loc, Vec<ASR::dimension_t>& dims,
AST::expr_t** m_args=nullptr, size_t n_args=0,
AST::expr_t** m_args=nullptr, [[maybe_unused]] size_t n_args=0,
bool raise_error=true, ASR::abiType abi=ASR::abiType::Source,
bool is_argument=false) {
ASR::ttype_t* type = nullptr;
Expand Down Expand Up @@ -2362,7 +2364,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
result = left_value >> right_value;
break;
}
default: { LCOMPILERS_ASSERT(false); } // should never happen
default: { throw SemanticError("ICE: Unknown binary operator", loc); } // should never happen
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_IntegerConstant_t(
al, loc, result, dest_type));
Expand Down Expand Up @@ -2416,7 +2418,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
result = left_value >> right_value;
break;
}
default: { LCOMPILERS_ASSERT(false); } // should never happen
default: { throw SemanticError("ICE: Unknown binary operator", loc); } // should never happen
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_UnsignedIntegerConstant_t(
al, loc, result, dest_type));
Expand Down Expand Up @@ -2458,7 +2460,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
case (ASR::binopType::Mul): { result = left_value * right_value; break; }
case (ASR::binopType::Div): { result = left_value / right_value; break; }
case (ASR::binopType::Pow): { result = std::pow(left_value, right_value); break; }
default: { LCOMPILERS_ASSERT(false); }
default: { throw SemanticError("ICE: Unknown binary operator", loc); }
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_RealConstant_t(
al, loc, result, dest_type));
Expand Down Expand Up @@ -3289,7 +3291,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
void visit_NamedExpr(const AST::NamedExpr_t &x) {
this->visit_expr(*x.m_target);
ASR::expr_t *target = ASRUtils::EXPR(tmp);
ASR::ttype_t *target_type = ASRUtils::expr_type(target);
[[maybe_unused]] ASR::ttype_t *target_type = ASRUtils::expr_type(target);
this->visit_expr(*x.m_value);
ASR::expr_t *value = ASRUtils::EXPR(tmp);
ASR::ttype_t *value_type = ASRUtils::expr_type(value);
Expand Down Expand Up @@ -3396,7 +3398,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
ASR::expr_t *left = ASRUtils::EXPR(tmp);
this->visit_expr(*x.m_right);
ASR::expr_t *right = ASRUtils::EXPR(tmp);
ASR::binopType op;
ASR::binopType op = ASR::binopType::Add /* temporary assignment */;
std::string op_name = "";
switch (x.m_op) {
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
Expand Down Expand Up @@ -5602,7 +5604,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
ASR::expr_t *right = ASRUtils::EXPR(tmp);
ASR::ttype_t* left_type = ASRUtils::expr_type(left);
ASR::ttype_t* right_type = ASRUtils::expr_type(right);
ASR::binopType op;
ASR::binopType op = ASR::binopType::Add /* temporary assignment */;
std::string op_name = "";
switch (x.m_op) {
case (AST::operatorType::Add) : { op = ASR::binopType::Add; break; }
Expand Down Expand Up @@ -6313,7 +6315,9 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
result = (strcmp < 0 || strcmp == 0);
break;
}
default: LCOMPILERS_ASSERT(false); // should never happen
default: {
throw SemanticError("ICE: Unknown compare operator", x.base.base.loc); // should never happen
}
}
value = ASR::down_cast<ASR::expr_t>(ASR::make_LogicalConstant_t(
al, x.base.base.loc, result, type));
Expand Down