diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-03 23:17:43 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:26 +0100 |
commit | 80c44d211c0d57f6e34f6dc57599ec6754e19f27 (patch) | |
tree | 9010e6013f29beb4f7e98db8bacf42845647c099 /gcc/rust/backend | |
parent | 19ed0a94fa485fbe9c388713c4cdb2bf633a1b86 (diff) | |
download | gcc-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>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-base.cc | 10 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 4 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-extern.h | 6 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-implitem.cc | 16 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-item.cc | 26 |
5 files changed, 25 insertions, 37 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); |