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;
|
||||
/// IR function pointer.
|
||||
ir::Func *ir;
|
||||
/// Resolved captures
|
||||
std::vector<std::string> captures;
|
||||
};
|
||||
/// Realization lookup table that maps a realized function name to the corresponding
|
||||
/// FunctionRealization instance.
|
||||
|
|
|
@ -285,15 +285,25 @@ types::TypePtr TypecheckVisitor::realizeType(types::ClassType *type) {
|
|||
|
||||
types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type, bool force) {
|
||||
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 (!force) {
|
||||
return (*r)->type;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
seqassert(in(ctx->cache->imports, type->ast->attributes.module) != nullptr,
|
||||
"bad module: '{}'", type->ast->attributes.module);
|
||||
auto &imp = ctx->cache->imports[type->ast->attributes.module];
|
||||
auto oldCtx = this->ctx;
|
||||
this->ctx = imp.ctx;
|
||||
// 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>();
|
||||
r->type = type->getFunc();
|
||||
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
|
||||
auto val =
|
||||
|
|
Loading…
Reference in New Issue