From 7eab9d18d97d0ea938c5c7194a7a82109d3a5ea6 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Sat, 7 Jan 2023 14:41:12 +0000 Subject: gccrs: Support associated type bound arguments This patch adds support for the GenercArgsBinding type, where you can specify the associated types of a trait bound using `` style syntax. Note that the type-resolution relys on the i32 impl for Add as type resolution will resolve the `a+a` to the core::ops::Add method so code generation will require this to exist. I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly creating an HIR::GenericArgs with a trait-object type and causing issues. the parsing is still correct but we dont have the mechanism to represent this in AST and HIR properly. I think we will need a new HIR::GenericArgs AssociatedTypeBindingBound or something similar. We are still lacking bounds checking during are type coercions and unifications so running this example using an f32 will wrongly pass type checking, this will need addressed next. Fixes #1720 gcc/rust/ChangeLog: * hir/tree/rust-hir-path.h: Add const get_identifier and get_type method. * typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings constructor. * typecheck/rust-hir-trait-resolve.cc: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Do not assert failure on size mismatch anymore. (TypeBoundPredicate::TypeBoundPredicate): Use new SubstitutionArgumentMappings constructor. (TypeBoundPredicate::operator=): Likewise. (TypeBoundPredicate::apply_generic_arguments): Likewise. (TypeBoundPredicateItem::get_tyty_for_receiver): Likewise. (TypeBoundPredicate::get_num_associated_bindings): Likewise. (TypeBoundPredicate::lookup_associated_type): Fix implementation for new system. (TypeBoundPredicate::get_associated_type_items): Likewise. * typecheck/rust-tyty.cc (SubstitutionRef::get_mappings_from_generic_args): Add new behavior. (SubstitutionRef::infer_substitions): Use new constructor and add comment. (SubstitutionRef::solve_missing_mappings_from_this): Use new constructor. * typecheck/rust-tyty.h: Define new constructors. gcc/testsuite/ChangeLog: * rust/compile/bounds.rs: change to use -fsyntax-only * rust/execute/torture/issue-1720.rs: New test. Signed-off-by: Philip Herron --- gcc/rust/hir/tree/rust-hir-path.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/rust/hir/tree') diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index 17eedb8..740de93 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -105,9 +105,11 @@ public: std::string as_string () const; - Identifier get_identifier () const { return identifier; } + Identifier &get_identifier () { return identifier; } + const Identifier &get_identifier () const { return identifier; } std::unique_ptr &get_type () { return type; } + const std::unique_ptr &get_type () const { return type; } Location get_locus () const { return locus; } }; -- cgit v1.1