[gcc r14-7434] gccrs: make distinction between error and empty for substution args

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 17:34:25 GMT 2024


https://gcc.gnu.org/g:048098d44462aa79d092ed23be5bffb4f77b1874

commit r14-7434-g048098d44462aa79d092ed23be5bffb4f77b1874
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Wed Mar 29 15:00:39 2023 +0100

    gccrs: make distinction between error and empty for substution args
    
    When handling generics of only lifetimes we have an empty
    SubstitutionArgumentMappings which was being detected as an error but this
    is not the case as we don't currently handle const generics or generic
    lifetimes so this makes the distinction between an error occurred or its
    simply empty because it was all only lifetime arguments and we don't care
    about it.
    
    Addresses #2043 #2039
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): this is an empty
            (TypeBoundPredicate::operator=): likewise
            * typecheck/rust-tyty-subst.cc (SubstitutionArgumentMappings::empty): new interface
            (SubstitutionArgumentMappings::is_error): this marks it as an error
            * typecheck/rust-tyty-subst.h: update prototypes
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-tyty-bounds.cc |  8 ++++----
 gcc/rust/typecheck/rust-tyty-subst.cc  | 20 +++++++++++++++-----
 gcc/rust/typecheck/rust-tyty-subst.h   |  5 ++++-
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc
index 6c36303baca..6977bee2f3f 100644
--- a/gcc/rust/typecheck/rust-tyty-bounds.cc
+++ b/gcc/rust/typecheck/rust-tyty-bounds.cc
@@ -271,7 +271,7 @@ namespace TyTy {
 
 TypeBoundPredicate::TypeBoundPredicate (
   const Resolver::TraitReference &trait_reference, Location locus)
-  : SubstitutionRef ({}, SubstitutionArgumentMappings::error ()),
+  : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()),
     reference (trait_reference.get_mappings ().get_defid ()), locus (locus),
     error_flag (false)
 {
@@ -286,7 +286,7 @@ TypeBoundPredicate::TypeBoundPredicate (
 
 TypeBoundPredicate::TypeBoundPredicate (
   DefId reference, std::vector<SubstitutionParamMapping> subst, Location locus)
-  : SubstitutionRef ({}, SubstitutionArgumentMappings::error ()),
+  : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()),
     reference (reference), locus (locus), error_flag (false)
 {
   substitutions.clear ();
@@ -299,7 +299,7 @@ TypeBoundPredicate::TypeBoundPredicate (
 }
 
 TypeBoundPredicate::TypeBoundPredicate (const TypeBoundPredicate &other)
-  : SubstitutionRef ({}, SubstitutionArgumentMappings::error ()),
+  : SubstitutionRef ({}, SubstitutionArgumentMappings::empty ()),
     reference (other.reference), locus (other.locus),
     error_flag (other.error_flag)
 {
@@ -337,7 +337,7 @@ TypeBoundPredicate::operator= (const TypeBoundPredicate &other)
   reference = other.reference;
   locus = other.locus;
   error_flag = other.error_flag;
-  used_arguments = SubstitutionArgumentMappings::error ();
+  used_arguments = SubstitutionArgumentMappings::empty ();
 
   substitutions.clear ();
   for (const auto &p : other.get_substs ())
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index 8ae61f4ee46..9715b08ad04 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -236,16 +236,17 @@ SubstitutionArg::as_string () const
 SubstitutionArgumentMappings::SubstitutionArgumentMappings (
   std::vector<SubstitutionArg> mappings,
   std::map<std::string, BaseType *> binding_args, Location locus,
-  ParamSubstCb param_subst_cb, bool trait_item_flag)
+  ParamSubstCb param_subst_cb, bool trait_item_flag, bool error_flag)
   : mappings (mappings), binding_args (binding_args), locus (locus),
-    param_subst_cb (param_subst_cb), trait_item_flag (trait_item_flag)
+    param_subst_cb (param_subst_cb), trait_item_flag (trait_item_flag),
+    error_flag (error_flag)
 {}
 
 SubstitutionArgumentMappings::SubstitutionArgumentMappings (
   const SubstitutionArgumentMappings &other)
   : mappings (other.mappings), binding_args (other.binding_args),
     locus (other.locus), param_subst_cb (nullptr),
-    trait_item_flag (other.trait_item_flag)
+    trait_item_flag (other.trait_item_flag), error_flag (other.error_flag)
 {}
 
 SubstitutionArgumentMappings &
@@ -257,6 +258,7 @@ SubstitutionArgumentMappings::operator= (
   locus = other.locus;
   param_subst_cb = nullptr;
   trait_item_flag = other.trait_item_flag;
+  error_flag = other.error_flag;
 
   return *this;
 }
@@ -264,13 +266,21 @@ SubstitutionArgumentMappings::operator= (
 SubstitutionArgumentMappings
 SubstitutionArgumentMappings::error ()
 {
-  return SubstitutionArgumentMappings ({}, {}, Location (), nullptr, false);
+  return SubstitutionArgumentMappings ({}, {}, Location (), nullptr, false,
+				       true);
+}
+
+SubstitutionArgumentMappings
+SubstitutionArgumentMappings::empty ()
+{
+  return SubstitutionArgumentMappings ({}, {}, Location (), nullptr, false,
+				       false);
 }
 
 bool
 SubstitutionArgumentMappings::is_error () const
 {
-  return mappings.size () == 0;
+  return error_flag;
 }
 
 bool
diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h
index c0439f5554b..37423746f13 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.h
+++ b/gcc/rust/typecheck/rust-tyty-subst.h
@@ -109,7 +109,8 @@ public:
 				std::map<std::string, BaseType *> binding_args,
 				Location locus,
 				ParamSubstCb param_subst_cb = nullptr,
-				bool trait_item_flag = false);
+				bool trait_item_flag = false,
+				bool error_flag = false);
 
   SubstitutionArgumentMappings (const SubstitutionArgumentMappings &other);
   SubstitutionArgumentMappings &
@@ -120,6 +121,7 @@ public:
     = default;
 
   static SubstitutionArgumentMappings error ();
+  static SubstitutionArgumentMappings empty ();
 
   bool is_error () const;
 
@@ -161,6 +163,7 @@ private:
   Location locus;
   ParamSubstCb param_subst_cb;
   bool trait_item_flag;
+  bool error_flag;
 };
 
 class SubstitutionRef


More information about the Gcc-cvs mailing list