diff --git a/codon/parser/ast/types.cpp b/codon/parser/ast/types.cpp index 7a3244a0..4e52b0c6 100644 --- a/codon/parser/ast/types.cpp +++ b/codon/parser/ast/types.cpp @@ -100,7 +100,7 @@ int LinkType::unify(Type *typ, Unification *undo) { if (undo) { LOG_TYPECHECK("[unify] {} := {}", id, typ->debugString(true)); // 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; seqassert(!typ->getLink() || typ->getLink()->kind != Unbound || typ->getLink()->id <= id, @@ -108,7 +108,7 @@ int LinkType::unify(Type *typ, Unification *undo) { type = typ->follow(); if (auto t = type->getLink()) if (trait && t->kind == Unbound && !t->trait) { - undo->traits.push_back(t.get()); + undo->traits.push_back(t->getLink()); t->trait = trait; } } @@ -205,7 +205,7 @@ bool LinkType::occurs(Type *typ, Type::Unification *undo) { if (tl->trait && occurs(tl->trait.get(), undo)) return true; 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; } return false; diff --git a/codon/parser/ast/types.h b/codon/parser/ast/types.h index 08c6e6f9..465c93eb 100644 --- a/codon/parser/ast/types.h +++ b/codon/parser/ast/types.h @@ -39,11 +39,11 @@ struct Type : public codon::SrcObject, public std::enable_shared_from_this /// Needed because the unify() is destructive. struct Unification { /// List of unbound types that have been changed. - std::vector linked; + std::vector> linked; /// List of unbound types whose level has been changed. - std::vector> leveled; + std::vector, int>> leveled; /// List of assigned traits. - std::vector traits; + std::vector> traits; /// Pointer to a TypecheckVisitor to support realization function types. TypecheckVisitor *realizator = nullptr; diff --git a/codon/parser/visitors/translate/translate.cpp b/codon/parser/visitors/translate/translate.cpp index f1346ce1..33779418 100644 --- a/codon/parser/visitors/translate/translate.cpp +++ b/codon/parser/visitors/translate/translate.cpp @@ -438,7 +438,7 @@ void TranslateVisitor::transformFunction(types::FuncType *type, FunctionStmt *as func->setAttribute(std::make_unique(attr)); for (int i = 0; i < names.size(); i++) 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)) { ctx->addBlock(); 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->setLLVMDeclarations(declare); f->setLLVMLiterals(literals); - func->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]); + // func->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]); } } // namespace ast diff --git a/codon/parser/visitors/typecheck/typecheck_infer.cpp b/codon/parser/visitors/typecheck/typecheck_infer.cpp index bf804274..95e50d2d 100644 --- a/codon/parser/visitors/typecheck/typecheck_infer.cpp +++ b/codon/parser/visitors/typecheck/typecheck_infer.cpp @@ -237,6 +237,7 @@ types::TypePtr TypecheckVisitor::realizeFunc(types::FuncType *type) { } else { r->ir = ctx->cache->module->Nr(type->realizedName()); } + r->ir->setUnmangledName(ctx->cache->reverseIdentifierLookup[type->ast->name]); auto parent = type->funcParent; if (!ast->attributes.parentClass.empty() && @@ -284,6 +285,7 @@ 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] = diff --git a/codon/sir/llvm/llvisitor.cpp b/codon/sir/llvm/llvisitor.cpp index cd0cf2ee..cbc431fd 100644 --- a/codon/sir/llvm/llvisitor.cpp +++ b/codon/sir/llvm/llvisitor.cpp @@ -874,6 +874,8 @@ void LLVMVisitor::visit(const InternalFunc *x) { } } + if (!result) + internalFuncMatchesIgnoreArgs("__new__", x); seqassert(result, "internal function {} not found", *x); B->CreateRet(result); }