aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-02-06 17:21:45 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-08-01 16:52:27 +0200
commitf1b91d0a2bcb74adf7c752592f95f0552afcad77 (patch)
tree8301ca40ee8b274529533135b41713c45a622367 /gcc/rust
parent3b47d8a369baa2fa8b2f22f4bedac2ed90363f3b (diff)
downloadgcc-f1b91d0a2bcb74adf7c752592f95f0552afcad77.zip
gcc-f1b91d0a2bcb74adf7c752592f95f0552afcad77.tar.gz
gcc-f1b91d0a2bcb74adf7c752592f95f0552afcad77.tar.bz2
gccrs: Use new name resolver to compile constant items
Constant items were handled only by the old resolver, this lead to an ICE when using the new resolver on some rust code containing a constant item as the new and the old resolver cannot be used at the same time. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Check the resolver flag and use the new one when required. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/backend/rust-compile-item.cc36
1 files changed, 26 insertions, 10 deletions
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index 8feed51..609528d 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -76,32 +76,48 @@ CompileItem::visit (HIR::StaticItem &var)
void
CompileItem::visit (HIR::ConstantItem &constant)
{
- if (ctx->lookup_const_decl (constant.get_mappings ().get_hirid (),
- &reference))
+ auto &mappings = constant.get_mappings ();
+
+ if (ctx->lookup_const_decl (mappings.get_hirid (), &reference))
return;
// resolve the type
TyTy::BaseType *resolved_type = nullptr;
+
bool ok
- = ctx->get_tyctx ()->lookup_type (constant.get_mappings ().get_hirid (),
- &resolved_type);
+ = ctx->get_tyctx ()->lookup_type (mappings.get_hirid (), &resolved_type);
rust_assert (ok);
// canonical path
- const Resolver::CanonicalPath *canonical_path = nullptr;
- ok = ctx->get_mappings ()->lookup_canonical_path (
- constant.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ Resolver::CanonicalPath canonical_path
+ = Resolver::CanonicalPath::create_empty ();
+
+ if (flag_name_resolution_2_0)
+ {
+ auto nr_ctx
+ = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+ canonical_path
+ = nr_ctx.values.to_canonical_path (mappings.get_nodeid ()).value ();
+ }
+ else
+ {
+ const Resolver::CanonicalPath *canonical_path_ptr = nullptr;
+ ok = ctx->get_mappings ()->lookup_canonical_path (mappings.get_nodeid (),
+ &canonical_path_ptr);
+ rust_assert (ok);
+ canonical_path = *canonical_path_ptr;
+ }
HIR::Expr *const_value_expr = constant.get_expr ().get ();
ctx->push_const_context ();
tree const_expr
- = compile_constant_item (resolved_type, canonical_path, const_value_expr,
+ = compile_constant_item (resolved_type, &canonical_path, const_value_expr,
constant.get_locus ());
ctx->pop_const_context ();
ctx->push_const (const_expr);
- ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+ ctx->insert_const_decl (mappings.get_hirid (), const_expr);
reference = const_expr;
}