From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 3B5BB3810AF9; Wed, 8 Jun 2022 12:52:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B5BB3810AF9 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Fixup name canonicalization for impl blocks X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 0866a4fbc6e7f70cd3708467419c60af8c6104f2 X-Git-Newrev: 91b16af14cb4f7cdf6414b1314c35202d5883fd9 Message-Id: <20220608125201.3B5BB3810AF9@sourceware.org> Date: Wed, 8 Jun 2022 12:52:01 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 12:52:01 -0000 https://gcc.gnu.org/g:91b16af14cb4f7cdf6414b1314c35202d5883fd9 commit 91b16af14cb4f7cdf6414b1314c35202d5883fd9 Author: Philip Herron Date: Thu Jun 2 12:13:43 2022 +0100 Fixup name canonicalization for impl blocks When we generate the path for impl items we need to base this of the Self type but this was ignoring cases like pointers, references or slices. This meant generic slices had the same path has generic pointers etc. The only reason we didn't end up with a linker symbol clash is due to the symbol hash. Diff: --- gcc/rust/resolve/rust-ast-resolve-item.cc | 2 ++ gcc/rust/resolve/rust-ast-resolve-type.cc | 49 ++++++++++++++++++++----------- gcc/rust/resolve/rust-ast-resolve-type.h | 7 +---- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 38e7713e45d..603037e8d8f 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -613,6 +613,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block) resolver->get_name_scope ().pop (); return; } + rust_assert (!self_cpath.is_empty ()); // Setup paths bool canonicalize_type_args = !impl_block.has_generics (); @@ -637,6 +638,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block) = CanonicalPath::new_seg (impl_block.get_node_id (), seg_buf); cpath = canonical_prefix.append (seg); } + // done setup paths auto Self diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index 141788019ee..2b5c68447a0 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -209,43 +209,58 @@ ResolveTypeToCanonicalPath::visit (AST::SliceType &slice) void ResolveType::visit (AST::ReferenceType &type) { - type.get_type_referenced ()->accept_vis (*this); - - if (canonical_path != nullptr && canonical_path->size () > 0) + CanonicalPath path = CanonicalPath::create_empty (); + resolved_node + = ResolveType::go (type.get_type_referenced ().get (), type.get_node_id (), + canonicalize_type_with_generics, &path); + if (canonical_path != nullptr) { - std::string seg = canonical_path->get (); - *canonical_path = CanonicalPath::new_seg (type.get_node_id (), "&" + seg); + std::string ref_type_str = type.is_mut () ? "mut" : ""; + std::string ref_path = "&" + ref_type_str + " " + path.get (); + *canonical_path = canonical_path->append ( + CanonicalPath::new_seg (type.get_node_id (), ref_path)); } } void ResolveType::visit (AST::RawPointerType &type) { - type.get_type_pointed_to ()->accept_vis (*this); - - if (canonical_path != nullptr && canonical_path->size () > 0) + CanonicalPath path = CanonicalPath::create_empty (); + resolved_node + = ResolveType::go (type.get_type_pointed_to ().get (), type.get_node_id (), + canonicalize_type_with_generics, &path); + if (canonical_path != nullptr) { - std::string seg = canonical_path->get (); - *canonical_path = CanonicalPath::new_seg (type.get_node_id (), "*" + seg); + std::string ptr_type_str + = type.get_pointer_type () == AST::RawPointerType::CONST ? "const" + : "mut"; + std::string ptr_path = "*" + ptr_type_str + " " + path.get (); + *canonical_path = canonical_path->append ( + CanonicalPath::new_seg (type.get_node_id (), ptr_path)); } } void ResolveType::visit (AST::InferredType &type) -{ - ok = true; -} +{} void ResolveType::visit (AST::NeverType &type) -{ - ok = true; -} +{} void ResolveType::visit (AST::SliceType &type) { - type.get_elem_type ()->accept_vis (*this); + CanonicalPath path = CanonicalPath::create_empty (); + resolved_node + = ResolveType::go (type.get_elem_type ().get (), type.get_node_id (), + canonicalize_type_with_generics, &path); + if (canonical_path != nullptr) + { + std::string slice_path = "[" + path.get () + "]"; + *canonical_path = canonical_path->append ( + CanonicalPath::new_seg (type.get_node_id (), slice_path)); + } } ResolveRelativeTypePath::ResolveRelativeTypePath (CanonicalPath qualified_path) diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index 933413537b6..d10cec2835b 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -211,15 +211,12 @@ public: ResolveType resolver (parent, canonicalize_type_with_generics, canonical_path); type->accept_vis (resolver); - if (!resolver.ok) - rust_error_at (type->get_locus (), "unresolved type"); return resolver.resolved_node; }; void visit (AST::BareFunctionType &fntype) override { - ok = true; for (auto ¶m : fntype.get_function_params ()) ResolveType::go (param.get_type ().get (), fntype.get_node_id ()); @@ -253,8 +250,6 @@ public: return; } - ok = !rel_canonical_path.is_empty (); - // lets try and resolve in one go else leave it up to the type resolver to // figure outer @@ -331,7 +326,7 @@ public: void visit (AST::QualifiedPathInType &path) override { - ok = ResolveRelativeTypePath::go (path); + ResolveRelativeTypePath::go (path); } void visit (AST::ArrayType &type) override;