aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-10-20 17:19:32 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-10-22 10:49:29 +0100
commit7d988344f74681b0fa97ada77e8390c8e4d69147 (patch)
treeafbe7c8869e6f5bf98dcaf2d6e1cdcc883025ec5 /gcc
parente9b10b3d2992eeb360527c103f1bf9a455f2a593 (diff)
downloadgcc-7d988344f74681b0fa97ada77e8390c8e4d69147.zip
gcc-7d988344f74681b0fa97ada77e8390c8e4d69147.tar.gz
gcc-7d988344f74681b0fa97ada77e8390c8e4d69147.tar.bz2
Cleanup interfaces for associated impl mappings
This changes the lookups to return boolean if they are found rather than default UNKNOWN_HIRID which is more ambigious.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc8
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check.h30
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc13
3 files changed, 30 insertions, 21 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 98c04df..9e8236c 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -197,11 +197,11 @@ ResolvePathRef::query_compile (HirId ref, TyTy::BaseType *lookup,
Analysis::NodeMapping trait_mappings
= trait_item_ref->get_parent_trait_mappings ();
- auto associated_impl_id
- = ctx->get_tyctx ()->lookup_associated_impl_mapping_for_self (
- trait_mappings.get_hirid (), receiver);
- rust_assert (associated_impl_id != UNKNOWN_HIRID);
+ HirId associated_impl_id;
+ ok = ctx->get_tyctx ()->lookup_associated_impl_mapping_for_self (
+ trait_mappings.get_hirid (), receiver, &associated_impl_id);
+ rust_assert (ok);
Resolver::AssociatedImplTrait *associated = nullptr;
bool found_associated_trait_impl
diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h
index bcad5db..d3dc4c9 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.h
+++ b/gcc/rust/typecheck/rust-hir-type-check.h
@@ -144,16 +144,24 @@ public:
void clear_associated_type_mapping (HirId id)
{
- associated_type_mappings[id] = UNKNOWN_HIRID;
+ auto it = associated_type_mappings.find (id);
+ rust_assert (it != associated_type_mappings.end ());
+ associated_type_mappings.erase (it);
}
- HirId lookup_associated_type_mapping (HirId id, HirId default_value)
+ // lookup any associated type mappings, the out parameter of mapping is
+ // allowed to be nullptr which allows this interface to do a simple does exist
+ // check
+ bool lookup_associated_type_mapping (HirId id, HirId *mapping)
{
auto it = associated_type_mappings.find (id);
if (it == associated_type_mappings.end ())
- return default_value;
+ return false;
+
+ if (mapping != nullptr)
+ *mapping = it->second;
- return it->second;
+ return true;
}
void insert_associated_impl_mapping (HirId trait_id,
@@ -169,19 +177,23 @@ public:
associated_traits_to_impls[trait_id].push_back ({impl_type, impl_id});
}
- HirId lookup_associated_impl_mapping_for_self (HirId trait_id,
- const TyTy::BaseType *self)
+ bool lookup_associated_impl_mapping_for_self (HirId trait_id,
+ const TyTy::BaseType *self,
+ HirId *mapping)
{
auto it = associated_traits_to_impls.find (trait_id);
if (it == associated_traits_to_impls.end ())
- return UNKNOWN_HIRID;
+ return false;
for (auto &item : it->second)
{
if (item.first->can_eq (self, false))
- return item.second;
+ {
+ *mapping = item.second;
+ return true;
+ }
}
- return UNKNOWN_HIRID;
+ return false;
}
void insert_autoderef_mappings (HirId id,
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index b6d88ee..232799b 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2198,9 +2198,7 @@ bool
PlaceholderType::can_resolve () const
{
auto context = Resolver::TypeCheckContext::get ();
- HirId val
- = context->lookup_associated_type_mapping (get_ty_ref (), UNKNOWN_HIRID);
- return val != UNKNOWN_HIRID;
+ return context->lookup_associated_type_mapping (get_ty_ref (), nullptr);
}
BaseType *
@@ -2208,12 +2206,11 @@ PlaceholderType::resolve () const
{
auto context = Resolver::TypeCheckContext::get ();
- rust_assert (can_resolve ());
- HirId val
- = context->lookup_associated_type_mapping (get_ty_ref (), UNKNOWN_HIRID);
- rust_assert (val != UNKNOWN_HIRID);
+ HirId mapping;
+ bool ok = context->lookup_associated_type_mapping (get_ty_ref (), &mapping);
+ rust_assert (ok);
- return TyVar (val).get_tyty ();
+ return TyVar (mapping).get_tyty ();
}
bool