mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
Fix memory leaks
This commit is contained in:
parent
bbdd51cf9e
commit
6b4f29a3f2
@ -100,7 +100,7 @@ int LinkType::unify(Type *typ, Unification *undo) {
|
|||||||
if (undo) {
|
if (undo) {
|
||||||
LOG_TYPECHECK("[unify] {} := {}", id, typ->debugString(true));
|
LOG_TYPECHECK("[unify] {} := {}", id, typ->debugString(true));
|
||||||
// Link current type to typ and ensure that this modification is recorded in undo.
|
// Link current type to typ and ensure that this modification is recorded in undo.
|
||||||
undo->linked.push_back(this);
|
undo->linked.push_back(getLink());
|
||||||
kind = Link;
|
kind = Link;
|
||||||
seqassert(!typ->getLink() || typ->getLink()->kind != Unbound ||
|
seqassert(!typ->getLink() || typ->getLink()->kind != Unbound ||
|
||||||
typ->getLink()->id <= id,
|
typ->getLink()->id <= id,
|
||||||
@ -108,7 +108,7 @@ int LinkType::unify(Type *typ, Unification *undo) {
|
|||||||
type = typ->follow();
|
type = typ->follow();
|
||||||
if (auto t = type->getLink())
|
if (auto t = type->getLink())
|
||||||
if (trait && t->kind == Unbound && !t->trait) {
|
if (trait && t->kind == Unbound && !t->trait) {
|
||||||
undo->traits.push_back(t.get());
|
undo->traits.push_back(t->getLink());
|
||||||
t->trait = trait;
|
t->trait = trait;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ bool LinkType::occurs(Type *typ, Type::Unification *undo) {
|
|||||||
if (tl->trait && occurs(tl->trait.get(), undo))
|
if (tl->trait && occurs(tl->trait.get(), undo))
|
||||||
return true;
|
return true;
|
||||||
if (undo && tl->level > level) {
|
if (undo && tl->level > level) {
|
||||||
undo->leveled.emplace_back(make_pair(tl.get(), tl->level));
|
undo->leveled.emplace_back(make_pair(tl, tl->level));
|
||||||
tl->level = level;
|
tl->level = level;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -39,11 +39,11 @@ struct Type : public codon::SrcObject, public std::enable_shared_from_this<Type>
|
|||||||
/// Needed because the unify() is destructive.
|
/// Needed because the unify() is destructive.
|
||||||
struct Unification {
|
struct Unification {
|
||||||
/// List of unbound types that have been changed.
|
/// List of unbound types that have been changed.
|
||||||
std::vector<LinkType *> linked;
|
std::vector<std::shared_ptr<LinkType>> linked;
|
||||||
/// List of unbound types whose level has been changed.
|
/// List of unbound types whose level has been changed.
|
||||||
std::vector<std::pair<LinkType *, int>> leveled;
|
std::vector<std::pair<std::shared_ptr<LinkType>, int>> leveled;
|
||||||
/// List of assigned traits.
|
/// List of assigned traits.
|
||||||
std::vector<LinkType *> traits;
|
std::vector<std::shared_ptr<LinkType>> traits;
|
||||||
/// Pointer to a TypecheckVisitor to support realization function types.
|
/// Pointer to a TypecheckVisitor to support realization function types.
|
||||||
TypecheckVisitor *realizator = nullptr;
|
TypecheckVisitor *realizator = nullptr;
|
||||||
|
|
||||||
|
@ -438,7 +438,7 @@ void TranslateVisitor::transformFunction(types::FuncType *type, FunctionStmt *as
|
|||||||
func->setAttribute(std::make_unique<ir::KeyValueAttribute>(attr));
|
func->setAttribute(std::make_unique<ir::KeyValueAttribute>(attr));
|
||||||
for (int i = 0; i < names.size(); i++)
|
for (int i = 0; i < names.size(); i++)
|
||||||
func->getArgVar(names[i])->setSrcInfo(ast->args[indices[i]].getSrcInfo());
|
func->getArgVar(names[i])->setSrcInfo(ast->args[indices[i]].getSrcInfo());
|
||||||
func->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]);
|
// func->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]);
|
||||||
if (!ast->attributes.has(Attr::C) && !ast->attributes.has(Attr::Internal)) {
|
if (!ast->attributes.has(Attr::C) && !ast->attributes.has(Attr::Internal)) {
|
||||||
ctx->addBlock();
|
ctx->addBlock();
|
||||||
for (auto i = 0; i < names.size(); i++)
|
for (auto i = 0; i < names.size(); i++)
|
||||||
@ -515,7 +515,7 @@ void TranslateVisitor::transformLLVMFunction(types::FuncType *type, FunctionStmt
|
|||||||
f->setLLVMBody(join(lines, "\n"));
|
f->setLLVMBody(join(lines, "\n"));
|
||||||
f->setLLVMDeclarations(declare);
|
f->setLLVMDeclarations(declare);
|
||||||
f->setLLVMLiterals(literals);
|
f->setLLVMLiterals(literals);
|
||||||
func->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]);
|
// func->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
|
@ -237,6 +237,7 @@ types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type) {
|
|||||||
} else {
|
} else {
|
||||||
r->ir = ctx->cache->module->Nr<ir::BodiedFunc>(type->realizedName());
|
r->ir = ctx->cache->module->Nr<ir::BodiedFunc>(type->realizedName());
|
||||||
}
|
}
|
||||||
|
r->ir->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]);
|
||||||
|
|
||||||
auto parent = type->funcParent;
|
auto parent = type->funcParent;
|
||||||
if (!ast->attributes.parentClass.empty() &&
|
if (!ast->attributes.parentClass.empty() &&
|
||||||
@ -284,6 +285,7 @@ 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] =
|
||||||
|
@ -874,6 +874,8 @@ void LLVMVisitor::visit(const InternalFunc *x) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
internalFuncMatchesIgnoreArgs<RecordType>("__new__", x);
|
||||||
seqassert(result, "internal function {} not found", *x);
|
seqassert(result, "internal function {} not found", *x);
|
||||||
B->CreateRet(result);
|
B->CreateRet(result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user