mirror of https://github.com/exaloop/codon.git
Remove debug comments [skip ci]
parent
3938b46a9a
commit
ef51677acf
|
@ -111,7 +111,6 @@ ir::Func *Cache::realizeFunction(types::FuncTypePtr type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// LOG("--> realizing {}", type->debugString(1));
|
|
||||||
int oldAge = typeCtx->age;
|
int oldAge = typeCtx->age;
|
||||||
typeCtx->age = 99999;
|
typeCtx->age = 99999;
|
||||||
auto tv = TypecheckVisitor(typeCtx);
|
auto tv = TypecheckVisitor(typeCtx);
|
||||||
|
|
|
@ -109,9 +109,8 @@ StmtPtr parseFile(Cache *cache, const std::string &file) {
|
||||||
|
|
||||||
cache->imports[file].content = lines;
|
cache->imports[file].content = lines;
|
||||||
auto result = parseCode(cache, file, code);
|
auto result = parseCode(cache, file, code);
|
||||||
|
// For debugging purposes:
|
||||||
// LOG("peg/{} := {}", file, result ? result->toString(0) : "<nullptr>");
|
// LOG("peg/{} := {}", file, result ? result->toString(0) : "<nullptr>");
|
||||||
// throw;
|
|
||||||
// LOG("fmt := {}", FormatVisitor::apply(result));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,6 @@ std::shared_ptr<json> DocVisitor::apply(const std::string &argv0,
|
||||||
auto path = getAbsolutePath(f);
|
auto path = getAbsolutePath(f);
|
||||||
ctx->setFilename(path);
|
ctx->setFilename(path);
|
||||||
ast = ast::parseFile(shared->cache, path);
|
ast = ast::parseFile(shared->cache, path);
|
||||||
// LOG("parsing {}", f);
|
|
||||||
DocVisitor(ctx).transformModule(std::move(ast));
|
DocVisitor(ctx).transformModule(std::move(ast));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -406,15 +406,6 @@ void FormatVisitor::visit(FunctionStmt *fstmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormatVisitor::visit(ClassStmt *stmt) {
|
void FormatVisitor::visit(ClassStmt *stmt) {
|
||||||
// if (cache &&
|
|
||||||
// cache->realizationAsts.find(fstmt->name) != cache->realizationAsts.end()) {
|
|
||||||
// fstmt = (const FunctionStmt *)(cache->realizationAsts[fstmt->name].get());
|
|
||||||
// } else if (cache) {
|
|
||||||
// for (auto &real : cache->realizations[fstmt->name])
|
|
||||||
// result += simplify(cache->realizationAsts[real.first]);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
std::vector<std::string> attrs;
|
std::vector<std::string> attrs;
|
||||||
|
|
||||||
if (!stmt->attributes.has(Attr::Extend))
|
if (!stmt->attributes.has(Attr::Extend))
|
||||||
|
|
|
@ -30,9 +30,6 @@ class FormatVisitor : public CallbackASTVisitor<std::string, std::string> {
|
||||||
private:
|
private:
|
||||||
template <typename T, typename... Ts> std::string renderExpr(T &&t, Ts &&...args) {
|
template <typename T, typename... Ts> std::string renderExpr(T &&t, Ts &&...args) {
|
||||||
std::string s;
|
std::string s;
|
||||||
// if (renderType)
|
|
||||||
// s += fmt::format("{}{}{}", typeStart,
|
|
||||||
// t->getType() ? t->getType()->toString() : "-", typeEnd);
|
|
||||||
return fmt::format("{}{}{}{}{}{}", exprStart, s, nodeStart, fmt::format(args...),
|
return fmt::format("{}{}{}{}{}{}", exprStart, s, nodeStart, fmt::format(args...),
|
||||||
nodeEnd, exprEnd);
|
nodeEnd, exprEnd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -883,7 +883,6 @@ void SimplifyVisitor::visit(ClassStmt *stmt) {
|
||||||
StmtPtr autoDeducedInit = nullptr;
|
StmtPtr autoDeducedInit = nullptr;
|
||||||
Stmt *firstInit = nullptr;
|
Stmt *firstInit = nullptr;
|
||||||
if (deduce && args.empty() && !extension) {
|
if (deduce && args.empty() && !extension) {
|
||||||
// LOG("deducing {}", stmt->name);
|
|
||||||
for (auto sp : getClassMethods(stmt->suite))
|
for (auto sp : getClassMethods(stmt->suite))
|
||||||
if (sp && sp->getFunction()) {
|
if (sp && sp->getFunction()) {
|
||||||
firstInit = sp.get();
|
firstInit = sp.get();
|
||||||
|
@ -910,7 +909,6 @@ void SimplifyVisitor::visit(ClassStmt *stmt) {
|
||||||
ctx->cache->classes[canonicalName].fields.push_back({m, nullptr});
|
ctx->cache->classes[canonicalName].fields.push_back({m, nullptr});
|
||||||
args.emplace_back(Param{m, N<IdExpr>(varName), nullptr});
|
args.emplace_back(Param{m, N<IdExpr>(varName), nullptr});
|
||||||
argSubstitutions.push_back(substitutions.size() - 1);
|
argSubstitutions.push_back(substitutions.size() - 1);
|
||||||
// LOG("deduction: {}: {} <-> {}", stmt->name, m, name);
|
|
||||||
}
|
}
|
||||||
ctx->bases.back().deducedMembers = nullptr;
|
ctx->bases.back().deducedMembers = nullptr;
|
||||||
break;
|
break;
|
||||||
|
@ -1069,8 +1067,7 @@ void SimplifyVisitor::visit(ClassStmt *stmt) {
|
||||||
seqassert(c, "not a class AST for {}", canonicalName);
|
seqassert(c, "not a class AST for {}", canonicalName);
|
||||||
preamble->globals.push_back(c->clone());
|
preamble->globals.push_back(c->clone());
|
||||||
c->suite = clone(suite);
|
c->suite = clone(suite);
|
||||||
// if (stmt->baseClasses.size())
|
|
||||||
// LOG("{} -> {}", stmt->name, c->toString(0));
|
|
||||||
}
|
}
|
||||||
stmts[0] = N<ClassStmt>(canonicalName, std::vector<Param>{}, N<SuiteStmt>(),
|
stmts[0] = N<ClassStmt>(canonicalName, std::vector<Param>{}, N<SuiteStmt>(),
|
||||||
Attr({Attr::Extend}), std::vector<ExprPtr>{},
|
Attr({Attr::Extend}), std::vector<ExprPtr>{},
|
||||||
|
|
|
@ -64,8 +64,6 @@ ir::Value *TranslateVisitor::transform(const ExprPtr &expr) {
|
||||||
}
|
}
|
||||||
if (expr->hasAttr(ExprAttr::Partial))
|
if (expr->hasAttr(ExprAttr::Partial))
|
||||||
p = expr->type->getPartial().get();
|
p = expr->type->getPartial().get();
|
||||||
// LOG("{} {}: {}", std::string(ctx->seqItems.size(), ' '), expr->attributes,
|
|
||||||
// expr->toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expr->accept(v);
|
expr->accept(v);
|
||||||
|
@ -501,7 +499,6 @@ void TranslateVisitor::transformFunction(types::FuncType *type, FunctionStmt *as
|
||||||
std::map<std::string, std::string> attr;
|
std::map<std::string, std::string> attr;
|
||||||
attr[".module"] = ast->attributes.module;
|
attr[".module"] = ast->attributes.module;
|
||||||
for (auto &a : ast->attributes.customAttr) {
|
for (auto &a : ast->attributes.customAttr) {
|
||||||
// LOG("{} -> {}", ast->name, a);
|
|
||||||
attr[a] = "";
|
attr[a] = "";
|
||||||
}
|
}
|
||||||
func->setAttribute(std::make_unique<ir::KeyValueAttribute>(attr));
|
func->setAttribute(std::make_unique<ir::KeyValueAttribute>(attr));
|
||||||
|
|
|
@ -46,14 +46,8 @@ TypePtr TypecheckVisitor::unify(TypePtr &a, const TypePtr &b, bool undoOnSuccess
|
||||||
} else {
|
} else {
|
||||||
undo.undo();
|
undo.undo();
|
||||||
}
|
}
|
||||||
// LOG("{} / {}", a->debugString(true), b->debugString(true));
|
|
||||||
if (!undoOnSuccess)
|
if (!undoOnSuccess)
|
||||||
a->unify(b.get(), &undo);
|
a->unify(b.get(), &undo);
|
||||||
// if (format("cannot unify {} and {}", a->toString(), b->toString()) ==
|
|
||||||
// "cannot unify ._lambda_82:0[...] and T2") {
|
|
||||||
// LOG("cannot unify {} and {}", a->debugString(1), b->debugString(1));
|
|
||||||
// a->unify(b.get(), &undo);
|
|
||||||
// }
|
|
||||||
error("cannot unify {} and {}", a->toString(), b->toString());
|
error("cannot unify {} and {}", a->toString(), b->toString());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,8 @@ std::shared_ptr<types::LinkType>
|
||||||
TypeContext::addUnbound(const Expr *expr, int level, bool setActive, char staticType) {
|
TypeContext::addUnbound(const Expr *expr, int level, bool setActive, char staticType) {
|
||||||
auto t = std::make_shared<types::LinkType>(
|
auto t = std::make_shared<types::LinkType>(
|
||||||
types::LinkType::Unbound, cache->unboundCount++, level, nullptr, staticType);
|
types::LinkType::Unbound, cache->unboundCount++, level, nullptr, staticType);
|
||||||
// if (t->id == 7815)
|
// Keep it for debugging purposes:
|
||||||
// LOG("debug");
|
// if (t->id == 7815) LOG("debug");
|
||||||
t->setSrcInfo(expr->getSrcInfo());
|
t->setSrcInfo(expr->getSrcInfo());
|
||||||
LOG_TYPECHECK("[ub] new {}: {} ({})", t->debugString(true), expr->toString(),
|
LOG_TYPECHECK("[ub] new {}: {} ({})", t->debugString(true), expr->toString(),
|
||||||
setActive);
|
setActive);
|
||||||
|
@ -202,17 +202,11 @@ int TypeContext::reorderNamedArgs(types::FuncType *func,
|
||||||
|
|
||||||
int starArgIndex = -1, kwstarArgIndex = -1;
|
int starArgIndex = -1, kwstarArgIndex = -1;
|
||||||
for (int i = 0; i < func->ast->args.size(); i++) {
|
for (int i = 0; i < func->ast->args.size(); i++) {
|
||||||
// if (!known.empty() && known[i] && !partial)
|
|
||||||
// continue;
|
|
||||||
if (startswith(func->ast->args[i].name, "**"))
|
if (startswith(func->ast->args[i].name, "**"))
|
||||||
kwstarArgIndex = i, score -= 2;
|
kwstarArgIndex = i, score -= 2;
|
||||||
else if (startswith(func->ast->args[i].name, "*"))
|
else if (startswith(func->ast->args[i].name, "*"))
|
||||||
starArgIndex = i, score -= 2;
|
starArgIndex = i, score -= 2;
|
||||||
}
|
}
|
||||||
// seqassert(known.empty() || starArgIndex == -1 || !known[starArgIndex],
|
|
||||||
// "partial *args");
|
|
||||||
// seqassert(known.empty() || kwstarArgIndex == -1 || !known[kwstarArgIndex],
|
|
||||||
// "partial **kwargs");
|
|
||||||
|
|
||||||
// 1. Assign positional arguments to slots
|
// 1. Assign positional arguments to slots
|
||||||
// Each slot contains a list of arg's indices
|
// Each slot contains a list of arg's indices
|
||||||
|
|
|
@ -868,9 +868,7 @@ ExprPtr TypecheckVisitor::transformDot(DotExpr *expr,
|
||||||
return transform(
|
return transform(
|
||||||
N<CallExpr>(N<DotExpr>(expr->expr, "_getattr"), N<StringExpr>(expr->member)));
|
N<CallExpr>(N<DotExpr>(expr->expr, "_getattr"), N<StringExpr>(expr->member)));
|
||||||
} else {
|
} else {
|
||||||
// For debugging purposes:
|
// For debugging purposes: ctx->findMethod(typ->name, expr->member);
|
||||||
if (expr->member == "ticker")
|
|
||||||
ctx->findMethod(typ->name, expr->member);
|
|
||||||
error("cannot find '{}' in {}", expr->member, typ->toString());
|
error("cannot find '{}' in {}", expr->member, typ->toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1020,7 +1018,6 @@ ExprPtr TypecheckVisitor::transformCall(CallExpr *expr, const types::TypePtr &in
|
||||||
ai--;
|
ai--;
|
||||||
} else {
|
} else {
|
||||||
// Case 3: Normal argument
|
// Case 3: Normal argument
|
||||||
// LOG("-> {}", expr->args[ai].value->toString());
|
|
||||||
expr->args[ai].value = transform(expr->args[ai].value, true);
|
expr->args[ai].value = transform(expr->args[ai].value, true);
|
||||||
// Unbound inType might become a generator that will need to be extracted, so
|
// Unbound inType might become a generator that will need to be extracted, so
|
||||||
// don't unify it yet.
|
// don't unify it yet.
|
||||||
|
@ -1046,8 +1043,6 @@ ExprPtr TypecheckVisitor::transformCall(CallExpr *expr, const types::TypePtr &in
|
||||||
ctx->bases.back().supers, expr->args);
|
ctx->bases.back().supers, expr->args);
|
||||||
if (m.empty())
|
if (m.empty())
|
||||||
error("no matching superf methods are available");
|
error("no matching superf methods are available");
|
||||||
// LOG("found {} <- {}", ctx->bases.back().type->getFunc()->toString(),
|
|
||||||
// m[0]->toString());
|
|
||||||
ExprPtr e = N<CallExpr>(N<IdExpr>(m[0]->ast->name), expr->args);
|
ExprPtr e = N<CallExpr>(N<IdExpr>(m[0]->ast->name), expr->args);
|
||||||
return transform(e, false, true);
|
return transform(e, false, true);
|
||||||
}
|
}
|
||||||
|
@ -1285,7 +1280,6 @@ ExprPtr TypecheckVisitor::transformCall(CallExpr *expr, const types::TypePtr &in
|
||||||
}
|
}
|
||||||
auto e = transform(expr->expr);
|
auto e = transform(expr->expr);
|
||||||
unify(expr->type, e->getType());
|
unify(expr->type, e->getType());
|
||||||
// LOG("-- {} / {}", e->toString(), e->type->debugString(true));
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1397,19 +1391,6 @@ ExprPtr TypecheckVisitor::transformCall(CallExpr *expr, const types::TypePtr &in
|
||||||
// Case 2. Normal function call.
|
// Case 2. Normal function call.
|
||||||
expr->args = args;
|
expr->args = args;
|
||||||
unify(expr->type, calleeFn->args[0]); // function return type
|
unify(expr->type, calleeFn->args[0]); // function return type
|
||||||
|
|
||||||
// HACK: Intercept Partial.__new__ and replace it with partial type
|
|
||||||
// TODO: needs cleaner logic for this. Maybe just use normal record type
|
|
||||||
// and just track partialized function args, not the whole function as it's done
|
|
||||||
// now. Major caveat: needs rewiring of the function generic partialization logic.
|
|
||||||
// if (startswith(calleeFn->ast->name, TYPE_PARTIAL) &&
|
|
||||||
// endswith(calleeFn->ast->name, ".__new__:0")) {
|
|
||||||
// seqassert(expr->type->getRecord(), "expected a partial record");
|
|
||||||
// auto r = expr->type->getRecord();
|
|
||||||
// expr->type = std::make_shared<PartialType>(r,
|
|
||||||
// ctx->cache->partials[r->name].first,
|
|
||||||
// ctx->cache->partials[r->name].second);
|
|
||||||
// }
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1837,12 +1818,6 @@ TypecheckVisitor::findMatchingMethods(types::ClassType *typ,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (score != -1) {
|
if (score != -1) {
|
||||||
// std::vector<std::string> ar;
|
|
||||||
// for (auto &a: args) {
|
|
||||||
// if (a.first.empty()) ar.push_back(a.second->toString());
|
|
||||||
// else ar.push_back(format("{}: {}", a.first, a.second->toString()));
|
|
||||||
// }
|
|
||||||
// LOG("- {} vs {}", m->toString(), join(ar, "; "));
|
|
||||||
results.push_back(methods[mi]);
|
results.push_back(methods[mi]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1969,7 +1944,6 @@ types::FuncTypePtr TypecheckVisitor::findDispatch(const std::string &fn) {
|
||||||
ctx->cache->functions[name].ast = ast;
|
ctx->cache->functions[name].ast = ast;
|
||||||
ctx->cache->functions[name].type = typ;
|
ctx->cache->functions[name].type = typ;
|
||||||
prependStmts->push_back(ast);
|
prependStmts->push_back(ast);
|
||||||
// LOG("dispatch: {}", ast->toString(1));
|
|
||||||
return typ;
|
return typ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -288,7 +288,6 @@ types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type) {
|
||||||
irType->setAstType(type->getFunc());
|
irType->setAstType(type->getFunc());
|
||||||
r->ir->realize(irType, names);
|
r->ir->realize(irType, names);
|
||||||
|
|
||||||
// LOG("-> {}", *(r->ir));
|
|
||||||
ctx->cache->functions[type->ast->name].realizations[type->realizedName()] = r;
|
ctx->cache->functions[type->ast->name].realizations[type->realizedName()] = r;
|
||||||
} else {
|
} else {
|
||||||
ctx->cache->functions[type->ast->name].realizations[oldKey] =
|
ctx->cache->functions[type->ast->name].realizations[oldKey] =
|
||||||
|
|
Loading…
Reference in New Issue