aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-09-10 14:44:42 +0000
committerGitHub <noreply@github.com>2021-09-10 14:44:42 +0000
commite3b7eb58844c446d097ddee00ecd455d5537c6b2 (patch)
tree30186abaf20b28e107b78a93cddba7143c68d2b8 /gcc
parent2bf19c1b20bfad19136e17c0c7fa765e161b789c (diff)
parent0c409fcf5678709303126aba07932f9f2a8519da (diff)
downloadgcc-e3b7eb58844c446d097ddee00ecd455d5537c6b2.zip
gcc-e3b7eb58844c446d097ddee00ecd455d5537c6b2.tar.gz
gcc-e3b7eb58844c446d097ddee00ecd455d5537c6b2.tar.bz2
Merge #669
669: Fix bug with monomorphizing of trait items r=philberty a=philberty When we monomorphize functions we need to check if we have already generated this function already. All function items have a DefId which is unique for the crate and HIR item this means for generic implementations of an item we end up with mappings of: DefId -> [ (concete-tyty-fntype, GCC::Function), ... ] So for any function we can lookup for that DefId is there a suitable version of this function already compiled. This was working untill we have generic trait items which also need to be handled in the same way. Fixes #668 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-context.h54
-rw-r--r--gcc/rust/backend/rust-compile-extern.h10
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h16
-rw-r--r--gcc/rust/backend/rust-compile-item.h8
4 files changed, 49 insertions, 39 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 05c15e3..3a92c32 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -160,32 +160,41 @@ public:
return true;
}
- void insert_function_decl (HirId id, ::Bfunction *fn,
- const TyTy::BaseType *ref)
+ void insert_function_decl (const TyTy::FnType *ref, ::Bfunction *fn)
{
+ auto id = ref->get_ty_ref ();
+ auto dId = ref->get_id ();
+
rust_assert (compiled_fn_map.find (id) == compiled_fn_map.end ());
compiled_fn_map[id] = fn;
- if (ref != nullptr)
- {
- std::pair<HirId, ::Bfunction *> elem (id, fn);
- mono_fns[ref] = std::move (elem);
- }
+
+ auto it = mono_fns.find (dId);
+ if (it == mono_fns.end ())
+ mono_fns[dId] = {};
+
+ mono_fns[dId].push_back ({ref, fn});
}
bool lookup_function_decl (HirId id, ::Bfunction **fn,
+ DefId dId = UNKNOWN_DEFID,
const TyTy::BaseType *ref = nullptr)
{
// for for any monomorphized fns
if (ref != nullptr)
{
- for (auto it = mono_fns.begin (); it != mono_fns.end (); it++)
+ rust_assert (dId != UNKNOWN_DEFID);
+
+ auto it = mono_fns.find (dId);
+ if (it == mono_fns.end ())
+ return false;
+
+ for (auto &e : mono_fns[dId])
{
- std::pair<HirId, ::Bfunction *> &val = it->second;
- const TyTy::BaseType *r = it->first;
+ const TyTy::BaseType *r = e.first;
+ ::Bfunction *f = e.second;
if (ref->is_equal (*r))
{
- *fn = val.second;
-
+ *fn = f;
return true;
}
}
@@ -316,18 +325,19 @@ private:
std::map<HirId, ::Bfunction *> compiled_fn_map;
std::map<HirId, ::Bexpression *> compiled_consts;
std::map<HirId, ::Blabel *> compiled_labels;
- std::vector< ::std::vector<Bstatement *> > statements;
- std::vector< ::Bblock *> scope_stack;
- std::vector< ::Bvariable *> loop_value_stack;
- std::vector< ::Blabel *> loop_begin_labels;
- std::map<const TyTy::BaseType *, std::pair<HirId, ::Btype *> > mono;
- std::map<const TyTy::BaseType *, std::pair<HirId, ::Bfunction *> > mono_fns;
+ std::vector<::std::vector<Bstatement *>> statements;
+ std::vector<::Bblock *> scope_stack;
+ std::vector<::Bvariable *> loop_value_stack;
+ std::vector<::Blabel *> loop_begin_labels;
+ std::map<const TyTy::BaseType *, std::pair<HirId, ::Btype *>> mono;
+ std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, ::Bfunction *>>>
+ mono_fns;
// To GCC middle-end
- std::vector< ::Btype *> type_decls;
- std::vector< ::Bvariable *> var_decls;
- std::vector< ::Bexpression *> const_decls;
- std::vector< ::Bfunction *> func_decls;
+ std::vector<::Btype *> type_decls;
+ std::vector<::Bvariable *> var_decls;
+ std::vector<::Bexpression *> const_decls;
+ std::vector<::Bfunction *> func_decls;
};
class TyTyResolveCompile : public TyTy::TyVisitor
diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h
index f0aacee..b8a8faf 100644
--- a/gcc/rust/backend/rust-compile-extern.h
+++ b/gcc/rust/backend/rust-compile-extern.h
@@ -100,14 +100,15 @@ public:
// 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))
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
+ fntype->get_id (), 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);
+ ctx->insert_function_decl (fntype, lookup);
return;
}
@@ -123,7 +124,7 @@ public:
{
Intrinsics compile (ctx);
Bfunction *fndecl = compile.compile (fntype);
- ctx->insert_function_decl (fntype->get_ty_ref (), fndecl, fntype);
+ ctx->insert_function_decl (fntype, fndecl);
return;
}
@@ -141,8 +142,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, fntype);
+ ctx->insert_function_decl (fntype, fndecl);
}
private:
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index bdeda22..1d3ad02 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -113,7 +113,8 @@ public:
// 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))
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
+ fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
@@ -121,8 +122,7 @@ public:
Bfunction *dummy = nullptr;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
{
- ctx->insert_function_decl (fntype->get_ty_ref (), lookup,
- fntype);
+ ctx->insert_function_decl (fntype, lookup);
}
reference
= ctx->get_backend ()->function_code_expression (lookup,
@@ -160,7 +160,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, fntype);
+ ctx->insert_function_decl (fntype, fndecl);
// setup the params
TyTy::BaseType *tyret = fntype->get_return_type ();
@@ -381,7 +381,8 @@ public:
// 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))
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
+ fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
@@ -389,8 +390,7 @@ public:
Bfunction *dummy = nullptr;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
{
- ctx->insert_function_decl (fntype->get_ty_ref (), lookup,
- fntype);
+ ctx->insert_function_decl (fntype, lookup);
}
reference
= ctx->get_backend ()->function_code_expression (lookup,
@@ -422,7 +422,7 @@ public:
Bfunction *fndecl
= ctx->get_backend ()->function (compiled_fn_type, fn_identifier,
asm_name, flags, func.get_locus ());
- ctx->insert_function_decl (fntype->get_ty_ref (), fndecl, fntype);
+ ctx->insert_function_decl (fntype, fndecl);
// setup the params
TyTy::BaseType *tyret = fntype->get_return_type ();
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 1871d10..b263cf6 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -150,7 +150,8 @@ public:
// 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))
+ if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
+ fntype->get_id (), fntype))
{
// has this been added to the list then it must be finished
if (ctx->function_completed (lookup))
@@ -158,8 +159,7 @@ public:
Bfunction *dummy = nullptr;
if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
{
- ctx->insert_function_decl (fntype->get_ty_ref (), lookup,
- fntype);
+ ctx->insert_function_decl (fntype, lookup);
}
reference
@@ -205,7 +205,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, fntype);
+ ctx->insert_function_decl (fntype, fndecl);
// setup the params
TyTy::BaseType *tyret = fntype->get_return_type ();