mirror of https://github.com/exaloop/codon.git
Fix tests
parent
e737536b38
commit
93f3c36c23
|
@ -185,6 +185,8 @@ struct Cache : public std::enable_shared_from_this<Cache> {
|
||||||
std::shared_ptr<FunctionStmt> ast;
|
std::shared_ptr<FunctionStmt> ast;
|
||||||
/// IR function pointer.
|
/// IR function pointer.
|
||||||
ir::Func *ir;
|
ir::Func *ir;
|
||||||
|
/// Resolved captures
|
||||||
|
std::vector<std::string> captures;
|
||||||
};
|
};
|
||||||
/// Realization lookup table that maps a realized function name to the corresponding
|
/// Realization lookup table that maps a realized function name to the corresponding
|
||||||
/// FunctionRealization instance.
|
/// FunctionRealization instance.
|
||||||
|
|
|
@ -285,15 +285,25 @@ types::TypePtr TypecheckVisitor::realizeType(types::ClassType *type) {
|
||||||
|
|
||||||
types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type, bool force) {
|
types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type, bool force) {
|
||||||
auto &realizations = ctx->cache->functions[type->ast->name].realizations;
|
auto &realizations = ctx->cache->functions[type->ast->name].realizations;
|
||||||
|
const auto &imp = ctx->cache->imports[type->ast->attributes.module];
|
||||||
if (auto r = in(realizations, type->realizedName())) {
|
if (auto r = in(realizations, type->realizedName())) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
|
bool ok = true;
|
||||||
|
// Enable later!
|
||||||
|
// for (auto &c: (*r)->captures) {
|
||||||
|
// auto h = imp.ctx->find(ctx->cache->rev(c));
|
||||||
|
// if (h && h->canonicalName != c) {
|
||||||
|
// ok = false;
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
if (ok)
|
||||||
return (*r)->type;
|
return (*r)->type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
seqassert(in(ctx->cache->imports, type->ast->attributes.module) != nullptr,
|
seqassert(in(ctx->cache->imports, type->ast->attributes.module) != nullptr,
|
||||||
"bad module: '{}'", type->ast->attributes.module);
|
"bad module: '{}'", type->ast->attributes.module);
|
||||||
auto &imp = ctx->cache->imports[type->ast->attributes.module];
|
|
||||||
auto oldCtx = this->ctx;
|
auto oldCtx = this->ctx;
|
||||||
this->ctx = imp.ctx;
|
this->ctx = imp.ctx;
|
||||||
// LOG("=> {}", ctx->moduleName.module, ctx->moduleName.path);
|
// LOG("=> {}", ctx->moduleName.module, ctx->moduleName.path);
|
||||||
|
@ -354,6 +364,10 @@ types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type, bool force)
|
||||||
auto r = realizations[key] = std::make_shared<Cache::Function::FunctionRealization>();
|
auto r = realizations[key] = std::make_shared<Cache::Function::FunctionRealization>();
|
||||||
r->type = type->getFunc();
|
r->type = type->getFunc();
|
||||||
r->ir = oldIR;
|
r->ir = oldIR;
|
||||||
|
for (auto &[c, _]: ast->attributes.captures) {
|
||||||
|
auto h = ctx->find(c);
|
||||||
|
r->captures.push_back(h ? h->canonicalName : "");
|
||||||
|
}
|
||||||
|
|
||||||
// Realizations should always be visible, so add them to the toplevel
|
// Realizations should always be visible, so add them to the toplevel
|
||||||
auto val =
|
auto val =
|
||||||
|
|
Loading…
Reference in New Issue