aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Dupak <dev@jakubdupak.com>2024-02-02 14:12:13 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-08-01 13:12:16 +0200
commita7b1a89da13b70fa81e12a4dc873c96ce38e1327 (patch)
tree740fdab5727106648311520203db3a349ec04442
parentd8cd08d30e0d9bfa02f29493352bac041659df7f (diff)
downloadgcc-a7b1a89da13b70fa81e12a4dc873c96ce38e1327.zip
gcc-a7b1a89da13b70fa81e12a4dc873c96ce38e1327.tar.gz
gcc-a7b1a89da13b70fa81e12a4dc873c96ce38e1327.tar.bz2
gccrs: TyTy: Collect variance info from types
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Collect variance info from types. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-item.cc17
1 files changed, 13 insertions, 4 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 16b4906..4bbd280 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -25,6 +25,7 @@
#include "rust-hir-trait-resolve.h"
#include "rust-substitution-mapper.h"
#include "rust-type-util.h"
+#include "rust-tyty-variance-analysis.h"
namespace Rust {
namespace Resolver {
@@ -204,7 +205,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
TyTy::ADTType::ReprOptions repr
= parse_repr_options (attrs, struct_decl.get_locus ());
- TyTy::BaseType *type = new TyTy::ADTType (
+ auto *type = new TyTy::ADTType (
struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (),
struct_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::TUPLE_STRUCT, std::move (variants),
@@ -215,6 +216,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
context->insert_type (struct_decl.get_mappings (), type);
infered = type;
+
+ context->get_variance_analysis_ctx ().add_type_constraints (*type);
}
void
@@ -266,7 +269,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
TyTy::ADTType::ReprOptions repr
= parse_repr_options (attrs, struct_decl.get_locus ());
- TyTy::BaseType *type = new TyTy::ADTType (
+ auto *type = new TyTy::ADTType (
struct_decl.get_mappings ().get_hirid (), mappings->get_next_hir_id (),
struct_decl.get_identifier ().as_string (), ident,
TyTy::ADTType::ADTKind::STRUCT_STRUCT, std::move (variants),
@@ -277,6 +280,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
context->insert_type (struct_decl.get_mappings (), type);
infered = type;
+
+ context->get_variance_analysis_ctx ().add_type_constraints (*type);
}
void
@@ -307,7 +312,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
RustIdent ident{*canonical_path, enum_decl.get_locus ()};
// multi variant ADT
- TyTy::BaseType *type
+ auto *type
= new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
enum_decl.get_identifier ().as_string (), ident,
@@ -316,6 +321,8 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
context->insert_type (enum_decl.get_mappings (), type);
infered = type;
+
+ context->get_variance_analysis_ctx ().add_type_constraints (*type);
}
void
@@ -363,7 +370,7 @@ TypeCheckItem::visit (HIR::Union &union_decl)
TyTy::VariantDef::VariantType::STRUCT, nullptr,
std::move (fields)));
- TyTy::BaseType *type
+ auto *type
= new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
mappings->get_next_hir_id (),
union_decl.get_identifier ().as_string (), ident,
@@ -372,6 +379,8 @@ TypeCheckItem::visit (HIR::Union &union_decl)
context->insert_type (union_decl.get_mappings (), type);
infered = type;
+
+ context->get_variance_analysis_ctx ().add_type_constraints (*type);
}
void