From e4ea09d6b8e501dc7bd7046da641b70e02814b09 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Fri, 26 Mar 2021 15:23:57 +0000 Subject: Add Generic Impl block support This extends the support from #237 to extend this to MethodCallExpr, this now follows a similar path to normal CallExprs and ensures the used arguments in substitution are preserved during unification of types. Part of method resolution is fixed here by taking advantage if is_equal instead of unify calls which could result in bad errors which are just part of the probe process to lookup possible candidates for method resolution. Fixes #306 --- gcc/rust/backend/rust-compile-implitem.h | 15 +++++++++++++++ gcc/rust/backend/rust-compile.cc | 19 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'gcc/rust/backend') diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h index 15aba9b..cee3a3b 100644 --- a/gcc/rust/backend/rust-compile-implitem.h +++ b/gcc/rust/backend/rust-compile-implitem.h @@ -272,6 +272,21 @@ public: } TyTy::FnType *fntype = static_cast (fntype_tyty); + if (fntype->has_subsititions_defined ()) + { + // we cant do anything for this only when it is used + if (concrete == nullptr) + return; + else + { + rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF); + fntype = static_cast (concrete); + + // override the Hir Lookups for the substituions in this context + fntype->override_context (); + } + } + // convert to the actual function type ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype); diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 7b1b2ff..a2f5247 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -122,9 +122,17 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) return; } + // lookup the expected function type + TyTy::BaseType *lookup_fntype = nullptr; + bool ok = ctx->get_tyctx ()->lookup_type ( + expr.get_method_name ().get_mappings ().get_hirid (), &lookup_fntype); + rust_assert (ok); + rust_assert (lookup_fntype->get_kind () == TyTy::TypeKind::FNDEF); + TyTy::FnType *fntype = static_cast (lookup_fntype); + // lookup compiled functions Bfunction *fn = nullptr; - if (!ctx->lookup_function_decl (ref, &fn)) + if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &fn)) { // this might fail because its a forward decl so we can attempt to // resolve it now @@ -146,8 +154,13 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) return; } - CompileInherentImplItem::Compile (self_type, resolved_item, ctx, true); - if (!ctx->lookup_function_decl (ref, &fn)) + if (!fntype->has_subsititions_defined ()) + 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)) { rust_error_at (expr.get_locus (), "forward decl was not compiled"); return; -- cgit v1.1