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