aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-03-10 16:17:52 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-03-10 16:51:03 +0000
commit894e9d29adadc13e9841f43df32a07939480846d (patch)
tree79d5a16c370b33a5082597aa160766bff658b8ee /gcc
parenta620a228c1d79d4725efd5d6ed5f0ebe398e6787 (diff)
downloadgcc-894e9d29adadc13e9841f43df32a07939480846d.zip
gcc-894e9d29adadc13e9841f43df32a07939480846d.tar.gz
gcc-894e9d29adadc13e9841f43df32a07939480846d.tar.bz2
Handle generic Slices and Arrays
Slices and Arrays are covariant types which means they can contain elements which bind generics such as ADT or FnTypes. This means substitutions can be recursive and this gives the typechecker a chance to handle this recursion on these types.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-substitution-mapper.h12
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc32
-rw-r--r--gcc/rust/typecheck/rust-tyty.h4
3 files changed, 46 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h
index 0d48bd2..5f17816 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -221,11 +221,19 @@ public:
resolved = type.handle_substitions (mappings);
}
+ void visit (TyTy::ArrayType &type) override
+ {
+ resolved = type.handle_substitions (mappings);
+ }
+
+ void visit (TyTy::SliceType &type) override
+ {
+ resolved = type.handle_substitions (mappings);
+ }
+
// nothing to do for these
void visit (TyTy::InferType &) override { gcc_unreachable (); }
void visit (TyTy::FnPtr &) override { gcc_unreachable (); }
- void visit (TyTy::ArrayType &) override { gcc_unreachable (); }
- void visit (TyTy::SliceType &) override { gcc_unreachable (); }
void visit (TyTy::BoolType &) override { gcc_unreachable (); }
void visit (TyTy::IntType &) override { gcc_unreachable (); }
void visit (TyTy::UintType &) override { gcc_unreachable (); }
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 0a29644..8d5cc5e 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1508,6 +1508,22 @@ ArrayType::clone () const
element_type, get_combined_refs ());
}
+ArrayType *
+ArrayType::handle_substitions (SubstitutionArgumentMappings mappings)
+{
+ auto mappings_table = Analysis::Mappings::get ();
+
+ ArrayType *ref = static_cast<ArrayType *> (clone ());
+ ref->set_ty_ref (mappings_table->get_next_hir_id ());
+
+ // might be &T or &ADT so this needs to be recursive
+ auto base = ref->get_element_type ();
+ BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
+ ref->element_type = TyVar (concrete->get_ty_ref ());
+
+ return ref;
+}
+
void
SliceType::accept_vis (TyVisitor &vis)
{
@@ -1581,6 +1597,22 @@ SliceType::clone () const
get_combined_refs ());
}
+SliceType *
+SliceType::handle_substitions (SubstitutionArgumentMappings mappings)
+{
+ auto mappings_table = Analysis::Mappings::get ();
+
+ SliceType *ref = static_cast<SliceType *> (clone ());
+ ref->set_ty_ref (mappings_table->get_next_hir_id ());
+
+ // might be &T or &ADT so this needs to be recursive
+ auto base = ref->get_element_type ();
+ BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
+ ref->element_type = TyVar (concrete->get_ty_ref ());
+
+ return ref;
+}
+
void
BoolType::accept_vis (TyVisitor &vis)
{
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index bf4110b..82262ab 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1665,6 +1665,8 @@ public:
HIR::Expr &get_capacity_expr () const { return capacity_expr; }
+ ArrayType *handle_substitions (SubstitutionArgumentMappings mappings);
+
private:
TyVar element_type;
HIR::Expr &capacity_expr;
@@ -1710,6 +1712,8 @@ public:
return get_element_type ()->is_concrete ();
}
+ SliceType *handle_substitions (SubstitutionArgumentMappings mappings);
+
private:
TyVar element_type;
};