translated = error_mark_node;
}
+void
+TyTyResolveCompile::visit (const TyTy::ConstType &)
+{
+ translated = error_mark_node;
+}
+
void
TyTyResolveCompile::visit (const TyTy::ProjectionType &type)
{
void visit (const TyTy::ReferenceType &) override;
void visit (const TyTy::PointerType &) override;
void visit (const TyTy::ParamType &) override;
+ void visit (const TyTy::ConstType &) override;
void visit (const TyTy::StrType &) override;
void visit (const TyTy::NeverType &) override;
void visit (const TyTy::PlaceholderType &) override;
case TyTy::PLACEHOLDER:
case TyTy::INFER:
case TyTy::PARAM:
+ case TyTy::CONST:
case TyTy::OPAQUE:
rust_unreachable ();
}
case TyTy::PROJECTION: // TODO: DUNNO
case TyTy::CLOSURE: // TODO: DUNNO
case TyTy::DYNAMIC: // TODO: dunno
+ case TyTy::CONST:
case TyTy::OPAQUE:
return false;
}
return;
case TyTy::OPAQUE:
return;
+ case TyTy::CONST:
+ return;
case TyTy::ERROR:
return;
}
resolved = type.handle_substitions (mappings);
}
+void
+SubstMapperInternal::visit (TyTy::ConstType &type)
+{
+ resolved = type.handle_substitions (mappings);
+}
+
void
SubstMapperInternal::visit (TyTy::PlaceholderType &type)
{
void visit (TyTy::ReferenceType &) override { rust_unreachable (); }
void visit (TyTy::PointerType &) override { rust_unreachable (); }
void visit (TyTy::ParamType &) override { rust_unreachable (); }
+ void visit (TyTy::ConstType &) override { rust_unreachable (); }
void visit (TyTy::StrType &) override { rust_unreachable (); }
void visit (TyTy::NeverType &) override { rust_unreachable (); }
void visit (TyTy::DynamicObjectType &) override { rust_unreachable (); }
void visit (TyTy::ReferenceType &type) override;
void visit (TyTy::PointerType &type) override;
void visit (TyTy::ParamType &type) override;
+ void visit (TyTy::ConstType &type) override;
void visit (TyTy::PlaceholderType &type) override;
void visit (TyTy::ProjectionType &type) override;
void visit (TyTy::ClosureType &type) override;
void visit (TyTy::ReferenceType &) override { rust_unreachable (); }
void visit (TyTy::PointerType &) override { rust_unreachable (); }
void visit (TyTy::ParamType &) override { rust_unreachable (); }
+ void visit (TyTy::ConstType &) override { rust_unreachable (); }
void visit (TyTy::StrType &) override { rust_unreachable (); }
void visit (TyTy::NeverType &) override { rust_unreachable (); }
void visit (TyTy::PlaceholderType &) override { rust_unreachable (); }
void visit (const TyTy::ReferenceType &) override {}
void visit (const TyTy::PointerType &) override {}
void visit (const TyTy::ParamType &) override {}
+ void visit (const TyTy::ConstType &) override {}
void visit (const TyTy::StrType &) override {}
void visit (const TyTy::NeverType &) override {}
void visit (const TyTy::PlaceholderType &) override {}
void visit (const TyTy::ProjectionType &) override {}
void visit (const TyTy::DynamicObjectType &) override {}
- void visit (const TyTy::OpaqueType &type) override {}
+ void visit (const TyTy::OpaqueType &) override {}
private:
GetUsedSubstArgs ();
assemble_builtin_candidate (LangItem::Kind::SIZED);
break;
+ case TyTy::CONST:
case TyTy::DYNAMIC:
case TyTy::ERROR:
break;
void visit (DynamicObjectType &) override { rust_unreachable (); }
void visit (ClosureType &type) override { rust_unreachable (); }
void visit (OpaqueType &type) override { rust_unreachable (); }
+ void visit (ConstType &type) override { rust_unreachable (); }
// tuple-structs
void visit (ADTType &type) override;
}
}
+ virtual void visit (const ConstType &type) override
+ {
+ ok = false;
+ if (emit_error_flag)
+ {
+ location_t ref_locus = mappings.lookup_location (type.get_ref ());
+ location_t base_locus
+ = mappings.lookup_location (get_base ()->get_ref ());
+ rich_location r (line_table, 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 ()),
const OpaqueType *base;
};
+class ConstCmp : public BaseCmp
+{
+ using Rust::TyTy::BaseCmp::visit;
+
+public:
+ ConstCmp (const ConstType *base, bool emit_errors)
+ : BaseCmp (base, emit_errors), base (base)
+ {}
+
+ // TODO
+
+private:
+ const BaseType *get_base () const override { return base; }
+
+ const ConstType *base;
+};
+
} // namespace TyTy
} // namespace Rust
}
void visit (OpaqueType &type) override {}
+
+ void visit (ConstType &type) override {}
};
/** Per crate context for generic type variance analysis. */
Variance variance) override;
void add_constraints_from_generic_args (HirId ref, SubstitutionRef &subst,
Variance variance,
- bool invariant_args) override{};
+ bool invariant_args) override {};
void add_constrints_from_param (ParamType ¶m, Variance variance) override;
Variance contra (Variance variance) override
virtual void visit (ReferenceType &type) = 0;
virtual void visit (PointerType &type) = 0;
virtual void visit (ParamType &type) = 0;
+ virtual void visit (ConstType &type) = 0;
virtual void visit (StrType &type) = 0;
virtual void visit (NeverType &type) = 0;
virtual void visit (PlaceholderType &type) = 0;
virtual void visit (const ReferenceType &type) = 0;
virtual void visit (const PointerType &type) = 0;
virtual void visit (const ParamType &type) = 0;
+ virtual void visit (const ConstType &type) = 0;
virtual void visit (const StrType &type) = 0;
virtual void visit (const NeverType &type) = 0;
virtual void visit (const PlaceholderType &type) = 0;
case TypeKind::OPAQUE:
return "Opaque";
+ case TypeKind::CONST:
+ return "Const";
+
case TypeKind::ERROR:
return "ERROR";
}
case OPAQUE:
case STR:
case DYNAMIC:
+ case CONST:
case ERROR:
return false;
case TUPLE:
case PARAM:
case PLACEHOLDER:
+ case CONST:
case OPAQUE:
return false;
case TUPLE:
case PARAM:
case PLACEHOLDER:
+ case CONST:
case OPAQUE:
return false;
return is_trait_self;
}
+// ConstType
+
+ConstType::ConstType (ConstKind kind, std::string symbol, TyTy::BaseType *ty,
+ tree value,
+ std::vector<TypeBoundPredicate> specified_bounds,
+ location_t locus, HirId ref, HirId ty_ref,
+ HIR::GenericParam ¶m, std::set<HirId> refs)
+ : BaseGeneric (ref, ty_ref, KIND,
+ {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol),
+ locus},
+ specified_bounds, refs),
+ const_kind (kind), ty (ty), value (value), symbol (symbol), param (param)
+{}
+
+void
+ConstType::accept_vis (TyVisitor &vis)
+{
+ vis.visit (*this);
+}
+
+void
+ConstType::accept_vis (TyConstVisitor &vis) const
+{
+ vis.visit (*this);
+}
+
+std::string
+ConstType::as_string () const
+{
+ return get_name ();
+}
+
+bool
+ConstType::can_eq (const BaseType *other, bool emit_errors) const
+{
+ ConstCmp r (this, emit_errors);
+ return r.can_eq (other);
+}
+
+BaseType *
+ConstType::clone () const
+{
+ return new ConstType (const_kind, symbol, ty, value, get_specified_bounds (),
+ ident.locus, ref, ty_ref, param, get_combined_refs ());
+}
+
+std::string
+ConstType::get_symbol () const
+{
+ return symbol;
+}
+
+HIR::GenericParam &
+ConstType::get_generic_param ()
+{
+ return param;
+}
+
+bool
+ConstType::can_resolve () const
+{
+ return false;
+}
+
+BaseType *
+ConstType::resolve () const
+{
+ rust_unreachable ();
+ return nullptr;
+}
+
+std::string
+ConstType::get_name () const
+{
+ return "CONST_TYPE";
+}
+
+bool
+ConstType::is_equal (const BaseType &other) const
+{
+ if (get_kind () != other.get_kind ())
+ {
+ return false;
+ }
+
+ // TODO
+
+ return false;
+}
+
+ConstType *
+ConstType::handle_substitions (SubstitutionArgumentMappings &mappings)
+{
+ rust_unreachable ();
+ return nullptr;
+}
+
// OpaqueType
OpaqueType::OpaqueType (location_t locus, HirId ref,
REF,
POINTER,
PARAM,
+ CONST,
ARRAY,
SLICE,
FNDEF,
HIR::GenericParam ¶m;
};
+class ConstType : public BaseGeneric
+{
+public:
+ static constexpr auto KIND = TypeKind::CONST;
+
+ enum ConstKind
+ {
+ Decl,
+ Value,
+ Infer,
+ Error
+ };
+
+ ConstType (ConstKind kind, std::string symbol, TyTy::BaseType *ty, tree value,
+ std::vector<TypeBoundPredicate> specified_bounds, location_t locus,
+ HirId ref, HirId ty_ref, HIR::GenericParam ¶m,
+ std::set<HirId> refs = std::set<HirId> ());
+
+ void accept_vis (TyVisitor &vis) override;
+ void accept_vis (TyConstVisitor &vis) const override;
+
+ ConstKind get_const_kind () const { return const_kind; }
+ TyTy::BaseType *get_ty () const { return ty; }
+ tree get_value () const { return value; }
+
+ std::string as_string () const override;
+
+ bool can_eq (const BaseType *other, bool emit_errors) const override final;
+
+ BaseType *clone () const final override;
+
+ std::string get_symbol () const override final;
+
+ HIR::GenericParam &get_generic_param () override final;
+
+ bool can_resolve () const override final;
+
+ BaseType *resolve () const override final;
+
+ std::string get_name () const override final;
+
+ bool is_equal (const BaseType &other) const override;
+
+ ConstType *handle_substitions (SubstitutionArgumentMappings &mappings);
+
+private:
+ ConstKind const_kind;
+ TyTy::BaseType *ty;
+ tree value;
+ std::string symbol;
+ HIR::GenericParam ¶m;
+};
+
class OpaqueType : public BaseType
{
public:
// <http://www.gnu.org/licenses/>.
#include "rust-unify.h"
+#include "rust-tyty.h"
#include "tree.h"
namespace Rust {
case TyTy::OPAQUE:
return expect_opaque (static_cast<TyTy::OpaqueType *> (ltype), rtype);
+ case TyTy::CONST:
+ return expect_const (static_cast<TyTy::ConstType *> (ltype), rtype);
+
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::PROJECTION:
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
+ case TyTy::CONST:
case TyTy::OPAQUE:
{
bool is_valid = (ltype->get_infer_kind ()
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::PROJECTION:
case TyTy::DYNAMIC:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::DYNAMIC:
case TyTy::CLOSURE:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
return rtype->clone ();
gcc_fallthrough ();
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::NEVER:
case TyTy::PLACEHOLDER:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::PLACEHOLDER:
case TyTy::PROJECTION:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
case TyTy::PROJECTION:
case TyTy::DYNAMIC:
case TyTy::OPAQUE:
+ case TyTy::CONST:
case TyTy::ERROR:
return new TyTy::ErrorType (0);
}
return ltype;
}
+TyTy::BaseType *
+UnifyRules::expect_const (TyTy::ConstType *ltype, TyTy::BaseType *rtype)
+{
+ if (rtype->get_kind () != TyTy::TypeKind::CONST)
+ return new TyTy::ErrorType (0);
+
+ // TODO
+ // TyTy::ConstType &lhs = *ltype;
+ // TyTy::ConstType &rhs = *static_cast<TyTy::ConstType *> (rtype);
+
+ return new TyTy::ErrorType (0);
+}
+
} // namespace Resolver
} // namespace Rust
TyTy::BaseType *rtype);
TyTy::BaseType *expect_opaque (TyTy::OpaqueType *ltype,
TyTy::BaseType *rtype);
+ TyTy::BaseType *expect_const (TyTy::ConstType *ltype, TyTy::BaseType *rtype);
private:
UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,