aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-03 23:17:43 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:26 +0100
commit80c44d211c0d57f6e34f6dc57599ec6754e19f27 (patch)
tree9010e6013f29beb4f7e98db8bacf42845647c099
parent19ed0a94fa485fbe9c388713c4cdb2bf633a1b86 (diff)
downloadgcc-80c44d211c0d57f6e34f6dc57599ec6754e19f27.zip
gcc-80c44d211c0d57f6e34f6dc57599ec6754e19f27.tar.gz
gcc-80c44d211c0d57f6e34f6dc57599ec6754e19f27.tar.bz2
gccrs: Change lookup_canonical_path's return path
Change the function's return type to wrap it within an optional. gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Change call site to accomodate new return type. * backend/rust-compile-base.h: Change parameter to use a reference. * backend/rust-compile-extern.h: Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Change call site for new return type. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit): Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * util/rust-hir-map.h: Update the function's prototype and change the function's return type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r--gcc/rust/backend/rust-compile-base.cc10
-rw-r--r--gcc/rust/backend/rust-compile-base.h4
-rw-r--r--gcc/rust/backend/rust-compile-extern.h6
-rw-r--r--gcc/rust/backend/rust-compile-implitem.cc16
-rw-r--r--gcc/rust/backend/rust-compile-item.cc26
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.cc3
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-enumitem.cc24
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-implitem.cc7
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-item.cc49
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check.cc6
-rw-r--r--gcc/rust/util/rust-hir-map.h11
11 files changed, 61 insertions, 101 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index add173c..8166c3a 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -650,11 +650,11 @@ HIRCompileBase::compile_function (
std::vector<HIR::FunctionParam> &function_params,
const HIR::FunctionQualifiers &qualifiers, HIR::Visibility &visibility,
AST::AttrVec &outer_attrs, location_t locus, HIR::BlockExpr *function_body,
- const Resolver::CanonicalPath *canonical_path, TyTy::FnType *fntype)
+ const Resolver::CanonicalPath &canonical_path, TyTy::FnType *fntype)
{
tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
std::string ir_symbol_name
- = canonical_path->get () + fntype->subst_as_string ();
+ = canonical_path.get () + fntype->subst_as_string ();
// we don't mangle the main fn since we haven't implemented the main shim
bool is_main_fn = fn_name.compare ("main") == 0;
@@ -677,7 +677,7 @@ HIRCompileBase::compile_function (
// conditionally mangle the function name
bool should_mangle = should_mangle_item (fndecl);
if (!is_main_fn && should_mangle)
- asm_name = ctx->mangle_item (fntype, *canonical_path);
+ asm_name = ctx->mangle_item (fntype, canonical_path);
SET_DECL_ASSEMBLER_NAME (fndecl,
get_identifier_with_length (asm_name.data (),
asm_name.length ()));
@@ -767,10 +767,10 @@ HIRCompileBase::compile_function (
tree
HIRCompileBase::compile_constant_item (
- TyTy::BaseType *resolved_type, const Resolver::CanonicalPath *canonical_path,
+ TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path,
HIR::Expr *const_value_expr, location_t locus)
{
- const std::string &ident = canonical_path->get ();
+ const std::string &ident = canonical_path.get ();
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
tree const_type = build_qualified_type (type, TYPE_QUAL_CONST);
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index 465a4ca..eeb3ff0 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -91,7 +91,7 @@ protected:
TyTy::BaseType *fn_return_ty);
tree compile_constant_item (TyTy::BaseType *resolved_type,
- const Resolver::CanonicalPath *canonical_path,
+ const Resolver::CanonicalPath &canonical_path,
HIR::Expr *const_value_expr, location_t locus);
tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param,
@@ -99,7 +99,7 @@ protected:
const HIR::FunctionQualifiers &qualifiers,
HIR::Visibility &visibility, AST::AttrVec &outer_attrs,
location_t locus, HIR::BlockExpr *function_body,
- const Resolver::CanonicalPath *canonical_path,
+ const Resolver::CanonicalPath &canonical_path,
TyTy::FnType *fntype);
static tree unit_expression (location_t locus);
diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h
index f596ed2..bacd1c0 100644
--- a/gcc/rust/backend/rust-compile-extern.h
+++ b/gcc/rust/backend/rust-compile-extern.h
@@ -134,10 +134,8 @@ public:
if (fntype->get_abi () == ABI::RUST)
{
// then we need to get the canonical path of it and mangle it
- const Resolver::CanonicalPath *canonical_path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- function.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ function.get_mappings ().get_nodeid ());
ir_symbol_name = canonical_path->get () + fntype->subst_as_string ();
asm_name = ctx->mangle_item (fntype, *canonical_path);
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 0f24417..4c7d8e8 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -27,14 +27,12 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
rust_assert (concrete != nullptr);
TyTy::BaseType *resolved_type = concrete;
- const Resolver::CanonicalPath *canonical_path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- constant.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ constant.get_mappings ().get_nodeid ());
HIR::Expr *const_value_expr = constant.get_expr ().get ();
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->push_const (const_expr);
ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
@@ -77,10 +75,8 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
fntype->override_context ();
}
- const Resolver::CanonicalPath *canonical_path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- func.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ func.get_mappings ().get_nodeid ());
// FIXME: How do we get the proper visibility here?
auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
@@ -90,7 +86,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
function.get_self (), function.get_function_params (),
function.get_qualifiers (), vis,
func.get_outer_attrs (), func.get_locus (),
- func.get_block_expr ().get (), canonical_path, fntype);
+ func.get_block_expr ().get (), *canonical_path, fntype);
reference = address_expression (fndecl, ref_locus);
}
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index e7b3a17..c0cac68 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -42,14 +42,12 @@ CompileItem::visit (HIR::StaticItem &var)
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
- const Resolver::CanonicalPath *canonical_path = nullptr;
- ok = ctx->get_mappings ().lookup_canonical_path (
- var.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
+ auto canonical_path = ctx->get_mappings ().lookup_canonical_path (
+ var.get_mappings ().get_nodeid ());
HIR::Expr *const_value_expr = var.get_expr ().get ();
ctx->push_const_context ();
- tree value = compile_constant_item (resolved_type, canonical_path,
+ tree value = compile_constant_item (resolved_type, *canonical_path,
const_value_expr, var.get_locus ());
ctx->pop_const_context ();
@@ -102,17 +100,15 @@ CompileItem::visit (HIR::ConstantItem &constant)
}
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;
+ canonical_path = ctx->get_mappings ()
+ .lookup_canonical_path (mappings.get_nodeid ())
+ .value ();
}
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 ();
@@ -178,10 +174,8 @@ CompileItem::visit (HIR::Function &function)
}
else
{
- const Resolver::CanonicalPath *path = nullptr;
- bool ok = ctx->get_mappings ().lookup_canonical_path (
- function.get_mappings ().get_nodeid (), &path);
- rust_assert (ok);
+ auto path = ctx->get_mappings ().lookup_canonical_path (
+ function.get_mappings ().get_nodeid ());
canonical_path = *path;
}
@@ -213,7 +207,7 @@ CompileItem::visit (HIR::Function &function)
function.get_function_params (),
function.get_qualifiers (), function.get_visibility (),
function.get_outer_attrs (), function.get_locus (),
- function.get_definition ().get (), &canonical_path,
+ function.get_definition ().get (), canonical_path,
fntype);
reference = address_expression (fndecl, ref_locus);
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 1d7bcc9..934d6ea 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -376,8 +376,7 @@ ResolveTypeToCanonicalPath::visit (AST::TypePath &path)
if (resolved_node == UNKNOWN_NODEID)
return;
- const CanonicalPath *type_path = nullptr;
- if (mappings.lookup_canonical_path (resolved_node, &type_path))
+ if (auto type_path = mappings.lookup_canonical_path (resolved_node))
{
auto &final_seg = path.get_segments ().back ();
switch (final_seg->get_type ())
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index 7bade03..72d8791 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -75,10 +75,8 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
rust_assert (ok);
context->insert_type (mapping, isize);
- const CanonicalPath *canonical_path = nullptr;
- ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
@@ -106,10 +104,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
TyTy::TyWithLocation (expected_ty),
TyTy::TyWithLocation (capacity_type), item.get_locus ());
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
@@ -155,10 +151,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
rust_assert (ok);
context->insert_type (mapping, isize);
- const CanonicalPath *canonical_path = nullptr;
- ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
@@ -203,10 +197,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
rust_assert (ok);
context->insert_type (mapping, isize);
- const CanonicalPath *canonical_path = nullptr;
- ok = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index f0f3cfa..58d59d9 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -461,11 +461,8 @@ TypeCheckImplItem::visit (HIR::Function &function)
TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty);
}
- const CanonicalPath *canonical_path = nullptr;
- bool ok
- = mappings.lookup_canonical_path (function.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (function.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, function.get_locus ()};
auto fnType = new TyTy::FnType (
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 3896abd..317d167 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -198,19 +198,17 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
{
auto nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
- auto canonical_path = nr_ctx.values.to_canonical_path (
- struct_decl.get_mappings ().get_nodeid ());
- path = canonical_path.value ();
+ path = nr_ctx.values
+ .to_canonical_path (struct_decl.get_mappings ().get_nodeid ())
+ .value ();
}
else
{
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (
- struct_decl.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
-
- path = *canonical_path;
+ path
+ = mappings
+ .lookup_canonical_path (struct_decl.get_mappings ().get_nodeid ())
+ .value ();
}
RustIdent ident{path, struct_decl.get_locus ()};
@@ -288,12 +286,10 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
}
else
{
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (
- struct_decl.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
-
- path = *canonical_path;
+ path
+ = mappings
+ .lookup_canonical_path (struct_decl.get_mappings ().get_nodeid ())
+ .value ();
}
RustIdent ident{path, struct_decl.get_locus ()};
@@ -347,11 +343,8 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
}
// get the path
- const CanonicalPath *canonical_path = nullptr;
- bool ok
- = mappings.lookup_canonical_path (enum_decl.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (enum_decl.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, enum_decl.get_locus ()};
// multi variant ADT
@@ -397,11 +390,8 @@ TypeCheckItem::visit (HIR::Union &union_decl)
}
// get the path
- const CanonicalPath *canonical_path = nullptr;
- bool ok
- = mappings.lookup_canonical_path (union_decl.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (union_decl.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, union_decl.get_locus ()};
// there is only a single variant
@@ -567,12 +557,9 @@ TypeCheckItem::visit (HIR::Function &function)
}
else
{
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (
- function.get_mappings ().get_nodeid (), &canonical_path);
- rust_assert (ok);
-
- path = *canonical_path;
+ path = mappings
+ .lookup_canonical_path (function.get_mappings ().get_nodeid ())
+ .value ();
}
RustIdent ident{path, function.get_locus ()};
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index 9ee2ff2..45cb75d 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -299,10 +299,8 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
}
auto &mappings = Analysis::Mappings::get ();
- const CanonicalPath *canonical_path = nullptr;
- bool ok = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid (),
- &canonical_path);
- rust_assert (ok);
+ auto canonical_path
+ = mappings.lookup_canonical_path (fn.get_mappings ().get_nodeid ());
RustIdent ident{*canonical_path, fn.get_locus ()};
auto resolved = new TyTy::FnType (
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index c556d76..eafa2ae 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -229,8 +229,7 @@ public:
void insert_canonical_path (NodeId id, const Resolver::CanonicalPath path)
{
- const Resolver::CanonicalPath *p = nullptr;
- if (lookup_canonical_path (id, &p))
+ if (auto p = lookup_canonical_path (id))
{
// if we have already stored a canonical path this is ok so long as
// this new path is equal or is smaller that the existing one but in
@@ -247,14 +246,14 @@ public:
paths.emplace (id, std::move (path));
}
- bool lookup_canonical_path (NodeId id, const Resolver::CanonicalPath **path)
+ tl::optional<const Resolver::CanonicalPath &>
+ lookup_canonical_path (NodeId id)
{
auto it = paths.find (id);
if (it == paths.end ())
- return false;
+ return tl::nullopt;
- *path = &it->second;
- return true;
+ return it->second;
}
void insert_lang_item (LangItem::Kind item_type, DefId id)