mirror of https://github.com/exaloop/codon.git
Inherit @__attribute__ attributes
parent
b74557bb2a
commit
e46e0d9fcd
|
@ -99,26 +99,26 @@ Compiler::parse(bool isCode, const std::string &file, const std::string &code,
|
|||
ast::TypecheckVisitor::apply(cache.get(), std::move(transformed));
|
||||
t3.log();
|
||||
|
||||
std::unordered_map<std::string, double> wxt;
|
||||
std::unordered_map<std::string, std::unordered_map<std::string, double>> wx;
|
||||
for (auto &[r, t] : cache->_timings) {
|
||||
if (auto f = cache->typeCtx->find(r)) {
|
||||
auto n = f->type->getFunc()->ast->name;
|
||||
wx[n][r] = t;
|
||||
wxt[n] += t;
|
||||
} else {
|
||||
wx["?"][r] = t;
|
||||
wxt["?"] += t;
|
||||
}
|
||||
}
|
||||
std::vector<std::pair<std::string, double>> q(wxt.begin(), wxt.end());
|
||||
sort(q.begin(), q.end(),
|
||||
[](const auto &a, const auto &b) { return b.second < a.second; });
|
||||
double s = 0;
|
||||
for (auto &[k, v] : q) {
|
||||
s += v;
|
||||
LOG_TIME(" [->] {:60} = {:10.3f} / {:10.3f}", k, v, s);
|
||||
}
|
||||
// std::unordered_map<std::string, double> wxt;
|
||||
// std::unordered_map<std::string, std::unordered_map<std::string, double>> wx;
|
||||
// for (auto &[r, t] : cache->_timings) {
|
||||
// if (auto f = cache->typeCtx->find(r)) {
|
||||
// auto n = f->type->getFunc()->ast->name;
|
||||
// wx[n][r] = t;
|
||||
// wxt[n] += t;
|
||||
// } else {
|
||||
// wx["?"][r] = t;
|
||||
// wxt["?"] += t;
|
||||
// }
|
||||
// }
|
||||
// std::vector<std::pair<std::string, double>> q(wxt.begin(), wxt.end());
|
||||
// sort(q.begin(), q.end(),
|
||||
// [](const auto &a, const auto &b) { return b.second < a.second; });
|
||||
// double s = 0;
|
||||
// for (auto &[k, v] : q) {
|
||||
// s += v;
|
||||
// LOG_TIME(" [->] {:60} = {:10.3f} / {:10.3f}", k, v, s);
|
||||
// }
|
||||
|
||||
if (codon::getLogger().flags & codon::Logger::FLAG_USER) {
|
||||
auto fo = fopen("_dump_typecheck.sexp", "w");
|
||||
|
|
|
@ -414,8 +414,6 @@ void FunctionStmt::parseDecorators() {
|
|||
std::vector<ExprPtr> newDecorators;
|
||||
for (auto &d : decorators) {
|
||||
if (d->isId(Attr::Attribute)) {
|
||||
if (decorators.size() != 1)
|
||||
E(Error::FN_SINGLE_DECORATOR, decorators[1], Attr::Attribute);
|
||||
attributes.isAttribute = true;
|
||||
} else if (d->isId(Attr::LLVM)) {
|
||||
attributes.set(Attr::LLVM);
|
||||
|
|
|
@ -120,8 +120,14 @@ void SimplifyVisitor::visit(FunctionStmt *stmt) {
|
|||
auto [isAttr, attrName] = getDecorator(stmt->decorators[i]);
|
||||
if (!attrName.empty()) {
|
||||
stmt->attributes.set(attrName);
|
||||
if (isAttr)
|
||||
if (isAttr) {
|
||||
const auto &otherAttr =
|
||||
ctx->cache->functions[ctx->cache->overloads[attrName][0].name]
|
||||
.ast->attributes.customAttr;
|
||||
for (const auto &a : otherAttr)
|
||||
stmt->attributes.set(a);
|
||||
stmt->decorators[i] = nullptr; // remove it from further consideration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ StmtPtr TypecheckVisitor::inferTypes(StmtPtr result, bool isToplevel) {
|
|||
if (f.second.type && f.second.realizations.empty() &&
|
||||
(attr.has(Attr::ForceRealize) || attr.has(Attr::Export) ||
|
||||
(attr.has(Attr::C) && !attr.has(Attr::CVarArg)))) {
|
||||
LOG("force-realize {}", f.first);
|
||||
seqassert(f.second.type->canRealize(), "cannot realize {}", f.first);
|
||||
realize(ctx->instantiate(f.second.type)->getFunc());
|
||||
seqassert(!f.second.realizations.empty(), "cannot realize {}", f.first);
|
||||
|
@ -409,7 +410,8 @@ types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type, bool force)
|
|||
realizations[key] = realizations[type->realizedName()];
|
||||
}
|
||||
|
||||
LOG("[realize] {} {}", type->realizedName(), ctx->realizationBases.back().iteration);
|
||||
// LOG("[realize] {} {}", type->realizedName(),
|
||||
// ctx->realizationBases.back().iteration);
|
||||
|
||||
if (force)
|
||||
realizations[type->realizedName()]->ast = r->ast;
|
||||
|
|
Loading…
Reference in New Issue