diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-10-21 22:17:19 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-10-22 10:40:20 +0100 |
commit | d17b799df72e7d5dc6379b8e46f5188c2981faed (patch) | |
tree | b53b53f544d6e9210a2d044d4f80a7810aecec72 /gcc/rust/backend | |
parent | 649e3e074bf8306bf0eb042f10483dbd61cd040b (diff) | |
download | gcc-d17b799df72e7d5dc6379b8e46f5188c2981faed.zip gcc-d17b799df72e7d5dc6379b8e46f5188c2981faed.tar.gz gcc-d17b799df72e7d5dc6379b8e46f5188c2981faed.tar.bz2 |
Remove second lookup for query compiled functions
When compiling method calls we need to compile functions in a query based
manar sometimes, recently there was a query mode api added to the relevant
functions which will return the address of the function when asked to try
and compile. This patch uses this returned address avoiding a duplicate
lookup for the compiled function
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 23a035f..1a9815b 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -322,12 +322,21 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) return; } - // lookup compiled functions + // address of compiled function + Bexpression *fn_expr = ctx->get_backend ()->error_expression (); + + // lookup compiled functions since it may have already been compiled Bfunction *fn = nullptr; - if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) + if (ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) + { + fn_expr + = ctx->get_backend ()->function_code_expression (fn, expr.get_locus ()); + } + else { - // this might fail because its a forward decl so we can attempt to - // resolve it now + // Now we can try and resolve the address since this might be a forward + // declared function, generic function which has not be compiled yet or + // its an not yet trait bound function HIR::ImplItem *resolved_item = ctx->get_mappings ()->lookup_hir_implitem ( expr.get_mappings ().get_crate_num (), ref, nullptr); if (resolved_item == nullptr) @@ -380,16 +389,9 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) return; } - CompileTraitItem::Compile (self_type, - trait_item_ref->get_hir_trait_item (), - ctx, fntype); - if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) - { - translated = ctx->get_backend ()->error_expression (); - rust_error_at (expr.get_locus (), - "forward declaration was not compiled"); - return; - } + fn_expr = CompileTraitItem::Compile ( + self_type, trait_item_ref->get_hir_trait_item (), ctx, fntype, + true, expr.get_locus ()); } else { @@ -418,20 +420,13 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) } if (!fntype->has_subsititions_defined ()) - CompileInherentImplItem::Compile (self_type, impl_item, ctx, - true); + fn_expr + = CompileInherentImplItem::Compile (self_type, impl_item, ctx, + true); else - CompileInherentImplItem::Compile (self_type, impl_item, ctx, - true, fntype); - - if (!ctx->lookup_function_decl ( - impl_item->get_impl_mappings ().get_hirid (), &fn)) - { - translated = ctx->get_backend ()->error_expression (); - rust_error_at (expr.get_locus (), - "forward declaration was not compiled"); - return; - } + fn_expr + = CompileInherentImplItem::Compile (self_type, impl_item, ctx, + true, fntype); } } else @@ -446,25 +441,16 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) } if (!fntype->has_subsititions_defined ()) - CompileInherentImplItem::Compile (self_type, resolved_item, ctx, - true); + fn_expr + = CompileInherentImplItem::Compile (self_type, resolved_item, ctx, + true); else - CompileInherentImplItem::Compile (self_type, resolved_item, ctx, - true, fntype); - - if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) - { - translated = ctx->get_backend ()->error_expression (); - rust_error_at (expr.get_locus (), - "forward declaration was not compiled"); - return; - } + fn_expr + = CompileInherentImplItem::Compile (self_type, resolved_item, ctx, + true, fntype); } } - Bexpression *fn_expr - = ctx->get_backend ()->function_code_expression (fn, expr.get_locus ()); - std::vector<Bexpression *> args; // lookup the autoderef mappings |