aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-03-09 15:35:18 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-03-09 18:18:35 +0000
commit01898e7cf2746e4dae0bee81ff5adfc1c00ae635 (patch)
tree9e8518e0c4d7f08511b9a0ae448e055a63fa1870 /gcc/rust/backend
parent0b35f5f10dc9d773b6cdaf60a30ce3e76d39bb35 (diff)
downloadgcc-01898e7cf2746e4dae0bee81ff5adfc1c00ae635.zip
gcc-01898e7cf2746e4dae0bee81ff5adfc1c00ae635.tar.gz
gcc-01898e7cf2746e4dae0bee81ff5adfc1c00ae635.tar.bz2
Separate function definitions from function pointers.
Function definitions can have substations (generics) where as function pointers cannot. These are distinct elements and their separation is important to support wildcards (inference variables) on BareFunctionTypes. To fix this the patch leverages the wrapper TyCtx which denotes a type that must be infered. Fixes #269
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-context.h17
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h4
-rw-r--r--gcc/rust/backend/rust-compile-item.h2
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h2
-rw-r--r--gcc/rust/backend/rust-compile.cc4
5 files changed, 25 insertions, 4 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index c2ed0bb..3f4a9ac 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -315,6 +315,23 @@ public:
ctx->get_mappings ()->lookup_location (type.get_ref ()));
}
+ void visit (TyTy::FnPtr &type) override
+ {
+ Btype *result_type
+ = TyTyResolveCompile::compile (ctx, type.get_return_type ());
+
+ std::vector<Btype *> parameters;
+ type.iterate_params ([&] (TyTy::BaseType *p) mutable -> bool {
+ Btype *pty = TyTyResolveCompile::compile (ctx, p);
+ parameters.push_back (pty);
+ return true;
+ });
+
+ translated = ctx->get_backend ()->function_ptr_type (
+ result_type, parameters,
+ ctx->get_mappings ()->lookup_location (type.get_ref ()));
+ }
+
void visit (TyTy::UnitType &) override
{
translated = ctx->get_backend ()->void_type ();
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 76cc608..1b6651a 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -110,7 +110,7 @@ public:
// setup the params
- TyTy::BaseType *tyret = fntype->return_type ();
+ TyTy::BaseType *tyret = fntype->get_return_type ();
std::vector<Bvariable *> param_vars;
size_t i = 0;
@@ -273,7 +273,7 @@ public:
ctx->insert_function_decl (method.get_mappings ().get_hirid (), fndecl);
// setup the params
- TyTy::BaseType *tyret = fntype->return_type ();
+ TyTy::BaseType *tyret = fntype->get_return_type ();
std::vector<Bvariable *> param_vars;
// insert self
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index c6b135b..5279218 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -141,7 +141,7 @@ public:
// setup the params
- TyTy::BaseType *tyret = fntype->return_type ();
+ TyTy::BaseType *tyret = fntype->get_return_type ();
std::vector<Bvariable *> param_vars;
size_t i = 0;
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index e043a50..815ebd5 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -58,6 +58,8 @@ public:
void visit (TyTy::ParamType &) override { gcc_unreachable (); }
+ void visit (TyTy::FnPtr &type) override { gcc_unreachable (); }
+
void visit (TyTy::UnitType &) override { translated = backend->void_type (); }
void visit (TyTy::FnType &type) override
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 2c83527..204cce7 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -62,7 +62,9 @@ CompileExpr::visit (HIR::CallExpr &expr)
}
// must be a tuple constructor
- if (tyty->get_kind () != TyTy::TypeKind::FNDEF)
+ bool is_fn = tyty->get_kind () == TyTy::TypeKind::FNDEF
+ || tyty->get_kind () == TyTy::TypeKind::FNPTR;
+ if (!is_fn)
{
Btype *type = TyTyResolveCompile::compile (ctx, tyty);