aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-item.h
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-13 14:36:25 +0000
committerGitHub <noreply@github.com>2021-05-13 14:36:25 +0000
commit5d7fbc4a78897f8f561bdd78b4d3bbc15f4b351f (patch)
tree167d95c3c3e816ddb3284ed078027f8a9ef1b7c6 /gcc/rust/backend/rust-compile-item.h
parent5134aaa9f0b37ea372cb185fe7aa6c26fe0a4c2e (diff)
parentfcd4ed431272414157eb90773f174405431eb6bd (diff)
downloadgcc-5d7fbc4a78897f8f561bdd78b4d3bbc15f4b351f.zip
gcc-5d7fbc4a78897f8f561bdd78b4d3bbc15f4b351f.tar.gz
gcc-5d7fbc4a78897f8f561bdd78b4d3bbc15f4b351f.tar.bz2
Merge #427
427: Fix duplicate function generation in the backend r=philberty a=philberty Fix duplicated function generation for generics When emitting the backend IR we need to check if we have already compiled one already. This is all due to the fact when we do generic substitutions in type resolution its only upon usage of a function the function is substituted it gains a new unique ty_ref HIR ID to make sure new substituted versions of a type have unique ids. Fixes #403 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r--gcc/rust/backend/rust-compile-item.h46
1 files changed, 25 insertions, 21 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 5a7d846..c3dc279 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -92,17 +92,6 @@ public:
if (!compile_fns)
return;
- // items can be forward compiled which means we may not need to invoke this
- // code
- Bfunction *lookup = nullptr;
- if (ctx->lookup_function_decl (function.get_mappings ().get_hirid (),
- &lookup))
- {
- // has this been added to the list then it must be finished
- if (ctx->function_completed (lookup))
- return;
- }
-
TyTy::BaseType *fntype_tyty;
if (!ctx->get_tyctx ()->lookup_type (function.get_mappings ().get_hirid (),
&fntype_tyty))
@@ -112,28 +101,43 @@ public:
return;
}
- if (fntype_tyty->get_kind () != TyTy::TypeKind::FNDEF)
- {
- rust_error_at (function.get_locus (), "invalid TyTy for function item");
- return;
- }
-
+ rust_assert (fntype_tyty->get_kind () == TyTy::TypeKind::FNDEF);
TyTy::FnType *fntype = static_cast<TyTy::FnType *> (fntype_tyty);
if (fntype->has_subsititions_defined ())
{
- // we cant do anything for this only when it is used
+ // we cant do anything for this only when it is used and a concrete type
+ // is given
if (concrete == nullptr)
return;
else
{
rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
fntype = static_cast<TyTy::FnType *> (concrete);
+ }
+ }
- // override the Hir Lookups for the substituions in this context
- fntype->override_context ();
+ // items can be forward compiled which means we may not need to invoke this
+ // code. We might also have already compiled this generic function as well.
+ Bfunction *lookup = nullptr;
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup, fntype))
+ {
+ // has this been added to the list then it must be finished
+ if (ctx->function_completed (lookup))
+ {
+ Bfunction *dummy = nullptr;
+ if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
+ ctx->insert_function_decl (fntype->get_ty_ref (), lookup, fntype);
+
+ return;
}
}
+ if (fntype->has_subsititions_defined ())
+ {
+ // override the Hir Lookups for the substituions in this context
+ fntype->override_context ();
+ }
+
::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
unsigned int flags = 0;
@@ -155,7 +159,7 @@ public:
Bfunction *fndecl
= ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
asm_name, flags, function.get_locus ());
- ctx->insert_function_decl (fntype->get_ty_ref (), fndecl);
+ ctx->insert_function_decl (fntype->get_ty_ref (), fndecl, fntype);
// setup the params
TyTy::BaseType *tyret = fntype->get_return_type ();