mirror of https://github.com/exaloop/codon
Fix asserts
parent
4563c68fdd
commit
33a82967d8
|
@ -244,7 +244,7 @@ int buildMode(const std::vector<const char *> &args) {
|
|||
extension = "";
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
seqassert(0, "unknown build kind");
|
||||
}
|
||||
const std::string filename =
|
||||
output.empty() ? makeOutputFilename(compiler->getInput(), extension) : output;
|
||||
|
@ -265,7 +265,7 @@ int buildMode(const std::vector<const char *> &args) {
|
|||
compiler->getLLVMVisitor()->compile(filename, libsVec);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
seqassert(0, "unknown build kind");
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -18,7 +18,7 @@ void Type::Unification::undo() {
|
|||
linked[i]->type = nullptr;
|
||||
}
|
||||
for (int i = int(leveled.size()) - 1; i >= 0; i--) {
|
||||
assert(leveled[i].first->kind == LinkType::Unbound);
|
||||
seqassert(leveled[i].first->kind == LinkType::Unbound, "not unbound");
|
||||
leveled[i].first->level = leveled[i].second;
|
||||
}
|
||||
for (auto &t : traits)
|
||||
|
@ -687,7 +687,7 @@ std::string StaticType::realizedName() const {
|
|||
deps.push_back(e.type->realizedName());
|
||||
if (!expr->staticValue.evaluated) // If not already evaluated, evaluate!
|
||||
const_cast<StaticType *>(this)->expr->staticValue = evaluate();
|
||||
assert(expr->staticValue.evaluated);
|
||||
seqassert(expr->staticValue.evaluated, "static value not evaluated");
|
||||
return expr->staticValue.toString();
|
||||
}
|
||||
StaticValue StaticType::evaluate() const {
|
||||
|
|
|
@ -301,7 +301,7 @@ void SimplifyVisitor::visit(ThrowStmt *stmt) {
|
|||
}
|
||||
|
||||
void SimplifyVisitor::visit(WithStmt *stmt) {
|
||||
assert(stmt->items.size());
|
||||
seqassert(stmt->items.size(), "stmt->items is empty");
|
||||
std::vector<StmtPtr> content;
|
||||
for (int i = int(stmt->items.size()) - 1; i >= 0; i--) {
|
||||
std::string var =
|
||||
|
@ -1437,7 +1437,7 @@ StmtPtr SimplifyVisitor::transformLLVMDefinition(const Stmt *codeStmt) {
|
|||
StmtPtr SimplifyVisitor::codegenMagic(const std::string &op, const Expr *typExpr,
|
||||
const std::vector<Param> &args, bool isRecord) {
|
||||
#define I(s) N<IdExpr>(s)
|
||||
assert(typExpr);
|
||||
seqassert(typExpr, "typExpr is null");
|
||||
ExprPtr ret;
|
||||
std::vector<Param> fargs;
|
||||
std::vector<StmtPtr> stmts;
|
||||
|
|
|
@ -89,7 +89,7 @@ TypeContext::addUnbound(const Expr *expr, int level, bool setActive, char static
|
|||
|
||||
types::TypePtr TypeContext::instantiate(const Expr *expr, types::TypePtr type,
|
||||
types::ClassType *generics, bool activate) {
|
||||
assert(type);
|
||||
seqassert(type, "type is null");
|
||||
std::unordered_map<int, types::TypePtr> genericCache;
|
||||
if (generics)
|
||||
for (auto &g : generics->generics)
|
||||
|
@ -122,12 +122,12 @@ types::TypePtr
|
|||
TypeContext::instantiateGeneric(const Expr *expr, types::TypePtr root,
|
||||
const std::vector<types::TypePtr> &generics) {
|
||||
auto c = root->getClass();
|
||||
assert(c);
|
||||
seqassert(c, "root class is null");
|
||||
auto g = std::make_shared<types::ClassType>("", ""); // dummy generic type
|
||||
if (generics.size() != c->generics.size())
|
||||
error(expr->getSrcInfo(), "generics do not match");
|
||||
for (int i = 0; i < c->generics.size(); i++) {
|
||||
assert(c->generics[i].type);
|
||||
seqassert(c->generics[i].type, "generic is null");
|
||||
g->generics.push_back(
|
||||
types::ClassType::Generic("", "", generics[i], c->generics[i].id));
|
||||
}
|
||||
|
|
|
@ -1143,8 +1143,9 @@ ExprPtr TypecheckVisitor::transformCall(CallExpr *expr, const types::TypePtr &in
|
|||
|
||||
// Typecheck given arguments with the expected (signature) types.
|
||||
bool unificationsDone = true;
|
||||
assert((expr->ordered && typeArgs.empty()) ||
|
||||
(!expr->ordered && typeArgs.size() == calleeFn->funcGenerics.size()));
|
||||
seqassert((expr->ordered && typeArgs.empty()) ||
|
||||
(!expr->ordered && typeArgs.size() == calleeFn->funcGenerics.size()),
|
||||
"bad vector sizes");
|
||||
for (int si = 0; !expr->ordered && si < calleeFn->funcGenerics.size(); si++)
|
||||
if (typeArgs[si]) {
|
||||
auto t = typeArgs[si]->type;
|
||||
|
|
|
@ -304,7 +304,7 @@ std::pair<int, StmtPtr> TypecheckVisitor::inferTypes(StmtPtr result, bool keepLa
|
|||
std::map<types::TypePtr, std::string> newActiveUnbounds;
|
||||
for (auto i = ctx->activeUnbounds.begin(); i != ctx->activeUnbounds.end();) {
|
||||
auto l = i->first->getLink();
|
||||
assert(l);
|
||||
seqassert(l, "link is null");
|
||||
if (l->kind == LinkType::Unbound) {
|
||||
newActiveUnbounds[i->first] = i->second;
|
||||
if (l->id >= minUnbound)
|
||||
|
@ -403,20 +403,21 @@ ir::types::Type *TypecheckVisitor::getLLVMType(const types::ClassType *t) {
|
|||
} else if (name == "str") {
|
||||
handle = module->getStringType();
|
||||
} else if (name == "Int" || name == "UInt") {
|
||||
assert(statics.size() == 1 && statics[0]->type == StaticValue::INT &&
|
||||
types.empty());
|
||||
seqassert(statics.size() == 1 && statics[0]->type == StaticValue::INT &&
|
||||
types.empty(),
|
||||
"bad generics/statics");
|
||||
handle = module->Nr<ir::types::IntNType>(statics[0]->getInt(), name == "Int");
|
||||
} else if (name == "Ptr") {
|
||||
assert(types.size() == 1 && statics.empty());
|
||||
seqassert(types.size() == 1 && statics.empty(), "bad generics/statics");
|
||||
handle = module->unsafeGetPointerType(types[0]);
|
||||
} else if (name == "Generator") {
|
||||
assert(types.size() == 1 && statics.empty());
|
||||
seqassert(types.size() == 1 && statics.empty(), "bad generics/statics");
|
||||
handle = module->unsafeGetGeneratorType(types[0]);
|
||||
} else if (name == TYPE_OPTIONAL) {
|
||||
assert(types.size() == 1 && statics.empty());
|
||||
seqassert(types.size() == 1 && statics.empty(), "bad generics/statics");
|
||||
handle = module->unsafeGetOptionalType(types[0]);
|
||||
} else if (name == "NoneType") {
|
||||
assert(types.empty() && statics.empty());
|
||||
seqassert(types.empty() && statics.empty(), "bad generics/statics");
|
||||
auto record =
|
||||
ir::cast<ir::types::RecordType>(module->unsafeGetMemberedType(realizedName));
|
||||
record->realize({}, {});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "manager.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "codon/sir/analyze/analysis.h"
|
||||
|
@ -49,7 +48,7 @@ std::string PassManager::registerPass(std::unique_ptr<Pass> pass,
|
|||
key = km.getUniqueKey(key);
|
||||
|
||||
for (const auto &req : reqs) {
|
||||
assert(deps.find(req) != deps.end());
|
||||
seqassert(deps.find(req) != deps.end(), "required key '{}' not found", req);
|
||||
deps[req].push_back(key);
|
||||
}
|
||||
|
||||
|
@ -76,7 +75,7 @@ std::string PassManager::registerAnalysis(std::unique_ptr<analyze::Analysis> ana
|
|||
key = km.getUniqueKey(key);
|
||||
|
||||
for (const auto &req : reqs) {
|
||||
assert(deps.find(req) != deps.end());
|
||||
seqassert(deps.find(req) != deps.end(), "required key '{}' not found", req);
|
||||
deps[req].push_back(key);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,11 @@ namespace {
|
|||
void compilationMessage(const std::string &header, const std::string &msg,
|
||||
const std::string &file, int line, int col) {
|
||||
auto &out = getLogger().err;
|
||||
assert(!(file.empty() && (line > 0 || col > 0)));
|
||||
assert(!(col > 0 && line <= 0));
|
||||
seqassert(!(file.empty() && (line > 0 || col > 0)),
|
||||
"empty filename with non-zero line/col: file={}, line={}, col={}", file,
|
||||
line, col);
|
||||
seqassert(!(col > 0 && line <= 0), "col but no line: file={}, line={}, col={}", file,
|
||||
line, col);
|
||||
out << "\033[1m";
|
||||
if (!file.empty())
|
||||
out << file.substr(file.rfind('/') + 1);
|
||||
|
|
Loading…
Reference in New Issue