aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir/tree/rust-hir-item.h
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-02-27 13:43:37 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:32:57 +0100
commitc29a3bc945c2d018f75974c12c29aaf99a978984 (patch)
tree70446069f91938748c7dc014416ec26937d86ae9 /gcc/rust/hir/tree/rust-hir-item.h
parentd3a3e52addbe07fed81209a29fe653d840dc67d2 (diff)
downloadgcc-c29a3bc945c2d018f75974c12c29aaf99a978984.zip
gcc-c29a3bc945c2d018f75974c12c29aaf99a978984.tar.gz
gcc-c29a3bc945c2d018f75974c12c29aaf99a978984.tar.bz2
gccrs: Refactor HIR to reduce the amount of raw pointers
Attempt to use references and smart pointers whenever possible. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): Remove usage of get function to retrieve a raw pointer. * backend/rust-compile-base.h: Change API usage from raw pointer to a reference. * backend/rust-compile-block.cc (CompileBlock::compile): Likewise. (CompileBlock::visit): Likewise. (CompileConditionalBlocks::visit): Likewise. * backend/rust-compile-block.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::Compile): Likewise. (CompileExpr::visit): Likewise. (check_match_scrutinee): Likewise. (CompileExpr::array_value_expr): Likewise. (CompileExpr::array_copied_expr): Likewise. (CompileExpr::generate_closure_function): Likewise. (CompileExpr::generate_possible_fn_trait_call): Likewise. * backend/rust-compile-expr.h: Likewise. * backend/rust-compile-fnparam.cc (CompileFnParam::compile): Likewise. (CompileFnParam::visit): Likewise. * backend/rust-compile-fnparam.h: Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-intrinsic.cc (compile_fn_params): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Likewise. (compile_range_pattern_bound): Likewise. (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-compile-pattern.h: Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. (HIRCompileBase::query_compile): Likewise. * backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise. * backend/rust-compile-struct-field-expr.cc (CompileStructExprField::Compile): Likewise. (CompileStructExprField::visit): Likewise. * backend/rust-compile-struct-field-expr.h: Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-compile.cc: Likewise. * backend/rust-mangle-v0.cc (v0_inherent_or_trait_impl_path): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-bir-builder.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_type_privacy): Likewise. (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise. * checks/lints/rust-lint-marklive.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir.h: Likewise. * typecheck/rust-autoderef.cc: Likewise. * typecheck/rust-hir-dot-operator.cc (MethodResolver::select): Likewise. * typecheck/rust-hir-inherent-impl-overlap.h: Likewise. * typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_item_candidate): Likewise. (PathProbeImplTrait::process_trait_impl_items_for_candidates): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise. (TraitItemReference::resolve_item): Likewise. * typecheck/rust-hir-type-check-base.cc: Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::Resolve): Likewise. (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-enumitem.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::Resolve): Likewise. (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::Resolve): Likewise. (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::visit): Likewise. (TypeCheckImplItemWithTrait::visit): Likewise. * typecheck/rust-hir-type-check-implitem.h: Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. (TypeCheckItem::resolve_impl_item): Likewise. (TypeCheckItem::resolve_impl_block_substitutions): Likewise. (TypeCheckItem::resolve_impl_block_self): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve): Likewise. (TypeCheckPattern::visit): Likewise. (ClosureParamInfer::Resolve): Likewise. (ClosureParamInfer::visit): Likewise. * typecheck/rust-hir-type-check-pattern.h: Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::Resolve): Likewise. (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-hir-type-check-struct-field.h: Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr): Likewise. (TypeCheckStructExpr::Resolve): Likewise. (TypeCheckStructExpr::resolve): Likewise. (TypeCheckStructExpr::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckResolveGenericArguments::resolve): Likewise. (TypeCheckType::Resolve): Likewise. (TypeCheckType::visit): Likewise. (TypeCheckType::resolve_root_path): Likewise. (TypeResolveGenericParam::Resolve): Likewise. (TypeResolveGenericParam::visit): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check-type.h: Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-hir-type-check.h: Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise. (TypeCheckBase::get_predicate_from_bound): Likewise. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. (TypeCheckMethodCallExpr::go): Likewise. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-subst.cc: Likewise. * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Likewise. (VariantDef::VariantDef): Remove copy constructor. (VariantDef::operator=): Change to move operator. (VariantDef::get_discriminant): Replace return type to a reference instead of a reference to a unique pointer. (VariantDef::clone): Change to references. (VariantDef::monomorphized_clone): Likewise. (FnType::as_string): Likewise. (FnType::clone): Likewise. * typecheck/rust-tyty.h: Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_impl_block): Likewise. * backend/rust-compile-asm.cc: Use a reference instead of the raw pointer value. * checks/errors/borrowck/rust-bir-builder-pattern.cc: Use references. * checks/errors/rust-hir-pattern-analysis.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/hir/tree/rust-hir-item.h')
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h59
1 files changed, 34 insertions, 25 deletions
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 1f53e85..3e98ad4 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -118,7 +118,7 @@ public:
Identifier get_type_representation () const { return type_representation; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
Analysis::NodeMapping get_type_mappings () const
{
@@ -277,7 +277,7 @@ public:
std::vector<LifetimeParam> &get_for_lifetimes () { return for_lifetimes; }
- std::unique_ptr<Type> &get_bound_type () { return bound_type; }
+ Type &get_bound_type () { return *bound_type; }
std::vector<std::unique_ptr<TypeParamBound>> &get_type_param_bounds ()
{
@@ -452,7 +452,7 @@ public:
ImplicitSelfKind get_self_kind () const { return self_kind; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
Analysis::NodeMapping get_mappings () { return mappings; }
@@ -547,9 +547,11 @@ public:
location_t get_locus () const { return locus; }
- std::unique_ptr<Pattern> &get_param_name () { return param_name; }
+ Pattern &get_param_name () { return *param_name; }
- std::unique_ptr<Type> &get_type () { return type; }
+ std::unique_ptr<Pattern> take_param_name () { return std::move (param_name); }
+
+ Type &get_type () { return *type; }
const Analysis::NodeMapping &get_mappings () const { return mappings; }
};
@@ -1056,7 +1058,7 @@ public:
location_t get_locus () const override final { return locus; }
ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; }
- std::unique_ptr<UseTree> &get_use_tree () { return use_tree; }
+ UseTree &get_use_tree () { return *use_tree; }
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
@@ -1210,7 +1212,7 @@ public:
}
// TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<BlockExpr> &get_definition () { return function_body; }
+ BlockExpr &get_definition () { return *function_body; }
const FunctionQualifiers &get_qualifiers () const { return qualifiers; }
@@ -1222,7 +1224,7 @@ public:
bool has_return_type () const { return return_type != nullptr; }
// TODO: is this better? Or is a "vis_block" better?
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
bool is_method () const { return !self.is_error (); }
@@ -1337,7 +1339,7 @@ public:
WhereClause &get_where_clause () { return where_clause; }
- std::unique_ptr<Type> &get_type_aliased () { return existing_type; }
+ Type &get_type_aliased () { return *existing_type; }
Identifier get_new_type_name () const { return new_type_name; }
@@ -1503,7 +1505,7 @@ public:
Identifier get_field_name () const { return field_name; }
- std::unique_ptr<Type> &get_field_type () { return field_type; }
+ Type &get_field_type () { return *field_type; }
Analysis::NodeMapping get_mappings () const { return mappings; }
@@ -1640,7 +1642,7 @@ public:
location_t get_locus () const { return locus; }
AST::AttrVec &get_outer_attrs () { return outer_attrs; }
- std::unique_ptr<HIR::Type> &get_field_type () { return field_type; }
+ HIR::Type &get_field_type () { return *field_type; }
};
// Rust tuple declared using struct keyword HIR node
@@ -1855,7 +1857,12 @@ public:
void accept_vis (HIRFullVisitor &vis) override;
void accept_vis (HIRStmtVisitor &vis) override;
- std::unique_ptr<Expr> &get_discriminant_expression () { return expression; }
+ Expr &get_discriminant_expression () { return *expression; }
+
+ std::unique_ptr<Expr> take_discriminant_expression ()
+ {
+ return std::move (expression);
+ }
protected:
// Clone function implementation as (not pure) virtual method
@@ -2126,9 +2133,9 @@ public:
void accept_vis (HIRImplVisitor &vis) override;
void accept_vis (HIRVisItemVisitor &vis) override;
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
- std::unique_ptr<Expr> &get_expr () { return const_expr; }
+ Expr &get_expr () { return *const_expr; }
Identifier get_identifier () const { return identifier; }
@@ -2222,9 +2229,9 @@ public:
bool is_mut () const { return mut == Mutability::Mut; }
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Expr &get_expr () { return *expr; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
ItemKind get_item_kind () const override { return ItemKind::Static; }
@@ -2324,7 +2331,7 @@ public:
return generic_params;
}
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
std::vector<FunctionParam> &get_function_params () { return function_params; }
@@ -2391,7 +2398,7 @@ public:
bool has_block_defined () const { return block_expr != nullptr; }
- std::unique_ptr<BlockExpr> &get_block_expr () { return block_expr; }
+ BlockExpr &get_block_expr () { return *block_expr; }
const std::string trait_identifier () const override final
{
@@ -2476,9 +2483,9 @@ public:
bool has_expr () const { return expr != nullptr; }
- std::unique_ptr<Type> &get_type () { return type; }
+ Type &get_type () { return *type; }
- std::unique_ptr<Expr> &get_expr () { return expr; }
+ Expr &get_expr () { return *expr; }
const std::string trait_identifier () const override final
{
@@ -2828,7 +2835,9 @@ public:
location_t get_locus () const override final { return locus; }
- std::unique_ptr<Type> &get_type () { return impl_type; };
+ Type &get_type () { return *impl_type; };
+
+ bool has_type () { return impl_type == nullptr; }
std::vector<std::unique_ptr<GenericParam>> &get_generic_params ()
{
@@ -2837,7 +2846,7 @@ public:
bool has_trait_ref () const { return trait_ref != nullptr; }
- std::unique_ptr<TypePath> &get_trait_ref () { return trait_ref; }
+ TypePath &get_trait_ref () { return *trait_ref; }
WhereClause &get_where_clause () { return where_clause; }
@@ -2976,7 +2985,7 @@ public:
Mutability get_mut () { return mut; }
- std::unique_ptr<Type> &get_item_type () { return item_type; }
+ Type &get_item_type () { return *item_type; }
ExternKind get_extern_kind () override { return ExternKind::Static; }
@@ -3033,7 +3042,7 @@ public:
Identifier get_param_name () const { return name; }
- std::unique_ptr<Type> &get_type () { return param_type; }
+ Type &get_type () { return *param_type; }
Analysis::NodeMapping get_mappings () const { return mappings; }
};
@@ -3132,7 +3141,7 @@ public:
return generic_params;
}
- std::unique_ptr<Type> &get_return_type () { return return_type; }
+ Type &get_return_type () { return *return_type; }
std::vector<NamedFunctionParam> &get_function_params ()
{