Skip to content

Add boiler plate for TyTy::ClosureType #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gcc/rust/backend/rust-compile-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ class TyTyResolveCompile : public TyTy::TyVisitor
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)
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/backend/rust-compile-tyty.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class TyTyCompile : public TyTy::TyVisitor

void visit (TyTy::DynamicObjectType &) override { gcc_unreachable (); }

void visit (TyTy::ClosureType &) override { gcc_unreachable (); }

private:
TyTyCompile (::Backend *backend)
: backend (backend), translated (nullptr),
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/typecheck/rust-hir-const-fold.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class ConstFoldType : public TyTy::TyVisitor

void visit (TyTy::DynamicObjectType &) override { gcc_unreachable (); }

void visit (TyTy::ClosureType &) override { gcc_unreachable (); }

private:
ConstFoldType (::Backend *backend)
: backend (backend), translated (backend->error_type ())
Expand Down
19 changes: 19 additions & 0 deletions gcc/rust/typecheck/rust-substitution-mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class SubstMapper : public TyTy::TyVisitor
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)
Expand Down Expand Up @@ -217,6 +218,11 @@ class SubstMapperInternal : public TyTy::TyVisitor
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 (); }
Expand Down Expand Up @@ -271,6 +277,14 @@ class SubstMapperFromExisting : public TyTy::TyVisitor
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 (); }
Expand Down Expand Up @@ -323,6 +337,11 @@ class GetUsedSubstArgs : public TyTy::TyVisitor
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 {}
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/typecheck/rust-tyty-call.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TypeCheckCallExpr : private TyVisitor
// 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)
Expand Down Expand Up @@ -116,6 +117,7 @@ class TypeCheckMethodCallExpr : private TyVisitor

// call fns
void visit (FnType &type) override;
void visit (ClosureType &type) override { gcc_unreachable (); }

private:
TypeCheckMethodCallExpr (HIR::MethodCallExpr &c,
Expand Down
39 changes: 39 additions & 0 deletions gcc/rust/typecheck/rust-tyty-cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,17 @@ class BaseCastRules : public TyVisitor
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 ()),
Expand Down Expand Up @@ -590,6 +601,19 @@ class InferCastRules : public BaseCastRules
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; }

Expand Down Expand Up @@ -749,6 +773,21 @@ class FnptrCastRules : public BaseCastRules
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;
Expand Down
43 changes: 43 additions & 0 deletions gcc/rust/typecheck/rust-tyty-cmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ class BaseCmp : public TyConstVisitor
}
}

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 ()),
Expand Down Expand Up @@ -651,6 +667,19 @@ class InferCmp : public BaseCmp
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;
Expand Down Expand Up @@ -792,6 +821,20 @@ class FnptrCmp : public BaseCmp
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;
Expand Down
41 changes: 41 additions & 0 deletions gcc/rust/typecheck/rust-tyty-coercion.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ class BaseCoercionRules : public TyVisitor
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 ()),
Expand Down Expand Up @@ -605,6 +616,19 @@ class InferCoercionRules : public BaseCoercionRules
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; }

Expand Down Expand Up @@ -764,6 +788,23 @@ class FnptrCoercionRules : public BaseCoercionRules
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;
Expand Down
39 changes: 39 additions & 0 deletions gcc/rust/typecheck/rust-tyty-rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ class BaseRules : public TyVisitor
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 ()),
Expand Down Expand Up @@ -625,6 +636,19 @@ class InferRules : public BaseRules
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; }

Expand Down Expand Up @@ -784,6 +808,21 @@ class FnptrRules : public BaseRules
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;
Expand Down
2 changes: 2 additions & 0 deletions gcc/rust/typecheck/rust-tyty-visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class TyVisitor
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
Expand Down Expand Up @@ -76,6 +77,7 @@ class TyConstVisitor
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
Expand Down
Loading