diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-04-28 12:46:21 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-04-28 12:49:41 +0100 |
commit | e547f7da588f596bf26923b12ba873878e05d51c (patch) | |
tree | e8e59b34c0c4bba0c932b172b6adc76d557f3b6b /gcc/rust | |
parent | ff1676e277af52b6aa19e45494d91a810a1c2070 (diff) | |
download | gcc-e547f7da588f596bf26923b12ba873878e05d51c.zip gcc-e547f7da588f596bf26923b12ba873878e05d51c.tar.gz gcc-e547f7da588f596bf26923b12ba873878e05d51c.tar.bz2 |
Tuples can contain TypeParameters
TypeParameters can be behind held within Tuples which need substitution but
these types cannot hold substitution mappings.
Fixes #396
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/typecheck/rust-substitution-mapper.h | 5 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 23 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.h | 12 |
3 files changed, 39 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h index 23105d6..739f1b5 100644 --- a/gcc/rust/typecheck/rust-substitution-mapper.h +++ b/gcc/rust/typecheck/rust-substitution-mapper.h @@ -154,7 +154,10 @@ public: } // these don't support generic arguments but might contain a type param - void visit (TyTy::TupleType &) override { gcc_unreachable (); } + void visit (TyTy::TupleType &type) override + { + resolved = type.handle_substitions (mappings); + } void visit (TyTy::ReferenceType &type) override { diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index cc6c2f8..b75c139 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -540,6 +540,29 @@ TupleType::clone () get_combined_refs ()); } +TupleType * +TupleType::handle_substitions (SubstitutionArgumentMappings mappings) +{ + auto mappings_table = Analysis::Mappings::get (); + + TupleType *tuple = static_cast<TupleType *> (clone ()); + tuple->set_ty_ref (mappings_table->get_next_hir_id ()); + + for (size_t i = 0; i < tuple->fields.size (); i++) + { + TyVar &field = fields.at (i); + if (field.get_tyty ()->contains_type_parameters ()) + { + BaseType *concrete + = Resolver::SubstMapperInternal::Resolve (field.get_tyty (), + mappings); + tuple->fields[i] = TyVar (concrete->get_ty_ref ()); + } + } + + return tuple; +} + void FnType::accept_vis (TyVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 0c8168d..bcc694b 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -379,6 +379,18 @@ public: std::string get_name () const override final { return as_string (); } + bool contains_type_parameters () const override final + { + for (auto &f : fields) + { + if (f.get_tyty ()->contains_type_parameters ()) + return true; + } + return false; + } + + TupleType *handle_substitions (SubstitutionArgumentMappings mappings); + private: std::vector<TyVar> fields; }; |