public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Fixup name canonicalization for impl blocks
@ 2022-06-08 12:52 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:52 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:91b16af14cb4f7cdf6414b1314c35202d5883fd9
commit 91b16af14cb4f7cdf6414b1314c35202d5883fd9
Author: Philip Herron <philip.herron@embecosm.com>
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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:52 [gcc/devel/rust/master] Fixup name canonicalization for impl blocks Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).