aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-14 21:38:35 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-19 15:36:37 +0100
commitfe9dd83b41346fa667c693e5dd10dc9fe80e93b3 (patch)
tree713b4c1681cc29a49ad43935b597d05629fc6e40 /gcc
parent1e74f08c141eca935005d45840f2b77acbf63531 (diff)
downloadgcc-fe9dd83b41346fa667c693e5dd10dc9fe80e93b3.zip
gcc-fe9dd83b41346fa667c693e5dd10dc9fe80e93b3.tar.gz
gcc-fe9dd83b41346fa667c693e5dd10dc9fe80e93b3.tar.bz2
ProjectionType this is a special TyTy initial boiler plate
This is a special type in the rust implementation which contains all the info to generate the relevant declarations to compile trait items which might be fully optional.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-context.h2
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h2
-rw-r--r--gcc/rust/typecheck/rust-hir-const-fold.h2
-rw-r--r--gcc/rust/typecheck/rust-substitution-mapper.h4
-rw-r--r--gcc/rust/typecheck/rust-tyty-call.h2
-rw-r--r--gcc/rust/typecheck/rust-tyty-cast.h11
-rw-r--r--gcc/rust/typecheck/rust-tyty-cmp.h16
-rw-r--r--gcc/rust/typecheck/rust-tyty-coercion.h11
-rw-r--r--gcc/rust/typecheck/rust-tyty-rules.h11
-rw-r--r--gcc/rust/typecheck/rust-tyty-visitor.h2
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc57
-rw-r--r--gcc/rust/typecheck/rust-tyty.h42
12 files changed, 162 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 8007c2f..8a3d413 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -338,6 +338,8 @@ public:
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
+
void visit (TyTy::ParamType &param) override
{
param.resolve ()->accept_vis (*this);
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index 3ddc29a..1a5747a 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -50,6 +50,8 @@ public:
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
+
void visit (TyTy::TupleType &type) override
{
if (type.num_fields () == 0)
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h
index 8efbb18..9e0450e 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold.h
@@ -55,6 +55,8 @@ public:
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
+
void visit (TyTy::TupleType &type) override
{
if (type.num_fields () == 0)
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h
index a3c00da..c7ea029 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -108,6 +108,7 @@ public:
void visit (TyTy::StrType &) override { gcc_unreachable (); }
void visit (TyTy::NeverType &) override { gcc_unreachable (); }
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
private:
SubstMapper (HirId ref, HIR::GenericArgs *generics, Location locus)
@@ -191,6 +192,7 @@ public:
void visit (TyTy::StrType &) override { gcc_unreachable (); }
void visit (TyTy::NeverType &) override { gcc_unreachable (); }
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
private:
SubstMapperInternal (HirId ref, TyTy::SubstitutionArgumentMappings &mappings)
@@ -248,6 +250,7 @@ public:
void visit (TyTy::StrType &) override { gcc_unreachable (); }
void visit (TyTy::NeverType &) override { gcc_unreachable (); }
void visit (TyTy::PlaceholderType &) override { gcc_unreachable (); }
+ void visit (TyTy::ProjectionType &) override { gcc_unreachable (); }
private:
SubstMapperFromExisting (TyTy::BaseType *concrete, TyTy::BaseType *receiver)
@@ -298,6 +301,7 @@ public:
void visit (TyTy::StrType &) override {}
void visit (TyTy::NeverType &) override {}
void visit (TyTy::PlaceholderType &) override {}
+ void visit (TyTy::ProjectionType &) override {}
private:
GetUsedSubstArgs () : args (TyTy::SubstitutionArgumentMappings::error ()) {}
diff --git a/gcc/rust/typecheck/rust-tyty-call.h b/gcc/rust/typecheck/rust-tyty-call.h
index 636d40b..4e74e59 100644
--- a/gcc/rust/typecheck/rust-tyty-call.h
+++ b/gcc/rust/typecheck/rust-tyty-call.h
@@ -56,6 +56,7 @@ public:
void visit (StrType &) override { gcc_unreachable (); }
void visit (NeverType &) override { gcc_unreachable (); }
void visit (PlaceholderType &) override { gcc_unreachable (); }
+ void visit (ProjectionType &) override { gcc_unreachable (); }
// tuple-structs
void visit (ADTType &type) override;
@@ -106,6 +107,7 @@ public:
void visit (StrType &) override { gcc_unreachable (); }
void visit (NeverType &) override { gcc_unreachable (); }
void visit (PlaceholderType &) override { gcc_unreachable (); }
+ void visit (ProjectionType &) override { gcc_unreachable (); }
// FIXME
void visit (FnPtr &type) override { gcc_unreachable (); }
diff --git a/gcc/rust/typecheck/rust-tyty-cast.h b/gcc/rust/typecheck/rust-tyty-cast.h
index c457931..51c9791 100644
--- a/gcc/rust/typecheck/rust-tyty-cast.h
+++ b/gcc/rust/typecheck/rust-tyty-cast.h
@@ -307,6 +307,17 @@ public:
type.as_string ().c_str ());
}
+ virtual void visit (ProjectionType &type) override
+ {
+ Location ref_locus = mappings->lookup_location (type.get_ref ());
+ Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
+ RichLocation r (ref_locus);
+ r.add_range (base_locus);
+ rust_error_at (r, "invalid cast [%s] to [%s]",
+ get_base ()->as_string ().c_str (),
+ type.as_string ().c_str ());
+ }
+
protected:
BaseCastRules (BaseType *base)
: mappings (Analysis::Mappings::get ()),
diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h
index 049a4b7..6801084 100644
--- a/gcc/rust/typecheck/rust-tyty-cmp.h
+++ b/gcc/rust/typecheck/rust-tyty-cmp.h
@@ -337,6 +337,22 @@ public:
}
}
+ virtual void visit (const ProjectionType &type) override
+ {
+ ok = false;
+ if (emit_error_flag)
+ {
+ Location ref_locus = mappings->lookup_location (type.get_ref ());
+ Location base_locus
+ = mappings->lookup_location (get_base ()->get_ref ());
+ RichLocation r (ref_locus);
+ r.add_range (base_locus);
+ rust_error_at (r, "expected [%s] got [%s]",
+ get_base ()->as_string ().c_str (),
+ type.as_string ().c_str ());
+ }
+ }
+
virtual void visit (const PlaceholderType &type) override
{
// it is ok for types to can eq to a placeholder
diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h
index f19871e..d30be7f 100644
--- a/gcc/rust/typecheck/rust-tyty-coercion.h
+++ b/gcc/rust/typecheck/rust-tyty-coercion.h
@@ -307,6 +307,17 @@ public:
type.as_string ().c_str ());
}
+ virtual void visit (ProjectionType &type) override
+ {
+ Location ref_locus = mappings->lookup_location (type.get_ref ());
+ Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
+ RichLocation r (ref_locus);
+ r.add_range (base_locus);
+ rust_error_at (r, "expected [%s] got [%s]",
+ get_base ()->as_string ().c_str (),
+ type.as_string ().c_str ());
+ }
+
protected:
BaseCoercionRules (BaseType *base)
: mappings (Analysis::Mappings::get ()),
diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h
index de9a5d9..ca4849b 100644
--- a/gcc/rust/typecheck/rust-tyty-rules.h
+++ b/gcc/rust/typecheck/rust-tyty-rules.h
@@ -329,6 +329,17 @@ public:
type.as_string ().c_str ());
}
+ virtual void visit (ProjectionType &type) override
+ {
+ Location ref_locus = mappings->lookup_location (type.get_ref ());
+ Location base_locus = mappings->lookup_location (get_base ()->get_ref ());
+ RichLocation r (ref_locus);
+ r.add_range (base_locus);
+ rust_error_at (r, "expected [%s] got [%s]",
+ get_base ()->as_string ().c_str (),
+ type.as_string ().c_str ());
+ }
+
protected:
BaseRules (BaseType *base)
: mappings (Analysis::Mappings::get ()),
diff --git a/gcc/rust/typecheck/rust-tyty-visitor.h b/gcc/rust/typecheck/rust-tyty-visitor.h
index 66b11b9..0e9a58b 100644
--- a/gcc/rust/typecheck/rust-tyty-visitor.h
+++ b/gcc/rust/typecheck/rust-tyty-visitor.h
@@ -47,6 +47,7 @@ public:
virtual void visit (StrType &type) = 0;
virtual void visit (NeverType &type) = 0;
virtual void visit (PlaceholderType &type) = 0;
+ virtual void visit (ProjectionType &type) = 0;
};
class TyConstVisitor
@@ -72,6 +73,7 @@ public:
virtual void visit (const StrType &type) = 0;
virtual void visit (const NeverType &type) = 0;
virtual void visit (const PlaceholderType &type) = 0;
+ virtual void visit (const ProjectionType &type) = 0;
};
} // namespace TyTy
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 2d165c3..ca4b3b8 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2015,6 +2015,8 @@ NeverType::clone () const
return new NeverType (get_ref (), get_ty_ref (), get_combined_refs ());
}
+// placeholder type
+
void
PlaceholderType::accept_vis (TyVisitor &vis)
{
@@ -2067,6 +2069,61 @@ PlaceholderType::clone () const
return new PlaceholderType (get_ref (), get_ty_ref (), get_combined_refs ());
}
+// Projection type
+
+void
+ProjectionType::accept_vis (TyVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+ProjectionType::accept_vis (TyConstVisitor &vis) const
+{
+ vis.visit (*this);
+}
+
+std::string
+ProjectionType::as_string () const
+{
+ return "<Projection>";
+}
+
+BaseType *
+ProjectionType::unify (BaseType *other)
+{
+ gcc_unreachable ();
+ return nullptr;
+}
+
+BaseType *
+ProjectionType::coerce (BaseType *other)
+{
+ gcc_unreachable ();
+ return nullptr;
+}
+
+BaseType *
+ProjectionType::cast (BaseType *other)
+{
+ gcc_unreachable ();
+ return nullptr;
+}
+
+bool
+ProjectionType::can_eq (const BaseType *other, bool emit_errors) const
+{
+ gcc_unreachable ();
+ return false;
+}
+
+BaseType *
+ProjectionType::clone () const
+{
+ return new ProjectionType (get_ref (), get_ty_ref (), base, trait, item,
+ get_combined_refs ());
+}
+
// rust-tyty-call.h
void
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index c1afa14..f01d6f8 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -54,6 +54,7 @@ enum TypeKind
ISIZE,
NEVER,
PLACEHOLDER,
+ PROJECTION,
// there are more to add...
ERROR
};
@@ -122,6 +123,9 @@ public:
case TypeKind::PLACEHOLDER:
return "Placeholder";
+ case TypeKind::PROJECTION:
+ return "Projection";
+
case TypeKind::ERROR:
return "ERROR";
}
@@ -1705,6 +1709,44 @@ public:
bool is_unit () const override { return true; }
};
+class ProjectionType : public BaseType
+{
+public:
+ ProjectionType (HirId ref, TyVar base, Resolver::TraitReference *trait,
+ DefId item, std::set<HirId> refs = std::set<HirId> ())
+ : BaseType (ref, ref, TypeKind::PROJECTION, refs), base (base),
+ trait (trait), item (item)
+ {}
+
+ ProjectionType (HirId ref, HirId ty_ref, TyVar base,
+ Resolver::TraitReference *trait, DefId item,
+ std::set<HirId> refs = std::set<HirId> ())
+ : BaseType (ref, ty_ref, TypeKind::PROJECTION, refs), base (base),
+ trait (trait), item (item)
+ {}
+
+ void accept_vis (TyVisitor &vis) override;
+ void accept_vis (TyConstVisitor &vis) const override;
+
+ std::string as_string () const override;
+
+ BaseType *unify (BaseType *other) override;
+ bool can_eq (const BaseType *other, bool emit_errors) const override final;
+ BaseType *coerce (BaseType *other) override;
+ BaseType *cast (BaseType *other) override;
+
+ BaseType *clone () const final override;
+
+ std::string get_name () const override final { return as_string (); }
+
+ bool is_unit () const override { return false; }
+
+private:
+ TyVar base;
+ Resolver::TraitReference *trait;
+ DefId item;
+};
+
} // namespace TyTy
} // namespace Rust