aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-03-26 15:23:57 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-03-27 18:55:14 +0000
commite4ea09d6b8e501dc7bd7046da641b70e02814b09 (patch)
treea01041da77d9276a52d0dbcb08d6a5c3913b03fe /gcc/rust/backend
parent380c8295051c6b42adb4f703268c7465aed57c44 (diff)
downloadgcc-e4ea09d6b8e501dc7bd7046da641b70e02814b09.zip
gcc-e4ea09d6b8e501dc7bd7046da641b70e02814b09.tar.gz
gcc-e4ea09d6b8e501dc7bd7046da641b70e02814b09.tar.bz2
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
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h15
-rw-r--r--gcc/rust/backend/rust-compile.cc19
2 files changed, 31 insertions, 3 deletions
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<TyTy::FnType *> (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<TyTy::FnType *> (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<TyTy::FnType *> (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;