aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
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.h19
-rw-r--r--gcc/rust/typecheck/rust-tyty-call.h2
-rw-r--r--gcc/rust/typecheck/rust-tyty-cast.h39
-rw-r--r--gcc/rust/typecheck/rust-tyty-cmp.h43
-rw-r--r--gcc/rust/typecheck/rust-tyty-coercion.h41
-rw-r--r--gcc/rust/typecheck/rust-tyty-rules.h39
-rw-r--r--gcc/rust/typecheck/rust-tyty-visitor.h2
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc67
-rw-r--r--gcc/rust/typecheck/rust-tyty.h71
12 files changed, 329 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 7a4344e..0da2198 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -661,6 +661,8 @@ public:
ctx->insert_compiled_type (type.get_ty_ref (), named_struct, &type);
}
+ void visit (TyTy::ClosureType &type) override { gcc_unreachable (); }
+
private:
TyTyResolveCompile (Context *ctx, bool trait_object_mode)
: ctx (ctx), trait_object_mode (trait_object_mode), translated (nullptr)
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index 40b297c..c544a45 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -239,6 +239,8 @@ public:
void visit (TyTy::DynamicObjectType &) override { gcc_unreachable (); }
+ void visit (TyTy::ClosureType &) override { gcc_unreachable (); }
+
private:
TyTyCompile (::Backend *backend)
: backend (backend), translated (nullptr),
diff --git a/gcc/rust/typecheck/rust-hir-const-fold.h b/gcc/rust/typecheck/rust-hir-const-fold.h
index 1466434..d8fbd8d 100644
--- a/gcc/rust/typecheck/rust-hir-const-fold.h
+++ b/gcc/rust/typecheck/rust-hir-const-fold.h
@@ -193,6 +193,8 @@ public:
void visit (TyTy::DynamicObjectType &) override { gcc_unreachable (); }
+ void visit (TyTy::ClosureType &) override { gcc_unreachable (); }
+
private:
ConstFoldType (::Backend *backend)
: backend (backend), translated (backend->error_type ())
diff --git a/gcc/rust/typecheck/rust-substitution-mapper.h b/gcc/rust/typecheck/rust-substitution-mapper.h
index 13496ff..a6e7e80 100644
--- a/gcc/rust/typecheck/rust-substitution-mapper.h
+++ b/gcc/rust/typecheck/rust-substitution-mapper.h
@@ -138,6 +138,7 @@ public:
void visit (TyTy::StrType &) override { gcc_unreachable (); }
void visit (TyTy::NeverType &) override { gcc_unreachable (); }
void visit (TyTy::DynamicObjectType &) override { gcc_unreachable (); }
+ void visit (TyTy::ClosureType &) override { gcc_unreachable (); }
private:
SubstMapper (HirId ref, HIR::GenericArgs *generics, Location locus)
@@ -217,6 +218,11 @@ public:
resolved = type.handle_substitions (mappings);
}
+ void visit (TyTy::ClosureType &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 (); }
@@ -271,6 +277,14 @@ public:
resolved = to_sub->handle_substitions (type.get_substitution_arguments ());
}
+ void visit (TyTy::ClosureType &type) override
+ {
+ rust_assert (type.was_substituted ());
+
+ TyTy::ClosureType *to_sub = static_cast<TyTy::ClosureType *> (receiver);
+ resolved = to_sub->handle_substitions (type.get_substitution_arguments ());
+ }
+
void visit (TyTy::InferType &) override { gcc_unreachable (); }
void visit (TyTy::TupleType &) override { gcc_unreachable (); }
void visit (TyTy::FnPtr &) override { gcc_unreachable (); }
@@ -323,6 +337,11 @@ public:
args = type.get_substitution_arguments ();
}
+ void visit (TyTy::ClosureType &type) override
+ {
+ args = type.get_substitution_arguments ();
+ }
+
void visit (TyTy::InferType &) override {}
void visit (TyTy::TupleType &) override {}
void visit (TyTy::FnPtr &) override {}
diff --git a/gcc/rust/typecheck/rust-tyty-call.h b/gcc/rust/typecheck/rust-tyty-call.h
index 906110a..2eeebd0 100644
--- a/gcc/rust/typecheck/rust-tyty-call.h
+++ b/gcc/rust/typecheck/rust-tyty-call.h
@@ -65,6 +65,7 @@ public:
// call fns
void visit (FnType &type) override;
void visit (FnPtr &type) override;
+ void visit (ClosureType &type) override { gcc_unreachable (); }
private:
TypeCheckCallExpr (HIR::CallExpr &c, Resolver::TypeCheckContext *context)
@@ -116,6 +117,7 @@ public:
// call fns
void visit (FnType &type) override;
+ void visit (ClosureType &type) override { gcc_unreachable (); }
private:
TypeCheckMethodCallExpr (HIR::MethodCallExpr &c,
diff --git a/gcc/rust/typecheck/rust-tyty-cast.h b/gcc/rust/typecheck/rust-tyty-cast.h
index fa50992..8165bbd 100644
--- a/gcc/rust/typecheck/rust-tyty-cast.h
+++ b/gcc/rust/typecheck/rust-tyty-cast.h
@@ -329,6 +329,17 @@ public:
type.as_string ().c_str ());
}
+ virtual void visit (ClosureType &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 ()),
@@ -590,6 +601,19 @@ public:
BaseCastRules::visit (type);
}
+ void visit (ClosureType &type) override
+ {
+ bool is_valid
+ = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
+ if (is_valid)
+ {
+ resolved = type.clone ();
+ return;
+ }
+
+ BaseCastRules::visit (type);
+ }
+
private:
BaseType *get_base () override { return base; }
@@ -749,6 +773,21 @@ private:
FnPtr *base;
};
+class ClosureCastRules : public BaseCastRules
+{
+ using Rust::TyTy::BaseCastRules::visit;
+
+public:
+ ClosureCastRules (ClosureType *base) : BaseCastRules (base), base (base) {}
+
+ // TODO
+
+private:
+ BaseType *get_base () override { return base; }
+
+ ClosureType *base;
+};
+
class ArrayCastRules : public BaseCastRules
{
using Rust::TyTy::BaseCastRules::visit;
diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h
index 030f702..519501f 100644
--- a/gcc/rust/typecheck/rust-tyty-cmp.h
+++ b/gcc/rust/typecheck/rust-tyty-cmp.h
@@ -391,6 +391,22 @@ public:
}
}
+ virtual void visit (const ClosureType &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 ());
+ }
+ }
+
protected:
BaseCmp (const BaseType *base, bool emit_errors)
: mappings (Analysis::Mappings::get ()),
@@ -651,6 +667,19 @@ public:
BaseCmp::visit (type);
}
+ void visit (const ClosureType &type) override
+ {
+ bool is_valid
+ = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
+ if (is_valid)
+ {
+ ok = true;
+ return;
+ }
+
+ BaseCmp::visit (type);
+ }
+
private:
const BaseType *get_base () const override { return base; }
const InferType *base;
@@ -792,6 +821,20 @@ private:
const FnPtr *base;
};
+class ClosureCmp : public BaseCmp
+{
+ using Rust::TyTy::BaseCmp::visit;
+
+public:
+ ClosureCmp (const ClosureType *base, bool emit_errors)
+ : BaseCmp (base, emit_errors), base (base)
+ {}
+
+private:
+ const BaseType *get_base () const override { return base; }
+ const ClosureType *base;
+};
+
class ArrayCmp : public BaseCmp
{
using Rust::TyTy::BaseCmp::visit;
diff --git a/gcc/rust/typecheck/rust-tyty-coercion.h b/gcc/rust/typecheck/rust-tyty-coercion.h
index 8853687..f4592f4 100644
--- a/gcc/rust/typecheck/rust-tyty-coercion.h
+++ b/gcc/rust/typecheck/rust-tyty-coercion.h
@@ -343,6 +343,17 @@ public:
type.as_string ().c_str ());
}
+ virtual void visit (ClosureType &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 ()),
@@ -605,6 +616,19 @@ public:
BaseCoercionRules::visit (type);
}
+ void visit (ClosureType &type) override
+ {
+ bool is_valid
+ = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
+ if (is_valid)
+ {
+ resolved = type.clone ();
+ return;
+ }
+
+ BaseCoercionRules::visit (type);
+ }
+
private:
BaseType *get_base () override { return base; }
@@ -764,6 +788,23 @@ private:
FnPtr *base;
};
+class ClosureCoercionRules : public BaseCoercionRules
+{
+ using Rust::TyTy::BaseCoercionRules::visit;
+
+public:
+ ClosureCoercionRules (ClosureType *base)
+ : BaseCoercionRules (base), base (base)
+ {}
+
+ // TODO
+
+private:
+ BaseType *get_base () override { return base; }
+
+ ClosureType *base;
+};
+
class ArrayCoercionRules : public BaseCoercionRules
{
using Rust::TyTy::BaseCoercionRules::visit;
diff --git a/gcc/rust/typecheck/rust-tyty-rules.h b/gcc/rust/typecheck/rust-tyty-rules.h
index b235ff0..67ab7d4 100644
--- a/gcc/rust/typecheck/rust-tyty-rules.h
+++ b/gcc/rust/typecheck/rust-tyty-rules.h
@@ -364,6 +364,17 @@ public:
type.as_string ().c_str ());
}
+ virtual void visit (ClosureType &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 ()),
@@ -625,6 +636,19 @@ public:
BaseRules::visit (type);
}
+ void visit (ClosureType &type) override
+ {
+ bool is_valid
+ = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
+ if (is_valid)
+ {
+ resolved = type.clone ();
+ return;
+ }
+
+ BaseRules::visit (type);
+ }
+
private:
BaseType *get_base () override { return base; }
@@ -784,6 +808,21 @@ private:
FnPtr *base;
};
+class ClosureRules : public BaseRules
+{
+ using Rust::TyTy::BaseRules::visit;
+
+public:
+ ClosureRules (ClosureType *base) : BaseRules (base), base (base) {}
+
+ // TODO
+
+private:
+ BaseType *get_base () override { return base; }
+
+ ClosureType *base;
+};
+
class ArrayRules : public BaseRules
{
using Rust::TyTy::BaseRules::visit;
diff --git a/gcc/rust/typecheck/rust-tyty-visitor.h b/gcc/rust/typecheck/rust-tyty-visitor.h
index a51edf4..fb91f2d 100644
--- a/gcc/rust/typecheck/rust-tyty-visitor.h
+++ b/gcc/rust/typecheck/rust-tyty-visitor.h
@@ -49,6 +49,7 @@ public:
virtual void visit (PlaceholderType &type) = 0;
virtual void visit (ProjectionType &type) = 0;
virtual void visit (DynamicObjectType &type) = 0;
+ virtual void visit (ClosureType &type) = 0;
};
class TyConstVisitor
@@ -76,6 +77,7 @@ public:
virtual void visit (const PlaceholderType &type) = 0;
virtual void visit (const ProjectionType &type) = 0;
virtual void visit (const DynamicObjectType &type) = 0;
+ virtual void visit (const ClosureType &type) = 0;
};
} // namespace TyTy
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 3f0d8a3..f08d8cb 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1112,6 +1112,73 @@ FnPtr::clone () const
}
void
+ClosureType::accept_vis (TyVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+ClosureType::accept_vis (TyConstVisitor &vis) const
+{
+ vis.visit (*this);
+}
+
+std::string
+ClosureType::as_string () const
+{
+ return "TODO";
+}
+
+BaseType *
+ClosureType::unify (BaseType *other)
+{
+ ClosureRules r (this);
+ return r.unify (other);
+}
+
+bool
+ClosureType::can_eq (const BaseType *other, bool emit_errors) const
+{
+ ClosureCmp r (this, emit_errors);
+ return r.can_eq (other);
+}
+
+BaseType *
+ClosureType::coerce (BaseType *other)
+{
+ ClosureCoercionRules r (this);
+ return r.coerce (other);
+}
+
+BaseType *
+ClosureType::cast (BaseType *other)
+{
+ ClosureCoercionRules r (this);
+ return r.coerce (other);
+}
+
+bool
+ClosureType::is_equal (const BaseType &other) const
+{
+ gcc_unreachable ();
+ return false;
+}
+
+BaseType *
+ClosureType::clone () const
+{
+ return new ClosureType (get_ref (), get_ty_ref (), id, parameter_types,
+ result_type, clone_substs (), get_combined_refs ());
+}
+
+ClosureType *
+ClosureType::handle_substitions (SubstitutionArgumentMappings mappings)
+{
+ gcc_unreachable ();
+ return nullptr;
+}
+
+void
ArrayType::accept_vis (TyVisitor &vis)
{
vis.visit (*this);
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index 2d3c1dc..8ab120e 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -61,6 +61,7 @@ enum TypeKind
PLACEHOLDER,
PROJECTION,
DYNAMIC,
+ CLOSURE,
// there are more to add...
ERROR
};
@@ -135,6 +136,9 @@ public:
case TypeKind::DYNAMIC:
return "Dynamic";
+ case TypeKind::CLOSURE:
+ return "Closure";
+
case TypeKind::ERROR:
return "ERROR";
}
@@ -1273,6 +1277,73 @@ private:
TyVar result_type;
};
+class ClosureType : public BaseType, public SubstitutionRef
+{
+public:
+ ClosureType (HirId ref, DefId id, std::vector<TyVar> parameter_types,
+ TyVar result_type,
+ std::vector<SubstitutionParamMapping> subst_refs,
+ std::set<HirId> refs = std::set<HirId> ())
+ : BaseType (ref, ref, TypeKind::CLOSURE, refs),
+ SubstitutionRef (std::move (subst_refs),
+ SubstitutionArgumentMappings::error ()),
+ parameter_types (std::move (parameter_types)),
+ result_type (std::move (result_type)), id (id)
+ {
+ LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
+ }
+
+ ClosureType (HirId ref, HirId ty_ref, DefId id,
+ std::vector<TyVar> parameter_types, TyVar result_type,
+ std::vector<SubstitutionParamMapping> subst_refs,
+ std::set<HirId> refs = std::set<HirId> ())
+ : BaseType (ref, ty_ref, TypeKind::CLOSURE, refs),
+ SubstitutionRef (std::move (subst_refs),
+ SubstitutionArgumentMappings::error ()),
+ parameter_types (std::move (parameter_types)),
+ result_type (std::move (result_type)), id (id)
+ {
+ LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
+ }
+
+ void accept_vis (TyVisitor &vis) override;
+ void accept_vis (TyConstVisitor &vis) const override;
+
+ std::string as_string () const override;
+ std::string get_name () const override final { return as_string (); }
+
+ 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;
+
+ bool is_equal (const BaseType &other) const override;
+
+ BaseType *clone () const final override;
+
+ bool needs_generic_substitutions () const override final
+ {
+ return needs_substitution ();
+ }
+
+ bool supports_substitutions () const override final { return true; }
+
+ bool has_subsititions_defined () const override final
+ {
+ return has_substitutions ();
+ }
+
+ ClosureType *
+ handle_substitions (SubstitutionArgumentMappings mappings) override final;
+
+private:
+ std::vector<TyVar> parameter_types;
+ TyVar result_type;
+ DefId id;
+};
+
class ArrayType : public BaseType
{
public: