diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 11129bcb86be..966ff527c15a 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -582,8 +582,9 @@ HIRCompileBase::compile_function_body (tree fndecl, if (function_body.has_expr ()) { - location_t locus = function_body.get_final_expr ()->get_locus (); - tree return_value = CompileExpr::Compile (function_body.expr.get (), ctx); + location_t locus = function_body.get_final_expr ().get_locus (); + tree return_value + = CompileExpr::Compile (function_body.get_final_expr (), ctx); // we can only return this if non unit value return type if (!fn_return_ty->is_unit ()) @@ -709,18 +710,18 @@ HIRCompileBase::compile_function ( size_t i = is_method ? 1 : 0; for (auto &referenced_param : function_params) { - auto tyty_param = fntype->param_at (i++); + auto &tyty_param = fntype->param_at (i++); auto param_tyty = tyty_param.second; auto compiled_param_type = TyTyResolveCompile::compile (ctx, param_tyty); location_t param_locus = referenced_param.get_locus (); Bvariable *compiled_param_var - = CompileFnParam::compile (ctx, fndecl, &referenced_param, + = CompileFnParam::compile (ctx, fndecl, referenced_param, compiled_param_type, param_locus); param_vars.push_back (compiled_param_var); - const HIR::Pattern ¶m_pattern = *referenced_param.get_param_name (); + const HIR::Pattern ¶m_pattern = referenced_param.get_param_name (); ctx->insert_var_decl (param_pattern.get_mappings ().get_hirid (), compiled_param_var); } @@ -768,14 +769,14 @@ HIRCompileBase::compile_function ( tree HIRCompileBase::compile_constant_item ( TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path, - HIR::Expr *const_value_expr, location_t locus) + HIR::Expr &const_value_expr, location_t locus) { const std::string &ident = canonical_path.get (); tree type = TyTyResolveCompile::compile (ctx, resolved_type); tree const_type = build_qualified_type (type, TYPE_QUAL_CONST); bool is_block_expr - = const_value_expr->get_expression_type () == HIR::Expr::ExprType::Block; + = const_value_expr.get_expression_type () == HIR::Expr::ExprType::Block; // in order to compile a block expr we want to reuse as much existing // machineary that we already have. This means the best approach is to @@ -789,14 +790,14 @@ HIRCompileBase::compile_constant_item ( TREE_READONLY (fndecl) = 1; tree enclosing_scope = NULL_TREE; - location_t start_location = const_value_expr->get_locus (); - location_t end_location = const_value_expr->get_locus (); + location_t start_location = const_value_expr.get_locus (); + location_t end_location = const_value_expr.get_locus (); if (is_block_expr) { - HIR::BlockExpr *function_body - = static_cast (const_value_expr); - start_location = function_body->get_locus (); - end_location = function_body->get_end_locus (); + HIR::BlockExpr &function_body + = static_cast (const_value_expr); + start_location = function_body.get_locus (); + end_location = function_body.get_end_locus (); } tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/, @@ -814,9 +815,9 @@ HIRCompileBase::compile_constant_item ( if (is_block_expr) { - HIR::BlockExpr *function_body - = static_cast (const_value_expr); - compile_function_body (fndecl, *function_body, resolved_type); + HIR::BlockExpr &function_body + = static_cast (const_value_expr); + compile_function_body (fndecl, function_body, resolved_type); } else { @@ -824,7 +825,7 @@ HIRCompileBase::compile_constant_item ( tree return_expr = Backend::return_statement (fndecl, value, - const_value_expr->get_locus ()); + const_value_expr.get_locus ()); ctx->add_statement (return_expr); } diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index 22d4ae6c6f66..bf175d748a0b 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -92,7 +92,7 @@ class HIRCompileBase tree compile_constant_item (TyTy::BaseType *resolved_type, const Resolver::CanonicalPath &canonical_path, - HIR::Expr *const_value_expr, location_t locus); + HIR::Expr &const_value_expr, location_t locus); tree compile_function (const std::string &fn_name, HIR::SelfParam &self_param, std::vector &function_params, diff --git a/gcc/rust/backend/rust-compile-block.cc b/gcc/rust/backend/rust-compile-block.cc index 3f5734378aa5..56d0c417f0ab 100644 --- a/gcc/rust/backend/rust-compile-block.cc +++ b/gcc/rust/backend/rust-compile-block.cc @@ -28,10 +28,10 @@ CompileBlock::CompileBlock (Context *ctx, Bvariable *result) {} tree -CompileBlock::compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result) +CompileBlock::compile (HIR::BlockExpr &expr, Context *ctx, Bvariable *result) { CompileBlock compiler (ctx, result); - compiler.visit (*expr); + compiler.visit (expr); return compiler.translated; } @@ -60,10 +60,10 @@ CompileBlock::visit (HIR::BlockExpr &expr) if (expr.has_expr ()) { - tree compiled_expr = CompileExpr::Compile (expr.expr.get (), ctx); + tree compiled_expr = CompileExpr::Compile (expr.get_final_expr (), ctx); if (result != nullptr) { - location_t locus = expr.get_final_expr ()->get_locus (); + location_t locus = expr.get_final_expr ().get_locus (); tree result_reference = Backend::var_expression (result, locus); tree assignment @@ -93,10 +93,8 @@ CompileConditionalBlocks::visit (HIR::IfExpr &expr) { fncontext fnctx = ctx->peek_fn (); tree fndecl = fnctx.fndecl; - tree condition_expr - = CompileExpr::Compile (expr.get_if_condition ().get (), ctx); - tree then_block - = CompileBlock::compile (expr.get_if_block ().get (), ctx, result); + tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx); + tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result); translated = Backend::if_statement (fndecl, condition_expr, then_block, NULL, expr.get_locus ()); @@ -107,23 +105,20 @@ CompileConditionalBlocks::visit (HIR::IfExprConseqElse &expr) { fncontext fnctx = ctx->peek_fn (); tree fndecl = fnctx.fndecl; - tree condition_expr - = CompileExpr::Compile (expr.get_if_condition ().get (), ctx); - tree then_block - = CompileBlock::compile (expr.get_if_block ().get (), ctx, result); + tree condition_expr = CompileExpr::Compile (expr.get_if_condition (), ctx); + tree then_block = CompileBlock::compile (expr.get_if_block (), ctx, result); // else block std::vector locals; - location_t start_location = expr.get_else_block ()->get_locus (); - location_t end_location = expr.get_else_block ()->get_locus (); // FIXME + location_t start_location = expr.get_else_block ().get_locus (); + location_t end_location = expr.get_else_block ().get_locus (); // FIXME tree enclosing_scope = ctx->peek_enclosing_scope (); tree else_block = Backend::block (fndecl, enclosing_scope, locals, start_location, end_location); ctx->push_block (else_block); tree else_stmt_decl - = CompileExprWithBlock::compile (expr.get_else_block ().get (), ctx, - result); + = CompileExprWithBlock::compile (&expr.get_else_block (), ctx, result); ctx->add_statement (else_stmt_decl); diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h index 52cf0572e6cc..6002331f5179 100644 --- a/gcc/rust/backend/rust-compile-block.h +++ b/gcc/rust/backend/rust-compile-block.h @@ -28,7 +28,7 @@ namespace Compile { class CompileBlock : private HIRCompileBase { public: - static tree compile (HIR::BlockExpr *expr, Context *ctx, Bvariable *result); + static tree compile (HIR::BlockExpr &expr, Context *ctx, Bvariable *result); protected: void visit (HIR::BlockExpr &expr); @@ -135,7 +135,7 @@ class CompileExprWithBlock : public HIRCompileBase, void visit (HIR::BlockExpr &expr) override { - translated = CompileBlock::compile (&expr, ctx, result); + translated = CompileBlock::compile (expr, ctx, result); } // Empty visit for unused Expression HIR nodes. diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 557b9fe59c58..64662580d913 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -40,24 +40,24 @@ CompileExpr::CompileExpr (Context *ctx) {} tree -CompileExpr::Compile (HIR::Expr *expr, Context *ctx) +CompileExpr::Compile (HIR::Expr &expr, Context *ctx) { CompileExpr compiler (ctx); - expr->accept_vis (compiler); + expr.accept_vis (compiler); return compiler.translated; } void CompileExpr::visit (HIR::TupleIndexExpr &expr) { - HIR::Expr *tuple_expr = expr.get_tuple_expr ().get (); + HIR::Expr &tuple_expr = expr.get_tuple_expr (); TupleIndex index = expr.get_tuple_index (); tree receiver_ref = CompileExpr::Compile (tuple_expr, ctx); TyTy::BaseType *tuple_expr_ty = nullptr; bool ok - = ctx->get_tyctx ()->lookup_type (tuple_expr->get_mappings ().get_hirid (), + = ctx->get_tyctx ()->lookup_type (tuple_expr.get_mappings ().get_hirid (), &tuple_expr_ty); rust_assert (ok); @@ -97,7 +97,7 @@ CompileExpr::visit (HIR::TupleExpr &expr) std::vector vals; for (auto &elem : expr.get_tuple_elems ()) { - auto e = CompileExpr::Compile (elem.get (), ctx); + auto e = CompileExpr::Compile (*elem, ctx); vals.push_back (e); } @@ -111,7 +111,7 @@ CompileExpr::visit (HIR::ReturnExpr &expr) auto fncontext = ctx->peek_fn (); tree return_value = expr.has_return_expr () - ? CompileExpr::Compile (expr.return_expr.get (), ctx) + ? CompileExpr::Compile (expr.get_expr (), ctx) : unit_expression (expr.get_locus ()); if (expr.has_return_expr ()) @@ -141,8 +141,8 @@ void CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr) { auto op = expr.get_expr_type (); - auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx); - auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx); + auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx); + auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx); // this might be an operator overload situation lets check TyTy::FnType *fntype; @@ -153,8 +153,7 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr) auto lang_item_type = LangItem::OperatorToLangItem (expr.get_expr_type ()); translated = resolve_operator_overload (lang_item_type, expr, lhs, rhs, - expr.get_lhs ().get (), - expr.get_rhs ().get ()); + expr.get_lhs (), expr.get_rhs ()); return; } @@ -185,8 +184,8 @@ void CompileExpr::visit (HIR::CompoundAssignmentExpr &expr) { auto op = expr.get_expr_type (); - auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx); - auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx); + auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx); + auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx); // this might be an operator overload situation lets check TyTy::FnType *fntype; @@ -198,8 +197,7 @@ CompileExpr::visit (HIR::CompoundAssignmentExpr &expr) expr.get_expr_type ()); auto compound_assignment = resolve_operator_overload (lang_item_type, expr, lhs, rhs, - expr.get_lhs ().get (), - expr.get_rhs ().get ()); + expr.get_lhs (), expr.get_rhs ()); ctx->add_statement (compound_assignment); return; @@ -235,7 +233,7 @@ void CompileExpr::visit (HIR::NegationExpr &expr) { auto op = expr.get_expr_type (); - auto negated_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); + auto negated_expr = CompileExpr::Compile (expr.get_expr (), ctx); auto location = expr.get_locus (); // this might be an operator overload situation lets check @@ -247,7 +245,7 @@ CompileExpr::visit (HIR::NegationExpr &expr) auto lang_item_type = LangItem::NegationOperatorToLangItem (op); translated = resolve_operator_overload (lang_item_type, expr, negated_expr, - nullptr, expr.get_expr ().get (), nullptr); + nullptr, expr.get_expr (), tl::nullopt); return; } @@ -258,8 +256,8 @@ void CompileExpr::visit (HIR::ComparisonExpr &expr) { auto op = expr.get_expr_type (); - auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx); - auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx); + auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx); + auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx); auto location = expr.get_locus (); translated = Backend::comparison_expression (op, lhs, rhs, location); @@ -269,8 +267,8 @@ void CompileExpr::visit (HIR::LazyBooleanExpr &expr) { auto op = expr.get_expr_type (); - auto lhs = CompileExpr::Compile (expr.get_lhs ().get (), ctx); - auto rhs = CompileExpr::Compile (expr.get_rhs ().get (), ctx); + auto lhs = CompileExpr::Compile (expr.get_lhs (), ctx); + auto rhs = CompileExpr::Compile (expr.get_rhs (), ctx); auto location = expr.get_locus (); translated = Backend::lazy_boolean_expression (op, lhs, rhs, location); @@ -289,14 +287,14 @@ CompileExpr::visit (HIR::TypeCastExpr &expr) TyTy::BaseType *casted_tyty = nullptr; if (!ctx->get_tyctx ()->lookup_type ( - expr.get_casted_expr ()->get_mappings ().get_hirid (), &casted_tyty)) + expr.get_casted_expr ().get_mappings ().get_hirid (), &casted_tyty)) { translated = error_mark_node; return; } auto type_to_cast_to = TyTyResolveCompile::compile (ctx, type_to_cast_to_ty); - auto casted_expr = CompileExpr::Compile (expr.get_casted_expr ().get (), ctx); + auto casted_expr = CompileExpr::Compile (expr.get_casted_expr (), ctx); std::vector *adjustments = nullptr; bool ok = ctx->get_tyctx ()->lookup_cast_autoderef_mappings ( @@ -377,7 +375,7 @@ CompileExpr::visit (HIR::BlockExpr &expr) &ret_var_stmt); ctx->add_statement (ret_var_stmt); - auto block_stmt = CompileBlock::compile (&expr, ctx, tmp); + auto block_stmt = CompileBlock::compile (expr, ctx, tmp); rust_assert (TREE_CODE (block_stmt) == BIND_EXPR); ctx->add_statement (block_stmt); @@ -387,7 +385,7 @@ CompileExpr::visit (HIR::BlockExpr &expr) void CompileExpr::visit (HIR::UnsafeBlockExpr &expr) { - expr.get_block_expr ()->accept_vis (*this); + expr.get_block_expr ().accept_vis (*this); } void @@ -459,7 +457,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr) auto lvalue_locus = ctx->get_mappings ().lookup_location (expected->get_ty_ref ()); auto rvalue_locus = argument->get_locus (); - auto rvalue = CompileStructExprField::Compile (argument.get (), ctx); + auto rvalue = CompileStructExprField::Compile (*argument, ctx); TyTy::BaseType *actual = nullptr; bool ok = ctx->get_tyctx ()->lookup_type ( @@ -491,7 +489,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr) auto lvalue_locus = ctx->get_mappings ().lookup_location (expected->get_ty_ref ()); auto rvalue_locus = argument->get_locus (); - auto rvalue = CompileStructExprField::Compile (argument.get (), ctx); + auto rvalue = CompileStructExprField::Compile (*argument, ctx); TyTy::BaseType *actual = nullptr; bool ok = ctx->get_tyctx ()->lookup_type ( @@ -516,7 +514,7 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr) std::vector ctor_arguments; if (adt->is_enum ()) { - HIR::Expr *discrim_expr = variant->get_discriminant (); + HIR::Expr &discrim_expr = variant->get_discriminant (); tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); tree folded_discrim_expr = fold_expr (discrim_expr_node); tree qualifier = folded_discrim_expr; @@ -535,21 +533,21 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr) void CompileExpr::visit (HIR::GroupedExpr &expr) { - translated = CompileExpr::Compile (expr.get_expr_in_parens ().get (), ctx); + translated = CompileExpr::Compile (expr.get_expr_in_parens (), ctx); } void CompileExpr::visit (HIR::FieldAccessExpr &expr) { - HIR::Expr *receiver_expr = expr.get_receiver_expr ().get (); + HIR::Expr &receiver_expr = expr.get_receiver_expr (); tree receiver_ref = CompileExpr::Compile (receiver_expr, ctx); // resolve the receiver back to ADT type TyTy::BaseType *receiver = nullptr; if (!ctx->get_tyctx ()->lookup_type ( - expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver)) + expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver)) { - rust_error_at (expr.get_receiver_expr ()->get_locus (), + rust_error_at (expr.get_receiver_expr ().get_locus (), "unresolved type for receiver"); return; } @@ -644,7 +642,7 @@ CompileExpr::visit (HIR::LoopExpr &expr) ctx->push_loop_begin_label (loop_begin_label); tree code_block - = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr); + = CompileBlock::compile (expr.get_loop_block (), ctx, nullptr); tree loop_expr = Backend::loop_expression (code_block, expr.get_locus ()); ctx->add_statement (loop_expr); @@ -671,8 +669,8 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr) } std::vector locals; - location_t start_location = expr.get_loop_block ()->get_locus (); - location_t end_location = expr.get_loop_block ()->get_locus (); // FIXME + location_t start_location = expr.get_loop_block ().get_locus (); + location_t end_location = expr.get_loop_block ().get_locus (); // FIXME tree enclosing_scope = ctx->peek_enclosing_scope (); tree loop_block = Backend::block (fnctx.fndecl, enclosing_scope, locals, @@ -685,15 +683,14 @@ CompileExpr::visit (HIR::WhileLoopExpr &expr) ctx->add_statement (loop_begin_label_decl); ctx->push_loop_begin_label (loop_begin_label); - tree condition - = CompileExpr::Compile (expr.get_predicate_expr ().get (), ctx); + tree condition = CompileExpr::Compile (expr.get_predicate_expr (), ctx); tree exit_condition = fold_build1_loc (expr.get_locus (), TRUTH_NOT_EXPR, boolean_type_node, condition); tree exit_expr = Backend::exit_expression (exit_condition, expr.get_locus ()); ctx->add_statement (exit_expr); tree code_block_stmt - = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr); + = CompileBlock::compile (expr.get_loop_block (), ctx, nullptr); rust_assert (TREE_CODE (code_block_stmt) == BIND_EXPR); ctx->add_statement (code_block_stmt); @@ -709,12 +706,12 @@ CompileExpr::visit (HIR::BreakExpr &expr) { if (expr.has_break_expr ()) { - tree compiled_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); + tree compiled_expr = CompileExpr::Compile (expr.get_expr (), ctx); Bvariable *loop_result_holder = ctx->peek_loop_context (); tree result_reference = Backend::var_expression (loop_result_holder, - expr.get_expr ()->get_locus ()); + expr.get_expr ().get_locus ()); tree assignment = Backend::assignment_statement (result_reference, compiled_expr, @@ -804,7 +801,7 @@ CompileExpr::visit (HIR::ContinueExpr &expr) void CompileExpr::visit (HIR::BorrowExpr &expr) { - tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); + tree main_expr = CompileExpr::Compile (expr.get_expr (), ctx); if (RS_DST_FLAG_P (TREE_TYPE (main_expr))) { translated = main_expr; @@ -831,7 +828,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr) return; } - tree main_expr = CompileExpr::Compile (expr.get_expr ().get (), ctx); + tree main_expr = CompileExpr::Compile (expr.get_expr (), ctx); // this might be an operator overload situation lets check TyTy::FnType *fntype; @@ -842,7 +839,7 @@ CompileExpr::visit (HIR::DereferenceExpr &expr) auto lang_item_type = LangItem::Kind::DEREF; tree operator_overload_call = resolve_operator_overload (lang_item_type, expr, main_expr, nullptr, - expr.get_expr ().get (), nullptr); + expr.get_expr (), tl::nullopt); // rust deref always returns a reference from this overload then we can // actually do the indirection @@ -902,8 +899,8 @@ CompileExpr::visit (HIR::LiteralExpr &expr) void CompileExpr::visit (HIR::AssignmentExpr &expr) { - auto lvalue = CompileExpr::Compile (expr.get_lhs ().get (), ctx); - auto rvalue = CompileExpr::Compile (expr.get_rhs ().get (), ctx); + auto lvalue = CompileExpr::Compile (expr.get_lhs (), ctx); + auto rvalue = CompileExpr::Compile (expr.get_rhs (), ctx); // assignments are coercion sites so lets convert the rvalue if necessary TyTy::BaseType *expected = nullptr; @@ -911,16 +908,16 @@ CompileExpr::visit (HIR::AssignmentExpr &expr) bool ok; ok = ctx->get_tyctx ()->lookup_type ( - expr.get_lhs ()->get_mappings ().get_hirid (), &expected); + expr.get_lhs ().get_mappings ().get_hirid (), &expected); rust_assert (ok); ok = ctx->get_tyctx ()->lookup_type ( - expr.get_rhs ()->get_mappings ().get_hirid (), &actual); + expr.get_rhs ().get_mappings ().get_hirid (), &actual); rust_assert (ok); rvalue = coercion_site (expr.get_mappings ().get_hirid (), rvalue, actual, - expected, expr.get_lhs ()->get_locus (), - expr.get_rhs ()->get_locus ()); + expected, expr.get_lhs ().get_locus (), + expr.get_rhs ().get_locus ()); // rust_debug_loc (expr.get_locus (), "XXXXXX assignment"); // debug_tree (rvalue); @@ -941,7 +938,7 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx) { TyTy::BaseType *scrutinee_expr_tyty = nullptr; if (!ctx->get_tyctx ()->lookup_type ( - expr.get_scrutinee_expr ()->get_mappings ().get_hirid (), + expr.get_scrutinee_expr ().get_mappings ().get_hirid (), &scrutinee_expr_tyty)) { return TyTy::TypeKind::ERROR; @@ -1019,7 +1016,7 @@ CompileExpr::visit (HIR::MatchExpr &expr) // lets compile the scrutinee expression tree match_scrutinee_rval - = CompileExpr::Compile (expr.get_scrutinee_expr ().get (), ctx); + = CompileExpr::Compile (expr.get_scrutinee_expr (), ctx); Bvariable *match_scrutinee_tmp_var = Backend::temporary_variable (fnctx.fndecl, enclosing_scope, @@ -1029,7 +1026,7 @@ CompileExpr::visit (HIR::MatchExpr &expr) ctx->add_statement (ret_var_stmt); tree match_scrutinee_expr = match_scrutinee_tmp_var->get_tree ( - expr.get_scrutinee_expr ()->get_locus ()); + expr.get_scrutinee_expr ().get_locus ()); tree assignment = Backend::assignment_statement (match_scrutinee_expr, match_scrutinee_rval, @@ -1062,14 +1059,13 @@ CompileExpr::visit (HIR::MatchExpr &expr) ctx->push_block (arm_body_block); // setup the bindings for the block - CompilePatternBindings::Compile (kase_pattern.get (), - match_scrutinee_expr, ctx); + CompilePatternBindings::Compile (*kase_pattern, match_scrutinee_expr, + ctx); // compile the expr and setup the assignment if required when tmp != // NULL location_t arm_locus = kase_arm.get_locus (); - tree kase_expr_tree - = CompileExpr::Compile (kase.get_expr ().get (), ctx); + tree kase_expr_tree = CompileExpr::Compile (kase.get_expr (), ctx); tree result_reference = Backend::var_expression (tmp, arm_locus); tree assignment = Backend::assignment_statement (result_reference, kase_expr_tree, @@ -1084,7 +1080,7 @@ CompileExpr::visit (HIR::MatchExpr &expr) ctx->pop_block (); tree check_expr - = CompilePatternCheckExpr::Compile (kase_pattern.get (), + = CompilePatternCheckExpr::Compile (*kase_pattern, match_scrutinee_expr, ctx); tree check_stmt @@ -1106,7 +1102,7 @@ CompileExpr::visit (HIR::CallExpr &expr) { TyTy::BaseType *tyty = nullptr; if (!ctx->get_tyctx ()->lookup_type ( - expr.get_fnexpr ()->get_mappings ().get_hirid (), &tyty)) + expr.get_fnexpr ().get_mappings ().get_hirid (), &tyty)) { rust_error_at (expr.get_locus (), "unknown type"); return; @@ -1132,7 +1128,7 @@ CompileExpr::visit (HIR::CallExpr &expr) { HirId variant_id; bool ok = ctx->get_tyctx ()->lookup_variant_definition ( - expr.get_fnexpr ()->get_mappings ().get_hirid (), &variant_id); + expr.get_fnexpr ().get_mappings ().get_hirid (), &variant_id); rust_assert (ok); ok = adt->lookup_variant_by_id (variant_id, &variant, @@ -1146,7 +1142,7 @@ CompileExpr::visit (HIR::CallExpr &expr) for (size_t i = 0; i < expr.get_arguments ().size (); i++) { auto &argument = expr.get_arguments ().at (i); - auto rvalue = CompileExpr::Compile (argument.get (), ctx); + auto rvalue = CompileExpr::Compile (*argument, ctx); // assignments are coercion sites so lets convert the rvalue if // necessary @@ -1175,7 +1171,7 @@ CompileExpr::visit (HIR::CallExpr &expr) std::vector ctor_arguments; if (adt->is_enum ()) { - HIR::Expr *discrim_expr = variant->get_discriminant (); + HIR::Expr &discrim_expr = variant->get_discriminant (); tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); tree folded_discrim_expr = fold_expr (discrim_expr_node); tree qualifier = folded_discrim_expr; @@ -1209,13 +1205,13 @@ CompileExpr::visit (HIR::CallExpr &expr) } const TyTy::FnType *fn = static_cast (base); - auto param = fn->param_at (index); + auto ¶m = fn->param_at (index); *result = param.second; return true; }; - auto fn_address = CompileExpr::Compile (expr.get_fnexpr ().get (), ctx); + auto fn_address = CompileExpr::Compile (expr.get_fnexpr (), ctx); // is this a closure call? bool possible_trait_call @@ -1242,7 +1238,7 @@ CompileExpr::visit (HIR::CallExpr &expr) for (size_t i = 0; i < expr.get_arguments ().size (); i++) { auto &argument = expr.get_arguments ().at (i); - auto rvalue = CompileExpr::Compile (argument.get (), ctx); + auto rvalue = CompileExpr::Compile (*argument, ctx); if (is_variadic && i >= required_num_args) { @@ -1282,7 +1278,7 @@ void CompileExpr::visit (HIR::MethodCallExpr &expr) { // method receiver - tree self = CompileExpr::Compile (expr.get_receiver ().get (), ctx); + tree self = CompileExpr::Compile (expr.get_receiver (), ctx); // lookup the expected function type TyTy::BaseType *lookup_fntype = nullptr; @@ -1322,7 +1318,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) // lookup the autoderef mappings HirId autoderef_mappings_id - = expr.get_receiver ()->get_mappings ().get_hirid (); + = expr.get_receiver ().get_mappings ().get_hirid (); std::vector *adjustments = nullptr; ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id, &adjustments); @@ -1330,7 +1326,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) // apply adjustments for the fn call self = resolve_adjustements (*adjustments, self, - expr.get_receiver ()->get_locus ()); + expr.get_receiver ().get_locus ()); std::vector args; args.push_back (self); // adjusted self @@ -1339,7 +1335,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr) for (size_t i = 0; i < expr.get_arguments ().size (); i++) { auto &argument = expr.get_arguments ().at (i); - auto rvalue = CompileExpr::Compile (argument.get (), ctx); + auto rvalue = CompileExpr::Compile (*argument, ctx); // assignments are coercion sites so lets convert the rvalue if // necessary, offset from the already adjusted implicit self @@ -1421,8 +1417,8 @@ CompileExpr::get_receiver_from_dyn (const TyTy::DynamicObjectType *dyn, tree CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs, - tree rhs, HIR::Expr *lhs_expr, - HIR::Expr *rhs_expr) + tree rhs, HIR::Expr &lhs_expr, + tl::optional rhs_expr) { TyTy::FnType *fntype; bool is_op_overload = ctx->get_tyctx ()->lookup_operator_overload ( @@ -1453,7 +1449,7 @@ CompileExpr::resolve_operator_overload (LangItem::Kind lang_item_type, rust_assert (ok); // apply adjustments for the fn call - tree self = resolve_adjustements (*adjustments, lhs, lhs_expr->get_locus ()); + tree self = resolve_adjustements (*adjustments, lhs, lhs_expr.get_locus ()); std::vector args; args.push_back (self); // adjusted self @@ -1730,7 +1726,7 @@ CompileExpr::visit (HIR::ArrayExpr &expr) const TyTy::ArrayType &array_tyty = static_cast (*tyty); - HIR::ArrayElems &elements = *expr.get_internal_elements (); + HIR::ArrayElems &elements = expr.get_internal_elements (); switch (elements.get_array_expr_type ()) { case HIR::ArrayElems::ArrayExprType::VALUES: { @@ -1759,7 +1755,7 @@ CompileExpr::array_value_expr (location_t expr_locus, size_t i = 0; for (auto &elem : elems.get_values ()) { - tree translated_expr = CompileExpr::Compile (elem.get (), ctx); + tree translated_expr = CompileExpr::Compile (*elem, ctx); constructor.push_back (translated_expr); indexes.push_back (i++); } @@ -1786,8 +1782,7 @@ CompileExpr::array_copied_expr (location_t expr_locus, } ctx->push_const_context (); - tree capacity_expr - = CompileExpr::Compile (elems.get_num_copies_expr ().get (), ctx); + tree capacity_expr = CompileExpr::Compile (elems.get_num_copies_expr (), ctx); ctx->pop_const_context (); if (!TREE_CONSTANT (capacity_expr)) @@ -1797,8 +1792,7 @@ CompileExpr::array_copied_expr (location_t expr_locus, } // get the compiled value - tree translated_expr - = CompileExpr::Compile (elems.get_elem_to_copy ().get (), ctx); + tree translated_expr = CompileExpr::Compile (elems.get_elem_to_copy (), ctx); tree max_domain = TYPE_MAX_VALUE (domain); tree min_domain = TYPE_MIN_VALUE (domain); @@ -2003,8 +1997,8 @@ HIRCompileBase::resolve_unsized_dyn_adjustment ( void CompileExpr::visit (HIR::RangeFromToExpr &expr) { - tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx); - tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx); + tree from = CompileExpr::Compile (expr.get_from_expr (), ctx); + tree to = CompileExpr::Compile (expr.get_to_expr (), ctx); if (from == error_mark_node || to == error_mark_node) { translated = error_mark_node; @@ -2026,7 +2020,7 @@ CompileExpr::visit (HIR::RangeFromToExpr &expr) void CompileExpr::visit (HIR::RangeFromExpr &expr) { - tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx); + tree from = CompileExpr::Compile (expr.get_from_expr (), ctx); if (from == error_mark_node) { translated = error_mark_node; @@ -2048,7 +2042,7 @@ CompileExpr::visit (HIR::RangeFromExpr &expr) void CompileExpr::visit (HIR::RangeToExpr &expr) { - tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx); + tree to = CompileExpr::Compile (expr.get_to_expr (), ctx); if (to == error_mark_node) { translated = error_mark_node; @@ -2083,8 +2077,8 @@ CompileExpr::visit (HIR::RangeFullExpr &expr) void CompileExpr::visit (HIR::RangeFromToInclExpr &expr) { - tree from = CompileExpr::Compile (expr.get_from_expr ().get (), ctx); - tree to = CompileExpr::Compile (expr.get_to_expr ().get (), ctx); + tree from = CompileExpr::Compile (expr.get_from_expr (), ctx); + tree to = CompileExpr::Compile (expr.get_to_expr (), ctx); if (from == error_mark_node || to == error_mark_node) { translated = error_mark_node; @@ -2106,9 +2100,8 @@ CompileExpr::visit (HIR::RangeFromToInclExpr &expr) void CompileExpr::visit (HIR::ArrayIndexExpr &expr) { - tree array_reference - = CompileExpr::Compile (expr.get_array_expr ().get (), ctx); - tree index = CompileExpr::Compile (expr.get_index_expr ().get (), ctx); + tree array_reference = CompileExpr::Compile (expr.get_array_expr (), ctx); + tree index = CompileExpr::Compile (expr.get_index_expr (), ctx); // this might be an core::ops::index lang item situation TyTy::FnType *fntype; @@ -2119,8 +2112,8 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr) auto lang_item_type = LangItem::Kind::INDEX; tree operator_overload_call = resolve_operator_overload (lang_item_type, expr, array_reference, - index, expr.get_array_expr ().get (), - expr.get_index_expr ().get ()); + index, expr.get_array_expr (), + expr.get_index_expr ()); tree actual_type = TREE_TYPE (operator_overload_call); bool can_indirect = TYPE_PTR_P (actual_type) || TYPE_REF_P (actual_type); @@ -2142,7 +2135,7 @@ CompileExpr::visit (HIR::ArrayIndexExpr &expr) // indirection if required TyTy::BaseType *array_expr_ty = nullptr; bool ok = ctx->get_tyctx ()->lookup_type ( - expr.get_array_expr ()->get_mappings ().get_hirid (), &array_expr_ty); + expr.get_array_expr ().get_mappings ().get_hirid (), &array_expr_ty); rust_assert (ok); // do we need to add an indirect reference @@ -2293,7 +2286,7 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, = Backend::struct_field_expression (args_param_expr, i, closure_param.get_locus ()); - CompilePatternBindings::Compile (closure_param.get_pattern ().get (), + CompilePatternBindings::Compile (closure_param.get_pattern (), compiled_param_var, ctx); i++; } @@ -2305,13 +2298,13 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, } // lookup locals - HIR::Expr *function_body = expr.get_expr ().get (); + HIR::Expr &function_body = expr.get_expr (); bool is_block_expr - = function_body->get_expression_type () == HIR::Expr::ExprType::Block; + = function_body.get_expression_type () == HIR::Expr::ExprType::Block; if (is_block_expr) { - auto body_mappings = function_body->get_mappings (); + auto body_mappings = function_body.get_mappings (); if (flag_name_resolution_2_0) { auto nr_ctx @@ -2332,13 +2325,13 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, } tree enclosing_scope = NULL_TREE; - location_t start_location = function_body->get_locus (); - location_t end_location = function_body->get_locus (); + location_t start_location = function_body.get_locus (); + location_t end_location = function_body.get_locus (); if (is_block_expr) { - HIR::BlockExpr *body = static_cast (function_body); - start_location = body->get_locus (); - end_location = body->get_end_locus (); + auto &body = static_cast (function_body); + start_location = body.get_locus (); + end_location = body.get_end_locus (); } tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/, @@ -2363,15 +2356,14 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, if (is_block_expr) { - HIR::BlockExpr *body = static_cast (function_body); - compile_function_body (fndecl, *body, tyret); + auto &body = static_cast (function_body); + compile_function_body (fndecl, body, tyret); } else { tree value = CompileExpr::Compile (function_body, ctx); tree return_expr - = Backend::return_statement (fndecl, value, - function_body->get_locus ()); + = Backend::return_statement (fndecl, value, function_body.get_locus ()); ctx->add_statement (return_expr); } @@ -2458,8 +2450,8 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr, } // need to apply any autoderef's to the self argument - HIR::Expr *fnexpr = expr.get_fnexpr ().get (); - HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid (); + HIR::Expr &fnexpr = expr.get_fnexpr (); + HirId autoderef_mappings_id = fnexpr.get_mappings ().get_hirid (); std::vector *adjustments = nullptr; bool ok = ctx->get_tyctx ()->lookup_autoderef_mappings (autoderef_mappings_id, &adjustments); @@ -2472,7 +2464,7 @@ CompileExpr::generate_possible_fn_trait_call (HIR::CallExpr &expr, std::vector tuple_arg_vals; for (auto &argument : expr.get_arguments ()) { - auto rvalue = CompileExpr::Compile (argument.get (), ctx); + auto rvalue = CompileExpr::Compile (*argument, ctx); tuple_arg_vals.push_back (rvalue); } diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index af2e1bca1ec6..59b919995e3e 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -28,7 +28,7 @@ namespace Compile { class CompileExpr : private HIRCompileBase, protected HIR::HIRExpressionVisitor { public: - static tree Compile (HIR::Expr *expr, Context *ctx); + static tree Compile (HIR::Expr &expr, Context *ctx); void visit (HIR::TupleIndexExpr &expr) override; void visit (HIR::TupleExpr &expr) override; @@ -99,8 +99,8 @@ class CompileExpr : private HIRCompileBase, protected HIR::HIRExpressionVisitor tree resolve_operator_overload (LangItem::Kind lang_item_type, HIR::OperatorExprMeta expr, tree lhs, - tree rhs, HIR::Expr *lhs_expr, - HIR::Expr *rhs_expr); + tree rhs, HIR::Expr &lhs_expr, + tl::optional rhs_expr); tree compile_bool_literal (const HIR::LiteralExpr &expr, const TyTy::BaseType *tyty); diff --git a/gcc/rust/backend/rust-compile-fnparam.cc b/gcc/rust/backend/rust-compile-fnparam.cc index 68066b8463d0..f73e23359252 100644 --- a/gcc/rust/backend/rust-compile-fnparam.cc +++ b/gcc/rust/backend/rust-compile-fnparam.cc @@ -31,20 +31,20 @@ CompileFnParam::CompileFnParam (Context *ctx, tree fndecl, tree decl_type, {} Bvariable * -CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam *param, +CompileFnParam::compile (Context *ctx, tree fndecl, HIR::FunctionParam ¶m, tree decl_type, location_t locus) { CompileFnParam compiler (ctx, fndecl, decl_type, locus); - param->get_param_name ()->accept_vis (compiler); + param.get_param_name ().accept_vis (compiler); return compiler.compiled_param; } Bvariable * -CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern *param, +CompileFnParam::compile (Context *ctx, tree fndecl, HIR::Pattern ¶m, tree decl_type, location_t locus) { CompileFnParam compiler (ctx, fndecl, decl_type, locus); - param->accept_vis (compiler); + param.accept_vis (compiler); return compiler.compiled_param; } @@ -72,21 +72,21 @@ void CompileFnParam::visit (HIR::StructPattern &pattern) { tree tmp_param_var = create_tmp_param_var (decl_type); - CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx); + CompilePatternBindings::Compile (pattern, tmp_param_var, ctx); } void CompileFnParam::visit (HIR::TupleStructPattern &pattern) { tree tmp_param_var = create_tmp_param_var (decl_type); - CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx); + CompilePatternBindings::Compile (pattern, tmp_param_var, ctx); } void CompileFnParam::visit (HIR::ReferencePattern &pattern) { tree tmp_param_var = create_tmp_param_var (decl_type); - CompilePatternBindings::Compile (&pattern, tmp_param_var, ctx); + CompilePatternBindings::Compile (pattern, tmp_param_var, ctx); } Bvariable * diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h index 9b50b1934680..c36f7914f346 100644 --- a/gcc/rust/backend/rust-compile-fnparam.h +++ b/gcc/rust/backend/rust-compile-fnparam.h @@ -29,9 +29,9 @@ class CompileFnParam : private HIRCompileBase, protected HIR::HIRPatternVisitor { public: static Bvariable *compile (Context *ctx, tree fndecl, - HIR::FunctionParam *param, tree decl_type, + HIR::FunctionParam ¶m, tree decl_type, location_t locus); - static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern *param, + static Bvariable *compile (Context *ctx, tree fndecl, HIR::Pattern ¶m, tree decl_type, location_t locus); void visit (HIR::IdentifierPattern &pattern) override; diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc index deac9d20f245..4bf21e5cbc42 100644 --- a/gcc/rust/backend/rust-compile-implitem.cc +++ b/gcc/rust/backend/rust-compile-implitem.cc @@ -30,7 +30,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant) auto canonical_path = ctx->get_mappings ().lookup_canonical_path ( constant.get_mappings ().get_nodeid ()); - HIR::Expr *const_value_expr = constant.get_expr ().get (); + HIR::Expr &const_value_expr = constant.get_expr (); tree const_expr = compile_constant_item (resolved_type, *canonical_path, const_value_expr, constant.get_locus ()); @@ -86,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 (), *canonical_path, fntype); reference = address_expression (fndecl, ref_locus); } diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index bc99ef942631..0ffc3634e130 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -321,7 +321,7 @@ compile_fn_params (Context *ctx, TyTy::FnType *fntype, tree fndecl, location_t param_locus = referenced_param->get_locus (); Bvariable *compiled_param_var - = CompileFnParam::compile (ctx, fndecl, referenced_param, + = CompileFnParam::compile (ctx, fndecl, *referenced_param, compiled_param_type, param_locus); compiled_param_variables->push_back (compiled_param_var); diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index fd928258f4aa..f35689730a67 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -45,7 +45,7 @@ CompileItem::visit (HIR::StaticItem &var) auto canonical_path = ctx->get_mappings ().lookup_canonical_path ( var.get_mappings ().get_nodeid ()); - HIR::Expr *const_value_expr = var.get_expr ().get (); + HIR::Expr &const_value_expr = var.get_expr (); ctx->push_const_context (); tree value = compile_constant_item (resolved_type, *canonical_path, const_value_expr, var.get_locus ()); @@ -105,7 +105,7 @@ CompileItem::visit (HIR::ConstantItem &constant) .value (); } - HIR::Expr *const_value_expr = constant.get_expr ().get (); + HIR::Expr &const_value_expr = constant.get_expr (); ctx->push_const_context (); tree const_expr = compile_constant_item (resolved_type, canonical_path, const_value_expr, @@ -207,8 +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, - fntype); + &function.get_definition (), canonical_path, fntype); reference = address_expression (fndecl, ref_locus); if (function.get_qualifiers ().is_const ()) @@ -220,7 +219,7 @@ CompileItem::visit (HIR::ImplBlock &impl_block) { TyTy::BaseType *self_lookup = nullptr; if (!ctx->get_tyctx ()->lookup_type ( - impl_block.get_type ()->get_mappings ().get_hirid (), &self_lookup)) + impl_block.get_type ().get_mappings ().get_hirid (), &self_lookup)) { rust_error_at (impl_block.get_locus (), "failed to resolve type of impl"); return; diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc index c462a6d7a025..a1d2e68914f6 100644 --- a/gcc/rust/backend/rust-compile-pattern.cc +++ b/gcc/rust/backend/rust-compile-pattern.cc @@ -67,7 +67,7 @@ CompilePatternCheckExpr::visit (HIR::PathInExpression &pattern) // must be enum match_scrutinee_expr = scrutinee_expr_qualifier_expr; - HIR::Expr *discrim_expr = variant->get_discriminant (); + HIR::Expr &discrim_expr = variant->get_discriminant (); tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); check_expr @@ -80,10 +80,9 @@ void CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern) { // Compile the literal - HIR::LiteralExpr *litexpr - = new HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (), - pattern.get_locus (), - std::vector ()); + auto litexpr = Rust::make_unique ( + HIR::LiteralExpr (pattern.get_mappings (), pattern.get_literal (), + pattern.get_locus (), std::vector ())); // Note: Floating point literals are currently accepted but will likely be // forbidden in LiteralPatterns in a future version of Rust. @@ -95,7 +94,7 @@ CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern) rust_sorry_at (pattern.get_locus (), "floating-point literal in pattern"); } - tree lit = CompileExpr::Compile (litexpr, ctx); + tree lit = CompileExpr::Compile (*litexpr, ctx); check_expr = Backend::comparison_expression (ComparisonOperator::EQUAL, match_scrutinee_expr, lit, @@ -103,19 +102,17 @@ CompilePatternCheckExpr::visit (HIR::LiteralPattern &pattern) } static tree -compile_range_pattern_bound (HIR::RangePatternBound *bound, +compile_range_pattern_bound (HIR::RangePatternBound &bound, Analysis::NodeMapping mappings, location_t locus, Context *ctx) { tree result = NULL_TREE; - switch (bound->get_bound_type ()) + switch (bound.get_bound_type ()) { case HIR::RangePatternBound::RangePatternBoundType::LITERAL: { - HIR::RangePatternBoundLiteral &ref - = *static_cast (bound); + auto &ref = static_cast (bound); - HIR::LiteralExpr *litexpr - = new HIR::LiteralExpr (mappings, ref.get_literal (), locus, + HIR::LiteralExpr litexpr (mappings, ref.get_literal (), locus, std::vector ()); result = CompileExpr::Compile (litexpr, ctx); @@ -123,8 +120,7 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound, break; case HIR::RangePatternBound::RangePatternBoundType::PATH: { - HIR::RangePatternBoundPath &ref - = *static_cast (bound); + auto &ref = static_cast (bound); result = ResolvePathRef::Compile (ref.get_path (), ctx); @@ -134,8 +130,7 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound, break; case HIR::RangePatternBound::RangePatternBoundType::QUALPATH: { - HIR::RangePatternBoundQualPath &ref - = *static_cast (bound); + auto &ref = static_cast (bound); result = ResolvePathRef::Compile (ref.get_qualified_path (), ctx); @@ -150,10 +145,10 @@ compile_range_pattern_bound (HIR::RangePatternBound *bound, void CompilePatternCheckExpr::visit (HIR::RangePattern &pattern) { - tree upper = compile_range_pattern_bound (pattern.get_upper_bound ().get (), + tree upper = compile_range_pattern_bound (pattern.get_upper_bound (), pattern.get_mappings (), pattern.get_locus (), ctx); - tree lower = compile_range_pattern_bound (pattern.get_lower_bound ().get (), + tree lower = compile_range_pattern_bound (pattern.get_lower_bound (), pattern.get_mappings (), pattern.get_locus (), ctx); @@ -175,7 +170,7 @@ CompilePatternCheckExpr::visit (HIR::ReferencePattern &pattern) { match_scrutinee_expr = indirect_expression (match_scrutinee_expr, pattern.get_locus ()); - pattern.get_referenced_pattern ()->accept_vis (*this); + pattern.get_referenced_pattern ().accept_vis (*this); } void @@ -183,14 +178,13 @@ CompilePatternCheckExpr::visit (HIR::AltPattern &pattern) { auto &alts = pattern.get_alts (); - check_expr = CompilePatternCheckExpr::Compile (alts.at (0).get (), + check_expr = CompilePatternCheckExpr::Compile (*alts.at (0), match_scrutinee_expr, ctx); auto end = alts.end (); for (auto i = alts.begin () + 1; i != end; i++) { tree next_expr - = CompilePatternCheckExpr::Compile (i->get (), match_scrutinee_expr, - ctx); + = CompilePatternCheckExpr::Compile (**i, match_scrutinee_expr, ctx); check_expr = Backend::arithmetic_or_logical_expression ( ArithmeticOrLogicalOperator::BITWISE_OR, check_expr, next_expr, (*i)->get_locus ()); @@ -229,7 +223,7 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern) // // would be DECL_QUALIFIER i think. For now this will just access the // // first record field and its respective qualifier because it will // // always be set because this is all a big special union - HIR::Expr *discrim_expr = variant->get_discriminant (); + HIR::Expr &discrim_expr = variant->get_discriminant (); tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); // find discriminant field of scrutinee @@ -282,11 +276,11 @@ CompilePatternCheckExpr::visit (HIR::StructPattern &pattern) ident.get_locus ()); tree check_expr_sub - = CompilePatternCheckExpr::Compile (ident.get_pattern ().get (), + = CompilePatternCheckExpr::Compile (ident.get_pattern (), field_expr, ctx); check_expr = Backend::arithmetic_or_logical_expression ( ArithmeticOrLogicalOperator::BITWISE_AND, check_expr, - check_expr_sub, ident.get_pattern ()->get_locus ()); + check_expr_sub, ident.get_pattern ().get_locus ()); } break; @@ -328,7 +322,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern) rust_assert (ok); // find expected discriminant - HIR::Expr *discrim_expr = variant->get_discriminant (); + HIR::Expr &discrim_expr = variant->get_discriminant (); tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); // find discriminant field of scrutinee @@ -357,8 +351,8 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern) tuple_field_index = 0; } - std::unique_ptr &items = pattern.get_items (); - switch (items->get_item_type ()) + HIR::TupleStructItems &items = pattern.get_items (); + switch (items.get_item_type ()) { case HIR::TupleStructItems::RANGED: { // TODO @@ -368,7 +362,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern) case HIR::TupleStructItems::MULTIPLE: { HIR::TupleStructItemsNoRange &items_no_range - = static_cast (*items.get ()); + = static_cast (items); rust_assert (items_no_range.get_patterns ().size () == variant->num_fields ()); @@ -381,8 +375,7 @@ CompilePatternCheckExpr::visit (HIR::TupleStructPattern &pattern) pattern->get_locus ()); tree check_expr_sub - = CompilePatternCheckExpr::Compile (pattern.get (), field_expr, - ctx); + = CompilePatternCheckExpr::Compile (*pattern, field_expr, ctx); check_expr = Backend::arithmetic_or_logical_expression ( ArithmeticOrLogicalOperator::BITWISE_AND, check_expr, check_expr_sub, pattern->get_locus ()); @@ -397,7 +390,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern) { check_expr = boolean_true_node; - switch (pattern.get_items ()->get_item_type ()) + switch (pattern.get_items ().get_item_type ()) { case HIR::TuplePatternItems::RANGED: { // TODO @@ -407,7 +400,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern) case HIR::TuplePatternItems::MULTIPLE: { auto &items = static_cast ( - *pattern.get_items ()); + pattern.get_items ()); size_t tuple_field_index = 0; for (auto &pat : items.get_patterns ()) @@ -418,7 +411,7 @@ CompilePatternCheckExpr::visit (HIR::TuplePattern &pattern) pat->get_locus ()); tree check_expr_sub - = CompilePatternCheckExpr::Compile (pat.get (), field_expr, ctx); + = CompilePatternCheckExpr::Compile (*pat, field_expr, ctx); check_expr = Backend::arithmetic_or_logical_expression ( ArithmeticOrLogicalOperator::BITWISE_AND, check_expr, check_expr_sub, pat->get_locus ()); @@ -459,8 +452,8 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern) rust_assert (variant->get_variant_type () == TyTy::VariantDef::VariantType::TUPLE); - std::unique_ptr &items = pattern.get_items (); - switch (items->get_item_type ()) + HIR::TupleStructItems &items = pattern.get_items (); + switch (items.get_item_type ()) { case HIR::TupleStructItems::RANGED: { // TODO @@ -470,7 +463,7 @@ CompilePatternBindings::visit (HIR::TupleStructPattern &pattern) case HIR::TupleStructItems::MULTIPLE: { HIR::TupleStructItemsNoRange &items_no_range - = static_cast (*items.get ()); + = static_cast (items); rust_assert (items_no_range.get_patterns ().size () == variant->num_fields ()); @@ -609,8 +602,8 @@ CompilePatternBindings::visit (HIR::ReferencePattern &pattern) tree derefed = indirect_expression (match_scrutinee_expr, pattern.get_locus ()); - CompilePatternBindings::Compile (pattern.get_referenced_pattern ().get (), - derefed, ctx); + CompilePatternBindings::Compile (pattern.get_referenced_pattern (), derefed, + ctx); } void @@ -670,12 +663,12 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern) tree access_expr = Backend::var_expression (tmp_var, pattern.get_locus ()); ctx->add_statement (init_stmt); - switch (pattern.get_items ()->get_item_type ()) + switch (pattern.get_items ().get_item_type ()) { case HIR::TuplePatternItems::ItemType::RANGED: { size_t tuple_idx = 0; auto &items - = static_cast (*pattern.get_items ()); + = static_cast (pattern.get_items ()); auto &items_lower = items.get_lower_patterns (); auto &items_upper = items.get_upper_patterns (); @@ -719,7 +712,7 @@ CompilePatternLet::visit (HIR::TuplePattern &pattern) case HIR::TuplePatternItems::ItemType::MULTIPLE: { size_t tuple_idx = 0; auto &items = static_cast ( - *pattern.get_items ()); + pattern.get_items ()); for (auto &sub : items.get_patterns ()) { diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h index 17c82fa30501..01fd0973e47a 100644 --- a/gcc/rust/backend/rust-compile-pattern.h +++ b/gcc/rust/backend/rust-compile-pattern.h @@ -26,11 +26,11 @@ class CompilePatternCheckExpr : public HIRCompileBase, public HIR::HIRPatternVisitor { public: - static tree Compile (HIR::Pattern *pattern, tree match_scrutinee_expr, + static tree Compile (HIR::Pattern &pattern, tree match_scrutinee_expr, Context *ctx) { CompilePatternCheckExpr compiler (ctx, match_scrutinee_expr); - pattern->accept_vis (compiler); + pattern.accept_vis (compiler); rust_assert (compiler.check_expr); return compiler.check_expr; } @@ -71,11 +71,11 @@ class CompilePatternBindings : public HIRCompileBase, public HIR::HIRPatternVisitor { public: - static void Compile (HIR::Pattern *pattern, tree match_scrutinee_expr, + static void Compile (HIR::Pattern &pattern, tree match_scrutinee_expr, Context *ctx) { CompilePatternBindings compiler (ctx, match_scrutinee_expr); - pattern->accept_vis (compiler); + pattern.accept_vis (compiler); } void visit (HIR::StructPattern &pattern) override; diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 58d9e8e3b100..5f6ba7cce433 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -81,7 +81,7 @@ ResolvePathRef::attempt_constructor_expression_lookup ( tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt); // make the ctor for the union - HIR::Expr *discrim_expr = variant->get_discriminant (); + HIR::Expr &discrim_expr = variant->get_discriminant (); tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); tree folded_discrim_expr = fold_expr (discrim_expr_node); tree qualifier = folded_discrim_expr; @@ -301,7 +301,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, TyTy::BaseType *self = nullptr; bool ok = ctx->get_tyctx ()->lookup_type ( - impl->get_type ()->get_mappings ().get_hirid (), &self); + impl->get_type ().get_mappings ().get_hirid (), &self); rust_assert (ok); if (!lookup->has_substitutions_defined ()) diff --git a/gcc/rust/backend/rust-compile-stmt.cc b/gcc/rust/backend/rust-compile-stmt.cc index e7ba370eb8e0..023c2c895a77 100644 --- a/gcc/rust/backend/rust-compile-stmt.cc +++ b/gcc/rust/backend/rust-compile-stmt.cc @@ -40,13 +40,13 @@ CompileStmt::Compile (HIR::Stmt *stmt, Context *ctx) void CompileStmt::visit (HIR::ExprStmt &stmt) { - translated = CompileExpr::Compile (stmt.get_expr ().get (), ctx); + translated = CompileExpr::Compile (stmt.get_expr (), ctx); } void CompileStmt::visit (HIR::LetStmt &stmt) { - HIR::Pattern &stmt_pattern = *stmt.get_pattern (); + HIR::Pattern &stmt_pattern = stmt.get_pattern (); HirId stmt_id = stmt_pattern.get_mappings ().get_hirid (); TyTy::BaseType *ty = nullptr; @@ -68,7 +68,7 @@ CompileStmt::visit (HIR::LetStmt &stmt) if (!stmt.has_init_expr ()) return; - tree init = CompileExpr::Compile (stmt.get_init_expr ().get (), ctx); + tree init = CompileExpr::Compile (stmt.get_init_expr (), ctx); // FIXME use error_mark_node, check that CompileExpr returns error_mark_node // on failure and make this an assertion if (init == nullptr) @@ -76,11 +76,11 @@ CompileStmt::visit (HIR::LetStmt &stmt) TyTy::BaseType *actual = nullptr; bool ok = ctx->get_tyctx ()->lookup_type ( - stmt.get_init_expr ()->get_mappings ().get_hirid (), &actual); + stmt.get_init_expr ().get_mappings ().get_hirid (), &actual); rust_assert (ok); - location_t lvalue_locus = stmt.get_pattern ()->get_locus (); - location_t rvalue_locus = stmt.get_init_expr ()->get_locus (); + location_t lvalue_locus = stmt.get_pattern ().get_locus (); + location_t rvalue_locus = stmt.get_init_expr ().get_locus (); TyTy::BaseType *expected = ty; init = coercion_site (stmt.get_mappings ().get_hirid (), init, actual, expected, lvalue_locus, rvalue_locus); diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.cc b/gcc/rust/backend/rust-compile-struct-field-expr.cc index d642e28a2021..e10ea57c285c 100644 --- a/gcc/rust/backend/rust-compile-struct-field-expr.cc +++ b/gcc/rust/backend/rust-compile-struct-field-expr.cc @@ -27,22 +27,22 @@ CompileStructExprField::CompileStructExprField (Context *ctx) {} tree -CompileStructExprField::Compile (HIR::StructExprField *field, Context *ctx) +CompileStructExprField::Compile (HIR::StructExprField &field, Context *ctx) { CompileStructExprField compiler (ctx); - switch (field->get_kind ()) + switch (field.get_kind ()) { case HIR::StructExprField::StructExprFieldKind::IDENTIFIER: - compiler.visit (static_cast (*field)); + compiler.visit (static_cast (field)); break; case HIR::StructExprField::StructExprFieldKind::IDENTIFIER_VALUE: compiler.visit ( - static_cast (*field)); + static_cast (field)); break; case HIR::StructExprField::StructExprFieldKind::INDEX_VALUE: - compiler.visit (static_cast (*field)); + compiler.visit (static_cast (field)); break; } return compiler.translated; @@ -51,13 +51,13 @@ CompileStructExprField::Compile (HIR::StructExprField *field, Context *ctx) void CompileStructExprField::visit (HIR::StructExprFieldIdentifierValue &field) { - translated = CompileExpr::Compile (field.get_value ().get (), ctx); + translated = CompileExpr::Compile (field.get_value (), ctx); } void CompileStructExprField::visit (HIR::StructExprFieldIndexValue &field) { - translated = CompileExpr::Compile (field.get_value ().get (), ctx); + translated = CompileExpr::Compile (field.get_value (), ctx); } void @@ -74,7 +74,7 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field) HIR::GenericArgs::create_empty ()); HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false, {}); - translated = CompileExpr::Compile (&expr, ctx); + translated = CompileExpr::Compile (expr, ctx); } } // namespace Compile diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.h b/gcc/rust/backend/rust-compile-struct-field-expr.h index 1ee4d1b15939..af1f3676e1bf 100644 --- a/gcc/rust/backend/rust-compile-struct-field-expr.h +++ b/gcc/rust/backend/rust-compile-struct-field-expr.h @@ -27,7 +27,7 @@ namespace Compile { class CompileStructExprField : private HIRCompileBase { public: - static tree Compile (HIR::StructExprField *field, Context *ctx); + static tree Compile (HIR::StructExprField &field, Context *ctx); protected: void visit (HIR::StructExprFieldIdentifierValue &field); diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index c8fe1cd9d629..e01335247143 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -428,7 +428,7 @@ TyTyResolveCompile::visit (const TyTy::ArrayType &type) = TyTyResolveCompile::compile (ctx, type.get_element_type ()); ctx->push_const_context (); - tree capacity_expr = CompileExpr::Compile (&type.get_capacity_expr (), ctx); + tree capacity_expr = CompileExpr::Compile (type.get_capacity_expr (), ctx); ctx->pop_const_context (); tree folded_capacity_expr = fold_expr (capacity_expr); diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h index 45ca01d4f709..eda233599f6f 100644 --- a/gcc/rust/backend/rust-compile-var-decl.h +++ b/gcc/rust/backend/rust-compile-var-decl.h @@ -68,12 +68,12 @@ class CompileVarDecl : public HIRCompileBase, public HIR::HIRPatternVisitor void visit (HIR::TuplePattern &pattern) override { - switch (pattern.get_items ()->get_item_type ()) + switch (pattern.get_items ().get_item_type ()) { case HIR::TuplePatternItems::ItemType::MULTIPLE: { rust_assert (TREE_CODE (translated_type) == RECORD_TYPE); auto &items = static_cast ( - *pattern.get_items ()); + pattern.get_items ()); size_t offs = 0; for (auto &sub : items.get_patterns ()) diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 82313a55e7ae..dea4a1db315a 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -286,11 +286,10 @@ HIRCompileBase::compute_address_for_trait_item ( rust_assert (associated_impl_block != nullptr); // lookup self for the associated impl - std::unique_ptr &self_type_path - = associated_impl_block->get_type (); + auto &self_type_path = associated_impl_block->get_type (); TyTy::BaseType *self = nullptr; bool ok = ctx->get_tyctx ()->lookup_type ( - self_type_path->get_mappings ().get_hirid (), &self); + self_type_path.get_mappings ().get_hirid (), &self); rust_assert (ok); // lookup the predicate item from the self diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc index 685236b2da49..ee6ae8c8e5a9 100644 --- a/gcc/rust/backend/rust-mangle-v0.cc +++ b/gcc/rust/backend/rust-mangle-v0.cc @@ -328,7 +328,7 @@ v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx, // lookup impl type TyTy::BaseType *impl_ty = nullptr; ok = ctx->get_tyctx ()->lookup_type ( - impl_block->get_type ()->get_mappings ().get_hirid (), &impl_ty); + impl_block->get_type ().get_mappings ().get_hirid (), &impl_ty); rust_assert (ok); // FIXME: dummy value for now @@ -342,7 +342,7 @@ v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx, TyTy::BaseType *trait_ty = nullptr; ok = ctx->get_tyctx ()->lookup_type ( - impl_block->get_trait_ref ()->get_mappings ().get_hirid (), &trait_ty); + impl_block->get_trait_ref ().get_mappings ().get_hirid (), &trait_ty); rust_assert (ok); v0path.trait_type = v0_type_prefix (ctx, trait_ty); diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc index 81fa2ea7b043..8459aee76b6b 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-expr-stmt.cc @@ -118,7 +118,7 @@ ExprStmtBuilder::visit (HIR::LiteralExpr &expr) void ExprStmtBuilder::visit (HIR::BorrowExpr &expr) { - auto operand = visit_expr (*expr.get_expr ()); + auto operand = visit_expr (expr.get_expr ()); if (ctx.place_db[operand].is_constant ()) { // Cannot borrow a constant, must create a temporary copy. @@ -133,7 +133,7 @@ ExprStmtBuilder::visit (HIR::BorrowExpr &expr) void ExprStmtBuilder::visit (HIR::DereferenceExpr &expr) { - auto operand = visit_expr (*expr.get_expr ()); + auto operand = visit_expr (expr.get_expr ()); return_place (ctx.place_db.lookup_or_add_path (Place::DEREF, lookup_type (expr), operand)); } @@ -148,15 +148,15 @@ ExprStmtBuilder::visit (HIR::ErrorPropagationExpr &expr) void ExprStmtBuilder::visit (HIR::NegationExpr &expr) { - PlaceId operand = visit_expr (*expr.get_expr ()); + PlaceId operand = visit_expr (expr.get_expr ()); return_expr (new Operator<1> ({move_place (operand)}), lookup_type (expr)); } void ExprStmtBuilder::visit (HIR::ArithmeticOrLogicalExpr &expr) { - PlaceId lhs = visit_expr (*expr.get_lhs ()); - PlaceId rhs = visit_expr (*expr.get_rhs ()); + PlaceId lhs = visit_expr (expr.get_lhs ()); + PlaceId rhs = visit_expr (expr.get_rhs ()); return_expr (new Operator<2> ({move_place (lhs), move_place (rhs)}), lookup_type (expr)); } @@ -164,8 +164,8 @@ ExprStmtBuilder::visit (HIR::ArithmeticOrLogicalExpr &expr) void ExprStmtBuilder::visit (HIR::ComparisonExpr &expr) { - PlaceId lhs = visit_expr (*expr.get_lhs ()); - PlaceId rhs = visit_expr (*expr.get_rhs ()); + PlaceId lhs = visit_expr (expr.get_lhs ()); + PlaceId rhs = visit_expr (expr.get_rhs ()); return_expr (new Operator<2> ({move_place (lhs), move_place (rhs)}), lookup_type (expr)); } @@ -181,15 +181,15 @@ ExprStmtBuilder::visit (HIR::LazyBooleanExpr &expr) void ExprStmtBuilder::visit (HIR::TypeCastExpr &expr) { - auto operand = visit_expr (*expr.get_expr ()); + auto operand = visit_expr (expr.get_expr ()); return_expr (new Operator<1> ({operand}), lookup_type (expr)); } void ExprStmtBuilder::visit (HIR::AssignmentExpr &expr) { - auto lhs = visit_expr (*expr.get_lhs ()); - auto rhs = visit_expr (*expr.get_rhs ()); + auto lhs = visit_expr (expr.get_lhs ()); + auto rhs = visit_expr (expr.get_rhs ()); push_assignment (lhs, rhs); translated = INVALID_PLACE; } @@ -197,25 +197,25 @@ ExprStmtBuilder::visit (HIR::AssignmentExpr &expr) void ExprStmtBuilder::visit (HIR::CompoundAssignmentExpr &expr) { - auto lhs = visit_expr (*expr.get_lhs ()); - auto rhs = visit_expr (*expr.get_rhs ()); + auto lhs = visit_expr (expr.get_lhs ()); + auto rhs = visit_expr (expr.get_rhs ()); push_assignment (lhs, new Operator<2> ({lhs, rhs})); } void ExprStmtBuilder::visit (HIR::GroupedExpr &expr) { - return_place (visit_expr (*expr.get_expr_in_parens ())); + return_place (visit_expr (expr.get_expr_in_parens ())); } void ExprStmtBuilder::visit (HIR::ArrayExpr &expr) { auto &elems = expr.get_internal_elements (); - switch (elems->get_array_expr_type ()) + switch (elems.get_array_expr_type ()) { case HIR::ArrayElems::VALUES: { - auto &elem_vals = (static_cast (*elems)); + auto &elem_vals = (static_cast (elems)); auto init_values = visit_list (elem_vals.get_values ()); move_all (init_values); return_expr (new InitializerExpr (std::move (init_values)), @@ -223,8 +223,8 @@ ExprStmtBuilder::visit (HIR::ArrayExpr &expr) break; } case HIR::ArrayElems::COPIED: { - auto &elem_copied = (static_cast (*elems)); - auto init = visit_expr (*elem_copied.get_elem_to_copy ()); + auto &elem_copied = (static_cast (elems)); + auto init = visit_expr (elem_copied.get_elem_to_copy ()); return_expr (new InitializerExpr ({init}), lookup_type (expr)); break; } @@ -234,8 +234,8 @@ ExprStmtBuilder::visit (HIR::ArrayExpr &expr) void ExprStmtBuilder::visit (HIR::ArrayIndexExpr &expr) { - auto lhs = visit_expr (*expr.get_array_expr ()); - auto rhs = visit_expr (*expr.get_index_expr ()); + auto lhs = visit_expr (expr.get_array_expr ()); + auto rhs = visit_expr (expr.get_index_expr ()); // The index is not tracked in BIR. std::ignore = rhs; return_place ( @@ -253,7 +253,7 @@ ExprStmtBuilder::visit (HIR::TupleExpr &expr) void ExprStmtBuilder::visit (HIR::TupleIndexExpr &expr) { - auto tuple = visit_expr (*expr.get_tuple_expr ()); + auto tuple = visit_expr (expr.get_tuple_expr ()); return_place (ctx.place_db.lookup_or_add_path (Place::FIELD, lookup_type (expr), tuple, expr.get_tuple_index ())); @@ -262,7 +262,7 @@ ExprStmtBuilder::visit (HIR::TupleIndexExpr &expr) void ExprStmtBuilder::visit (HIR::CallExpr &expr) { - PlaceId fn = visit_expr (*expr.get_fnexpr ()); + PlaceId fn = visit_expr (expr.get_fnexpr ()); std::vector arguments = visit_list (expr.get_arguments ()); const auto fn_type @@ -286,7 +286,7 @@ ExprStmtBuilder::visit (HIR::MethodCallExpr &expr) void ExprStmtBuilder::visit (HIR::FieldAccessExpr &expr) { - auto receiver = visit_expr (*expr.get_receiver_expr ()); + auto receiver = visit_expr (expr.get_receiver_expr ()); auto type = autoderef (receiver); rust_assert (type->get_kind () == TyTy::ADT); auto adt = type->as (); @@ -338,7 +338,7 @@ ExprStmtBuilder::visit (HIR::BlockExpr &block) if (block.has_expr () && !unreachable) { push_assignment (block_ctx.label_var, - visit_expr (*block.get_final_expr ())); + visit_expr (block.get_final_expr ())); } if (!ctx.get_current_bb ().is_terminated ()) { @@ -351,9 +351,9 @@ ExprStmtBuilder::visit (HIR::BlockExpr &block) } else if (block.has_expr () && !unreachable) { - return_place (visit_expr (*block.get_final_expr (), + return_place (visit_expr (block.get_final_expr (), take_or_create_return_place ( - lookup_type (*block.get_final_expr ())))); + lookup_type (block.get_final_expr ())))); } if (!unreachable) @@ -379,7 +379,7 @@ ExprStmtBuilder::visit (HIR::BreakExpr &brk) LoopAndLabelCtx info = brk.has_label () ? get_label_ctx (brk.get_label ()) : get_unnamed_loop_ctx (); if (brk.has_break_expr ()) - push_assignment (info.label_var, visit_expr (*brk.get_expr ())); + push_assignment (info.label_var, visit_expr (brk.get_expr ())); start_new_consecutive_bb (); unwind_until (ctx.place_db.get_scope (info.continue_scope).parent); @@ -390,22 +390,22 @@ ExprStmtBuilder::visit (HIR::BreakExpr &brk) void ExprStmtBuilder::visit (HIR::RangeFromToExpr &range) { - auto from = visit_expr (*range.get_from_expr ()); - auto to = visit_expr (*range.get_to_expr ()); + auto from = visit_expr (range.get_from_expr ()); + auto to = visit_expr (range.get_to_expr ()); return_expr (new InitializerExpr ({from, to}), lookup_type (range)); } void ExprStmtBuilder::visit (HIR::RangeFromExpr &expr) { - auto from = visit_expr (*expr.get_from_expr ()); + auto from = visit_expr (expr.get_from_expr ()); return_expr (new InitializerExpr ({from}), lookup_type (expr)); } void ExprStmtBuilder::visit (HIR::RangeToExpr &expr) { - auto to = visit_expr (*expr.get_to_expr ()); + auto to = visit_expr (expr.get_to_expr ()); return_expr (new InitializerExpr ({to}), lookup_type (expr)); } @@ -418,15 +418,15 @@ ExprStmtBuilder::visit (HIR::RangeFullExpr &expr) void ExprStmtBuilder::visit (HIR::RangeFromToInclExpr &expr) { - auto from = visit_expr (*expr.get_from_expr ()); - auto to = visit_expr (*expr.get_to_expr ()); + auto from = visit_expr (expr.get_from_expr ()); + auto to = visit_expr (expr.get_to_expr ()); return_expr (new InitializerExpr ({from, to}), lookup_type (expr)); } void ExprStmtBuilder::visit (HIR::RangeToInclExpr &expr) { - auto to = visit_expr (*expr.get_to_expr ()); + auto to = visit_expr (expr.get_to_expr ()); return_expr (new InitializerExpr ({to}), lookup_type (expr)); } @@ -436,7 +436,7 @@ ExprStmtBuilder::visit (HIR::ReturnExpr &ret) if (ret.has_return_expr ()) { push_assignment (RETURN_VALUE_PLACE, - move_place (visit_expr (*ret.get_expr ()))); + move_place (visit_expr (ret.get_expr ()))); } unwind_until (ROOT_SCOPE); ctx.get_current_bb ().statements.emplace_back (Statement::Kind::RETURN); @@ -454,7 +454,7 @@ ExprStmtBuilder::visit (HIR::LoopExpr &expr) { auto loop = setup_loop (expr); - std::ignore = visit_expr (*expr.get_loop_block ()); + std::ignore = visit_expr (expr.get_loop_block ()); if (!ctx.get_current_bb ().is_terminated ()) push_goto (loop.continue_bb); @@ -466,12 +466,12 @@ ExprStmtBuilder::visit (HIR::WhileLoopExpr &expr) { auto loop = setup_loop (expr); - auto cond_val = visit_expr (*expr.get_predicate_expr ()); + auto cond_val = visit_expr (expr.get_predicate_expr ()); auto body_bb = new_bb (); push_switch (cond_val, {body_bb, loop.break_bb}); ctx.current_bb = body_bb; - std::ignore = visit_expr (*expr.get_loop_block ()); + std::ignore = visit_expr (expr.get_loop_block ()); push_goto (loop.continue_bb); ctx.current_bb = loop.break_bb; @@ -489,15 +489,15 @@ ExprStmtBuilder::visit (HIR::IfExpr &expr) { // If without else cannot return a non-unit value (see [E0317]). - if (expr.get_if_block ()->statements.empty ()) + if (expr.get_if_block ().statements.empty ()) return; - push_switch (visit_expr (*expr.get_if_condition ())); + push_switch (visit_expr (expr.get_if_condition ())); BasicBlockId if_block = ctx.current_bb; ctx.current_bb = new_bb (); BasicBlockId then_start_block = ctx.current_bb; - std::ignore = visit_expr (*expr.get_if_block ()); + std::ignore = visit_expr (expr.get_if_block ()); if (!ctx.get_current_bb ().is_terminated ()) push_goto (INVALID_BB); // Resolved later. BasicBlockId then_end_block = ctx.current_bb; @@ -518,21 +518,21 @@ ExprStmtBuilder::visit (HIR::IfExpr &expr) void ExprStmtBuilder::visit (HIR::IfExprConseqElse &expr) { - push_switch (move_place (visit_expr (*expr.get_if_condition ()))); + push_switch (move_place (visit_expr (expr.get_if_condition ()))); BasicBlockId if_end_bb = ctx.current_bb; PlaceId result = take_or_create_return_place (lookup_type (expr)); ctx.current_bb = new_bb (); BasicBlockId then_start_bb = ctx.current_bb; - std::ignore = visit_expr (*expr.get_if_block (), result); + std::ignore = visit_expr (expr.get_if_block (), result); if (!ctx.get_current_bb ().is_terminated ()) push_goto (INVALID_BB); // Resolved later. BasicBlockId then_end_bb = ctx.current_bb; ctx.current_bb = new_bb (); BasicBlockId else_start_bb = ctx.current_bb; - std::ignore = visit_expr (*expr.get_else_block (), result); + std::ignore = visit_expr (expr.get_else_block (), result); if (!ctx.get_current_bb ().is_terminated ()) push_goto (INVALID_BB); // Resolved later. BasicBlockId else_end_bb = ctx.current_bb; @@ -645,35 +645,35 @@ ExprStmtBuilder::visit (HIR::LetStmt &stmt) tl::optional type_annotation; if (stmt.has_type ()) - type_annotation = lookup_type (*stmt.get_type ()); + type_annotation = lookup_type (stmt.get_type ()); - if (stmt.get_pattern ()->get_pattern_type () == HIR::Pattern::IDENTIFIER) + if (stmt.get_pattern ().get_pattern_type () == HIR::Pattern::IDENTIFIER) { // Only if a pattern is just an identifier, no destructuring is needed. // Hoverer PatternBindingBuilder cannot change existing temporary // (init expr is evaluated before pattern binding) into a // variable, so it would emit extra assignment. - auto var = declare_variable (stmt.get_pattern ()->get_mappings ()); + auto var = declare_variable (stmt.get_pattern ().get_mappings ()); if (stmt.has_type ()) - push_user_type_ascription (var, lookup_type (*stmt.get_type ())); + push_user_type_ascription (var, lookup_type (stmt.get_type ())); if (stmt.has_init_expr ()) - std::ignore = visit_expr (*stmt.get_init_expr (), var); + std::ignore = visit_expr (stmt.get_init_expr (), var); } else { if (stmt.has_init_expr ()) - init = visit_expr (*stmt.get_init_expr ()); + init = visit_expr (stmt.get_init_expr ()); PatternBindingBuilder (ctx, init, type_annotation) - .go (*stmt.get_pattern ()); + .go (stmt.get_pattern ()); } } void ExprStmtBuilder::visit (HIR::ExprStmt &stmt) { - PlaceId result = visit_expr (*stmt.get_expr ()); + PlaceId result = visit_expr (stmt.get_expr ()); // We must read the value for current liveness and we must not store it into // the same place. if (result != INVALID_PLACE) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h index 1cc55569c7ca..1c72a7a6f2df 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h @@ -61,15 +61,15 @@ class LazyBooleanExprBuilder : public AbstractExprBuilder protected: void visit (HIR::LazyBooleanExpr &expr) override { - auto lhs = visit_expr (*expr.get_lhs ()); + auto lhs = visit_expr (expr.get_lhs ()); push_switch (move_place (lhs), {short_circuit_bb}); start_new_consecutive_bb (); - return_place (visit_expr (*expr.get_rhs ())); + return_place (visit_expr (expr.get_rhs ())); } void visit (HIR::GroupedExpr &expr) override { - expr.get_expr_in_parens ()->accept_vis (*this); + expr.get_expr_in_parens ().accept_vis (*this); } protected: diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h index 8b5adabcb6e2..08473479bde2 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-pattern.h @@ -107,7 +107,7 @@ class PatternBindingBuilder : protected AbstractBuilder, return ty->as ()->get_base (); }); - pattern.get_referenced_pattern ()->accept_vis (*this); + pattern.get_referenced_pattern ().accept_vis (*this); } void visit (HIR::SlicePattern &pattern) override @@ -161,7 +161,7 @@ class PatternBindingBuilder : protected AbstractBuilder, init = init.map ([&] (PlaceId id) { return ctx.place_db.lookup_or_add_path ( - Place::FIELD, lookup_type (*tuple->get_tuple_pattern ()), id, + Place::FIELD, lookup_type (tuple->get_tuple_pattern ()), id, tuple->get_index ()); }); @@ -174,7 +174,7 @@ class PatternBindingBuilder : protected AbstractBuilder, ->get_field_type (); }); - tuple->get_tuple_pattern ()->accept_vis (*this); + tuple->get_tuple_pattern ().accept_vis (*this); break; } case HIR::StructPatternField::IDENT_PAT: { @@ -191,7 +191,7 @@ class PatternBindingBuilder : protected AbstractBuilder, field_ty->get_field_type (), saved.init.value (), field_index); - ident_field->get_pattern ()->accept_vis (*this); + ident_field->get_pattern ().accept_vis (*this); break; } case HIR::StructPatternField::IDENT: { @@ -253,17 +253,17 @@ class PatternBindingBuilder : protected AbstractBuilder, SavedState saved (this); size_t index = 0; - switch (pattern.get_items ()->get_item_type ()) + switch (pattern.get_items ().get_item_type ()) { case HIR::TuplePatternItems::MULTIPLE: { auto &items = static_cast ( - *pattern.get_items ()); + pattern.get_items ()); visit_tuple_fields (items.get_patterns (), saved, index); break; } case HIR::TuplePatternItems::RANGED: { auto &items = static_cast ( - *pattern.get_items ()); + pattern.get_items ()); auto tyty = ctx.place_db[init.value ()].tyty; rust_assert (tyty->get_kind () == TyTy::TUPLE); @@ -297,11 +297,11 @@ class PatternBindingBuilder : protected AbstractBuilder, }); size_t index = 0; - switch (pattern.get_items ()->get_item_type ()) + switch (pattern.get_items ().get_item_type ()) { case HIR::TupleStructItems::RANGED: { auto &items - = static_cast (*pattern.get_items ()); + = static_cast (pattern.get_items ()); rust_assert (type->get_kind () == TyTy::ADT); auto adt_ty = static_cast (type); @@ -318,7 +318,7 @@ class PatternBindingBuilder : protected AbstractBuilder, } case HIR::TupleStructItems::MULTIPLE: { auto &items = static_cast ( - *pattern.get_items ()); + pattern.get_items ()); visit_tuple_fields (items.get_patterns (), saved, index); break; } diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h index 787b7017e1b6..51486105da2f 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h @@ -52,12 +52,12 @@ class StructBuilder : public AbstractBuilder, public HIR::HIRFullVisitor } void visit (HIR::StructExprFieldIdentifierValue &field) override { - auto value = ExprStmtBuilder (ctx).build (*field.get_value ()); + auto value = ExprStmtBuilder (ctx).build (field.get_value ()); handle_named_field (field, value); } void visit (HIR::StructExprFieldIndexValue &field) override { - auto value = ExprStmtBuilder (ctx).build (*field.get_value ()); + auto value = ExprStmtBuilder (ctx).build (field.get_value ()); coercion_site (value, struct_ty->get_field_at_index (field.get_tuple_index ()) ->get_field_type ()); diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h index e9108703be1d..d1374cf66573 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder.h @@ -49,7 +49,7 @@ class Builder final : public AbstractBuilder for (auto ¶m : function.get_function_params ()) handle_param (param); - handle_body (*function.get_definition ()); + handle_body (function.get_definition ()); return Function{ std::move (ctx.place_db), @@ -114,14 +114,14 @@ class Builder final : public AbstractBuilder void handle_param (HIR::FunctionParam ¶m) { - auto param_type = lookup_type (*param.get_param_name ()); + auto param_type = lookup_type (param.get_param_name ()); auto &pattern = param.get_param_name (); - if (pattern->get_pattern_type () == HIR::Pattern::IDENTIFIER - && !static_cast (*pattern).get_is_ref ()) + if (pattern.get_pattern_type () == HIR::Pattern::IDENTIFIER + && !static_cast (pattern).get_is_ref ()) { // Avoid useless temporary variable for parameter to look like MIR. - translated = declare_variable (pattern->get_mappings ()); + translated = declare_variable (pattern.get_mappings ()); ctx.arguments.push_back (translated); } else @@ -129,11 +129,9 @@ class Builder final : public AbstractBuilder translated = ctx.place_db.add_temporary (param_type); ctx.arguments.push_back (translated); PatternBindingBuilder (ctx, translated, tl::nullopt) - .go (*param.get_param_name ()); + .go (param.get_param_name ()); } - rust_assert (param.get_type () != nullptr); - // Set parameter place to use functions regions, not the fresh ones. ctx.place_db[translated].regions = bind_regions (Resolver::TypeCheckContext::get () diff --git a/gcc/rust/checks/errors/borrowck/rust-function-collector.h b/gcc/rust/checks/errors/borrowck/rust-function-collector.h index 725d312f1113..9c922f7b76b9 100644 --- a/gcc/rust/checks/errors/borrowck/rust-function-collector.h +++ b/gcc/rust/checks/errors/borrowck/rust-function-collector.h @@ -56,13 +56,13 @@ class FunctionCollector : public HIR::HIRFullVisitor void visit (HIR::Function &function) override { functions.push_back (&function); - function.get_definition ()->accept_vis (*this); + function.get_definition ().accept_vis (*this); } void visit (HIR::ClosureExpr &closure) override { closures.push_back (&closure); - closure.get_expr ()->accept_vis (*this); + closure.get_expr ().accept_vis (*this); } // TODO: recurse for nested closures and functions. diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index d2e448c41f4f..8f10421dc0ec 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -258,16 +258,13 @@ PrivacyReporter::check_base_type_privacy (Analysis::NodeMapping &node_mappings, } void -PrivacyReporter::check_type_privacy (const HIR::Type *type) +PrivacyReporter::check_type_privacy (const HIR::Type &type) { - rust_assert (type); - TyTy::BaseType *lookup = nullptr; - rust_assert ( - ty_ctx.lookup_type (type->get_mappings ().get_hirid (), &lookup)); + rust_assert (ty_ctx.lookup_type (type.get_mappings ().get_hirid (), &lookup)); - auto node_mappings = type->get_mappings (); - return check_base_type_privacy (node_mappings, lookup, type->get_locus ()); + auto node_mappings = type.get_mappings (); + return check_base_type_privacy (node_mappings, lookup, type.get_locus ()); } void @@ -313,100 +310,98 @@ PrivacyReporter::visit (HIR::LiteralExpr &) void PrivacyReporter::visit (HIR::BorrowExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::DereferenceExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::ErrorPropagationExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::NegationExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::ArithmeticOrLogicalExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void PrivacyReporter::visit (HIR::ComparisonExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void PrivacyReporter::visit (HIR::LazyBooleanExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void PrivacyReporter::visit (HIR::TypeCastExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::AssignmentExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void PrivacyReporter::visit (HIR::CompoundAssignmentExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void PrivacyReporter::visit (HIR::GroupedExpr &expr) { - expr.get_expr_in_parens ()->accept_vis (*this); + expr.get_expr_in_parens ().accept_vis (*this); } void PrivacyReporter::visit (HIR::ArrayExpr &expr) { - HIR::ArrayElems &elements = *expr.get_internal_elements (); + HIR::ArrayElems &elements = expr.get_internal_elements (); switch (elements.get_array_expr_type ()) { case HIR::ArrayElems::ArrayExprType::VALUES: { - HIR::ArrayElemsValues &elems - = static_cast (elements); + auto &elems = static_cast (elements); for (auto &value : elems.get_values ()) value->accept_vis (*this); } return; case HIR::ArrayElems::ArrayExprType::COPIED: - HIR::ArrayElemsCopied &elems - = static_cast (elements); - elems.get_elem_to_copy ()->accept_vis (*this); + auto &elems = static_cast (elements); + elems.get_elem_to_copy ().accept_vis (*this); } } void PrivacyReporter::visit (HIR::ArrayIndexExpr &expr) { - expr.get_array_expr ()->accept_vis (*this); - expr.get_index_expr ()->accept_vis (*this); + expr.get_array_expr ().accept_vis (*this); + expr.get_index_expr ().accept_vis (*this); } void @@ -419,7 +414,7 @@ PrivacyReporter::visit (HIR::TupleExpr &expr) void PrivacyReporter::visit (HIR::TupleIndexExpr &expr) { - expr.get_tuple_expr ()->accept_vis (*this); + expr.get_tuple_expr ().accept_vis (*this); } void @@ -435,13 +430,13 @@ PrivacyReporter::visit (HIR::StructExprFieldIdentifier &) void PrivacyReporter::visit (HIR::StructExprFieldIdentifierValue &field) { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void PrivacyReporter::visit (HIR::StructExprFieldIndexValue &field) { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void @@ -454,7 +449,7 @@ PrivacyReporter::visit (HIR::StructExprStructFields &expr) void PrivacyReporter::visit (HIR::CallExpr &expr) { - expr.get_fnexpr ()->accept_vis (*this); + expr.get_fnexpr ().accept_vis (*this); for (auto ¶m : expr.get_arguments ()) param->accept_vis (*this); @@ -463,7 +458,7 @@ PrivacyReporter::visit (HIR::CallExpr &expr) void PrivacyReporter::visit (HIR::MethodCallExpr &expr) { - expr.get_receiver ()->accept_vis (*this); + expr.get_receiver ().accept_vis (*this); for (auto ¶m : expr.get_arguments ()) param->accept_vis (*this); @@ -472,7 +467,7 @@ PrivacyReporter::visit (HIR::MethodCallExpr &expr) void PrivacyReporter::visit (HIR::FieldAccessExpr &expr) { - expr.get_receiver_expr ()->accept_vis (*this); + expr.get_receiver_expr ().accept_vis (*this); // FIXME: We should also check if the field is public? } @@ -490,8 +485,7 @@ PrivacyReporter::visit (HIR::BlockExpr &expr) stmt->accept_vis (*this); auto &last_expr = expr.get_final_expr (); - if (last_expr) - last_expr->accept_vis (*this); + last_expr.accept_vis (*this); } void @@ -502,27 +496,26 @@ void PrivacyReporter::visit (HIR::BreakExpr &expr) { auto &break_expr = expr.get_expr (); - if (break_expr) - break_expr->accept_vis (*this); + break_expr.accept_vis (*this); } void PrivacyReporter::visit (HIR::RangeFromToExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::RangeFromExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::RangeToExpr &expr) { - expr.get_to_expr ()->accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void @@ -532,8 +525,8 @@ PrivacyReporter::visit (HIR::RangeFullExpr &) void PrivacyReporter::visit (HIR::RangeFromToInclExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void @@ -545,49 +538,48 @@ PrivacyReporter::visit (HIR::RangeToInclExpr &) void PrivacyReporter::visit (HIR::ReturnExpr &expr) { - if (expr.get_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::UnsafeBlockExpr &expr) { - expr.get_block_expr ()->accept_vis (*this); + expr.get_block_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::LoopExpr &expr) { - expr.get_loop_block ()->accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void PrivacyReporter::visit (HIR::WhileLoopExpr &expr) { - expr.get_predicate_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_predicate_expr ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void PrivacyReporter::visit (HIR::WhileLetLoopExpr &expr) { - expr.get_cond ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_cond ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void PrivacyReporter::visit (HIR::IfExpr &expr) { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void PrivacyReporter::visit (HIR::IfExprConseqElse &expr) { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); + expr.get_else_block ().accept_vis (*this); } void @@ -608,7 +600,7 @@ PrivacyReporter::visit (HIR::IfLetExprConseqElse &) void PrivacyReporter::visit (HIR::MatchExpr &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); } void @@ -651,9 +643,9 @@ void PrivacyReporter::visit (HIR::Function &function) { for (auto ¶m : function.get_function_params ()) - check_type_privacy (param.get_type ().get ()); + check_type_privacy (param.get_type ()); - function.get_definition ()->accept_vis (*this); + function.get_definition ().accept_vis (*this); } void @@ -710,14 +702,14 @@ void PrivacyReporter::visit (HIR::ConstantItem &const_item) { // TODO: We need to visit the type - const_item.get_expr ()->accept_vis (*this); + const_item.get_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::StaticItem &static_item) { // TODO: We need to visit the type - static_item.get_expr ()->accept_vis (*this); + static_item.get_expr ().accept_vis (*this); } void @@ -750,17 +742,15 @@ PrivacyReporter::visit (HIR::EmptyStmt &) void PrivacyReporter::visit (HIR::LetStmt &stmt) { - if (stmt.get_type ()) - check_type_privacy (stmt.get_type ().get ()); + check_type_privacy (stmt.get_type ()); - if (stmt.get_init_expr ()) - stmt.get_init_expr ()->accept_vis (*this); + stmt.get_init_expr ().accept_vis (*this); } void PrivacyReporter::visit (HIR::ExprStmt &stmt) { - stmt.get_expr ()->accept_vis (*this); + stmt.get_expr ().accept_vis (*this); } } // namespace Privacy diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h index d54732f5e38c..d706ff59171e 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h @@ -75,7 +75,7 @@ types * @param type Reference to an explicit type used in a statement, expression * or parameter */ - void check_type_privacy (const HIR::Type *type); + void check_type_privacy (const HIR::Type &type); virtual void visit (HIR::StructExprFieldIdentifier &field); virtual void visit (HIR::StructExprFieldIdentifierValue &field); diff --git a/gcc/rust/checks/errors/privacy/rust-reachability.cc b/gcc/rust/checks/errors/privacy/rust-reachability.cc index 0afd056a1b70..a6ef6c451440 100644 --- a/gcc/rust/checks/errors/privacy/rust-reachability.cc +++ b/gcc/rust/checks/errors/privacy/rust-reachability.cc @@ -132,7 +132,7 @@ ReachabilityVisitor::visit (HIR::StructStruct &struct_item) { for (auto &field : struct_item.get_fields ()) if (field.get_visibility ().is_public ()) - ctx.update_reachability (field.get_field_type ()->get_mappings (), + ctx.update_reachability (field.get_field_type ().get_mappings (), struct_reach); } diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 27b32b111523..0b50a46b1a1c 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -157,72 +157,72 @@ ConstChecker::visit (LiteralExpr &) void ConstChecker::visit (BorrowExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (DereferenceExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (ErrorPropagationExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (NegationExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (ArithmeticOrLogicalExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void ConstChecker::visit (ComparisonExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void ConstChecker::visit (LazyBooleanExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void ConstChecker::visit (TypeCastExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (AssignmentExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void ConstChecker::visit (CompoundAssignmentExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void ConstChecker::visit (GroupedExpr &expr) { - expr.get_expr_in_parens ()->accept_vis (*this); + expr.get_expr_in_parens ().accept_vis (*this); } void @@ -235,11 +235,11 @@ ConstChecker::visit (ArrayElemsValues &elems) void ConstChecker::visit (ArrayElemsCopied &elems) { - elems.get_elem_to_copy ()->accept_vis (*this); + elems.get_elem_to_copy ().accept_vis (*this); const_context.enter (elems.get_mappings ().get_hirid ()); - elems.get_num_copies_expr ()->accept_vis (*this); + elems.get_num_copies_expr ().accept_vis (*this); const_context.exit (); } @@ -247,14 +247,14 @@ ConstChecker::visit (ArrayElemsCopied &elems) void ConstChecker::visit (ArrayExpr &expr) { - expr.get_internal_elements ()->accept_vis (*this); + expr.get_internal_elements ().accept_vis (*this); } void ConstChecker::visit (ArrayIndexExpr &expr) { - expr.get_array_expr ()->accept_vis (*this); - expr.get_index_expr ()->accept_vis (*this); + expr.get_array_expr ().accept_vis (*this); + expr.get_index_expr ().accept_vis (*this); } void @@ -267,7 +267,7 @@ ConstChecker::visit (TupleExpr &expr) void ConstChecker::visit (TupleIndexExpr &expr) { - expr.get_tuple_expr ()->accept_vis (*this); + expr.get_tuple_expr ().accept_vis (*this); } void @@ -281,13 +281,13 @@ ConstChecker::visit (StructExprFieldIdentifier &) void ConstChecker::visit (StructExprFieldIdentifierValue &field) { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void ConstChecker::visit (StructExprFieldIndexValue &field) { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void @@ -348,10 +348,10 @@ ConstChecker::check_function_call (HirId fn_id, location_t locus) void ConstChecker::visit (CallExpr &expr) { - if (!expr.get_fnexpr ()) + if (!expr.has_fnexpr ()) return; - NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid (); + NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid (); NodeId ref_node_id; // We don't care about types here @@ -374,7 +374,7 @@ ConstChecker::visit (CallExpr &expr) void ConstChecker::visit (MethodCallExpr &expr) { - expr.get_receiver ()->accept_vis (*this); + expr.get_receiver ().accept_vis (*this); for (auto &arg : expr.get_arguments ()) arg->accept_vis (*this); @@ -383,13 +383,13 @@ ConstChecker::visit (MethodCallExpr &expr) void ConstChecker::visit (FieldAccessExpr &expr) { - expr.get_receiver_expr ()->accept_vis (*this); + expr.get_receiver_expr ().accept_vis (*this); } void ConstChecker::visit (ClosureExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void @@ -399,7 +399,7 @@ ConstChecker::visit (BlockExpr &expr) stmt->accept_vis (*this); if (expr.has_expr ()) - expr.get_final_expr ()->accept_vis (*this); + expr.get_final_expr ().accept_vis (*this); } void @@ -410,26 +410,26 @@ void ConstChecker::visit (BreakExpr &expr) { if (expr.has_break_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (RangeFromToExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void ConstChecker::visit (RangeFromExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); } void ConstChecker::visit (RangeToExpr &expr) { - expr.get_to_expr ()->accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void @@ -439,8 +439,8 @@ ConstChecker::visit (RangeFullExpr &) void ConstChecker::visit (RangeFromToInclExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void @@ -453,62 +453,62 @@ void ConstChecker::visit (ReturnExpr &expr) { if (expr.has_return_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void ConstChecker::visit (UnsafeBlockExpr &expr) { - expr.get_block_expr ()->accept_vis (*this); + expr.get_block_expr ().accept_vis (*this); } void ConstChecker::visit (LoopExpr &expr) { - expr.get_loop_block ()->accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void ConstChecker::visit (WhileLoopExpr &expr) { - expr.get_predicate_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_predicate_expr ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void ConstChecker::visit (WhileLetLoopExpr &expr) { - expr.get_cond ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_cond ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void ConstChecker::visit (IfExpr &expr) { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void ConstChecker::visit (IfExprConseqElse &expr) { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); + expr.get_else_block ().accept_vis (*this); } void ConstChecker::visit (IfLetExpr &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void ConstChecker::visit (IfLetExprConseqElse &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); // TODO: Visit else expression } @@ -516,10 +516,10 @@ ConstChecker::visit (IfLetExprConseqElse &expr) void ConstChecker::visit (MatchExpr &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); for (auto &match_arm : expr.get_match_cases ()) - match_arm.get_expr ()->accept_vis (*this); + match_arm.get_expr ().accept_vis (*this); } void @@ -592,9 +592,9 @@ ConstChecker::visit (Function &function) ConstGenericCtx::Function); for (auto ¶m : function.get_function_params ()) - param.get_type ()->accept_vis (*this); + param.get_type ().accept_vis (*this); - function.get_definition ()->accept_vis (*this); + function.get_definition ().accept_vis (*this); if (const_fn) const_context.exit (); @@ -638,7 +638,7 @@ ConstChecker::visit (EnumItemDiscriminant &item) { const_context.enter (item.get_mappings ().get_hirid ()); - item.get_discriminant_expression ()->accept_vis (*this); + item.get_discriminant_expression ().accept_vis (*this); const_context.exit (); } @@ -662,7 +662,7 @@ ConstChecker::visit (ConstantItem &const_item) { const_context.enter (const_item.get_mappings ().get_hirid ()); - const_item.get_expr ()->accept_vis (*this); + const_item.get_expr ().accept_vis (*this); const_context.exit (); } @@ -672,7 +672,7 @@ ConstChecker::visit (StaticItem &static_item) { const_context.enter (static_item.get_mappings ().get_hirid ()); - static_item.get_expr ()->accept_vis (*this); + static_item.get_expr ().accept_vis (*this); const_context.exit (); } @@ -681,14 +681,14 @@ void ConstChecker::visit (TraitItemFunc &item) { if (item.has_block_defined ()) - item.get_block_expr ()->accept_vis (*this); + item.get_block_expr ().accept_vis (*this); } void ConstChecker::visit (TraitItemConst &item) { if (item.has_expr ()) - item.get_expr ()->accept_vis (*this); + item.get_expr ().accept_vis (*this); } void @@ -823,13 +823,13 @@ void ConstChecker::visit (LetStmt &stmt) { if (stmt.has_init_expr ()) - stmt.get_init_expr ()->accept_vis (*this); + stmt.get_init_expr ().accept_vis (*this); } void ConstChecker::visit (ExprStmt &stmt) { - stmt.get_expr ()->accept_vis (*this); + stmt.get_expr ().accept_vis (*this); } void @@ -877,7 +877,7 @@ ConstChecker::visit (ArrayType &type) { const_context.enter (type.get_mappings ().get_hirid ()); - type.get_size_expr ()->accept_vis (*this); + type.get_size_expr ().accept_vis (*this); const_context.exit (); } diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index ff307ae21134..bf2f32c5cabe 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -260,14 +260,14 @@ UnsafeChecker::visit (LiteralExpr &) void UnsafeChecker::visit (BorrowExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (DereferenceExpr &expr) { TyTy::BaseType *to_deref_type; - auto to_deref = expr.get_expr ()->get_mappings ().get_hirid (); + auto to_deref = expr.get_expr ().get_mappings ().get_hirid (); rust_assert (context.lookup_type (to_deref, &to_deref_type)); @@ -280,60 +280,60 @@ UnsafeChecker::visit (DereferenceExpr &expr) void UnsafeChecker::visit (ErrorPropagationExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (NegationExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (ArithmeticOrLogicalExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void UnsafeChecker::visit (ComparisonExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void UnsafeChecker::visit (LazyBooleanExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void UnsafeChecker::visit (TypeCastExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (AssignmentExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void UnsafeChecker::visit (CompoundAssignmentExpr &expr) { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void UnsafeChecker::visit (GroupedExpr &expr) { - expr.get_expr_in_parens ()->accept_vis (*this); + expr.get_expr_in_parens ().accept_vis (*this); } void @@ -346,20 +346,20 @@ UnsafeChecker::visit (ArrayElemsValues &elems) void UnsafeChecker::visit (ArrayElemsCopied &elems) { - elems.get_elem_to_copy ()->accept_vis (*this); + elems.get_elem_to_copy ().accept_vis (*this); } void UnsafeChecker::visit (ArrayExpr &expr) { - expr.get_internal_elements ()->accept_vis (*this); + expr.get_internal_elements ().accept_vis (*this); } void UnsafeChecker::visit (ArrayIndexExpr &expr) { - expr.get_array_expr ()->accept_vis (*this); - expr.get_index_expr ()->accept_vis (*this); + expr.get_array_expr ().accept_vis (*this); + expr.get_index_expr ().accept_vis (*this); } void @@ -372,7 +372,7 @@ UnsafeChecker::visit (TupleExpr &expr) void UnsafeChecker::visit (TupleIndexExpr &expr) { - expr.get_tuple_expr ()->accept_vis (*this); + expr.get_tuple_expr ().accept_vis (*this); } void @@ -386,13 +386,13 @@ UnsafeChecker::visit (StructExprFieldIdentifier &) void UnsafeChecker::visit (StructExprFieldIdentifierValue &field) { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void UnsafeChecker::visit (StructExprFieldIndexValue &field) { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void @@ -409,10 +409,10 @@ UnsafeChecker::visit (StructExprStructBase &) void UnsafeChecker::visit (CallExpr &expr) { - if (!expr.get_fnexpr ()) + if (!expr.has_fnexpr ()) return; - NodeId ast_node_id = expr.get_fnexpr ()->get_mappings ().get_nodeid (); + NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid (); NodeId ref_node_id; // There are no unsafe types, and functions are defined in the name resolver. @@ -455,7 +455,7 @@ UnsafeChecker::visit (MethodCallExpr &expr) check_unsafe_call (static_cast (method->first), expr.get_locus (), "method"); - expr.get_receiver ()->accept_vis (*this); + expr.get_receiver ().accept_vis (*this); for (auto &arg : expr.get_arguments ()) arg->accept_vis (*this); @@ -464,14 +464,14 @@ UnsafeChecker::visit (MethodCallExpr &expr) void UnsafeChecker::visit (FieldAccessExpr &expr) { - expr.get_receiver_expr ()->accept_vis (*this); + expr.get_receiver_expr ().accept_vis (*this); if (unsafe_context.is_in_context ()) return; TyTy::BaseType *receiver_ty; auto ok = context.lookup_type ( - expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver_ty); + expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver_ty); rust_assert (ok); if (receiver_ty->get_kind () == TyTy::TypeKind::ADT) @@ -487,7 +487,7 @@ UnsafeChecker::visit (FieldAccessExpr &expr) void UnsafeChecker::visit (ClosureExpr &expr) { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void @@ -497,7 +497,7 @@ UnsafeChecker::visit (BlockExpr &expr) stmt->accept_vis (*this); if (expr.has_expr ()) - expr.get_final_expr ()->accept_vis (*this); + expr.get_final_expr ().accept_vis (*this); } void @@ -508,26 +508,26 @@ void UnsafeChecker::visit (BreakExpr &expr) { if (expr.has_break_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (RangeFromToExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void UnsafeChecker::visit (RangeFromExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); } void UnsafeChecker::visit (RangeToExpr &expr) { - expr.get_to_expr ()->accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void @@ -537,21 +537,21 @@ UnsafeChecker::visit (RangeFullExpr &) void UnsafeChecker::visit (RangeFromToInclExpr &expr) { - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); + expr.get_from_expr ().accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void UnsafeChecker::visit (RangeToInclExpr &expr) { - expr.get_to_expr ()->accept_vis (*this); + expr.get_to_expr ().accept_vis (*this); } void UnsafeChecker::visit (ReturnExpr &expr) { if (expr.has_return_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void @@ -559,7 +559,7 @@ UnsafeChecker::visit (UnsafeBlockExpr &expr) { unsafe_context.enter (expr.get_mappings ().get_hirid ()); - expr.get_block_expr ()->accept_vis (*this); + expr.get_block_expr ().accept_vis (*this); unsafe_context.exit (); } @@ -567,50 +567,50 @@ UnsafeChecker::visit (UnsafeBlockExpr &expr) void UnsafeChecker::visit (LoopExpr &expr) { - expr.get_loop_block ()->accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void UnsafeChecker::visit (WhileLoopExpr &expr) { - expr.get_predicate_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_predicate_expr ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void UnsafeChecker::visit (WhileLetLoopExpr &expr) { - expr.get_cond ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); + expr.get_cond ().accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void UnsafeChecker::visit (IfExpr &expr) { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void UnsafeChecker::visit (IfExprConseqElse &expr) { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); + expr.get_else_block ().accept_vis (*this); } void UnsafeChecker::visit (IfLetExpr &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void UnsafeChecker::visit (IfLetExprConseqElse &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); // TODO: Visit else expression } @@ -618,10 +618,10 @@ UnsafeChecker::visit (IfLetExprConseqElse &expr) void UnsafeChecker::visit (MatchExpr &expr) { - expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); for (auto &match_arm : expr.get_match_cases ()) - match_arm.get_expr ()->accept_vis (*this); + match_arm.get_expr ().accept_vis (*this); } void @@ -698,7 +698,7 @@ UnsafeChecker::visit (Function &function) if (is_unsafe_fn) unsafe_context.enter (function.get_mappings ().get_hirid ()); - function.get_definition ()->accept_vis (*this); + function.get_definition ().accept_vis (*this); if (is_unsafe_fn) unsafe_context.exit (); @@ -746,27 +746,27 @@ UnsafeChecker::visit (Union &) void UnsafeChecker::visit (ConstantItem &const_item) { - const_item.get_expr ()->accept_vis (*this); + const_item.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (StaticItem &static_item) { - static_item.get_expr ()->accept_vis (*this); + static_item.get_expr ().accept_vis (*this); } void UnsafeChecker::visit (TraitItemFunc &item) { if (item.has_block_defined ()) - item.get_block_expr ()->accept_vis (*this); + item.get_block_expr ().accept_vis (*this); } void UnsafeChecker::visit (TraitItemConst &item) { if (item.has_expr ()) - item.get_expr ()->accept_vis (*this); + item.get_expr ().accept_vis (*this); } void @@ -897,13 +897,13 @@ void UnsafeChecker::visit (LetStmt &stmt) { if (stmt.has_init_expr ()) - stmt.get_init_expr ()->accept_vis (*this); + stmt.get_init_expr ().accept_vis (*this); } void UnsafeChecker::visit (ExprStmt &stmt) { - stmt.get_expr ()->accept_vis (*this); + stmt.get_expr ().accept_vis (*this); } void diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index 47f5540c0295..a50e18e9ec03 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -124,7 +124,7 @@ MarkLive::visit (HIR::PathInExpression &expr) void MarkLive::visit (HIR::MethodCallExpr &expr) { - expr.get_receiver ()->accept_vis (*this); + expr.get_receiver ().accept_vis (*this); visit_path_segment (expr.get_method_name ()); for (auto &argument : expr.get_arguments ()) argument->accept_vis (*this); @@ -172,14 +172,14 @@ void MarkLive::visit (HIR::FieldAccessExpr &expr) { // visit receiver at first - expr.get_receiver_expr ()->accept_vis (*this); + expr.get_receiver_expr ().accept_vis (*this); // resolve the receiver back to ADT type TyTy::BaseType *receiver = nullptr; if (!tyctx->lookup_type ( - expr.get_receiver_expr ()->get_mappings ().get_hirid (), &receiver)) + expr.get_receiver_expr ().get_mappings ().get_hirid (), &receiver)) { - rust_error_at (expr.get_receiver_expr ()->get_locus (), + rust_error_at (expr.get_receiver_expr ().get_locus (), "unresolved type for receiver"); } @@ -211,7 +211,7 @@ MarkLive::visit (HIR::FieldAccessExpr &expr) rust_assert (ok); if (index >= variant->num_fields ()) { - rust_error_at (expr.get_receiver_expr ()->get_locus (), + rust_error_at (expr.get_receiver_expr ().get_locus (), "cannot access struct %s by index: %lu", adt->get_name ().c_str (), (unsigned long) index); return; @@ -226,7 +226,7 @@ void MarkLive::visit (HIR::TupleIndexExpr &expr) { // TODO: unused tuple field detection - expr.get_tuple_expr ()->accept_vis (*this); + expr.get_tuple_expr ().accept_vis (*this); } void @@ -234,7 +234,7 @@ MarkLive::visit (HIR::TypeAlias &alias) { NodeId ast_node_id; resolver->lookup_resolved_type ( - alias.get_type_aliased ()->get_mappings ().get_nodeid (), &ast_node_id); + alias.get_type_aliased ().get_mappings ().get_nodeid (), &ast_node_id); if (auto hid = mappings.lookup_node_to_hir (ast_node_id)) mark_hir_id (*hid); else diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h b/gcc/rust/checks/lints/rust-lint-marklive.h index 585a7271c561..a1e8c110a3d3 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.h +++ b/gcc/rust/checks/lints/rust-lint-marklive.h @@ -43,44 +43,44 @@ class MarkLive : public MarkLiveBase void visit (HIR::BorrowExpr &expr) override { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void visit (HIR::DereferenceExpr &expr) override { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void visit (HIR::NegationExpr &expr) override { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void visit (HIR::LazyBooleanExpr &expr) override { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void visit (HIR::TypeCastExpr &expr) override { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void visit (HIR::GroupedExpr &expr) override { - expr.get_expr_in_parens ()->accept_vis (*this); + expr.get_expr_in_parens ().accept_vis (*this); } void visit (HIR::ArrayExpr &expr) override { - expr.get_internal_elements ()->accept_vis (*this); + expr.get_internal_elements ().accept_vis (*this); } void visit (HIR::ArrayIndexExpr &expr) override { - expr.get_array_expr ()->accept_vis (*this); - expr.get_index_expr ()->accept_vis (*this); + expr.get_array_expr ().accept_vis (*this); + expr.get_index_expr ().accept_vis (*this); } void visit (HIR::ArrayElemsValues &expr) override @@ -107,57 +107,57 @@ class MarkLive : public MarkLiveBase } if (expr.has_expr ()) { - expr.get_final_expr ()->accept_vis (*this); + expr.get_final_expr ().accept_vis (*this); } } void visit (HIR::UnsafeBlockExpr &expr) override { - expr.get_block_expr ()->accept_vis (*this); + expr.get_block_expr ().accept_vis (*this); } void visit (HIR::LoopExpr &expr) override { - expr.get_loop_block ()->accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); } void visit (HIR::BreakExpr &expr) override { if (expr.has_break_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void visit (HIR::WhileLoopExpr &expr) override { - expr.get_loop_block ()->accept_vis (*this); - expr.get_predicate_expr ()->accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); + expr.get_predicate_expr ().accept_vis (*this); } void visit (HIR::Function &function) override { - function.get_definition ()->accept_vis (*this); + function.get_definition ().accept_vis (*this); } void visit (HIR::ReturnExpr &expr) override { if (expr.has_return_expr ()) - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } void visit (HIR::WhileLetLoopExpr &expr) override { - expr.get_loop_block ()->accept_vis (*this); - expr.get_cond ()->accept_vis (*this); + expr.get_loop_block ().accept_vis (*this); + expr.get_cond ().accept_vis (*this); } void visit (HIR::ExprStmt &stmt) override { - stmt.get_expr ()->accept_vis (*this); + stmt.get_expr ().accept_vis (*this); } void visit (HIR::CallExpr &expr) override { - expr.get_fnexpr ()->accept_vis (*this); + expr.get_fnexpr ().accept_vis (*this); for (auto &argument : expr.get_arguments ()) argument->accept_vis (*this); } @@ -169,8 +169,8 @@ class MarkLive : public MarkLiveBase } void visit (HIR::ComparisonExpr &expr) override { - expr.get_lhs ()->accept_vis (*this); - expr.get_rhs ()->accept_vis (*this); + expr.get_lhs ().accept_vis (*this); + expr.get_rhs ().accept_vis (*this); } void visit (HIR::AssignmentExpr &expr) override @@ -187,33 +187,33 @@ class MarkLive : public MarkLiveBase void visit (HIR::IfExpr &expr) override { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); } void visit (HIR::IfExprConseqElse &expr) override { - expr.get_if_condition ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); + expr.get_if_condition ().accept_vis (*this); + expr.get_if_block ().accept_vis (*this); + expr.get_else_block ().accept_vis (*this); } void visit (HIR::MatchExpr &expr) override { - expr.get_scrutinee_expr ()->accept_vis (*this); + expr.get_scrutinee_expr ().accept_vis (*this); std::vector &cases = expr.get_match_cases (); for (auto &&caz : cases) { auto case_arm = caz.get_arm (); if (case_arm.has_match_arm_guard ()) - case_arm.get_guard_expr ()->accept_vis (*this); - caz.get_expr ()->accept_vis (*this); + case_arm.get_guard_expr ().accept_vis (*this); + caz.get_expr ().accept_vis (*this); } } void visit (HIR::TraitItemFunc &item) override { - item.get_block_expr ()->accept_vis (*this); + item.get_block_expr ().accept_vis (*this); } void visit (HIR::ImplBlock &impl) override @@ -228,7 +228,7 @@ class MarkLive : public MarkLiveBase { if (stmt.has_init_expr ()) { - stmt.get_init_expr ()->accept_vis (*this); + stmt.get_init_expr ().accept_vis (*this); } } @@ -253,7 +253,7 @@ class MarkLive : public MarkLiveBase virtual void visit (HIR::StructExprFieldIdentifierValue &field) override { - field.get_value ()->accept_vis (*this); + field.get_value ().accept_vis (*this); } void visit (HIR::StructExprStructBase &stct) override @@ -269,7 +269,7 @@ class MarkLive : public MarkLiveBase void visit (HIR::ClosureExpr &expr) override { - expr.get_expr ()->accept_vis (*this); + expr.get_expr ().accept_vis (*this); } private: diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index bcacc8de9682..bacb949fa38f 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -786,7 +786,7 @@ Dump::visit (QualifiedPathInType &e) end_field ("path_type"); begin_field ("associated_segment"); - do_typepathsegment (*e.get_associated_segment ()); + do_typepathsegment (e.get_associated_segment ()); end_field ("associated_segment"); visit_collection ("segments", e.get_segments ()); @@ -897,7 +897,7 @@ Dump::visit (ArithmeticOrLogicalExpr &e) } put_field ("expr_type", str); do_operatorexpr (e); - visit_field ("right_expr", *e.get_rhs ()); + visit_field ("right_expr", e.get_rhs ()); end ("ArithmeticOrLogicalExpr"); } @@ -932,7 +932,7 @@ Dump::visit (ComparisonExpr &e) } put_field ("expr_type", str); do_operatorexpr (e); - visit_field ("right_expr", *e.get_rhs ()); + visit_field ("right_expr", e.get_rhs ()); end ("ComparisonExpr"); } @@ -955,7 +955,7 @@ Dump::visit (LazyBooleanExpr &e) } do_operatorexpr (e); - visit_field ("right_expr", *e.get_rhs ()); + visit_field ("right_expr", e.get_rhs ()); end ("LazyBooleanExpr"); } @@ -973,7 +973,7 @@ Dump::visit (AssignmentExpr &e) { begin ("AssignmentExpr"); do_operatorexpr (e); - visit_field ("right_expr", *e.get_rhs ()); + visit_field ("right_expr", e.get_rhs ()); end ("AssignmentExpr"); } @@ -983,7 +983,7 @@ Dump::visit (CompoundAssignmentExpr &e) begin ("CompoundAssignmentExpr"); do_operatorexpr (e); - visit_field ("right_expr", *e.get_rhs ()); + visit_field ("right_expr", e.get_rhs ()); std::string str; @@ -1680,7 +1680,7 @@ Dump::visit (TypeAlias &e) else put_field ("where clause", e.get_where_clause ().as_string ()); - put_field ("type", e.get_type_aliased ()->as_string ()); + put_field ("type", e.get_type_aliased ().as_string ()); end ("TypeAlias"); } @@ -2046,7 +2046,7 @@ Dump::visit (IdentifierPattern &e) put_field ("mut", std::to_string (e.is_mut ())); if (e.has_pattern_to_bind ()) - put_field ("to_bind", e.get_to_bind ()->as_string ()); + put_field ("to_bind", e.get_to_bind ().as_string ()); else put_field ("to_bind", "none"); @@ -2090,8 +2090,8 @@ Dump::visit (RangePattern &e) { begin ("RangePattern"); do_mappings (e.get_mappings ()); - put_field ("lower", e.get_lower_bound ()->as_string ()); - put_field ("upper", e.get_upper_bound ()->as_string ()); + put_field ("lower", e.get_lower_bound ().as_string ()); + put_field ("upper", e.get_upper_bound ().as_string ()); put_field ("has_ellipsis_syntax", std::to_string (e.get_has_ellipsis_syntax ())); end ("RangePattern"); @@ -2103,7 +2103,7 @@ Dump::visit (ReferencePattern &e) begin ("ReferencePattern"); do_mappings (e.get_mappings ()); put_field ("mut", std::to_string (e.is_mut ())); - put_field ("pattern", e.get_referenced_pattern ()->as_string ()); + put_field ("pattern", e.get_referenced_pattern ().as_string ()); end ("ReferencePattern"); } @@ -2115,7 +2115,7 @@ Dump::visit (StructPatternFieldTuplePat &e) auto oa = e.get_outer_attrs (); do_outer_attrs (oa); put_field ("index", std::to_string (e.get_index ())); - put_field ("tuple_pattern", e.get_tuple_pattern ()->as_string ()); + put_field ("tuple_pattern", e.get_tuple_pattern ().as_string ()); end ("StructPatternFieldTuplePat"); } @@ -2126,7 +2126,7 @@ Dump::visit (StructPatternFieldIdentPat &e) auto oa = e.get_outer_attrs (); do_outer_attrs (oa); put_field ("ident", e.get_identifier ().as_string ()); - put_field ("ident_pattern", e.get_pattern ()->as_string ()); + put_field ("ident_pattern", e.get_pattern ().as_string ()); end ("StructPatternFieldIdentPat"); } @@ -2244,7 +2244,7 @@ Dump::visit (LetStmt &e) auto oa = e.get_outer_attrs (); do_outer_attrs (oa); - put_field ("variable_pattern", e.get_pattern ()->as_string ()); + put_field ("variable_pattern", e.get_pattern ().as_string ()); visit_field ("type", e.get_type ()); visit_field ("init_expr", e.get_init_expr ()); @@ -2305,7 +2305,7 @@ Dump::visit (ParenthesisedType &e) { begin ("ParenthesisedType"); do_type (e); - put_field ("type_in_parens", e.get_type_in_parens ()->as_string ()); + put_field ("type_in_parens", e.get_type_in_parens ().as_string ()); end ("ParenthesisedType"); } @@ -2341,7 +2341,7 @@ Dump::visit (RawPointerType &e) begin ("RawPointerType"); do_type (e); put_field ("mut", Rust::enum_to_str (e.get_mut ())); - put_field ("type", e.get_type ()->as_string ()); + put_field ("type", e.get_type ().as_string ()); end ("RawPointerType"); } @@ -2352,7 +2352,7 @@ Dump::visit (ReferenceType &e) do_type (e); put_field ("lifetime", e.get_lifetime ().as_string ()); put_field ("mut", enum_to_str (e.get_mut ())); - put_field ("type", e.get_base_type ()->as_string ()); + put_field ("type", e.get_base_type ().as_string ()); end ("ReferenceType"); } diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 9851cb1bb1dc..0c742d715e94 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -200,7 +200,7 @@ class OperatorExpr : public ExprWithoutBlock public: location_t get_locus () const override final { return locus; } - std::unique_ptr &get_expr () { return main_or_left_expr; } + Expr &get_expr () { return *main_or_left_expr; } ExprType get_expression_type () const override final { @@ -414,8 +414,8 @@ class ArithmeticOrLogicalExpr : public OperatorExpr void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); } void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); } - std::unique_ptr &get_lhs () { return main_or_left_expr; } - std::unique_ptr &get_rhs () { return right_expr; } + Expr &get_lhs () { return *main_or_left_expr; } + Expr &get_rhs () { return *right_expr; } protected: /* Use covariance to implement clone function as returning this object rather @@ -486,8 +486,8 @@ class ComparisonExpr : public OperatorExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_lhs () { return main_or_left_expr; } - std::unique_ptr &get_rhs () { return right_expr; } + Expr &get_lhs () { return *main_or_left_expr; } + Expr &get_rhs () { return *right_expr; } ExprType get_kind () { return expr_type; } @@ -560,8 +560,8 @@ class LazyBooleanExpr : public OperatorExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_lhs () { return main_or_left_expr; } - std::unique_ptr &get_rhs () { return right_expr; } + Expr &get_lhs () { return *main_or_left_expr; } + Expr &get_rhs () { return *right_expr; } protected: /* Use covariance to implement clone function as returning this object rather @@ -622,12 +622,9 @@ class TypeCastExpr : public OperatorExpr void accept_vis (HIRExpressionVisitor &vis) override; // FIXME: isn't it the same as get_expr() from parent? - std::unique_ptr &get_casted_expr () { return main_or_left_expr; } + Expr &get_casted_expr () { return *main_or_left_expr; } - std::unique_ptr &get_type_to_convert_to () - { - return type_to_convert_to; - } + Type &get_type_to_convert_to () { return *type_to_convert_to; } protected: /* Use covariance to implement clone function as returning this object rather @@ -689,8 +686,8 @@ class AssignmentExpr : public OperatorExpr void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); } void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); } - std::unique_ptr &get_lhs () { return main_or_left_expr; } - std::unique_ptr &get_rhs () { return right_expr; } + Expr &get_lhs () { return *main_or_left_expr; } + Expr &get_rhs () { return *right_expr; } protected: /* Use covariance to implement clone function as returning this object rather @@ -759,9 +756,9 @@ class CompoundAssignmentExpr : public OperatorExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_lhs () { return main_or_left_expr; } + Expr &get_lhs () { return *main_or_left_expr; } - std::unique_ptr &get_rhs () { return right_expr; } + Expr &get_rhs () { return *right_expr; } void visit_lhs (HIRFullVisitor &vis) { main_or_left_expr->accept_vis (vis); } void visit_rhs (HIRFullVisitor &vis) { right_expr->accept_vis (vis); } @@ -821,7 +818,7 @@ class GroupedExpr : public ExprWithoutBlock, public WithInnerAttrs void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_expr_in_parens () { return expr_in_parens; } + Expr &get_expr_in_parens () { return *expr_in_parens; } ExprType get_expression_type () const override final { @@ -973,9 +970,9 @@ class ArrayElemsCopied : public ArrayElems void accept_vis (HIRFullVisitor &vis) override; - std::unique_ptr &get_elem_to_copy () { return elem_to_copy; } + Expr &get_elem_to_copy () { return *elem_to_copy; } - std::unique_ptr &get_num_copies_expr () { return num_copies; } + Expr &get_num_copies_expr () { return *num_copies; } ArrayElems::ArrayExprType get_array_expr_type () const override final { @@ -1043,10 +1040,7 @@ class ArrayExpr : public ExprWithoutBlock, public WithInnerAttrs void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_internal_elements () - { - return internal_elements; - }; + ArrayElems &get_internal_elements () { return *internal_elements; }; ExprType get_expression_type () const override final { @@ -1112,8 +1106,8 @@ class ArrayIndexExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_array_expr () { return array_expr; } - std::unique_ptr &get_index_expr () { return index_expr; } + Expr &get_array_expr () { return *array_expr; } + Expr &get_index_expr () { return *index_expr; } ExprType get_expression_type () const override final { @@ -1266,7 +1260,7 @@ class TupleIndexExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_tuple_expr () { return tuple_expr; } + Expr &get_tuple_expr () { return *tuple_expr; } ExprType get_expression_type () const override final { @@ -1511,7 +1505,7 @@ class StructExprFieldWithVal : public StructExprField public: std::string as_string () const override; - std::unique_ptr &get_value () { return value; } + Expr &get_value () { return *value; } }; // Identifier and value variant of StructExprField HIR node @@ -1784,7 +1778,8 @@ class CallExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_fnexpr () { return function; } + bool has_fnexpr () const { return function != nullptr; } + Expr &get_fnexpr () { return *function; } size_t num_params () const { return params.size (); } @@ -1871,7 +1866,7 @@ class MethodCallExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_receiver () { return receiver; } + Expr &get_receiver () { return *receiver; } PathExprSegment &get_method_name () { return method_name; }; const PathExprSegment &get_method_name () const { return method_name; }; @@ -1955,7 +1950,7 @@ class FieldAccessExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_receiver_expr () { return receiver; } + Expr &get_receiver_expr () { return *receiver; } Identifier get_field_name () const { return field; } @@ -2045,9 +2040,9 @@ struct ClosureParam } std::vector &get_outer_attrs () { return outer_attrs; } - std::unique_ptr &get_pattern () { return pattern; } + Pattern &get_pattern () { return *pattern; } - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } location_t get_locus () const { return locus; } }; @@ -2115,8 +2110,8 @@ class ClosureExpr : public ExprWithoutBlock bool has_return_type () const { return return_type != nullptr; } - std::unique_ptr &get_return_type () { return return_type; }; - std::unique_ptr &get_expr () { return expr; } + Type &get_return_type () { return *return_type; }; + Expr &get_expr () { return *expr; } bool has_params () const { return !params.empty (); } std::vector &get_params () { return params; } @@ -2230,7 +2225,7 @@ class BlockExpr : public ExprWithBlock, public WithInnerAttrs bool is_final_stmt (Stmt *stmt) { return statements.back ().get () == stmt; } - std::unique_ptr &get_final_expr () { return expr; } + Expr &get_final_expr () { return *expr; } std::vector > &get_statements () { return statements; } @@ -2375,7 +2370,7 @@ class BreakExpr : public ExprWithoutBlock Lifetime &get_label () { return label; } - std::unique_ptr &get_expr () { return break_expr; } + Expr &get_expr () { return *break_expr; } ExprType get_expression_type () const override final { @@ -2455,8 +2450,8 @@ class RangeFromToExpr : public RangeExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_from_expr () { return from; } - std::unique_ptr &get_to_expr () { return to; } + Expr &get_from_expr () { return *from; } + Expr &get_to_expr () { return *to; } protected: /* Use covariance to implement clone function as returning this object rather @@ -2509,7 +2504,7 @@ class RangeFromExpr : public RangeExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_from_expr () { return from; } + Expr &get_from_expr () { return *from; } protected: /* Use covariance to implement clone function as returning this object rather @@ -2563,7 +2558,7 @@ class RangeToExpr : public RangeExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_to_expr () { return to; } + Expr &get_to_expr () { return *to; } protected: /* Use covariance to implement clone function as returning this object rather @@ -2653,8 +2648,8 @@ class RangeFromToInclExpr : public RangeExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_from_expr () { return from; } - std::unique_ptr &get_to_expr () { return to; } + Expr &get_from_expr () { return *from; } + Expr &get_to_expr () { return *to; } protected: /* Use covariance to implement clone function as returning this object rather @@ -2708,7 +2703,7 @@ class RangeToInclExpr : public RangeExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_to_expr () { return to; }; + Expr &get_to_expr () { return *to; }; protected: /* Use covariance to implement clone function as returning this object rather @@ -2777,7 +2772,7 @@ class ReturnExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_expr () { return return_expr; } + Expr &get_expr () { return *return_expr; } ExprType get_expression_type () const override final { @@ -2843,7 +2838,7 @@ class UnsafeBlockExpr : public ExprWithBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_block_expr () { return expr; } + BlockExpr &get_block_expr () { return *expr; } ExprType get_expression_type () const override final { @@ -2919,7 +2914,7 @@ class BaseLoopExpr : public ExprWithBlock location_t get_locus () const override final { return locus; } - std::unique_ptr &get_loop_block () { return loop_block; }; + HIR::BlockExpr &get_loop_block () { return *loop_block; }; LoopLabel &get_loop_label () { return loop_label; } }; @@ -2997,7 +2992,7 @@ class WhileLoopExpr : public BaseLoopExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_predicate_expr () { return condition; } + Expr &get_predicate_expr () { return *condition; } protected: /* Use covariance to implement clone function as returning this object rather @@ -3073,7 +3068,7 @@ class WhileLetLoopExpr : public BaseLoopExpr void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_cond () { return condition; } + Expr &get_cond () { return *condition; } std::vector > &get_patterns () { return match_arm_patterns; @@ -3156,8 +3151,8 @@ class IfExpr : public ExprWithBlock void vis_if_condition (HIRFullVisitor &vis) { condition->accept_vis (vis); } void vis_if_block (HIRFullVisitor &vis) { if_block->accept_vis (vis); } - std::unique_ptr &get_if_condition () { return condition; } - std::unique_ptr &get_if_block () { return if_block; } + Expr &get_if_condition () { return *condition; } + BlockExpr &get_if_block () { return *if_block; } ExprType get_expression_type () const final override { return ExprType::If; } @@ -3220,7 +3215,7 @@ class IfExprConseqElse : public IfExpr void vis_else_block (HIRFullVisitor &vis) { else_block->accept_vis (vis); } - std::unique_ptr &get_else_block () { return else_block; } + ExprWithBlock &get_else_block () { return *else_block; } protected: /* Use covariance to implement clone function as returning this object rather @@ -3311,14 +3306,14 @@ class IfLetExpr : public ExprWithBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_scrutinee_expr () { return value; } + Expr &get_scrutinee_expr () { return *value; } std::vector > &get_patterns () { return match_arm_patterns; } - std::unique_ptr &get_if_block () { return if_block; } + BlockExpr &get_if_block () { return *if_block; } ExprType get_expression_type () const final override { @@ -3391,7 +3386,7 @@ class IfLetExprConseqElse : public IfLetExpr void vis_else_block (HIRFullVisitor &vis) { else_block->accept_vis (vis); } - std::unique_ptr &get_else_block () { return else_block; } + ExprWithBlock &get_else_block () { return *else_block; } protected: /* Use covariance to implement clone function as returning this object rather @@ -3491,7 +3486,7 @@ struct MatchArm return match_arm_patterns; } - std::unique_ptr &get_guard_expr () { return guard_expr; } + Expr &get_guard_expr () { return *guard_expr; } location_t get_locus () const { return locus; } }; @@ -3535,7 +3530,7 @@ struct MatchCase Analysis::NodeMapping get_mappings () const { return mappings; } MatchArm &get_arm () { return arm; } - std::unique_ptr &get_expr () { return expr; } + Expr &get_expr () { return *expr; } }; // Match expression HIR node @@ -3596,7 +3591,7 @@ class MatchExpr : public ExprWithBlock, public WithInnerAttrs void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_scrutinee_expr () { return branch_value; } + Expr &get_scrutinee_expr () { return *branch_value; } AST::AttrVec get_inner_attrs () const { return inner_attrs; } const std::vector &get_match_cases () const { return match_arms; } std::vector &get_match_cases () { return match_arms; } @@ -3660,7 +3655,7 @@ class AwaitExpr : public ExprWithoutBlock void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; - std::unique_ptr &get_awaited_expr () { return awaited_expr; } + Expr &get_awaited_expr () { return *awaited_expr; } ExprType get_expression_type () const final override { @@ -3717,7 +3712,7 @@ class AsyncBlockExpr : public ExprWithBlock location_t get_locus () const override final { return locus; } bool get_has_move () const { return has_move; } - std::unique_ptr &get_block_expr () { return block_expr; } + BlockExpr &get_block_expr () { return *block_expr; } void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRExpressionVisitor &vis) override; @@ -3742,31 +3737,31 @@ class OperatorExprMeta public: OperatorExprMeta (HIR::CompoundAssignmentExpr &expr) : node_mappings (expr.get_mappings ()), - lvalue_mappings (expr.get_expr ()->get_mappings ()), + lvalue_mappings (expr.get_expr ().get_mappings ()), locus (expr.get_locus ()) {} OperatorExprMeta (HIR::ArithmeticOrLogicalExpr &expr) : node_mappings (expr.get_mappings ()), - lvalue_mappings (expr.get_expr ()->get_mappings ()), + lvalue_mappings (expr.get_expr ().get_mappings ()), locus (expr.get_locus ()) {} OperatorExprMeta (HIR::NegationExpr &expr) : node_mappings (expr.get_mappings ()), - lvalue_mappings (expr.get_expr ()->get_mappings ()), + lvalue_mappings (expr.get_expr ().get_mappings ()), locus (expr.get_locus ()) {} OperatorExprMeta (HIR::DereferenceExpr &expr) : node_mappings (expr.get_mappings ()), - lvalue_mappings (expr.get_expr ()->get_mappings ()), + lvalue_mappings (expr.get_expr ().get_mappings ()), locus (expr.get_locus ()) {} OperatorExprMeta (HIR::ArrayIndexExpr &expr) : node_mappings (expr.get_mappings ()), - lvalue_mappings (expr.get_array_expr ()->get_mappings ()), + lvalue_mappings (expr.get_array_expr ().get_mappings ()), locus (expr.get_locus ()) {} diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 7e0c8c6ffca9..19b61cbabf77 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -120,7 +120,7 @@ class TypeParam : public GenericParam Identifier get_type_representation () const { return type_representation; } - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } Analysis::NodeMapping get_type_mappings () const { @@ -279,7 +279,7 @@ class TypeBoundWhereClauseItem : public WhereClauseItem std::vector &get_for_lifetimes () { return for_lifetimes; } - std::unique_ptr &get_bound_type () { return bound_type; } + Type &get_bound_type () { return *bound_type; } std::vector> &get_type_param_bounds () { @@ -454,7 +454,7 @@ struct SelfParam ImplicitSelfKind get_self_kind () const { return self_kind; } - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } Analysis::NodeMapping get_mappings () { return mappings; } @@ -549,9 +549,11 @@ struct FunctionParam location_t get_locus () const { return locus; } - std::unique_ptr &get_param_name () { return param_name; } + Pattern &get_param_name () { return *param_name; } - std::unique_ptr &get_type () { return type; } + std::unique_ptr take_param_name () { return std::move (param_name); } + + Type &get_type () { return *type; } const Analysis::NodeMapping &get_mappings () const { return mappings; } }; @@ -1058,7 +1060,7 @@ class UseDeclaration : public VisItem location_t get_locus () const override final { return locus; } ItemKind get_item_kind () const override { return ItemKind::UseDeclaration; } - std::unique_ptr &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; @@ -1212,7 +1214,7 @@ class Function : public VisItem, public ImplItem } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_definition () { return function_body; } + BlockExpr &get_definition () { return *function_body; } const FunctionQualifiers &get_qualifiers () const { return qualifiers; } @@ -1224,7 +1226,7 @@ class Function : public VisItem, public ImplItem bool has_return_type () const { return return_type != nullptr; } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_return_type () { return return_type; } + Type &get_return_type () { return *return_type; } bool is_method () const { return !self.is_error (); } @@ -1339,7 +1341,7 @@ class TypeAlias : public VisItem, public ImplItem WhereClause &get_where_clause () { return where_clause; } - std::unique_ptr &get_type_aliased () { return existing_type; } + Type &get_type_aliased () { return *existing_type; } Identifier get_new_type_name () const { return new_type_name; } @@ -1505,7 +1507,7 @@ class StructField Identifier get_field_name () const { return field_name; } - std::unique_ptr &get_field_type () { return field_type; } + Type &get_field_type () { return *field_type; } Analysis::NodeMapping get_mappings () const { return mappings; } @@ -1642,7 +1644,7 @@ class TupleField location_t get_locus () const { return locus; } AST::AttrVec &get_outer_attrs () { return outer_attrs; } - std::unique_ptr &get_field_type () { return field_type; } + HIR::Type &get_field_type () { return *field_type; } }; // Rust tuple declared using struct keyword HIR node @@ -1857,7 +1859,12 @@ class EnumItemDiscriminant : public EnumItem void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRStmtVisitor &vis) override; - std::unique_ptr &get_discriminant_expression () { return expression; } + Expr &get_discriminant_expression () { return *expression; } + + std::unique_ptr take_discriminant_expression () + { + return std::move (expression); + } protected: // Clone function implementation as (not pure) virtual method @@ -2128,9 +2135,9 @@ class ConstantItem : public VisItem, public ImplItem void accept_vis (HIRImplVisitor &vis) override; void accept_vis (HIRVisItemVisitor &vis) override; - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } - std::unique_ptr &get_expr () { return const_expr; } + Expr &get_expr () { return *const_expr; } Identifier get_identifier () const { return identifier; } @@ -2224,9 +2231,9 @@ class StaticItem : public VisItem bool is_mut () const { return mut == Mutability::Mut; } - std::unique_ptr &get_expr () { return expr; } + Expr &get_expr () { return *expr; } - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } ItemKind get_item_kind () const override { return ItemKind::Static; } @@ -2326,7 +2333,7 @@ class TraitFunctionDecl return generic_params; } - std::unique_ptr &get_return_type () { return return_type; } + Type &get_return_type () { return *return_type; } std::vector &get_function_params () { return function_params; } @@ -2393,7 +2400,7 @@ class TraitItemFunc : public TraitItem bool has_block_defined () const { return block_expr != nullptr; } - std::unique_ptr &get_block_expr () { return block_expr; } + BlockExpr &get_block_expr () { return *block_expr; } const std::string trait_identifier () const override final { @@ -2478,9 +2485,9 @@ class TraitItemConst : public TraitItem bool has_expr () const { return expr != nullptr; } - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } - std::unique_ptr &get_expr () { return expr; } + Expr &get_expr () { return *expr; } const std::string trait_identifier () const override final { @@ -2826,7 +2833,7 @@ class ImplBlock : public VisItem, public WithInnerAttrs location_t get_locus () const override final { return locus; } - std::unique_ptr &get_type () { return impl_type; }; + Type &get_type () { return *impl_type; }; std::vector> &get_generic_params () { @@ -2835,7 +2842,7 @@ class ImplBlock : public VisItem, public WithInnerAttrs bool has_trait_ref () const { return trait_ref != nullptr; } - std::unique_ptr &get_trait_ref () { return trait_ref; } + TypePath &get_trait_ref () { return *trait_ref; } WhereClause &get_where_clause () { return where_clause; } @@ -2974,7 +2981,7 @@ class ExternalStaticItem : public ExternalItem Mutability get_mut () { return mut; } - std::unique_ptr &get_item_type () { return item_type; } + Type &get_item_type () { return *item_type; } ExternKind get_extern_kind () override { return ExternKind::Static; } @@ -3031,7 +3038,7 @@ struct NamedFunctionParam Identifier get_param_name () const { return name; } - std::unique_ptr &get_type () { return param_type; } + Type &get_type () { return *param_type; } Analysis::NodeMapping get_mappings () const { return mappings; } }; @@ -3130,7 +3137,7 @@ class ExternalFunctionItem : public ExternalItem return generic_params; } - std::unique_ptr &get_return_type () { return return_type; } + Type &get_return_type () { return *return_type; } std::vector &get_function_params () { diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index 0566e2e2a1cb..b561c30c49dc 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -107,8 +107,8 @@ class GenericArgsBinding Identifier &get_identifier () { return identifier; } const Identifier &get_identifier () const { return identifier; } - std::unique_ptr &get_type () { return type; } - const std::unique_ptr &get_type () const { return type; } + Type &get_type () { return *type; } + const Type &get_type () const { return *type; } location_t get_locus () const { return locus; } }; @@ -574,7 +574,7 @@ class TypePathFunction TypePathFunction (TypePathFunction const &other) { return_type = other.has_return_type () - ? other.get_return_type ()->clone_type () + ? other.get_return_type ().clone_type () : nullptr; inputs.reserve (other.inputs.size ()); @@ -588,7 +588,7 @@ class TypePathFunction TypePathFunction &operator= (TypePathFunction const &other) { return_type = other.has_return_type () - ? other.get_return_type ()->clone_type () + ? other.get_return_type ().clone_type () : nullptr; inputs.reserve (other.inputs.size ()); @@ -610,8 +610,8 @@ class TypePathFunction }; std::vector > &get_params () { return inputs; }; - const std::unique_ptr &get_return_type () const { return return_type; }; - std::unique_ptr &get_return_type () { return return_type; }; + const Type &get_return_type () const { return *return_type; }; + Type &get_return_type () { return *return_type; }; }; // Segment used in type path with a function argument @@ -811,9 +811,9 @@ class QualifiedPathType Analysis::NodeMapping get_mappings () const { return mappings; } - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } - std::unique_ptr &get_trait () { return trait; } + TypePath &get_trait () { return *trait; } bool trait_has_generic_args () const { @@ -963,10 +963,7 @@ class QualifiedPathInType : public TypeNoBounds QualifiedPathType &get_path_type () { return path_type; } - std::unique_ptr &get_associated_segment () - { - return associated_segment; - } + TypePathSegment &get_associated_segment () { return *associated_segment; } std::vector > &get_segments () { diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index e65a62f20a84..bedc6de51f69 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -132,7 +132,7 @@ class IdentifierPattern : public Pattern bool is_mut () const { return mut == Mutability::Mut; } bool get_is_ref () const { return is_ref; } - std::unique_ptr &get_to_bind () { return to_bind; } + Pattern &get_to_bind () { return *to_bind; } void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRPatternVisitor &vis) override; @@ -405,9 +405,9 @@ class RangePattern : public Pattern return PatternType::RANGE; } - std::unique_ptr &get_lower_bound () { return lower; } + RangePatternBound &get_lower_bound () { return *lower; } - std::unique_ptr &get_upper_bound () { return upper; } + RangePatternBound &get_upper_bound () { return *upper; } protected: /* Use covariance to implement clone function as returning this object rather @@ -476,7 +476,7 @@ class ReferencePattern : public Pattern return PatternType::REFERENCE; } - std::unique_ptr &get_referenced_pattern () { return pattern; } + Pattern &get_referenced_pattern () { return *pattern; } protected: /* Use covariance to implement clone function as returning this object rather @@ -572,7 +572,7 @@ class StructPatternFieldTuplePat : public StructPatternField void accept_vis (HIRFullVisitor &vis) override; TupleIndex get_index () { return index; } - std::unique_ptr &get_tuple_pattern () { return tuple_pattern; } + Pattern &get_tuple_pattern () { return *tuple_pattern; } ItemType get_item_type () const override final { return ItemType::TUPLE_PAT; } @@ -630,7 +630,7 @@ class StructPatternFieldIdentPat : public StructPatternField Identifier get_identifier () const { return ident; } - std::unique_ptr &get_pattern () { return ident_pattern; } + Pattern &get_pattern () { return *ident_pattern; } protected: /* Use covariance to implement clone function as returning this object rather @@ -1002,7 +1002,7 @@ class TupleStructPattern : public Pattern PathInExpression &get_path () { return path; } - std::unique_ptr &get_items () { return items; } + TupleStructItems &get_items () { return *items; } const Analysis::NodeMapping &get_mappings () const override final { @@ -1221,8 +1221,8 @@ class TuplePattern : public Pattern return PatternType::TUPLE; } - std::unique_ptr &get_items () { return items; } - const std::unique_ptr &get_items () const { return items; } + TuplePatternItems &get_items () { return *items; } + const TuplePatternItems &get_items () const { return *items; } protected: /* Use covariance to implement clone function as returning this object rather diff --git a/gcc/rust/hir/tree/rust-hir-stmt.h b/gcc/rust/hir/tree/rust-hir-stmt.h index a51dab7b82af..f63717732020 100644 --- a/gcc/rust/hir/tree/rust-hir-stmt.h +++ b/gcc/rust/hir/tree/rust-hir-stmt.h @@ -144,11 +144,11 @@ class LetStmt : public Stmt } std::vector &get_outer_attrs () { return outer_attrs; } - std::unique_ptr &get_type () { return type; } + HIR::Type &get_type () { return *type; } - std::unique_ptr &get_init_expr () { return init_expr; } + HIR::Expr &get_init_expr () { return *init_expr; } - std::unique_ptr &get_pattern () { return variables_pattern; } + HIR::Pattern &get_pattern () { return *variables_pattern; } bool is_item () const override final { return false; } @@ -186,7 +186,7 @@ class ExprStmt : public Stmt bool is_item () const override final { return false; } - std::unique_ptr &get_expr () { return expr; } + Expr &get_expr () { return *expr; } // Copy constructor with clone ExprStmt (ExprStmt const &other) diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h index 8f068ef230e0..a8ac4a1b076e 100644 --- a/gcc/rust/hir/tree/rust-hir-type.h +++ b/gcc/rust/hir/tree/rust-hir-type.h @@ -271,7 +271,7 @@ class ParenthesisedType : public TypeNoBounds * parenthesised type, it must be in parentheses. */ return type_in_parens->to_trait_bound (true); } - std::unique_ptr &get_type_in_parens () { return type_in_parens; } + Type &get_type_in_parens () { return *type_in_parens; } void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRTypeVisitor &vis) override; }; @@ -439,7 +439,7 @@ class RawPointerType : public TypeNoBounds void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRTypeVisitor &vis) override; - std::unique_ptr &get_type () { return type; } + Type &get_type () { return *type; } Mutability get_mut () const { return mut; } @@ -447,7 +447,7 @@ class RawPointerType : public TypeNoBounds bool is_const () const { return mut == Mutability::Imm; } - std::unique_ptr &get_base_type () { return type; } + Type &get_base_type () { return *type; } protected: /* Use covariance to implement clone function as returning this object rather @@ -520,7 +520,7 @@ class ReferenceType : public TypeNoBounds Mutability get_mut () const { return mut; } - std::unique_ptr &get_base_type () { return type; } + Type &get_base_type () { return *type; } protected: /* Use covariance to implement clone function as returning this object rather @@ -578,9 +578,9 @@ class ArrayType : public TypeNoBounds void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRTypeVisitor &vis) override; - std::unique_ptr &get_element_type () { return elem_type; } + Type &get_element_type () { return *elem_type; } - std::unique_ptr &get_size_expr () { return size; } + Expr &get_size_expr () { return *size; } protected: /* Use covariance to implement clone function as returning this object rather @@ -633,7 +633,7 @@ class SliceType : public TypeNoBounds void accept_vis (HIRFullVisitor &vis) override; void accept_vis (HIRTypeVisitor &vis) override; - std::unique_ptr &get_element_type () { return elem_type; } + Type &get_element_type () { return *elem_type; } protected: /* Use covariance to implement clone function as returning this object rather @@ -743,7 +743,7 @@ struct MaybeNamedParam location_t get_locus () const { return locus; } - std::unique_ptr &get_type () { return param_type; } + Type &get_type () { return *param_type; } ParamKind get_param_kind () const { return param_kind; } @@ -828,7 +828,7 @@ class BareFunctionType : public TypeNoBounds } // TODO: would a "vis_type" be better? - std::unique_ptr &get_return_type () { return return_type; } + Type &get_return_type () { return *return_type; } protected: /* Use covariance to implement clone function as returning this object rather diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index b427f1d204dc..90d57c23ec80 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -757,11 +757,8 @@ class ConstGenericParam : public GenericParam bool has_default_expression () { return default_expression != nullptr; } std::string get_name () { return name; } - std::unique_ptr &get_type () { return type; } - std::unique_ptr &get_default_expression () - { - return default_expression; - } + Type &get_type () { return *type; } + Expr &get_default_expression () { return *default_expression; } protected: /* Use covariance to implement clone function as returning this object rather diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc index 285857323225..a0a2b50019bc 100644 --- a/gcc/rust/typecheck/rust-autoderef.cc +++ b/gcc/rust/typecheck/rust-autoderef.cc @@ -209,7 +209,7 @@ resolve_operator_overload_fn ( == 0) { TraitReference *trait_reference - = TraitResolver::Lookup (*parent->get_trait_ref ().get ()); + = TraitResolver::Lookup (parent->get_trait_ref ()); if (!trait_reference->is_error ()) { TyTy::BaseType *lookup = nullptr; diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc index 2c8e53e9bc4d..38535ccfd743 100644 --- a/gcc/rust/typecheck/rust-hir-dot-operator.cc +++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc @@ -200,104 +200,103 @@ MethodResolver::select (TyTy::BaseType &receiver) }; std::vector trait_fns; - mappings.iterate_impl_blocks ( - [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool { - bool is_trait_impl = impl->has_trait_ref (); - if (!is_trait_impl) - return true; - - // look for impl implementation else lookup the associated trait item - for (auto &impl_item : impl->get_impl_items ()) - { - bool is_fn = impl_item->get_impl_item_type () - == HIR::ImplItem::ImplItemType::FUNCTION; - if (!is_fn) - continue; - - HIR::Function *func = static_cast (impl_item.get ()); - if (!func->is_method ()) - continue; - - bool name_matches = func->get_function_name ().as_string ().compare ( - segment_name.as_string ()) - == 0; - if (!name_matches) - continue; - - TyTy::BaseType *ty = nullptr; - if (!query_type (func->get_mappings ().get_hirid (), &ty)) - continue; - if (ty->get_kind () == TyTy::TypeKind::ERROR) - continue; - - rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF); - TyTy::FnType *fnty = static_cast (ty); - const TyTy::BaseType *impl_self - = TypeCheckItem::ResolveImplBlockSelf (*impl); - - // see: - // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280 - // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660 - bool impl_self_is_ptr - = impl_self->get_kind () == TyTy::TypeKind::POINTER; - bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF; - if (receiver_is_raw_ptr && impl_self_is_ptr) - { - const TyTy::PointerType &sptr - = *static_cast (impl_self); - const TyTy::PointerType &ptr - = *static_cast (raw); - - // we could do this via lang-item assemblies if we refactor this - bool mut_match = sptr.mutability () == ptr.mutability (); - if (!mut_match) - continue; - } - else if (receiver_is_ref && impl_self_is_ref) - { - const TyTy::ReferenceType &sptr - = *static_cast (impl_self); - const TyTy::ReferenceType &ptr - = *static_cast (raw); - - // we could do this via lang-item assemblies if we refactor this - bool mut_match = sptr.mutability () == ptr.mutability (); - if (!mut_match) - continue; - } + mappings.iterate_impl_blocks ([&] (HirId id, + HIR::ImplBlock *impl) mutable -> bool { + bool is_trait_impl = impl->has_trait_ref (); + if (!is_trait_impl) + return true; - inherent_impl_fns.push_back ({func, impl, fnty}); - return true; - } + // look for impl implementation else lookup the associated trait item + for (auto &impl_item : impl->get_impl_items ()) + { + bool is_fn = impl_item->get_impl_item_type () + == HIR::ImplItem::ImplItemType::FUNCTION; + if (!is_fn) + continue; + + HIR::Function *func = static_cast (impl_item.get ()); + if (!func->is_method ()) + continue; + + bool name_matches = func->get_function_name ().as_string ().compare ( + segment_name.as_string ()) + == 0; + if (!name_matches) + continue; + + TyTy::BaseType *ty = nullptr; + if (!query_type (func->get_mappings ().get_hirid (), &ty)) + continue; + if (ty->get_kind () == TyTy::TypeKind::ERROR) + continue; + + rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF); + TyTy::FnType *fnty = static_cast (ty); + const TyTy::BaseType *impl_self + = TypeCheckItem::ResolveImplBlockSelf (*impl); + + // see: + // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280 + // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660 + bool impl_self_is_ptr + = impl_self->get_kind () == TyTy::TypeKind::POINTER; + bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF; + if (receiver_is_raw_ptr && impl_self_is_ptr) + { + const TyTy::PointerType &sptr + = *static_cast (impl_self); + const TyTy::PointerType &ptr + = *static_cast (raw); + + // we could do this via lang-item assemblies if we refactor this + bool mut_match = sptr.mutability () == ptr.mutability (); + if (!mut_match) + continue; + } + else if (receiver_is_ref && impl_self_is_ref) + { + const TyTy::ReferenceType &sptr + = *static_cast (impl_self); + const TyTy::ReferenceType &ptr + = *static_cast (raw); + + // we could do this via lang-item assemblies if we refactor this + bool mut_match = sptr.mutability () == ptr.mutability (); + if (!mut_match) + continue; + } + + inherent_impl_fns.push_back ({func, impl, fnty}); + return true; + } - TraitReference *trait_ref - = TraitResolver::Resolve (*impl->get_trait_ref ().get ()); - rust_assert (!trait_ref->is_error ()); + TraitReference *trait_ref = TraitResolver::Resolve (impl->get_trait_ref ()); + rust_assert (!trait_ref->is_error ()); - auto item_ref - = trait_ref->lookup_trait_item (segment_name.as_string (), - TraitItemReference::TraitItemType::FN); - if (item_ref->is_error ()) - return true; + auto item_ref + = trait_ref->lookup_trait_item (segment_name.as_string (), + TraitItemReference::TraitItemType::FN); + if (item_ref->is_error ()) + return true; - const HIR::Trait *trait = trait_ref->get_hir_trait_ref (); - HIR::TraitItem *item = item_ref->get_hir_trait_item (); - if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC) - return true; + const HIR::Trait *trait = trait_ref->get_hir_trait_ref (); + HIR::TraitItem *item = item_ref->get_hir_trait_item (); + if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC) + return true; - HIR::TraitItemFunc *func = static_cast (item); - if (!func->get_decl ().is_method ()) - return true; + HIR::TraitItemFunc *func = static_cast (item); + if (!func->get_decl ().is_method ()) + return true; - TyTy::BaseType *ty = item_ref->get_tyty (); - rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF); - TyTy::FnType *fnty = static_cast (ty); + TyTy::BaseType *ty = item_ref->get_tyty (); + rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF); + TyTy::FnType *fnty = static_cast (ty); - trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref}; - trait_fns.push_back (candidate); + trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref}; + trait_fns.push_back (candidate); - return true; - }); + return true; + }); // lookup specified bounds for an associated item struct precdicate_candidate diff --git a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h index a9edc42f1a62..b390d00f031b 100644 --- a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h +++ b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h @@ -54,7 +54,7 @@ class OverlappingImplItemPass : public TypeCheckBase // impl-type -> [ (item, name), ... ] // } - HirId impl_type_id = impl->get_type ()->get_mappings ().get_hirid (); + HirId impl_type_id = impl->get_type ().get_mappings ().get_hirid (); TyTy::BaseType *impl_type = nullptr; bool ok = query_type (impl_type_id, &impl_type); if (!ok) diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index aa74f2e56d55..fa3ef47ebeaa 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -297,7 +297,7 @@ PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) { current_impl = impl; - HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid (); + HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid (); TyTy::BaseType *impl_block_ty = nullptr; if (!query_type (impl_ty_id, &impl_block_ty)) return; @@ -472,8 +472,7 @@ PathProbeImplTrait::process_trait_impl_items_for_candidates () if (!impl->has_trait_ref ()) return true; - TraitReference *resolved - = TraitResolver::Lookup (*(impl->get_trait_ref ().get ())); + TraitReference *resolved = TraitResolver::Lookup (impl->get_trait_ref ()); if (!trait_reference->is_equal (*resolved)) return true; diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 642bf2706fb6..259d7a703bfa 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -189,8 +189,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) // The one exception is the implicit Self type of a trait bool apply_sized = !is_self; auto param_type - = TypeResolveGenericParam::Resolve (generic_param.get (), - apply_sized); + = TypeResolveGenericParam::Resolve (*generic_param, apply_sized); context->insert_type (generic_param->get_mappings (), param_type); substitutions.push_back ( TyTy::SubstitutionParamMapping (typaram, param_type)); @@ -241,7 +240,7 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) auto predicate = get_predicate_from_bound ( b->get_path (), - nullptr /*this will setup a PLACEHOLDER for self*/); + tl::nullopt /*this will setup a PLACEHOLDER for self*/); if (predicate.is_error ()) return &TraitReference::error_node (); @@ -357,11 +356,11 @@ TraitItemReference::resolve_item (HIR::TraitItemFunc &func) auto expected_ret_tyty = resolved_fn_type->get_return_type (); context->push_return_type (TypeCheckContextItem (&func), expected_ret_tyty); - auto block_expr_ty = TypeCheckExpr::Resolve (func.get_block_expr ().get ()); + auto block_expr_ty = TypeCheckExpr::Resolve (func.get_block_expr ()); location_t fn_return_locus = func.get_decl ().has_return_type () - ? func.get_decl ().get_return_type ()->get_locus () + ? func.get_decl ().get_return_type ().get_locus () : func.get_locus (); coercion_site (func.get_mappings ().get_hirid (), diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc index 82782c68f418..c1700fafdfc9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc @@ -374,22 +374,21 @@ TypeCheckBase::resolve_generic_params ( break; case HIR::GenericParam::GenericKind::CONST: { - auto param - = static_cast (generic_param.get ()); - auto specified_type - = TypeCheckType::Resolve (param->get_type ().get ()); + auto ¶m + = static_cast (*generic_param); + auto specified_type = TypeCheckType::Resolve (param.get_type ()); - if (param->has_default_expression ()) + if (param.has_default_expression ()) { - auto expr_type = TypeCheckExpr::Resolve ( - param->get_default_expression ().get ()); - - coercion_site ( - param->get_mappings ().get_hirid (), - TyTy::TyWithLocation (specified_type), - TyTy::TyWithLocation ( - expr_type, param->get_default_expression ()->get_locus ()), - param->get_locus ()); + auto expr_type + = TypeCheckExpr::Resolve (param.get_default_expression ()); + + coercion_site (param.get_mappings ().get_hirid (), + TyTy::TyWithLocation (specified_type), + TyTy::TyWithLocation ( + expr_type, + param.get_default_expression ().get_locus ()), + param.get_locus ()); } context->insert_type (generic_param->get_mappings (), @@ -398,8 +397,7 @@ TypeCheckBase::resolve_generic_params ( break; case HIR::GenericParam::GenericKind::TYPE: { - auto param_type - = TypeResolveGenericParam::Resolve (generic_param.get ()); + auto param_type = TypeResolveGenericParam::Resolve (*generic_param); context->insert_type (generic_param->get_mappings (), param_type); substitutions.push_back (TyTy::SubstitutionParamMapping ( diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h index b085b4b7a4e3..8b071949eb4f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.h +++ b/gcc/rust/typecheck/rust-hir-type-check-base.h @@ -37,10 +37,10 @@ class TypeCheckBase TraitReference *resolve_trait_path (HIR::TypePath &); - TyTy::TypeBoundPredicate - get_predicate_from_bound (HIR::TypePath &path, HIR::Type *associated_self, - BoundPolarity polarity - = BoundPolarity::RegularBound); + TyTy::TypeBoundPredicate get_predicate_from_bound ( + HIR::TypePath &path, + tl::optional> associated_self, + BoundPolarity polarity = BoundPolarity::RegularBound); bool check_for_unconstrained ( const std::vector ¶ms_to_constrain, @@ -55,7 +55,7 @@ class TypeCheckBase location_t locus); void resolve_generic_params ( - const std::vector > &generic_params, + const std::vector> &generic_params, std::vector &substitutions); TyTy::TypeBoundPredicate get_marker_predicate (LangItem::Kind item_type, diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc index 82051aea9bd0..34763eed52fa 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc @@ -16,6 +16,7 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-hir-expr.h" #include "rust-hir-type-check-type.h" #include "rust-hir-type-check-expr.h" #include "rust-hir-type-check-enumitem.h" @@ -25,25 +26,25 @@ namespace Rust { namespace Resolver { TyTy::VariantDef * -TypeCheckEnumItem::Resolve (HIR::EnumItem *item, int64_t last_discriminant) +TypeCheckEnumItem::Resolve (HIR::EnumItem &item, int64_t last_discriminant) { TypeCheckEnumItem resolver (last_discriminant); - switch (item->get_enum_item_kind ()) + switch (item.get_enum_item_kind ()) { case HIR::EnumItem::EnumItemKind::Named: - resolver.visit (static_cast (*item)); + resolver.visit (static_cast (item)); break; case HIR::EnumItem::EnumItemKind::Tuple: - resolver.visit (static_cast (*item)); + resolver.visit (static_cast (item)); break; case HIR::EnumItem::EnumItemKind::Struct: - resolver.visit (static_cast (*item)); + resolver.visit (static_cast (item)); break; case HIR::EnumItem::EnumItemKind::Discriminant: - resolver.visit (static_cast (*item)); + resolver.visit (static_cast (item)); break; } return resolver.variant; @@ -64,11 +65,10 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item) mappings.get_next_hir_id ( item.get_mappings ().get_crate_num ()), item.get_mappings ().get_local_defid ()); - HIR::LiteralExpr *discim_expr - = new HIR::LiteralExpr (mapping, std::to_string (last_discriminant), - HIR::Literal::LitType::INT, - PrimitiveCoreType::CORETYPE_I64, item.get_locus (), - {}); + auto discim_expr = Rust::make_unique ( + HIR::LiteralExpr (mapping, std::to_string (last_discriminant), + HIR::Literal::LitType::INT, + PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {})); TyTy::BaseType *isize = nullptr; bool ok = context->lookup_builtin ("isize", &isize); @@ -82,7 +82,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item) variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), item.get_mappings ().get_defid (), item.get_identifier ().as_string (), ident, - discim_expr); + std::move (discim_expr)); } void @@ -92,13 +92,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item) rust_error_at (item.get_locus (), "discriminant too big"); auto &discriminant = item.get_discriminant_expression (); - auto capacity_type = TypeCheckExpr::Resolve (discriminant.get ()); + auto capacity_type = TypeCheckExpr::Resolve (discriminant); if (capacity_type->get_kind () == TyTy::TypeKind::ERROR) return; TyTy::ISizeType *expected_ty - = new TyTy::ISizeType (discriminant->get_mappings ().get_hirid ()); - context->insert_type (discriminant->get_mappings (), expected_ty); + = new TyTy::ISizeType (discriminant.get_mappings ().get_hirid ()); + context->insert_type (discriminant.get_mappings (), expected_ty); unify_site (item.get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty), @@ -111,7 +111,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item) variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), item.get_mappings ().get_defid (), item.get_identifier ().as_string (), ident, - item.get_discriminant_expression ().get ()); + item.take_discriminant_expression ()); } void @@ -125,7 +125,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) for (auto &field : item.get_tuple_fields ()) { TyTy::BaseType *field_type - = TypeCheckType::Resolve (field.get_field_type ().get ()); + = TypeCheckType::Resolve (field.get_field_type ()); TyTy::StructFieldType *ty_field = new TyTy::StructFieldType (field.get_mappings ().get_hirid (), std::to_string (idx), field_type, @@ -140,11 +140,10 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) mappings.get_next_hir_id ( item.get_mappings ().get_crate_num ()), item.get_mappings ().get_local_defid ()); - HIR::LiteralExpr *discim_expr - = new HIR::LiteralExpr (mapping, std::to_string (last_discriminant), - HIR::Literal::LitType::INT, - PrimitiveCoreType::CORETYPE_I64, item.get_locus (), - {}); + auto discim_expr = Rust::make_unique ( + HIR::LiteralExpr (mapping, std::to_string (last_discriminant), + HIR::Literal::LitType::INT, + PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {})); TyTy::BaseType *isize = nullptr; bool ok = context->lookup_builtin ("isize", &isize); @@ -159,7 +158,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) item.get_mappings ().get_defid (), item.get_identifier ().as_string (), ident, TyTy::VariantDef::VariantType::TUPLE, - discim_expr, fields); + std::move (discim_expr), fields); } void @@ -172,7 +171,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) for (auto &field : item.get_struct_fields ()) { TyTy::BaseType *field_type - = TypeCheckType::Resolve (field.get_field_type ().get ()); + = TypeCheckType::Resolve (field.get_field_type ()); TyTy::StructFieldType *ty_field = new TyTy::StructFieldType (field.get_mappings ().get_hirid (), field.get_field_name ().as_string (), @@ -186,11 +185,10 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) mappings.get_next_hir_id ( item.get_mappings ().get_crate_num ()), item.get_mappings ().get_local_defid ()); - HIR::LiteralExpr *discrim_expr - = new HIR::LiteralExpr (mapping, std::to_string (last_discriminant), - HIR::Literal::LitType::INT, - PrimitiveCoreType::CORETYPE_I64, item.get_locus (), - {}); + auto discrim_expr = Rust::make_unique ( + HIR::LiteralExpr (mapping, std::to_string (last_discriminant), + HIR::Literal::LitType::INT, + PrimitiveCoreType::CORETYPE_I64, item.get_locus (), {})); TyTy::BaseType *isize = nullptr; bool ok = context->lookup_builtin ("isize", &isize); @@ -205,7 +203,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) item.get_mappings ().get_defid (), item.get_identifier ().as_string (), ident, TyTy::VariantDef::VariantType::STRUCT, - discrim_expr, fields); + std::move (discrim_expr), fields); } } // namespace Resolver diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h index 5f68d8e9869a..baed198d4343 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.h @@ -28,7 +28,7 @@ namespace Resolver { class TypeCheckEnumItem : public TypeCheckBase { public: - static TyTy::VariantDef *Resolve (HIR::EnumItem *item, + static TyTy::VariantDef *Resolve (HIR::EnumItem &item, int64_t last_discriminant); protected: diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 8485f9c3acfa..805f9799d2fe 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -36,17 +36,17 @@ TypeCheckExpr::TypeCheckExpr () : TypeCheckBase (), infered (nullptr) {} // Perform type checking on expr. Also runs type unification algorithm. // Returns the unified type of expr TyTy::BaseType * -TypeCheckExpr::Resolve (HIR::Expr *expr) +TypeCheckExpr::Resolve (HIR::Expr &expr) { TypeCheckExpr resolver; - expr->accept_vis (resolver); + expr.accept_vis (resolver); if (resolver.infered == nullptr) - return new TyTy::ErrorType (expr->get_mappings ().get_hirid ()); + return new TyTy::ErrorType (expr.get_mappings ().get_hirid ()); - auto ref = expr->get_mappings ().get_hirid (); + auto ref = expr.get_mappings ().get_hirid (); resolver.infered->set_ref (ref); - resolver.context->insert_type (expr->get_mappings (), resolver.infered); + resolver.context->insert_type (expr.get_mappings (), resolver.infered); return resolver.infered; } @@ -54,10 +54,10 @@ TypeCheckExpr::Resolve (HIR::Expr *expr) void TypeCheckExpr::visit (HIR::TupleIndexExpr &expr) { - auto resolved = TypeCheckExpr::Resolve (expr.get_tuple_expr ().get ()); + auto resolved = TypeCheckExpr::Resolve (expr.get_tuple_expr ()); if (resolved->get_kind () == TyTy::TypeKind::ERROR) { - rust_error_at (expr.get_tuple_expr ()->get_locus (), + rust_error_at (expr.get_tuple_expr ().get_locus (), "failed to resolve TupleIndexExpr receiver"); return; } @@ -73,7 +73,7 @@ TypeCheckExpr::visit (HIR::TupleIndexExpr &expr) || resolved->get_kind () == TyTy::TypeKind::TUPLE; if (!is_valid_type) { - rust_error_at (expr.get_tuple_expr ()->get_locus (), + rust_error_at (expr.get_tuple_expr ().get_locus (), "Expected Tuple or ADT got: %s", resolved->as_string ().c_str ()); return; @@ -141,7 +141,7 @@ TypeCheckExpr::visit (HIR::TupleExpr &expr) std::vector fields; for (auto &elem : expr.get_tuple_elems ()) { - auto field_ty = TypeCheckExpr::Resolve (elem.get ()); + auto field_ty = TypeCheckExpr::Resolve (*elem); fields.push_back (TyTy::TyVar (field_ty->get_ref ())); } infered = new TyTy::TupleType (expr.get_mappings ().get_hirid (), @@ -161,11 +161,11 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr) auto fn_return_tyty = context->peek_return_type (); location_t expr_locus = expr.has_return_expr () - ? expr.get_expr ()->get_locus () + ? expr.get_expr ().get_locus () : expr.get_locus (); TyTy::BaseType *expr_ty = expr.has_return_expr () - ? TypeCheckExpr::Resolve (expr.get_expr ().get ()) + ? TypeCheckExpr::Resolve (expr.get_expr ()) : TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); coercion_site (expr.get_mappings ().get_hirid (), @@ -178,8 +178,7 @@ TypeCheckExpr::visit (HIR::ReturnExpr &expr) void TypeCheckExpr::visit (HIR::CallExpr &expr) { - TyTy::BaseType *function_tyty - = TypeCheckExpr::Resolve (expr.get_fnexpr ().get ()); + TyTy::BaseType *function_tyty = TypeCheckExpr::Resolve (expr.get_fnexpr ()); rust_debug_loc (expr.get_locus (), "resolved_call_expr to: {%s}", function_tyty->get_name ().c_str ()); @@ -193,19 +192,19 @@ TypeCheckExpr::visit (HIR::CallExpr &expr) // lookup variant id HirId variant_id; bool ok = context->lookup_variant_definition ( - expr.get_fnexpr ()->get_mappings ().get_hirid (), &variant_id); + expr.get_fnexpr ().get_mappings ().get_hirid (), &variant_id); rust_assert (ok); TyTy::VariantDef *lookup_variant = nullptr; ok = adt->lookup_variant_by_id (variant_id, &lookup_variant); rust_assert (ok); - variant = *lookup_variant; + variant = std::move (*lookup_variant); } else { rust_assert (adt->number_of_variants () == 1); - variant = *adt->get_variants ().at (0); + variant = std::move (*adt->get_variants ().at (0)); } infered @@ -235,12 +234,12 @@ TypeCheckExpr::visit (HIR::AssignmentExpr &expr) { infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); - auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ()); - auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ()); + auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); + auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); coercion_site (expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()), - TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()), + TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()), + TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()), expr.get_locus ()); } @@ -249,14 +248,14 @@ TypeCheckExpr::visit (HIR::CompoundAssignmentExpr &expr) { infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); - auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ()); - auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ()); + auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); + auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); // we dont care about the result of the unify from a compound assignment // since this is a unit-type expr coercion_site (expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()), - TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()), + TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()), + TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()), expr.get_locus ()); auto lang_item_type @@ -288,8 +287,8 @@ TypeCheckExpr::visit (HIR::LiteralExpr &expr) void TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr) { - auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ()); - auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ()); + auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); + auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); auto lang_item_type = LangItem::OperatorToLangItem (expr.get_expr_type ()); bool operator_overloaded @@ -312,8 +311,8 @@ TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr) { case ArithmeticOrLogicalOperator::LEFT_SHIFT: case ArithmeticOrLogicalOperator::RIGHT_SHIFT: { - TyTy::TyWithLocation from (rhs, expr.get_rhs ()->get_locus ()); - TyTy::TyWithLocation to (lhs, expr.get_lhs ()->get_locus ()); + TyTy::TyWithLocation from (rhs, expr.get_rhs ().get_locus ()); + TyTy::TyWithLocation to (lhs, expr.get_lhs ().get_locus ()); infered = cast_site (expr.get_mappings ().get_hirid (), from, to, expr.get_locus ()); } @@ -322,8 +321,8 @@ TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr) default: { infered = unify_site ( expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()), - TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()), + TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()), + TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()), expr.get_locus ()); } break; @@ -333,12 +332,12 @@ TypeCheckExpr::visit (HIR::ArithmeticOrLogicalExpr &expr) void TypeCheckExpr::visit (HIR::ComparisonExpr &expr) { - auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ()); - auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ()); + auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); + auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); unify_site (expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()), - TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()), + TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()), + TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()), expr.get_locus ()); bool ok = context->lookup_builtin ("bool", &infered); @@ -348,8 +347,8 @@ TypeCheckExpr::visit (HIR::ComparisonExpr &expr) void TypeCheckExpr::visit (HIR::LazyBooleanExpr &expr) { - auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ().get ()); - auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ().get ()); + auto lhs = TypeCheckExpr::Resolve (expr.get_lhs ()); + auto rhs = TypeCheckExpr::Resolve (expr.get_rhs ()); // we expect the lhs and rhs must be bools at this point TyTy::BaseType *boolean_node = nullptr; @@ -359,27 +358,27 @@ TypeCheckExpr::visit (HIR::LazyBooleanExpr &expr) // verify the lhs and rhs before unifying together lhs = unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (boolean_node, - expr.get_lhs ()->get_locus ()), - TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()), + expr.get_lhs ().get_locus ()), + TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()), expr.get_locus ()); rhs = unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (boolean_node, - expr.get_rhs ()->get_locus ()), - TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()), + expr.get_rhs ().get_locus ()), + TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()), expr.get_locus ()); infered = unify_site (expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (lhs, expr.get_lhs ()->get_locus ()), - TyTy::TyWithLocation (rhs, expr.get_rhs ()->get_locus ()), + TyTy::TyWithLocation (lhs, expr.get_lhs ().get_locus ()), + TyTy::TyWithLocation (rhs, expr.get_rhs ().get_locus ()), expr.get_locus ()); } void TypeCheckExpr::visit (HIR::NegationExpr &expr) { - auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ().get ()); + auto negated_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ()); // check for operator overload auto lang_item_type @@ -444,15 +443,14 @@ TypeCheckExpr::visit (HIR::IfExpr &expr) bool ok = context->lookup_builtin ("bool", &bool_ty); rust_assert (ok); - TyTy::BaseType *cond_type - = TypeCheckExpr::Resolve (expr.get_if_condition ().get ()); + TyTy::BaseType *cond_type = TypeCheckExpr::Resolve (expr.get_if_condition ()); unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (bool_ty), TyTy::TyWithLocation (cond_type, - expr.get_if_condition ()->get_locus ()), + expr.get_if_condition ().get_locus ()), expr.get_locus ()); - TypeCheckExpr::Resolve (expr.get_if_block ().get ()); + TypeCheckExpr::Resolve (expr.get_if_block ()); infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); } @@ -464,17 +462,15 @@ TypeCheckExpr::visit (HIR::IfExprConseqElse &expr) bool ok = context->lookup_builtin ("bool", &bool_ty); rust_assert (ok); - TyTy::BaseType *cond_type - = TypeCheckExpr::Resolve (expr.get_if_condition ().get ()); + TyTy::BaseType *cond_type = TypeCheckExpr::Resolve (expr.get_if_condition ()); unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (bool_ty), TyTy::TyWithLocation (cond_type, - expr.get_if_condition ()->get_locus ()), + expr.get_if_condition ().get_locus ()), expr.get_locus ()); - auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ().get ()); - auto else_blk_resolved - = TypeCheckExpr::Resolve (expr.get_else_block ().get ()); + auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ()); + auto else_blk_resolved = TypeCheckExpr::Resolve (expr.get_else_block ()); if (if_blk_resolved->get_kind () == TyTy::NEVER) infered = else_blk_resolved; @@ -482,13 +478,13 @@ TypeCheckExpr::visit (HIR::IfExprConseqElse &expr) infered = if_blk_resolved; else { - infered = unify_site ( - expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (if_blk_resolved, - expr.get_if_block ()->get_locus ()), - TyTy::TyWithLocation (else_blk_resolved, - expr.get_else_block ()->get_locus ()), - expr.get_locus ()); + infered + = unify_site (expr.get_mappings ().get_hirid (), + TyTy::TyWithLocation (if_blk_resolved, + expr.get_if_block ().get_locus ()), + TyTy::TyWithLocation ( + else_blk_resolved, expr.get_else_block ().get_locus ()), + expr.get_locus ()); } } @@ -498,12 +494,12 @@ TypeCheckExpr::visit (HIR::IfLetExpr &expr) // this needs to perform a least upper bound coercion on the blocks and then // unify the scruintee and arms TyTy::BaseType *scrutinee_tyty - = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ()); + = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ()); for (auto &pattern : expr.get_patterns ()) { TyTy::BaseType *kase_arm_ty - = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty); + = TypeCheckPattern::Resolve (*pattern, scrutinee_tyty); unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (scrutinee_tyty), @@ -511,7 +507,7 @@ TypeCheckExpr::visit (HIR::IfLetExpr &expr) expr.get_locus ()); } - TypeCheckExpr::Resolve (expr.get_if_block ().get ()); + TypeCheckExpr::Resolve (expr.get_if_block ()); infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); } @@ -520,12 +516,12 @@ void TypeCheckExpr::visit (HIR::IfLetExprConseqElse &expr) { TyTy::BaseType *scrutinee_tyty - = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ()); + = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ()); for (auto &pattern : expr.get_patterns ()) { TyTy::BaseType *kase_arm_ty - = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty); + = TypeCheckPattern::Resolve (*pattern, scrutinee_tyty); unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (scrutinee_tyty), @@ -533,9 +529,8 @@ TypeCheckExpr::visit (HIR::IfLetExprConseqElse &expr) expr.get_locus ()); } - auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ().get ()); - auto else_blk_resolved - = TypeCheckExpr::Resolve (expr.get_else_block ().get ()); + auto if_blk_resolved = TypeCheckExpr::Resolve (expr.get_if_block ()); + auto else_blk_resolved = TypeCheckExpr::Resolve (expr.get_else_block ()); if (if_blk_resolved->get_kind () == TyTy::NEVER) infered = else_blk_resolved; @@ -543,20 +538,20 @@ TypeCheckExpr::visit (HIR::IfLetExprConseqElse &expr) infered = if_blk_resolved; else { - infered = unify_site ( - expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (if_blk_resolved, - expr.get_if_block ()->get_locus ()), - TyTy::TyWithLocation (else_blk_resolved, - expr.get_else_block ()->get_locus ()), - expr.get_locus ()); + infered + = unify_site (expr.get_mappings ().get_hirid (), + TyTy::TyWithLocation (if_blk_resolved, + expr.get_if_block ().get_locus ()), + TyTy::TyWithLocation ( + else_blk_resolved, expr.get_else_block ().get_locus ()), + expr.get_locus ()); } } void TypeCheckExpr::visit (HIR::UnsafeBlockExpr &expr) { - infered = TypeCheckExpr::Resolve (expr.get_block_expr ().get ()); + infered = TypeCheckExpr::Resolve (expr.get_block_expr ()); } void @@ -571,7 +566,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) if (!s->is_item ()) continue; - TypeCheckStmt::Resolve (s.get ()); + TypeCheckStmt::Resolve (*s); } for (auto &s : expr.get_statements ()) @@ -579,7 +574,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) if (s->is_item ()) continue; - auto resolved = TypeCheckStmt::Resolve (s.get ()); + auto resolved = TypeCheckStmt::Resolve (*s); if (resolved == nullptr) { rust_error_at (s->get_locus (), "failure to resolve type"); @@ -598,7 +593,7 @@ TypeCheckExpr::visit (HIR::BlockExpr &expr) } if (expr.has_expr ()) - infered = TypeCheckExpr::Resolve (expr.get_final_expr ().get ())->clone (); + infered = TypeCheckExpr::Resolve (expr.get_final_expr ())->clone (); else if (expr.is_tail_reachable ()) infered = TyTy::TupleType::get_unit_type (expr.get_mappings ().get_hirid ()); @@ -654,14 +649,13 @@ TypeCheckExpr::visit (HIR::RangeFromToExpr &expr) // resolve the range expressions and these types must unify then we use that // type to substitute into the ADT - TyTy::BaseType *from_ty - = TypeCheckExpr::Resolve (expr.get_from_expr ().get ()); - TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ().get ()); + TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_from_expr ()); + TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ()); TyTy::BaseType *unified = unify_site ( expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (from_ty, expr.get_from_expr ()->get_locus ()), - TyTy::TyWithLocation (to_ty, expr.get_to_expr ()->get_locus ()), + TyTy::TyWithLocation (from_ty, expr.get_from_expr ().get_locus ()), + TyTy::TyWithLocation (to_ty, expr.get_to_expr ().get_locus ()), expr.get_locus ()); // substitute it in @@ -706,8 +700,7 @@ TypeCheckExpr::visit (HIR::RangeFromExpr &expr) // resolve the range expressions and these types must unify then we use that // type to substitute into the ADT - TyTy::BaseType *from_ty - = TypeCheckExpr::Resolve (expr.get_from_expr ().get ()); + TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_from_expr ()); // substitute it in std::vector subst_mappings; @@ -751,7 +744,7 @@ TypeCheckExpr::visit (HIR::RangeToExpr &expr) // resolve the range expressions and these types must unify then we use that // type to substitute into the ADT - TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_to_expr ().get ()); + TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_to_expr ()); // substitute it in std::vector subst_mappings; @@ -823,13 +816,12 @@ TypeCheckExpr::visit (HIR::RangeFromToInclExpr &expr) // resolve the range expressions and these types must unify then we use that // type to substitute into the ADT - TyTy::BaseType *from_ty - = TypeCheckExpr::Resolve (expr.get_from_expr ().get ()); - TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ().get ()); + TyTy::BaseType *from_ty = TypeCheckExpr::Resolve (expr.get_from_expr ()); + TyTy::BaseType *to_ty = TypeCheckExpr::Resolve (expr.get_to_expr ()); TyTy::BaseType *unified = unify_site ( expr.get_mappings ().get_hirid (), - TyTy::TyWithLocation (from_ty, expr.get_from_expr ()->get_locus ()), - TyTy::TyWithLocation (to_ty, expr.get_to_expr ()->get_locus ()), + TyTy::TyWithLocation (from_ty, expr.get_from_expr ().get_locus ()), + TyTy::TyWithLocation (to_ty, expr.get_to_expr ().get_locus ()), expr.get_locus ()); // substitute it in @@ -846,11 +838,11 @@ TypeCheckExpr::visit (HIR::RangeFromToInclExpr &expr) void TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr) { - auto array_expr_ty = TypeCheckExpr::Resolve (expr.get_array_expr ().get ()); + auto array_expr_ty = TypeCheckExpr::Resolve (expr.get_array_expr ()); if (array_expr_ty->get_kind () == TyTy::TypeKind::ERROR) return; - auto index_expr_ty = TypeCheckExpr::Resolve (expr.get_index_expr ().get ()); + auto index_expr_ty = TypeCheckExpr::Resolve (expr.get_index_expr ()); if (index_expr_ty->get_kind () == TyTy::TypeKind::ERROR) return; @@ -873,10 +865,10 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr) if (maybe_simple_array_access && direct_array_expr_ty->get_kind () == TyTy::TypeKind::ARRAY) { - unify_site (expr.get_index_expr ()->get_mappings ().get_hirid (), + unify_site (expr.get_index_expr ().get_mappings ().get_hirid (), TyTy::TyWithLocation (size_ty), TyTy::TyWithLocation (index_expr_ty, - expr.get_index_expr ()->get_locus ()), + expr.get_index_expr ().get_locus ()), expr.get_locus ()); TyTy::ArrayType *array_type @@ -903,8 +895,8 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr) // error[E0277]: the type `[{integer}]` cannot be indexed by `u32` rich_location r (line_table, expr.get_locus ()); - r.add_range (expr.get_array_expr ()->get_locus ()); - r.add_range (expr.get_index_expr ()->get_locus ()); + r.add_range (expr.get_array_expr ().get_locus ()); + r.add_range (expr.get_index_expr ().get_locus ()); rust_error_at (r, ErrorCode::E0277, "the type %<%s%> cannot be indexed by %<%s%>", array_expr_ty->get_name ().c_str (), @@ -914,7 +906,7 @@ TypeCheckExpr::visit (HIR::ArrayIndexExpr &expr) void TypeCheckExpr::visit (HIR::ArrayExpr &expr) { - HIR::ArrayElems &elements = *expr.get_internal_elements (); + auto &elements = expr.get_internal_elements (); HIR::Expr *capacity_expr = nullptr; TyTy::BaseType *element_type = nullptr; @@ -923,25 +915,24 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr) case HIR::ArrayElems::ArrayExprType::COPIED: { HIR::ArrayElemsCopied &elems = static_cast (elements); - element_type - = TypeCheckExpr::Resolve (elems.get_elem_to_copy ().get ()); + element_type = TypeCheckExpr::Resolve (elems.get_elem_to_copy ()); auto capacity_type - = TypeCheckExpr::Resolve (elems.get_num_copies_expr ().get ()); + = TypeCheckExpr::Resolve (elems.get_num_copies_expr ()); TyTy::BaseType *expected_ty = nullptr; bool ok = context->lookup_builtin ("usize", &expected_ty); rust_assert (ok); - context->insert_type (elems.get_num_copies_expr ()->get_mappings (), + context->insert_type (elems.get_num_copies_expr ().get_mappings (), expected_ty); - unify_site ( - expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty), - TyTy::TyWithLocation (capacity_type, - elems.get_num_copies_expr ()->get_locus ()), - expr.get_locus ()); + unify_site (expr.get_mappings ().get_hirid (), + TyTy::TyWithLocation (expected_ty), + TyTy::TyWithLocation ( + capacity_type, elems.get_num_copies_expr ().get_locus ()), + expr.get_locus ()); - capacity_expr = elems.get_num_copies_expr ().get (); + capacity_expr = &elems.get_num_copies_expr (); } break; @@ -952,7 +943,7 @@ TypeCheckExpr::visit (HIR::ArrayExpr &expr) std::vector types; for (auto &elem : elems.get_values ()) { - types.push_back (TypeCheckExpr::Resolve (elem.get ())); + types.push_back (TypeCheckExpr::Resolve (*elem)); } // this is a LUB @@ -996,7 +987,7 @@ void TypeCheckExpr::visit (HIR::StructExprStruct &struct_expr) { TyTy::BaseType *struct_path_ty - = TypeCheckExpr::Resolve (&struct_expr.get_struct_name ()); + = TypeCheckExpr::Resolve (struct_expr.get_struct_name ()); if (struct_path_ty->get_kind () != TyTy::TypeKind::ADT) { rust_error_at (struct_expr.get_struct_name ().get_locus (), @@ -1028,19 +1019,19 @@ TypeCheckExpr::visit (HIR::StructExprStruct &struct_expr) void TypeCheckExpr::visit (HIR::StructExprStructFields &struct_expr) { - infered = TypeCheckStructExpr::Resolve (&struct_expr); + infered = TypeCheckStructExpr::Resolve (struct_expr); } void TypeCheckExpr::visit (HIR::GroupedExpr &expr) { - infered = TypeCheckExpr::Resolve (expr.get_expr_in_parens ().get ()); + infered = TypeCheckExpr::Resolve (expr.get_expr_in_parens ()); } void TypeCheckExpr::visit (HIR::FieldAccessExpr &expr) { - auto struct_base = TypeCheckExpr::Resolve (expr.get_receiver_expr ().get ()); + auto struct_base = TypeCheckExpr::Resolve (expr.get_receiver_expr ()); // FIXME does this require autoderef here? if (struct_base->get_kind () == TyTy::TypeKind::REF) @@ -1081,10 +1072,10 @@ TypeCheckExpr::visit (HIR::FieldAccessExpr &expr) void TypeCheckExpr::visit (HIR::MethodCallExpr &expr) { - auto receiver_tyty = TypeCheckExpr::Resolve (expr.get_receiver ().get ()); + auto receiver_tyty = TypeCheckExpr::Resolve (expr.get_receiver ()); if (receiver_tyty->get_kind () == TyTy::TypeKind::ERROR) { - rust_error_at (expr.get_receiver ()->get_locus (), + rust_error_at (expr.get_receiver ().get_locus (), "failed to resolve receiver in MethodCallExpr"); return; } @@ -1143,7 +1134,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) // stored onto the receiver to so as we don't trigger duplicate deref mappings // ICE when an argument is a method call HirId autoderef_mappings_id - = expr.get_receiver ()->get_mappings ().get_hirid (); + = expr.get_receiver ().get_mappings ().get_hirid (); context->insert_autoderef_mappings (autoderef_mappings_id, std::move (candidate.adjustments)); @@ -1191,7 +1182,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) if (impl_self_infer->get_kind () == TyTy::TypeKind::ERROR) { rich_location r (line_table, expr.get_locus ()); - r.add_range (impl.get_type ()->get_locus ()); + r.add_range (impl.get_type ().get_locus ()); rust_error_at ( r, "failed to resolve impl type for method call resolution"); return; @@ -1263,11 +1254,10 @@ TypeCheckExpr::visit (HIR::LoopExpr &expr) { context->push_new_loop_context (expr.get_mappings ().get_hirid (), expr.get_locus ()); - TyTy::BaseType *block_expr - = TypeCheckExpr::Resolve (expr.get_loop_block ().get ()); + TyTy::BaseType *block_expr = TypeCheckExpr::Resolve (expr.get_loop_block ()); if (!block_expr->is_unit ()) { - rust_error_at (expr.get_loop_block ()->get_locus (), + rust_error_at (expr.get_loop_block ().get_locus (), "expected %<()%> got %s", block_expr->as_string ().c_str ()); return; @@ -1292,13 +1282,12 @@ TypeCheckExpr::visit (HIR::WhileLoopExpr &expr) { context->push_new_while_loop_context (expr.get_mappings ().get_hirid ()); - TypeCheckExpr::Resolve (expr.get_predicate_expr ().get ()); - TyTy::BaseType *block_expr - = TypeCheckExpr::Resolve (expr.get_loop_block ().get ()); + TypeCheckExpr::Resolve (expr.get_predicate_expr ()); + TyTy::BaseType *block_expr = TypeCheckExpr::Resolve (expr.get_loop_block ()); if (!block_expr->is_unit ()) { - rust_error_at (expr.get_loop_block ()->get_locus (), + rust_error_at (expr.get_loop_block ().get_locus (), "expected %<()%> got %s", block_expr->as_string ().c_str ()); return; @@ -1321,7 +1310,7 @@ TypeCheckExpr::visit (HIR::BreakExpr &expr) if (expr.has_break_expr ()) { TyTy::BaseType *break_expr_tyty - = TypeCheckExpr::Resolve (expr.get_expr ().get ()); + = TypeCheckExpr::Resolve (expr.get_expr ()); TyTy::BaseType *loop_context = context->peek_loop_context (); if (loop_context->get_kind () == TyTy::TypeKind::ERROR) @@ -1336,7 +1325,7 @@ TypeCheckExpr::visit (HIR::BreakExpr &expr) = unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (loop_context), TyTy::TyWithLocation (break_expr_tyty, - expr.get_expr ()->get_locus ()), + expr.get_expr ().get_locus ()), expr.get_locus ()); context->swap_head_loop_context (unified_ty); } @@ -1360,8 +1349,7 @@ TypeCheckExpr::visit (HIR::ContinueExpr &expr) void TypeCheckExpr::visit (HIR::BorrowExpr &expr) { - TyTy::BaseType *resolved_base - = TypeCheckExpr::Resolve (expr.get_expr ().get ()); + TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ()); // In Rust this is valid because of DST's // @@ -1391,8 +1379,7 @@ TypeCheckExpr::visit (HIR::BorrowExpr &expr) void TypeCheckExpr::visit (HIR::DereferenceExpr &expr) { - TyTy::BaseType *resolved_base - = TypeCheckExpr::Resolve (expr.get_expr ().get ()); + TyTy::BaseType *resolved_base = TypeCheckExpr::Resolve (expr.get_expr ()); rust_debug_loc (expr.get_locus (), "attempting deref operator overload"); auto lang_item_type = LangItem::Kind::DEREF; @@ -1433,14 +1420,14 @@ void TypeCheckExpr::visit (HIR::TypeCastExpr &expr) { TyTy::BaseType *expr_to_convert - = TypeCheckExpr::Resolve (expr.get_casted_expr ().get ()); + = TypeCheckExpr::Resolve (expr.get_casted_expr ()); TyTy::BaseType *tyty_to_convert_to - = TypeCheckType::Resolve (expr.get_type_to_convert_to ().get ()); + = TypeCheckType::Resolve (expr.get_type_to_convert_to ()); TyTy::TyWithLocation from (expr_to_convert, - expr.get_casted_expr ()->get_locus ()); + expr.get_casted_expr ().get_locus ()); TyTy::TyWithLocation to (tyty_to_convert_to, - expr.get_type_to_convert_to ()->get_locus ()); + expr.get_type_to_convert_to ().get_locus ()); infered = cast_site (expr.get_mappings ().get_hirid (), from, to, expr.get_locus ()); } @@ -1451,7 +1438,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr) // this needs to perform a least upper bound coercion on the blocks and then // unify the scruintee and arms TyTy::BaseType *scrutinee_tyty - = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ().get ()); + = TypeCheckExpr::Resolve (expr.get_scrutinee_expr ()); std::vector kase_block_tys; for (auto &kase : expr.get_match_cases ()) @@ -1461,14 +1448,14 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr) for (auto &pattern : kase_arm.get_patterns ()) { TyTy::BaseType *kase_arm_ty - = TypeCheckPattern::Resolve (pattern.get (), scrutinee_tyty); + = TypeCheckPattern::Resolve (*pattern, scrutinee_tyty); if (kase_arm_ty->get_kind () == TyTy ::TypeKind::ERROR) return; TyTy::BaseType *checked_kase = unify_site ( expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (scrutinee_tyty, - expr.get_scrutinee_expr ()->get_locus ()), + expr.get_scrutinee_expr ().get_locus ()), TyTy::TyWithLocation (kase_arm_ty, pattern->get_locus ()), expr.get_locus ()); if (checked_kase->get_kind () == TyTy::TypeKind::ERROR) @@ -1476,8 +1463,7 @@ TypeCheckExpr::visit (HIR::MatchExpr &expr) } // check the kase type - TyTy::BaseType *kase_block_ty - = TypeCheckExpr::Resolve (kase.get_expr ().get ()); + TyTy::BaseType *kase_block_ty = TypeCheckExpr::Resolve (kase.get_expr ()); kase_block_tys.push_back (kase_block_ty); } @@ -1519,17 +1505,17 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr) TyTy::BaseType *param_tyty = nullptr; if (p.has_type_given ()) { - param_tyty = TypeCheckType::Resolve (p.get_type ().get ()); + param_tyty = TypeCheckType::Resolve (p.get_type ()); } else { - param_tyty = ClosureParamInfer::Resolve (p.get_pattern ().get ()); + param_tyty = ClosureParamInfer::Resolve (p.get_pattern ()); } TyTy::TyVar param_ty (param_tyty->get_ref ()); parameter_types.push_back (param_ty); - TypeCheckPattern::Resolve (p.get_pattern ().get (), param_ty.get_tyty ()); + TypeCheckPattern::Resolve (p.get_pattern (), param_ty.get_tyty ()); } // we generate an implicit hirid for the closure args @@ -1540,18 +1526,17 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr) context->insert_implicit_type (closure_args); location_t result_type_locus = expr.has_return_type () - ? expr.get_return_type ()->get_locus () + ? expr.get_return_type ().get_locus () : expr.get_locus (); TyTy::TyVar result_type = expr.has_return_type () ? TyTy::TyVar ( - TypeCheckType::Resolve (expr.get_return_type ().get ())->get_ref ()) + TypeCheckType::Resolve (expr.get_return_type ())->get_ref ()) : TyTy::TyVar::get_implicit_infer_var (expr.get_locus ()); // resolve the block - location_t closure_expr_locus = expr.get_expr ()->get_locus (); - TyTy::BaseType *closure_expr_ty - = TypeCheckExpr::Resolve (expr.get_expr ().get ()); + location_t closure_expr_locus = expr.get_expr ().get_locus (); + TyTy::BaseType *closure_expr_ty = TypeCheckExpr::Resolve (expr.get_expr ()); coercion_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (result_type.get_tyty (), result_type_locus), @@ -1744,7 +1729,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type, == 0) { TraitReference *trait_reference - = TraitResolver::Lookup (*parent->get_trait_ref ().get ()); + = TraitResolver::Lookup (parent->get_trait_ref ()); if (!trait_reference->is_error ()) { TyTy::BaseType *lookup = nullptr; @@ -1783,7 +1768,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type, // type check the arguments if required TyTy::FnType *type = static_cast (lookup); rust_assert (type->num_params () > 0); - auto fnparam = type->param_at (0); + auto &fnparam = type->param_at (0); // typecheck the self unify_site (expr.get_mappings ().get_hirid (), @@ -1796,7 +1781,7 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type, else { rust_assert (type->num_params () == 2); - auto fnparam = type->param_at (1); + auto &fnparam = type->param_at (1); unify_site (expr.get_mappings ().get_hirid (), TyTy::TyWithLocation (fnparam.second), TyTy::TyWithLocation (rhs), expr.get_locus ()); @@ -1912,8 +1897,8 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr, // store the adjustments for code-generation to know what to do which must be // stored onto the receiver to so as we don't trigger duplicate deref mappings // ICE when an argument is a method call - HIR::Expr *fnexpr = expr.get_fnexpr ().get (); - HirId autoderef_mappings_id = fnexpr->get_mappings ().get_hirid (); + HIR::Expr &fnexpr = expr.get_fnexpr (); + HirId autoderef_mappings_id = fnexpr.get_mappings ().get_hirid (); context->insert_autoderef_mappings (autoderef_mappings_id, std::move (candidate.adjustments)); context->insert_receiver (expr.get_mappings ().get_hirid (), receiver_tyty); @@ -1950,7 +1935,7 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr, std::vector call_args; for (auto &arg : expr.get_arguments ()) { - TyTy::BaseType *a = TypeCheckExpr::Resolve (arg.get ()); + TyTy::BaseType *a = TypeCheckExpr::Resolve (*arg); call_args.push_back (TyTy::TyVar (a->get_ref ())); } diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 9ea4dc6e59c4..7842afa31531 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -29,7 +29,7 @@ namespace Resolver { class TypeCheckExpr : private TypeCheckBase, private HIR::HIRExpressionVisitor { public: - static TyTy::BaseType *Resolve (HIR::Expr *expr); + static TyTy::BaseType *Resolve (HIR::Expr &expr); void visit (HIR::TupleIndexExpr &expr) override; void visit (HIR::TupleExpr &expr) override; diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc index 75666b214c8d..d9b7c139ee1d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc @@ -18,6 +18,8 @@ #include "rust-hir-type-check-implitem.h" #include "rust-diagnostics.h" +#include "rust-hir-full-decls.h" +#include "rust-hir-pattern.h" #include "rust-hir-type-check-base.h" #include "rust-hir-type-check-type.h" #include "rust-hir-type-check-expr.h" @@ -34,27 +36,26 @@ TypeCheckTopLevelExternItem::TypeCheckTopLevelExternItem ( {} TyTy::BaseType * -TypeCheckTopLevelExternItem::Resolve (HIR::ExternalItem *item, +TypeCheckTopLevelExternItem::Resolve (HIR::ExternalItem &item, const HIR::ExternBlock &parent) { // is it already resolved? auto context = TypeCheckContext::get (); TyTy::BaseType *resolved = nullptr; bool already_resolved - = context->lookup_type (item->get_mappings ().get_hirid (), &resolved); + = context->lookup_type (item.get_mappings ().get_hirid (), &resolved); if (already_resolved) return resolved; TypeCheckTopLevelExternItem resolver (parent); - item->accept_vis (resolver); + item.accept_vis (resolver); return resolver.resolved; } void TypeCheckTopLevelExternItem::visit (HIR::ExternalStaticItem &item) { - TyTy::BaseType *actual_type - = TypeCheckType::Resolve (item.get_item_type ().get ()); + TyTy::BaseType *actual_type = TypeCheckType::Resolve (item.get_item_type ()); context->insert_type (item.get_mappings (), actual_type); resolved = actual_type; @@ -85,7 +86,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) case HIR::GenericParam::GenericKind::TYPE: { auto param_type - = TypeResolveGenericParam::Resolve (generic_param.get ()); + = TypeResolveGenericParam::Resolve (*generic_param); context->insert_type (generic_param->get_mappings (), param_type); @@ -102,7 +103,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) { for (auto &where_clause_item : function.get_where_clause ().get_items ()) { - ResolveWhereClauseItem::Resolve (*where_clause_item.get (), + ResolveWhereClauseItem::Resolve (*where_clause_item, region_constraints); } } @@ -113,8 +114,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid ()); else { - auto resolved - = TypeCheckType::Resolve (function.get_return_type ().get ()); + auto resolved = TypeCheckType::Resolve (function.get_return_type ()); if (resolved == nullptr) { rust_error_at (function.get_locus (), @@ -124,14 +124,15 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) ret_type = resolved->clone (); ret_type->set_ref ( - function.get_return_type ()->get_mappings ().get_hirid ()); + function.get_return_type ().get_mappings ().get_hirid ()); } std::vector > params; + std::unique_ptr param_pattern = nullptr; for (auto ¶m : function.get_function_params ()) { // get the name as well required for later on - auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ()); + auto param_tyty = TypeCheckType::Resolve (param.get_type ()); // these are implicit mappings and not used auto crate_num = mappings.get_current_crate (); @@ -139,13 +140,13 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) mappings.get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); - HIR::IdentifierPattern *param_pattern - = new HIR::IdentifierPattern (mapping, param.get_param_name (), - UNDEF_LOCATION, false, Mutability::Imm, - std::unique_ptr (nullptr)); + param_pattern = Rust::make_unique ( + HIR::IdentifierPattern (mapping, param.get_param_name (), + UNDEF_LOCATION, false, Mutability::Imm, + std::unique_ptr (nullptr))); params.push_back ( - std::pair (param_pattern, + std::pair (param_pattern.get (), param_tyty)); context->insert_type (param.get_mappings (), param_tyty); @@ -313,7 +314,7 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalTypeItem &type) } TypeCheckImplItem::TypeCheckImplItem ( - HIR::ImplBlock *parent, TyTy::BaseType *self, + HIR::ImplBlock &parent, TyTy::BaseType *self, std::vector substitutions) : TypeCheckBase (), parent (parent), self (self), substitutions (substitutions) @@ -321,20 +322,20 @@ TypeCheckImplItem::TypeCheckImplItem ( TyTy::BaseType * TypeCheckImplItem::Resolve ( - HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self, + HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self, std::vector substitutions) { // is it already resolved? auto context = TypeCheckContext::get (); TyTy::BaseType *resolved = nullptr; bool already_resolved - = context->lookup_type (item->get_impl_mappings ().get_hirid (), &resolved); + = context->lookup_type (item.get_impl_mappings ().get_hirid (), &resolved); if (already_resolved) return resolved; // resolve TypeCheckImplItem resolver (parent, self, substitutions); - item->accept_vis (resolver); + item.accept_vis (resolver); return resolver.result; } @@ -359,8 +360,7 @@ TypeCheckImplItem::visit (HIR::Function &function) = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid ()); else { - auto resolved - = TypeCheckType::Resolve (function.get_return_type ().get ()); + auto resolved = TypeCheckType::Resolve (function.get_return_type ()); if (resolved == nullptr) { rust_error_at (function.get_locus (), @@ -370,10 +370,11 @@ TypeCheckImplItem::visit (HIR::Function &function) ret_type = resolved->clone (); ret_type->set_ref ( - function.get_return_type ()->get_mappings ().get_hirid ()); + function.get_return_type ().get_mappings ().get_hirid ()); } std::vector > params; + std::unique_ptr self_pattern = nullptr; if (function.is_method ()) { // these are implicit mappings and not used @@ -387,16 +388,17 @@ TypeCheckImplItem::visit (HIR::Function &function) // reuse the HIR identifier pattern which requires it HIR::SelfParam &self_param = function.get_self_param (); // FIXME: which location should be used for Rust::Identifier for `self`? - HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern ( - mapping, {"self"}, self_param.get_locus (), self_param.is_ref (), - self_param.get_mut (), std::unique_ptr (nullptr)); + self_pattern = Rust::make_unique ( + HIR::IdentifierPattern (mapping, {"self"}, self_param.get_locus (), + self_param.is_ref (), self_param.get_mut (), + std::unique_ptr (nullptr))); // might have a specified type TyTy::BaseType *self_type = nullptr; if (self_param.has_type ()) { - std::unique_ptr &specified_type = self_param.get_type (); - self_type = TypeCheckType::Resolve (specified_type.get ()); + auto &specified_type = self_param.get_type (); + self_type = TypeCheckType::Resolve (specified_type); } else { @@ -447,18 +449,21 @@ TypeCheckImplItem::visit (HIR::Function &function) context->insert_type (self_param.get_mappings (), self_type); params.push_back ( - std::pair (self_pattern, self_type)); + std::pair (self_pattern.get (), + self_type)); } for (auto ¶m : function.get_function_params ()) { // get the name as well required for later on - auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ()); - params.push_back (std::pair ( - param.get_param_name ().get (), param_tyty)); + auto param_tyty = TypeCheckType::Resolve (param.get_type ()); context->insert_type (param.get_mappings (), param_tyty); - TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty); + TypeCheckPattern::Resolve (param.get_param_name (), param_tyty); + + params.push_back ( + std::pair (¶m.get_param_name (), + param_tyty)); } auto canonical_path @@ -485,17 +490,16 @@ TypeCheckImplItem::visit (HIR::Function &function) context->push_return_type (TypeCheckContextItem (parent, &function), expected_ret_tyty); - auto block_expr_ty - = TypeCheckExpr::Resolve (function.get_definition ().get ()); + auto block_expr_ty = TypeCheckExpr::Resolve (function.get_definition ()); location_t fn_return_locus = function.has_function_return_type () - ? function.get_return_type ()->get_locus () + ? function.get_return_type ().get_locus () : function.get_locus (); - coercion_site (function.get_definition ()->get_mappings ().get_hirid (), + coercion_site (function.get_definition ().get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ret_tyty, fn_return_locus), TyTy::TyWithLocation (block_expr_ty), - function.get_definition ()->get_locus ()); + function.get_definition ().get_locus ()); context->pop_return_type (); } @@ -503,14 +507,13 @@ TypeCheckImplItem::visit (HIR::Function &function) void TypeCheckImplItem::visit (HIR::ConstantItem &constant) { - TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ()); - TyTy::BaseType *expr_type - = TypeCheckExpr::Resolve (constant.get_expr ().get ()); + TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ()); + TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ()); TyTy::BaseType *unified = unify_site ( constant.get_mappings ().get_hirid (), - TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()), - TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()), + TyTy::TyWithLocation (type, constant.get_type ().get_locus ()), + TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()), constant.get_locus ()); context->insert_type (constant.get_mappings (), unified); result = unified; @@ -525,7 +528,7 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias) resolve_generic_params (alias.get_generic_params (), substitutions); TyTy::BaseType *actual_type - = TypeCheckType::Resolve (alias.get_type_aliased ().get ()); + = TypeCheckType::Resolve (alias.get_type_aliased ()); context->insert_type (alias.get_mappings (), actual_type); result = actual_type; @@ -538,7 +541,7 @@ TypeCheckImplItem::visit (HIR::TypeAlias &alias) } TypeCheckImplItemWithTrait::TypeCheckImplItemWithTrait ( - HIR::ImplBlock *parent, TyTy::BaseType *self, + HIR::ImplBlock &parent, TyTy::BaseType *self, TyTy::TypeBoundPredicate &trait_reference, std::vector substitutions) : TypeCheckBase (), trait_reference (trait_reference), @@ -550,13 +553,13 @@ TypeCheckImplItemWithTrait::TypeCheckImplItemWithTrait ( TyTy::TypeBoundPredicateItem TypeCheckImplItemWithTrait::Resolve ( - HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self, + HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self, TyTy::TypeBoundPredicate &trait_reference, std::vector substitutions) { TypeCheckImplItemWithTrait resolver (parent, self, trait_reference, substitutions); - item->accept_vis (resolver); + item.accept_vis (resolver); return resolver.resolved_trait_item; } @@ -565,7 +568,7 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant) { // normal resolution of the item TyTy::BaseType *lookup - = TypeCheckImplItem::Resolve (parent, &constant, self, substitutions); + = TypeCheckImplItem::Resolve (parent, constant, self, substitutions); // map the impl item to the associated trait item const auto tref = trait_reference.get (); @@ -618,7 +621,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type) { // normal resolution of the item TyTy::BaseType *lookup - = TypeCheckImplItem::Resolve (parent, &type, self, substitutions); + = TypeCheckImplItem::Resolve (parent, type, self, substitutions); // map the impl item to the associated trait item const auto tref = trait_reference.get (); @@ -679,7 +682,7 @@ TypeCheckImplItemWithTrait::visit (HIR::Function &function) { // normal resolution of the item TyTy::BaseType *lookup - = TypeCheckImplItem::Resolve (parent, &function, self, substitutions); + = TypeCheckImplItem::Resolve (parent, function, self, substitutions); // map the impl item to the associated trait item const auto tref = trait_reference.get (); diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index 64eb208d15d2..872d9d04b841 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -29,7 +29,7 @@ class TypeCheckTopLevelExternItem : public TypeCheckBase, public HIR::HIRExternalItemVisitor { public: - static TyTy::BaseType *Resolve (HIR::ExternalItem *item, + static TyTy::BaseType *Resolve (HIR::ExternalItem &item, const HIR::ExternBlock &parent); void visit (HIR::ExternalStaticItem &item) override; @@ -47,7 +47,7 @@ class TypeCheckImplItem : public TypeCheckBase, public HIR::HIRImplVisitor { public: static TyTy::BaseType * - Resolve (HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self, + Resolve (HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self, std::vector substitutions); void visit (HIR::Function &function) override; @@ -55,10 +55,10 @@ class TypeCheckImplItem : public TypeCheckBase, public HIR::HIRImplVisitor void visit (HIR::TypeAlias &type_alias) override; protected: - TypeCheckImplItem (HIR::ImplBlock *parent, TyTy::BaseType *self, + TypeCheckImplItem (HIR::ImplBlock &parent, TyTy::BaseType *self, std::vector substitutions); - HIR::ImplBlock *parent; + HIR::ImplBlock &parent; TyTy::BaseType *self; std::vector substitutions; @@ -70,7 +70,7 @@ class TypeCheckImplItemWithTrait : public TypeCheckBase, { public: static TyTy::TypeBoundPredicateItem - Resolve (HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self, + Resolve (HIR::ImplBlock &parent, HIR::ImplItem &item, TyTy::BaseType *self, TyTy::TypeBoundPredicate &trait_reference, std::vector substitutions); @@ -86,7 +86,7 @@ class TypeCheckImplItemWithTrait : public TypeCheckBase, private: TypeCheckImplItemWithTrait ( - HIR::ImplBlock *parent, TyTy::BaseType *self, + HIR::ImplBlock &parent, TyTy::BaseType *self, TyTy::TypeBoundPredicate &trait_reference, std::vector substitutions); @@ -95,7 +95,7 @@ class TypeCheckImplItemWithTrait : public TypeCheckBase, TyTy::TypeBoundPredicate &trait_reference; TyTy::TypeBoundPredicateItem resolved_trait_item; - HIR::ImplBlock *parent; + HIR::ImplBlock &parent; TyTy::BaseType *self; std::vector substitutions; TyTy::RegionConstraints region_constraints; diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 669a48263ef8..8da95ec9b615 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -147,7 +147,7 @@ void TypeCheckItem::visit (HIR::TypeAlias &alias) { TyTy::BaseType *actual_type - = TypeCheckType::Resolve (alias.get_type_aliased ().get ()); + = TypeCheckType::Resolve (alias.get_type_aliased ()); context->insert_type (alias.get_mappings (), actual_type); @@ -179,7 +179,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl) for (auto &field : struct_decl.get_fields ()) { TyTy::BaseType *field_type - = TypeCheckType::Resolve (field.get_field_type ().get ()); + = TypeCheckType::Resolve (field.get_field_type ()); auto *ty_field = new TyTy::StructFieldType (field.get_mappings ().get_hirid (), std::to_string (idx), field_type, @@ -261,7 +261,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) for (auto &field : struct_decl.get_fields ()) { TyTy::BaseType *field_type - = TypeCheckType::Resolve (field.get_field_type ().get ()); + = TypeCheckType::Resolve (field.get_field_type ()); auto *ty_field = new TyTy::StructFieldType (field.get_mappings ().get_hirid (), field.get_field_name ().as_string (), @@ -336,7 +336,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl) for (auto &variant : enum_decl.get_variants ()) { TyTy::VariantDef *field_type - = TypeCheckEnumItem::Resolve (variant.get (), discriminant_value); + = TypeCheckEnumItem::Resolve (*variant, discriminant_value); discriminant_value++; variants.push_back (field_type); @@ -379,7 +379,7 @@ TypeCheckItem::visit (HIR::Union &union_decl) for (auto &variant : union_decl.get_variants ()) { TyTy::BaseType *variant_type - = TypeCheckType::Resolve (variant.get_field_type ().get ()); + = TypeCheckType::Resolve (variant.get_field_type ()); auto *ty_variant = new TyTy::StructFieldType (variant.get_mappings ().get_hirid (), variant.get_field_name ().as_string (), @@ -419,14 +419,14 @@ TypeCheckItem::visit (HIR::Union &union_decl) void TypeCheckItem::visit (HIR::StaticItem &var) { - TyTy::BaseType *type = TypeCheckType::Resolve (var.get_type ().get ()); - TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (var.get_expr ().get ()); + TyTy::BaseType *type = TypeCheckType::Resolve (var.get_type ()); + TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (var.get_expr ()); TyTy::BaseType *unified = coercion_site (var.get_mappings ().get_hirid (), - TyTy::TyWithLocation (type, var.get_type ()->get_locus ()), + TyTy::TyWithLocation (type, var.get_type ().get_locus ()), TyTy::TyWithLocation (expr_type, - var.get_expr ()->get_locus ()), + var.get_expr ().get_locus ()), var.get_locus ()); context->insert_type (var.get_mappings (), unified); infered = unified; @@ -435,14 +435,13 @@ TypeCheckItem::visit (HIR::StaticItem &var) void TypeCheckItem::visit (HIR::ConstantItem &constant) { - TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ()); - TyTy::BaseType *expr_type - = TypeCheckExpr::Resolve (constant.get_expr ().get ()); + TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ()); + TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ()); TyTy::BaseType *unified = unify_site ( constant.get_mappings ().get_hirid (), - TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()), - TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()), + TyTy::TyWithLocation (type, constant.get_type ().get_locus ()), + TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()), constant.get_locus ()); context->insert_type (constant.get_mappings (), unified); infered = unified; @@ -469,8 +468,7 @@ TypeCheckItem::visit (HIR::ImplBlock &impl_block) // resolve each impl_item for (auto &impl_item : impl_block.get_impl_items ()) { - TypeCheckImplItem::Resolve (&impl_block, impl_item.get (), self, - substitutions); + TypeCheckImplItem::Resolve (impl_block, *impl_item, self, substitutions); } // validate the impl items @@ -494,7 +492,7 @@ TypeCheckItem::resolve_impl_item (HIR::ImplBlock &impl_block, TyTy::BaseType *self = resolve_impl_block_self (impl_block); - return TypeCheckImplItem::Resolve (&impl_block, &item, self, substitutions); + return TypeCheckImplItem::Resolve (impl_block, item, self, substitutions); } void @@ -518,8 +516,7 @@ TypeCheckItem::visit (HIR::Function &function) = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid ()); else { - auto resolved - = TypeCheckType::Resolve (function.get_return_type ().get ()); + auto resolved = TypeCheckType::Resolve (function.get_return_type ()); if (resolved->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at (function.get_locus (), @@ -529,18 +526,18 @@ TypeCheckItem::visit (HIR::Function &function) ret_type = resolved->clone (); ret_type->set_ref ( - function.get_return_type ()->get_mappings ().get_hirid ()); + function.get_return_type ().get_mappings ().get_hirid ()); } std::vector> params; for (auto ¶m : function.get_function_params ()) { // get the name as well required for later on - auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ()); - params.emplace_back (param.get_param_name ().get (), param_tyty); + auto param_tyty = TypeCheckType::Resolve (param.get_type ()); + params.emplace_back (¶m.get_param_name (), param_tyty); context->insert_type (param.get_mappings (), param_tyty); - TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty); + TypeCheckPattern::Resolve (param.get_param_name (), param_tyty); } auto path = CanonicalPath::create_empty (); @@ -583,16 +580,15 @@ TypeCheckItem::visit (HIR::Function &function) expected_ret_tyty); context->switch_to_fn_body (); - auto block_expr_ty - = TypeCheckExpr::Resolve (function.get_definition ().get ()); + auto block_expr_ty = TypeCheckExpr::Resolve (function.get_definition ()); location_t fn_return_locus = function.has_function_return_type () - ? function.get_return_type ()->get_locus () + ? function.get_return_type ().get_locus () : function.get_locus (); - coercion_site (function.get_definition ()->get_mappings ().get_hirid (), + coercion_site (function.get_definition ().get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ret_tyty, fn_return_locus), TyTy::TyWithLocation (block_expr_ty), - function.get_definition ()->get_locus ()); + function.get_definition ().get_locus ()); context->pop_return_type (); @@ -646,7 +642,7 @@ TypeCheckItem::visit (HIR::ExternBlock &extern_block) { for (auto &item : extern_block.get_extern_items ()) { - TypeCheckTopLevelExternItem::Resolve (item.get (), extern_block); + TypeCheckTopLevelExternItem::Resolve (*item, extern_block); } } @@ -668,17 +664,16 @@ TypeCheckItem::resolve_impl_block_substitutions (HIR::ImplBlock &impl_block, TraitReference *trait_reference = &TraitReference::error_node (); if (impl_block.has_trait_ref ()) { - std::unique_ptr &ref = impl_block.get_trait_ref (); - trait_reference = TraitResolver::Resolve (*ref); + auto &ref = impl_block.get_trait_ref (); + trait_reference = TraitResolver::Resolve (ref); rust_assert (!trait_reference->is_error ()); // we don't error out here see: gcc/testsuite/rust/compile/traits2.rs // for example - specified_bound - = get_predicate_from_bound (*ref, impl_block.get_type ().get ()); + specified_bound = get_predicate_from_bound (ref, impl_block.get_type ()); } - TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ().get ()); + TyTy::BaseType *self = TypeCheckType::Resolve (impl_block.get_type ()); // inherit the bounds if (!specified_bound.is_error ()) @@ -705,14 +700,13 @@ TypeCheckItem::validate_trait_impl_block ( TraitReference *trait_reference = &TraitReference::error_node (); if (impl_block.has_trait_ref ()) { - std::unique_ptr &ref = impl_block.get_trait_ref (); - trait_reference = TraitResolver::Resolve (*ref); + auto &ref = impl_block.get_trait_ref (); + trait_reference = TraitResolver::Resolve (ref); rust_assert (!trait_reference->is_error ()); // we don't error out here see: gcc/testsuite/rust/compile/traits2.rs // for example - specified_bound - = get_predicate_from_bound (*ref, impl_block.get_type ().get ()); + specified_bound = get_predicate_from_bound (ref, impl_block.get_type ()); } bool is_trait_impl_block = !trait_reference->is_error (); @@ -722,8 +716,7 @@ TypeCheckItem::validate_trait_impl_block ( if (!specified_bound.is_error ()) { auto trait_item_ref - = TypeCheckImplItemWithTrait::Resolve (&impl_block, - impl_item.get (), self, + = TypeCheckImplItemWithTrait::Resolve (impl_block, *impl_item, self, specified_bound, substitutions); if (!trait_item_ref.is_error ()) @@ -795,7 +788,7 @@ TypeCheckItem::validate_trait_impl_block ( TyTy::BaseType * TypeCheckItem::resolve_impl_block_self (HIR::ImplBlock &impl_block) { - return TypeCheckType::Resolve (impl_block.get_type ().get ()); + return TypeCheckType::Resolve (impl_block.get_type ()); } } // namespace Resolver diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index d2962e6c2f19..6841417d71ca 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -34,8 +34,7 @@ void TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr) { HIR::QualifiedPathType qual_path_type = expr.get_path_type (); - TyTy::BaseType *root - = TypeCheckType::Resolve (qual_path_type.get_type ().get ()); + TyTy::BaseType *root = TypeCheckType::Resolve (qual_path_type.get_type ()); if (root->get_kind () == TyTy::TypeKind::ERROR) return; @@ -48,8 +47,8 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr) } // Resolve the trait now - std::unique_ptr &trait_path_ref = qual_path_type.get_trait (); - TraitReference *trait_ref = TraitResolver::Resolve (*trait_path_ref.get ()); + HIR::TypePath &trait_path_ref = qual_path_type.get_trait (); + TraitReference *trait_ref = TraitResolver::Resolve (trait_path_ref); if (trait_ref->is_error ()) return; @@ -64,8 +63,7 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr) // get the predicate for the bound auto specified_bound - = get_predicate_from_bound (*trait_path_ref.get (), - qual_path_type.get_type ().get ()); + = get_predicate_from_bound (trait_path_ref, qual_path_type.get_type ()); if (specified_bound.is_error ()) return; @@ -456,7 +454,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, { // we need to setup with apropriate bounds HIR::TypePath &bound_path - = *associated->get_impl_block ()->get_trait_ref ().get (); + = associated->get_impl_block ()->get_trait_ref (); const auto &trait_ref = *TraitResolver::Resolve (bound_path); rust_assert (!trait_ref.is_error ()); diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index a871ae7676cc..97d50f96aa1d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -28,28 +28,28 @@ TypeCheckPattern::TypeCheckPattern (TyTy::BaseType *parent) {} TyTy::BaseType * -TypeCheckPattern::Resolve (HIR::Pattern *pattern, TyTy::BaseType *parent) +TypeCheckPattern::Resolve (HIR::Pattern &pattern, TyTy::BaseType *parent) { TypeCheckPattern resolver (parent); - pattern->accept_vis (resolver); + pattern.accept_vis (resolver); if (resolver.infered == nullptr) - return new TyTy::ErrorType (pattern->get_mappings ().get_hirid ()); + return new TyTy::ErrorType (pattern.get_mappings ().get_hirid ()); - resolver.context->insert_type (pattern->get_mappings (), resolver.infered); + resolver.context->insert_type (pattern.get_mappings (), resolver.infered); return resolver.infered; } void TypeCheckPattern::visit (HIR::PathInExpression &pattern) { - infered = TypeCheckExpr::Resolve (&pattern); + infered = TypeCheckExpr::Resolve (pattern); } void TypeCheckPattern::visit (HIR::TupleStructPattern &pattern) { - TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (&pattern.get_path ()); + TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (pattern.get_path ()); if (pattern_ty->get_kind () != TyTy::TypeKind::ADT) { rust_error_at ( @@ -98,8 +98,8 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern) // error[E0023]: this pattern has 0 fields, but the corresponding tuple // variant has 1 field - std::unique_ptr &items = pattern.get_items (); - switch (items->get_item_type ()) + auto &items = pattern.get_items (); + switch (items.get_item_type ()) { case HIR::TupleStructItems::RANGED: { // TODO @@ -109,7 +109,7 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern) case HIR::TupleStructItems::MULTIPLE: { HIR::TupleStructItemsNoRange &items_no_range - = static_cast (*items.get ()); + = static_cast (items); if (items_no_range.get_patterns ().size () != variant->num_fields ()) { @@ -153,7 +153,7 @@ emit_invalid_field_error (location_t loc, Rust::TyTy::VariantDef *variant, void TypeCheckPattern::visit (HIR::StructPattern &pattern) { - TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (&pattern.get_path ()); + TyTy::BaseType *pattern_ty = TypeCheckExpr::Resolve (pattern.get_path ()); if (pattern_ty->get_kind () != TyTy::TypeKind::ADT) { rust_error_at (pattern.get_locus (), @@ -215,7 +215,7 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern) case HIR::StructPatternField::ItemType::IDENT_PAT: { HIR::StructPatternFieldIdentPat &ident - = static_cast (*field.get ()); + = static_cast (*field); TyTy::StructFieldType *field = nullptr; if (!variant->lookup_field (ident.get_identifier ().as_string (), @@ -228,13 +228,13 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern) named_fields.push_back (ident.get_identifier ().as_string ()); TyTy::BaseType *fty = field->get_field_type (); - TypeCheckPattern::Resolve (ident.get_pattern ().get (), fty); + TypeCheckPattern::Resolve (ident.get_pattern (), fty); } break; case HIR::StructPatternField::ItemType::IDENT: { HIR::StructPatternFieldIdent &ident - = static_cast (*field.get ()); + = static_cast (*field); TyTy::StructFieldType *field = nullptr; if (!variant->lookup_field (ident.get_identifier ().as_string (), @@ -295,12 +295,11 @@ void TypeCheckPattern::visit (HIR::TuplePattern &pattern) { std::unique_ptr items; - switch (pattern.get_items ()->get_item_type ()) + switch (pattern.get_items ().get_item_type ()) { case HIR::TuplePatternItems::ItemType::MULTIPLE: { - HIR::TuplePatternItemsMultiple &ref - = *static_cast ( - pattern.get_items ().get ()); + auto &ref = static_cast ( + pattern.get_items ()); auto resolved_parent = parent->destructure (); if (resolved_parent->get_kind () != TyTy::TUPLE) @@ -329,8 +328,7 @@ TypeCheckPattern::visit (HIR::TuplePattern &pattern) auto &p = patterns[i]; TyTy::BaseType *par_type = par.get_field (i); - TyTy::BaseType *elem - = TypeCheckPattern::Resolve (p.get (), par_type); + TyTy::BaseType *elem = TypeCheckPattern::Resolve (*p, par_type); pattern_elems.push_back (TyTy::TyVar (elem->get_ref ())); } infered = new TyTy::TupleType (pattern.get_mappings ().get_hirid (), @@ -398,10 +396,10 @@ TypeCheckPattern::visit (HIR::ReferencePattern &pattern) return; } - TyTy::ReferenceType *ref_ty_ty = static_cast (parent); + auto &ref_ty_ty = static_cast (*parent); TyTy::BaseType *infered_base - = TypeCheckPattern::Resolve (pattern.get_referenced_pattern ().get (), - ref_ty_ty->get_base ()); + = TypeCheckPattern::Resolve (pattern.get_referenced_pattern (), + ref_ty_ty.get_base ()); infered = new TyTy::ReferenceType (pattern.get_mappings ().get_hirid (), TyTy::TyVar (infered_base->get_ref ()), pattern.is_mut () ? Mutability::Mut @@ -433,15 +431,14 @@ TypeCheckPattern::emit_pattern_size_error (const HIR::Pattern &pattern, TyTy::BaseType * TypeCheckPattern::typecheck_range_pattern_bound ( - std::unique_ptr &bound, - Analysis::NodeMapping mappings, location_t locus) + Rust::HIR::RangePatternBound &bound, Analysis::NodeMapping mappings, + location_t locus) { TyTy::BaseType *resolved_bound = nullptr; - switch (bound->get_bound_type ()) + switch (bound.get_bound_type ()) { case HIR::RangePatternBound::RangePatternBoundType::LITERAL: { - HIR::RangePatternBoundLiteral &ref - = *static_cast (bound.get ()); + auto &ref = static_cast (bound); HIR::Literal lit = ref.get_literal (); @@ -450,18 +447,16 @@ TypeCheckPattern::typecheck_range_pattern_bound ( break; case HIR::RangePatternBound::RangePatternBoundType::PATH: { - HIR::RangePatternBoundPath &ref - = *static_cast (bound.get ()); + auto &ref = static_cast (bound); - resolved_bound = TypeCheckExpr::Resolve (&ref.get_path ()); + resolved_bound = TypeCheckExpr::Resolve (ref.get_path ()); } break; case HIR::RangePatternBound::RangePatternBoundType::QUALPATH: { - HIR::RangePatternBoundQualPath &ref - = *static_cast (bound.get ()); + auto &ref = static_cast (bound); - resolved_bound = TypeCheckExpr::Resolve (&ref.get_qualified_path ()); + resolved_bound = TypeCheckExpr::Resolve (ref.get_qualified_path ()); } break; } @@ -478,7 +473,7 @@ TypeCheckPattern::visit (HIR::AltPattern &pattern) std::vector types; for (auto &alt_pattern : alts) { - types.push_back (TypeCheckPattern::Resolve (alt_pattern.get (), parent)); + types.push_back (TypeCheckPattern::Resolve (*alt_pattern, parent)); } TyTy::BaseType *alt_pattern_type @@ -497,16 +492,16 @@ TypeCheckPattern::visit (HIR::AltPattern &pattern) } TyTy::BaseType * -ClosureParamInfer::Resolve (HIR::Pattern *pattern) +ClosureParamInfer::Resolve (HIR::Pattern &pattern) { ClosureParamInfer resolver; - pattern->accept_vis (resolver); + pattern.accept_vis (resolver); if (resolver.infered->get_kind () != TyTy::TypeKind::ERROR) { resolver.context->insert_implicit_type (resolver.infered); resolver.mappings.insert_location (resolver.infered->get_ref (), - pattern->get_locus ()); + pattern.get_locus ()); } return resolver.infered; } @@ -537,7 +532,7 @@ void ClosureParamInfer::visit (HIR::ReferencePattern &pattern) { TyTy::BaseType *element - = ClosureParamInfer::Resolve (pattern.get_referenced_pattern ().get ()); + = ClosureParamInfer::Resolve (pattern.get_referenced_pattern ()); HirId id = pattern.get_mappings ().get_hirid (); infered = new TyTy::ReferenceType (id, TyTy::TyVar (element->get_ref ()), diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.h b/gcc/rust/typecheck/rust-hir-type-check-pattern.h index 4820b7406df2..a4de0aae1936 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.h +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.h @@ -28,7 +28,7 @@ namespace Resolver { class TypeCheckPattern : public TypeCheckBase, public HIR::HIRPatternVisitor { public: - static TyTy::BaseType *Resolve (HIR::Pattern *pattern, + static TyTy::BaseType *Resolve (HIR::Pattern &pattern, TyTy::BaseType *parent); void visit (HIR::PathInExpression &pattern) override; @@ -47,9 +47,10 @@ class TypeCheckPattern : public TypeCheckBase, public HIR::HIRPatternVisitor private: TypeCheckPattern (TyTy::BaseType *parent); - TyTy::BaseType *typecheck_range_pattern_bound ( - std::unique_ptr &bound, - Analysis::NodeMapping mappings, location_t locus); + TyTy::BaseType * + typecheck_range_pattern_bound (Rust::HIR::RangePatternBound &bound, + Analysis::NodeMapping mappings, + location_t locus); void emit_pattern_size_error (const HIR::Pattern &pattern, size_t expected_field_count, @@ -62,7 +63,7 @@ class TypeCheckPattern : public TypeCheckBase, public HIR::HIRPatternVisitor class ClosureParamInfer : private TypeCheckBase, private HIR::HIRPatternVisitor { public: - static TyTy::BaseType *Resolve (HIR::Pattern *pattern); + static TyTy::BaseType *Resolve (HIR::Pattern &pattern); void visit (HIR::PathInExpression &pattern) override; void visit (HIR::StructPattern &pattern) override; diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc index 16925c9f7e09..5a22a5265add 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.cc @@ -28,17 +28,17 @@ namespace Rust { namespace Resolver { TyTy::BaseType * -TypeCheckStmt::Resolve (HIR::Stmt *stmt) +TypeCheckStmt::Resolve (HIR::Stmt &stmt) { TypeCheckStmt resolver; - stmt->accept_vis (resolver); + stmt.accept_vis (resolver); return resolver.infered; } void TypeCheckStmt::visit (HIR::ExprStmt &stmt) { - infered = TypeCheckExpr::Resolve (stmt.get_expr ().get ()); + infered = TypeCheckExpr::Resolve (stmt.get_expr ()); } void @@ -52,21 +52,20 @@ TypeCheckStmt::visit (HIR::ExternBlock &extern_block) { for (auto &item : extern_block.get_extern_items ()) { - TypeCheckTopLevelExternItem::Resolve (item.get (), extern_block); + TypeCheckTopLevelExternItem::Resolve (*item, extern_block); } } void TypeCheckStmt::visit (HIR::ConstantItem &constant) { - TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ()); - TyTy::BaseType *expr_type - = TypeCheckExpr::Resolve (constant.get_expr ().get ()); + TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ()); + TyTy::BaseType *expr_type = TypeCheckExpr::Resolve (constant.get_expr ()); infered = coercion_site ( constant.get_mappings ().get_hirid (), - TyTy::TyWithLocation (type, constant.get_type ()->get_locus ()), - TyTy::TyWithLocation (expr_type, constant.get_expr ()->get_locus ()), + TyTy::TyWithLocation (type, constant.get_type ().get_locus ()), + TyTy::TyWithLocation (expr_type, constant.get_expr ().get_locus ()), constant.get_locus ()); context->insert_type (constant.get_mappings (), infered); } @@ -76,13 +75,13 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) { infered = TyTy::TupleType::get_unit_type (stmt.get_mappings ().get_hirid ()); - HIR::Pattern &stmt_pattern = *stmt.get_pattern (); + auto &stmt_pattern = stmt.get_pattern (); TyTy::BaseType *init_expr_ty = nullptr; location_t init_expr_locus = UNKNOWN_LOCATION; if (stmt.has_init_expr ()) { - init_expr_locus = stmt.get_init_expr ()->get_locus (); - init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ().get ()); + init_expr_locus = stmt.get_init_expr ().get_locus (); + init_expr_ty = TypeCheckExpr::Resolve (stmt.get_init_expr ()); if (init_expr_ty->get_kind () == TyTy::TypeKind::ERROR) return; @@ -94,8 +93,8 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) location_t specified_ty_locus; if (stmt.has_type ()) { - specified_ty = TypeCheckType::Resolve (stmt.get_type ().get ()); - specified_ty_locus = stmt.get_type ()->get_locus (); + specified_ty = TypeCheckType::Resolve (stmt.get_type ()); + specified_ty_locus = stmt.get_type ().get_locus (); } // let x:i32 = 123; @@ -105,19 +104,19 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) TyTy::TyWithLocation (specified_ty, specified_ty_locus), TyTy::TyWithLocation (init_expr_ty, init_expr_locus), stmt.get_locus ()); - TypeCheckPattern::Resolve (&stmt_pattern, specified_ty); + TypeCheckPattern::Resolve (stmt_pattern, specified_ty); } else { // let x:i32; if (specified_ty != nullptr) { - TypeCheckPattern::Resolve (&stmt_pattern, specified_ty); + TypeCheckPattern::Resolve (stmt_pattern, specified_ty); } // let x = 123; else if (init_expr_ty != nullptr) { - TypeCheckPattern::Resolve (&stmt_pattern, init_expr_ty); + TypeCheckPattern::Resolve (stmt_pattern, init_expr_ty); } // let x; else @@ -127,7 +126,7 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) TyTy::InferType::InferTypeKind::GENERAL, TyTy::InferType::TypeHint::Default (), stmt.get_locus ()); - TypeCheckPattern::Resolve (&stmt_pattern, infer); + TypeCheckPattern::Resolve (stmt_pattern, infer); } } } @@ -135,12 +134,12 @@ TypeCheckStmt::visit (HIR::LetStmt &stmt) void TypeCheckStmt::visit (HIR::TypePath &path) { - infered = TypeCheckType::Resolve (&path); + infered = TypeCheckType::Resolve (path); } void TypeCheckStmt::visit (HIR::QualifiedPathInType &path) { - infered = TypeCheckType::Resolve (&path); + infered = TypeCheckType::Resolve (path); } void diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.h b/gcc/rust/typecheck/rust-hir-type-check-stmt.h index 138780f9035e..7df221f56e51 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.h +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.h @@ -28,7 +28,7 @@ namespace Resolver { class TypeCheckStmt : private TypeCheckBase, private HIR::HIRStmtVisitor { public: - static TyTy::BaseType *Resolve (HIR::Stmt *stmt); + static TyTy::BaseType *Resolve (HIR::Stmt &stmt); void visit (HIR::ExprStmt &stmt) override; void visit (HIR::EmptyStmt &stmt) override; diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h index 792eebf3ff5e..1d4d1fa5e147 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h +++ b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h @@ -33,7 +33,7 @@ namespace Resolver { class TypeCheckStructExpr : public TypeCheckBase { public: - static TyTy::BaseType *Resolve (HIR::StructExprStructFields *expr); + static TyTy::BaseType *Resolve (HIR::StructExprStructFields &expr); // Helper for making any errors static Error @@ -49,7 +49,7 @@ class TypeCheckStructExpr : public TypeCheckBase bool visit (HIR::StructExprFieldIdentifier &field); private: - TypeCheckStructExpr (HIR::Expr *e); + TypeCheckStructExpr (HIR::Expr &e); // result TyTy::BaseType *resolved; diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc index 5999b2dcbc39..47881021b699 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc @@ -24,18 +24,18 @@ namespace Rust { namespace Resolver { -TypeCheckStructExpr::TypeCheckStructExpr (HIR::Expr *e) +TypeCheckStructExpr::TypeCheckStructExpr (HIR::Expr &e) : TypeCheckBase (), - resolved (new TyTy::ErrorType (e->get_mappings ().get_hirid ())), + resolved (new TyTy::ErrorType (e.get_mappings ().get_hirid ())), struct_path_resolved (nullptr), variant (&TyTy::VariantDef::get_error_node ()) {} TyTy::BaseType * -TypeCheckStructExpr::Resolve (HIR::StructExprStructFields *expr) +TypeCheckStructExpr::Resolve (HIR::StructExprStructFields &expr) { TypeCheckStructExpr resolver (expr); - resolver.resolve (*expr); + resolver.resolve (expr); return resolver.resolved; } @@ -43,7 +43,7 @@ void TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) { TyTy::BaseType *struct_path_ty - = TypeCheckExpr::Resolve (&struct_expr.get_struct_name ()); + = TypeCheckExpr::Resolve (struct_expr.get_struct_name ()); if (struct_path_ty->get_kind () != TyTy::TypeKind::ADT) { rust_error_at (struct_expr.get_struct_name ().get_locus (), @@ -56,7 +56,7 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) if (struct_expr.has_struct_base ()) { TyTy::BaseType *base_resolved - = TypeCheckExpr::Resolve (struct_expr.struct_base->base_struct.get ()); + = TypeCheckExpr::Resolve (*struct_expr.struct_base->base_struct); TyTy::BaseType *base_unify = unify_site ( struct_expr.struct_base->base_struct->get_mappings ().get_hirid (), TyTy::TyWithLocation (struct_path_resolved), @@ -284,8 +284,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field) return false; } - TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ().get ()); - location_t value_locus = field.get_value ()->get_locus (); + TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ()); + location_t value_locus = field.get_value ().get_locus (); HirId coercion_site_id = field.get_mappings ().get_hirid (); resolved_field_value_expr @@ -330,8 +330,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field) return false; } - TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ().get ()); - location_t value_locus = field.get_value ()->get_locus (); + TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ()); + location_t value_locus = field.get_value ().get_locus (); HirId coercion_site_id = field.get_mappings ().get_hirid (); resolved_field_value_expr @@ -385,7 +385,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field) HIR::GenericArgs::create_empty ()); HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false, {}); - TyTy::BaseType *value = TypeCheckExpr::Resolve (&expr); + TyTy::BaseType *value = TypeCheckExpr::Resolve (expr); location_t value_locus = expr.get_locus (); HirId coercion_site_id = field.get_mappings ().get_hirid (); diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 36f64a770e90..df27bbc30a80 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -18,6 +18,7 @@ #include "rust-hir-type-check-type.h" #include "options.h" +#include "optional.h" #include "rust-hir-trait-resolve.h" #include "rust-hir-type-check-expr.h" #include "rust-hir-path-probe.h" @@ -26,18 +27,19 @@ #include "rust-mapping-common.h" #include "rust-substitution-mapper.h" #include "rust-type-util.h" +#include namespace Rust { namespace Resolver { HIR::GenericArgs -TypeCheckResolveGenericArguments::resolve (HIR::TypePathSegment *segment) +TypeCheckResolveGenericArguments::resolve (HIR::TypePathSegment &segment) { - TypeCheckResolveGenericArguments resolver (segment->get_locus ()); - switch (segment->get_type ()) + TypeCheckResolveGenericArguments resolver (segment.get_locus ()); + switch (segment.get_type ()) { case HIR::TypePathSegment::SegmentType::GENERIC: - resolver.visit (static_cast (*segment)); + resolver.visit (static_cast (segment)); break; default: @@ -53,20 +55,20 @@ TypeCheckResolveGenericArguments::visit (HIR::TypePathSegmentGeneric &generic) } TyTy::BaseType * -TypeCheckType::Resolve (HIR::Type *type) +TypeCheckType::Resolve (HIR::Type &type) { // is it already resolved? auto context = TypeCheckContext::get (); TyTy::BaseType *resolved = nullptr; bool already_resolved - = context->lookup_type (type->get_mappings ().get_hirid (), &resolved); + = context->lookup_type (type.get_mappings ().get_hirid (), &resolved); if (already_resolved) return resolved; - TypeCheckType resolver (type->get_mappings ().get_hirid ()); - type->accept_vis (resolver); + TypeCheckType resolver (type.get_mappings ().get_hirid ()); + type.accept_vis (resolver); rust_assert (resolver.translated != nullptr); - resolver.context->insert_type (type->get_mappings (), resolver.translated); + resolver.context->insert_type (type.get_mappings (), resolver.translated); return resolver.translated; } @@ -82,7 +84,7 @@ TypeCheckType::visit (HIR::BareFunctionType &fntype) TyTy::BaseType *return_type; if (fntype.has_return_type ()) { - return_type = TypeCheckType::Resolve (fntype.get_return_type ().get ()); + return_type = TypeCheckType::Resolve (fntype.get_return_type ()); } else { @@ -95,7 +97,7 @@ TypeCheckType::visit (HIR::BareFunctionType &fntype) std::vector params; for (auto ¶m : fntype.get_function_params ()) { - TyTy::BaseType *ptype = TypeCheckType::Resolve (param.get_type ().get ()); + TyTy::BaseType *ptype = TypeCheckType::Resolve (param.get_type ()); params.push_back (TyTy::TyVar (ptype->get_ref ())); } @@ -121,7 +123,7 @@ TypeCheckType::visit (HIR::TupleType &tuple) std::vector fields; for (auto &elem : tuple.get_elems ()) { - auto field_ty = TypeCheckType::Resolve (elem.get ()); + auto field_ty = TypeCheckType::Resolve (*elem); fields.push_back (TyTy::TyVar (field_ty->get_ref ())); } @@ -163,8 +165,7 @@ void TypeCheckType::visit (HIR::QualifiedPathInType &path) { HIR::QualifiedPathType qual_path_type = path.get_path_type (); - TyTy::BaseType *root - = TypeCheckType::Resolve (qual_path_type.get_type ().get ()); + TyTy::BaseType *root = TypeCheckType::Resolve (qual_path_type.get_type ()); if (root->get_kind () == TyTy::TypeKind::ERROR) { rust_debug_loc (path.get_locus (), "failed to resolve the root"); @@ -176,7 +177,7 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) // then this is just a normal path-in-expression NodeId root_resolved_node_id = UNKNOWN_NODEID; bool ok = resolver->lookup_resolved_type ( - qual_path_type.get_type ()->get_mappings ().get_nodeid (), + qual_path_type.get_type ().get_mappings ().get_nodeid (), &root_resolved_node_id); rust_assert (ok); @@ -189,8 +190,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) } // Resolve the trait now - std::unique_ptr &trait_path_ref = qual_path_type.get_trait (); - TraitReference *trait_ref = TraitResolver::Resolve (*trait_path_ref.get ()); + auto &trait_path_ref = qual_path_type.get_trait (); + TraitReference *trait_ref = TraitResolver::Resolve (trait_path_ref); if (trait_ref->is_error ()) return; @@ -203,9 +204,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) } // get the predicate for the bound - auto specified_bound - = get_predicate_from_bound (*qual_path_type.get_trait ().get (), - qual_path_type.get_type ().get ()); + auto specified_bound = get_predicate_from_bound (qual_path_type.get_trait (), + qual_path_type.get_type ()); if (specified_bound.is_error ()) return; @@ -213,14 +213,13 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) root->inherit_bounds ({specified_bound}); // lookup the associated item from the specified bound - std::unique_ptr &item_seg - = path.get_associated_segment (); - HIR::PathIdentSegment item_seg_identifier = item_seg->get_ident_segment (); + HIR::TypePathSegment &item_seg = path.get_associated_segment (); + HIR::PathIdentSegment item_seg_identifier = item_seg.get_ident_segment (); TyTy::TypeBoundPredicateItem item = specified_bound.lookup_associated_item (item_seg_identifier.as_string ()); if (item.is_error ()) { - rust_error_at (item_seg->get_locus (), "unknown associated item"); + rust_error_at (item_seg.get_locus (), "unknown associated item"); return; } @@ -286,17 +285,16 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) } // turbo-fish segment path:: - if (item_seg->get_type () == HIR::TypePathSegment::SegmentType::GENERIC) + if (item_seg.get_type () == HIR::TypePathSegment::SegmentType::GENERIC) { - HIR::TypePathSegmentGeneric &generic_seg - = static_cast (*item_seg.get ()); + auto &generic_seg = static_cast (item_seg); // turbo-fish segment path:: if (generic_seg.has_generic_args ()) { if (!translated->has_substitutions_defined ()) { - rust_error_at (item_seg->get_locus (), + rust_error_at (item_seg.get_locus (), "substitutions not supported for %s", translated->as_string ().c_str ()); translated @@ -447,13 +445,13 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, // turbo-fish segment path:: if (seg->is_generic_segment ()) { - HIR::TypePathSegmentGeneric *generic_segment - = static_cast (seg.get ()); + auto &generic_segment + = static_cast (*seg); auto regions = context->regions_from_generic_args ( - generic_segment->get_generic_args ()); + generic_segment.get_generic_args ()); lookup = SubstMapper::Resolve (lookup, path.get_locus (), - &generic_segment->get_generic_args (), + &generic_segment.get_generic_args (), regions); if (lookup->get_kind () == TyTy::TypeKind::ERROR) return new TyTy::ErrorType (seg->get_mappings ().get_hirid ()); @@ -562,12 +560,12 @@ TypeCheckType::resolve_segments ( if (seg->is_generic_segment ()) { - auto *generic_segment - = static_cast (seg.get ()); + auto &generic_segment + = static_cast (*seg); std::vector regions; for (auto &lifetime : - generic_segment->get_generic_args ().get_lifetime_args ()) + generic_segment.get_generic_args ().get_lifetime_args ()) { auto region = context->lookup_and_resolve_lifetime (lifetime); if (!region.has_value ()) @@ -580,7 +578,7 @@ TypeCheckType::resolve_segments ( } tyseg = SubstMapper::Resolve (tyseg, expr_locus, - &generic_segment->get_generic_args (), + &generic_segment.get_generic_args (), regions); if (tyseg->get_kind () == TyTy::TypeKind::ERROR) return new TyTy::ErrorType (expr_id); @@ -644,7 +642,7 @@ TypeCheckType::visit (HIR::TraitObjectType &type) TyTy::TypeBoundPredicate predicate = get_predicate_from_bound ( trait_bound.get_path (), - nullptr /*this will setup a PLACEHOLDER for self*/); + tl::nullopt /*this will setup a PLACEHOLDER for self*/); if (!predicate.is_error () && predicate.is_object_safe (true, type.get_locus ())) @@ -660,33 +658,31 @@ TypeCheckType::visit (HIR::TraitObjectType &type) void TypeCheckType::visit (HIR::ArrayType &type) { - auto capacity_type = TypeCheckExpr::Resolve (type.get_size_expr ().get ()); + auto capacity_type = TypeCheckExpr::Resolve (type.get_size_expr ()); if (capacity_type->get_kind () == TyTy::TypeKind::ERROR) return; TyTy::BaseType *expected_ty = nullptr; bool ok = context->lookup_builtin ("usize", &expected_ty); rust_assert (ok); - context->insert_type (type.get_size_expr ()->get_mappings (), expected_ty); + context->insert_type (type.get_size_expr ().get_mappings (), expected_ty); - unify_site (type.get_size_expr ()->get_mappings ().get_hirid (), + unify_site (type.get_size_expr ().get_mappings ().get_hirid (), TyTy::TyWithLocation (expected_ty), TyTy::TyWithLocation (capacity_type, - type.get_size_expr ()->get_locus ()), - type.get_size_expr ()->get_locus ()); + type.get_size_expr ().get_locus ()), + type.get_size_expr ().get_locus ()); - TyTy::BaseType *base - = TypeCheckType::Resolve (type.get_element_type ().get ()); + TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ()); translated = new TyTy::ArrayType (type.get_mappings ().get_hirid (), - type.get_locus (), *type.get_size_expr (), + type.get_locus (), type.get_size_expr (), TyTy::TyVar (base->get_ref ())); } void TypeCheckType::visit (HIR::SliceType &type) { - TyTy::BaseType *base - = TypeCheckType::Resolve (type.get_element_type ().get ()); + TyTy::BaseType *base = TypeCheckType::Resolve (type.get_element_type ()); translated = new TyTy::SliceType (type.get_mappings ().get_hirid (), type.get_locus (), TyTy::TyVar (base->get_ref ())); @@ -694,7 +690,7 @@ TypeCheckType::visit (HIR::SliceType &type) void TypeCheckType::visit (HIR::ReferenceType &type) { - TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ().get ()); + TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ()); rust_assert (type.has_lifetime ()); auto region = context->lookup_and_resolve_lifetime (type.get_lifetime ()); if (!region.has_value ()) @@ -711,7 +707,7 @@ TypeCheckType::visit (HIR::ReferenceType &type) void TypeCheckType::visit (HIR::RawPointerType &type) { - TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ().get ()); + TyTy::BaseType *base = TypeCheckType::Resolve (type.get_base_type ()); translated = new TyTy::PointerType (type.get_mappings ().get_hirid (), TyTy::TyVar (base->get_ref ()), type.get_mut ()); @@ -737,21 +733,21 @@ TypeCheckType::visit (HIR::NeverType &type) } TyTy::ParamType * -TypeResolveGenericParam::Resolve (HIR::GenericParam *param, bool apply_sized) +TypeResolveGenericParam::Resolve (HIR::GenericParam ¶m, bool apply_sized) { TypeResolveGenericParam resolver (apply_sized); - switch (param->get_kind ()) + switch (param.get_kind ()) { case HIR::GenericParam::GenericKind::TYPE: - resolver.visit (static_cast (*param)); + resolver.visit (static_cast (param)); break; case HIR::GenericParam::GenericKind::CONST: - resolver.visit (static_cast (*param)); + resolver.visit (static_cast (param)); break; case HIR::GenericParam::GenericKind::LIFETIME: - resolver.visit (static_cast (*param)); + resolver.visit (static_cast (param)); break; } return resolver.resolved; @@ -773,9 +769,9 @@ void TypeResolveGenericParam::visit (HIR::TypeParam ¶m) { if (param.has_type ()) - TypeCheckType::Resolve (param.get_type ().get ()); + TypeCheckType::Resolve (param.get_type ()); - HIR::Type *implicit_self_bound = nullptr; + std::unique_ptr implicit_self_bound = nullptr; if (param.has_type_param_bounds ()) { // We need two possible parameter types. One with no Bounds and one with @@ -793,8 +789,8 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m) param.get_mappings ().get_nodeid (), implicit_id, param.get_mappings ().get_local_defid ()); - implicit_self_bound - = new HIR::TypePath (mappings, {}, BUILTINS_LOCATION, false); + implicit_self_bound = Rust::make_unique ( + HIR::TypePath (mappings, {}, BUILTINS_LOCATION, false)); } std::map> predicates; @@ -823,13 +819,11 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m) switch (bound->get_bound_type ()) { case HIR::TypeParamBound::BoundType::TRAITBOUND: { - HIR::TraitBound *b - = static_cast (bound.get ()); + HIR::TraitBound &b = static_cast (*bound); - TyTy::TypeBoundPredicate predicate - = get_predicate_from_bound (b->get_path (), - implicit_self_bound, - b->get_polarity ()); + TyTy::TypeBoundPredicate predicate = get_predicate_from_bound ( + b.get_path (), tl::optional (std::ref (*implicit_self_bound)), + b.get_polarity ()); if (!predicate.is_error ()) { switch (predicate.get_polarity ()) @@ -842,7 +836,7 @@ TypeResolveGenericParam::visit (HIR::TypeParam ¶m) else { // emit error message - rich_location r (line_table, b->get_locus ()); + rich_location r (line_table, b.get_locus ()); r.add_range (predicate.get ()->get_locus ()); rust_error_at ( r, "antibound for %s is not applied here", @@ -940,7 +934,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) } auto &binding_type_path = item.get_bound_type (); - TyTy::BaseType *binding = TypeCheckType::Resolve (binding_type_path.get ()); + TyTy::BaseType *binding = TypeCheckType::Resolve (binding_type_path); // FIXME double check there might be a trait cycle here see TypeParam handling @@ -953,8 +947,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) auto *b = static_cast (bound.get ()); TyTy::TypeBoundPredicate predicate - = get_predicate_from_bound (b->get_path (), - binding_type_path.get ()); + = get_predicate_from_bound (b->get_path (), binding_type_path); if (!predicate.is_error ()) specified_bounds.push_back (std::move (predicate)); } @@ -984,7 +977,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) // When we apply these bounds we must lookup which type this binding // resolves to, as this is the type which will be used during resolution // of the block. - NodeId ast_node_id = binding_type_path->get_mappings ().get_nodeid (); + NodeId ast_node_id = binding_type_path.get_mappings ().get_nodeid (); // then lookup the reference_node_id NodeId ref_node_id = UNKNOWN_NODEID; @@ -993,7 +986,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) // FIXME rust_error_at (UNDEF_LOCATION, "Failed to lookup type reference for node: %s", - binding_type_path->as_string ().c_str ()); + binding_type_path.as_string ().c_str ()); return; } @@ -1006,7 +999,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) { rust_error_at (mappings.lookup_location (*hid), "Failed to resolve where-clause binding type: %s", - binding_type_path->as_string ().c_str ()); + binding_type_path.as_string ().c_str ()); return; } diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h index 3083a94f97b2..814903f316bd 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.h +++ b/gcc/rust/typecheck/rust-hir-type-check-type.h @@ -31,7 +31,7 @@ namespace Resolver { class TypeCheckResolveGenericArguments : public TypeCheckBase { public: - static HIR::GenericArgs resolve (HIR::TypePathSegment *segment); + static HIR::GenericArgs resolve (HIR::TypePathSegment &segment); void visit (HIR::TypePathSegmentGeneric &generic); @@ -46,7 +46,7 @@ class TypeCheckResolveGenericArguments : public TypeCheckBase class TypeCheckType : public TypeCheckBase, public HIR::HIRTypeVisitor { public: - static TyTy::BaseType *Resolve (HIR::Type *type); + static TyTy::BaseType *Resolve (HIR::Type &type); void visit (HIR::BareFunctionType &fntype) override; void visit (HIR::TupleType &tuple) override; @@ -96,7 +96,7 @@ class TypeCheckType : public TypeCheckBase, public HIR::HIRTypeVisitor class TypeResolveGenericParam : public TypeCheckBase { public: - static TyTy::ParamType *Resolve (HIR::GenericParam *param, + static TyTy::ParamType *Resolve (HIR::GenericParam ¶m, bool apply_sized = true); protected: diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index 129576f75823..24d116400036 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -19,10 +19,12 @@ #include "rust-hir-type-check.h" #include "rust-hir-full.h" #include "rust-hir-inherent-impl-overlap.h" +#include "rust-hir-pattern.h" #include "rust-hir-type-check-expr.h" #include "rust-hir-type-check-item.h" #include "rust-hir-type-check-pattern.h" #include "rust-hir-type-check-struct-field.h" +#include "rust-make-unique.h" extern bool saw_errors (void); @@ -136,11 +138,10 @@ TyTy::BaseType * TraitItemReference::get_type_from_constant ( /*const*/ HIR::TraitItemConst &constant) const { - TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ().get ()); + TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ()); if (constant.has_expr ()) { - TyTy::BaseType *expr - = TypeCheckExpr::Resolve (constant.get_expr ().get ()); + TyTy::BaseType *expr = TypeCheckExpr::Resolve (constant.get_expr ()); return unify_site (constant.get_mappings ().get_hirid (), TyTy::TyWithLocation (type), @@ -181,7 +182,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const case HIR::GenericParam::GenericKind::TYPE: { auto param_type - = TypeResolveGenericParam::Resolve (generic_param.get ()); + = TypeResolveGenericParam::Resolve (*generic_param); context->insert_type (generic_param->get_mappings (), param_type); @@ -205,8 +206,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const ret_type = TyTy::TupleType::get_unit_type (fn.get_mappings ().get_hirid ()); else { - auto resolved - = TypeCheckType::Resolve (function.get_return_type ().get ()); + auto resolved = TypeCheckType::Resolve (function.get_return_type ()); if (resolved->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at (fn.get_locus (), "failed to resolve return type"); @@ -215,10 +215,12 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const ret_type = resolved->clone (); ret_type->set_ref ( - function.get_return_type ()->get_mappings ().get_hirid ()); + function.get_return_type ().get_mappings ().get_hirid ()); } std::vector > params; + + std::unique_ptr self_pattern = nullptr; if (function.is_method ()) { // these are implicit mappings and not used @@ -232,16 +234,17 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const // for compilation to know parameter names. The types are ignored // but we reuse the HIR identifier pattern which requires it HIR::SelfParam &self_param = function.get_self (); - HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern ( - mapping, {"self"}, self_param.get_locus (), self_param.is_ref (), - self_param.is_mut () ? Mutability::Mut : Mutability::Imm, - std::unique_ptr (nullptr)); + self_pattern + = Rust::make_unique (HIR::IdentifierPattern ( + mapping, {"self"}, self_param.get_locus (), self_param.is_ref (), + self_param.is_mut () ? Mutability::Mut : Mutability::Imm, + std::unique_ptr (nullptr))); // might have a specified type TyTy::BaseType *self_type = nullptr; if (self_param.has_type ()) { - std::unique_ptr &specified_type = self_param.get_type (); - self_type = TypeCheckType::Resolve (specified_type.get ()); + HIR::Type &specified_type = self_param.get_type (); + self_type = TypeCheckType::Resolve (specified_type); } else { @@ -284,18 +287,20 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const context->insert_type (self_param.get_mappings (), self_type); params.push_back ( - std::pair (self_pattern, self_type)); + std::pair (self_pattern.get (), + self_type)); } for (auto ¶m : function.get_function_params ()) { // get the name as well required for later on - auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ()); - params.push_back (std::pair ( - param.get_param_name ().get (), param_tyty)); + auto param_tyty = TypeCheckType::Resolve (param.get_type ()); + params.push_back ( + std::pair (¶m.get_param_name (), + param_tyty)); context->insert_type (param.get_mappings (), param_tyty); - TypeCheckPattern::Resolve (param.get_param_name ().get (), param_tyty); + TypeCheckPattern::Resolve (param.get_param_name (), param_tyty); } auto &mappings = Analysis::Mappings::get (); @@ -308,7 +313,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const function.get_function_name ().as_string (), ident, function.is_method () ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG : TyTy::FnType::FNTYPE_DEFAULT_FLAGS, - ABI::RUST, std::move (params), ret_type, substitutions, + ABI::RUST, params, ret_type, substitutions, TyTy::SubstitutionArgumentMappings::empty ( context->get_lifetime_resolver ().get_num_bound_regions ()), region_constraints); diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index c85a83955b9c..23055ae322c0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -42,7 +42,7 @@ class TypeCheckContextItem }; TypeCheckContextItem (HIR::Function *item); - TypeCheckContextItem (HIR::ImplBlock *impl_block, HIR::Function *item); + TypeCheckContextItem (HIR::ImplBlock &impl_block, HIR::Function *item); TypeCheckContextItem (HIR::TraitItemFunc *trait_item); TypeCheckContextItem (const TypeCheckContextItem &other); diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc index 079bd956d313..50892a3365c9 100644 --- a/gcc/rust/typecheck/rust-type-util.cc +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -99,8 +99,9 @@ query_type (HirId reference, TyTy::BaseType **result) auto block = mappings.lookup_hir_extern_block (extern_item->second); rust_assert (block.has_value ()); - *result = TypeCheckTopLevelExternItem::Resolve (extern_item->first, - *block.value ()); + *result + = TypeCheckTopLevelExternItem::Resolve (*extern_item.value ().first, + *block.value ()); context->query_completed (reference); return true; } diff --git a/gcc/rust/typecheck/rust-typecheck-context.cc b/gcc/rust/typecheck/rust-typecheck-context.cc index b4ff6d674443..490fc6091dad 100644 --- a/gcc/rust/typecheck/rust-typecheck-context.cc +++ b/gcc/rust/typecheck/rust-typecheck-context.cc @@ -640,9 +640,9 @@ TypeCheckContextItem::TypeCheckContextItem (HIR::Function *item) : type (ItemType::ITEM), item (item) {} -TypeCheckContextItem::TypeCheckContextItem (HIR::ImplBlock *impl_block, +TypeCheckContextItem::TypeCheckContextItem (HIR::ImplBlock &impl_block, HIR::Function *item) - : type (ItemType::IMPL_ITEM), item (impl_block, item) + : type (ItemType::IMPL_ITEM), item (&impl_block, item) {} TypeCheckContextItem::TypeCheckContextItem (HIR::TraitItemFunc *trait_item) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 4734b6746fc5..b3c19efadee9 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -70,7 +70,7 @@ TypeBoundsProbe::scan () if (!impl->has_trait_ref ()) return true; - HirId impl_ty_id = impl->get_type ()->get_mappings ().get_hirid (); + HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid (); TyTy::BaseType *impl_type = nullptr; if (!query_type (impl_ty_id, &impl_type)) return true; @@ -81,7 +81,7 @@ TypeBoundsProbe::scan () return true; } - possible_trait_paths.push_back ({impl->get_trait_ref ().get (), impl}); + possible_trait_paths.push_back ({&impl->get_trait_ref (), impl}); return true; }); @@ -182,9 +182,10 @@ TypeCheckBase::resolve_trait_path (HIR::TypePath &path) } TyTy::TypeBoundPredicate -TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, - HIR::Type *associated_self, - BoundPolarity polarity) +TypeCheckBase::get_predicate_from_bound ( + HIR::TypePath &type_path, + tl::optional> associated_self, + BoundPolarity polarity) { TyTy::TypeBoundPredicate lookup = TyTy::TypeBoundPredicate::error (); bool already_resolved @@ -215,9 +216,9 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, break; case HIR::TypePathSegment::SegmentType::FUNCTION: { - auto final_function_seg - = static_cast (final_seg.get ()); - auto &fn = final_function_seg->get_function_path (); + auto &final_function_seg + = static_cast (*final_seg); + auto &fn = final_function_seg.get_function_path (); // we need to make implicit generic args which must be an implicit // Tuple @@ -243,7 +244,7 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, // resolve the fn_once_output type which assumes there must be an output // set rust_assert (fn.has_return_type ()); - TypeCheckType::Resolve (fn.get_return_type ().get ()); + TypeCheckType::Resolve (fn.get_return_type ()); HIR::TraitItem *trait_item = mappings @@ -252,10 +253,10 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, .value (); std::vector bindings; - location_t output_locus = fn.get_return_type ()->get_locus (); + location_t output_locus = fn.get_return_type ().get_locus (); HIR::GenericArgsBinding binding (Identifier ( trait_item->trait_identifier ()), - fn.get_return_type ()->clone_type (), + fn.get_return_type ().clone_type (), output_locus); bindings.push_back (std::move (binding)); @@ -271,11 +272,11 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, break; } - if (associated_self != nullptr) + if (associated_self.has_value ()) { std::vector> type_args; - type_args.push_back ( - std::unique_ptr (associated_self->clone_type ())); + type_args.push_back (std::unique_ptr ( + associated_self.value ().get ().clone_type ())); for (auto &arg : args.get_type_args ()) { type_args.push_back (std::unique_ptr (arg->clone_type ())); @@ -292,7 +293,7 @@ TypeCheckBase::get_predicate_from_bound (HIR::TypePath &type_path, if (!args.is_empty () || predicate.requires_generic_args ()) { // this is applying generic arguments to a trait reference - predicate.apply_generic_arguments (&args, associated_self != nullptr); + predicate.apply_generic_arguments (&args, associated_self.has_value ()); } context->insert_resolved_predicate (type_path.get_mappings ().get_hirid (), diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index f5d12b80464e..36a6b3d858d8 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -80,7 +80,7 @@ TypeCheckCallExpr::visit (ADTType &type) BaseType *field_tyty = field->get_field_type (); location_t arg_locus = argument->get_locus (); - BaseType *arg = Resolver::TypeCheckExpr::Resolve (argument.get ()); + BaseType *arg = Resolver::TypeCheckExpr::Resolve (*argument); if (arg->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at (argument->get_locus (), @@ -139,8 +139,7 @@ TypeCheckCallExpr::visit (FnType &type) for (auto &argument : call.get_arguments ()) { location_t arg_locus = argument->get_locus (); - auto argument_expr_tyty - = Resolver::TypeCheckExpr::Resolve (argument.get ()); + auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument); if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at ( @@ -152,8 +151,8 @@ TypeCheckCallExpr::visit (FnType &type) // it might be a variadic function if (i < type.num_params ()) { - auto fnparam = type.param_at (i); - HIR::Pattern *fn_param_pattern = fnparam.first; + auto &fnparam = type.param_at (i); + auto &fn_param_pattern = fnparam.first; BaseType *param_ty = fnparam.second; location_t param_locus = fn_param_pattern == nullptr @@ -272,8 +271,7 @@ TypeCheckCallExpr::visit (FnPtr &type) { location_t arg_locus = argument->get_locus (); BaseType *fnparam = type.get_param_type_at (i); - auto argument_expr_tyty - = Resolver::TypeCheckExpr::Resolve (argument.get ()); + auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*argument); if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at ( @@ -322,8 +320,7 @@ TypeCheckMethodCallExpr::go (FnType *ref, HIR::MethodCallExpr &call, std::vector args; for (auto &arg : call.get_arguments ()) { - BaseType *argument_expr_tyty - = Resolver::TypeCheckExpr::Resolve (arg.get ()); + BaseType *argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (*arg); if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at (arg->get_locus (), @@ -337,7 +334,7 @@ TypeCheckMethodCallExpr::go (FnType *ref, HIR::MethodCallExpr &call, TypeCheckMethodCallExpr checker (call.get_mappings (), args, call.get_locus (), - call.get_receiver ()->get_locus (), + call.get_receiver ().get_locus (), adjusted_self, context); return checker.check (*ref); } @@ -377,7 +374,7 @@ TypeCheckMethodCallExpr::check (FnType &type) { location_t arg_locus = argument.get_locus (); - auto fnparam = type.param_at (i); + auto &fnparam = type.param_at (i); HIR::Pattern *fn_param_pattern = fnparam.first; BaseType *param_ty = fnparam.second; location_t param_locus diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index 48dcd95e181a..988f82f4bd7c 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -630,7 +630,7 @@ SubstitutionRef::get_mappings_from_generic_args ( for (auto &binding : args.get_binding_args ()) { BaseType *resolved - = Resolver::TypeCheckType::Resolve (binding.get_type ().get ()); + = Resolver::TypeCheckType::Resolve (binding.get_type ()); if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR) { @@ -698,7 +698,7 @@ SubstitutionRef::get_mappings_from_generic_args ( std::vector mappings = used_arguments.get_mappings (); for (auto &arg : args.get_type_args ()) { - BaseType *resolved = Resolver::TypeCheckType::Resolve (arg.get ()); + BaseType *resolved = Resolver::TypeCheckType::Resolve (*arg); if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR) { rust_error_at (args.get_locus (), "failed to resolve type arguments"); diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 7b17231d5ae0..67890d68a4c5 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -31,6 +31,7 @@ #include "rust-hir-type-bounds.h" #include "options.h" +#include namespace Rust { namespace TyTy { @@ -595,7 +596,8 @@ BaseType::monomorphized_clone () const { std::vector> cloned_params; for (auto &p : fn->get_params ()) - cloned_params.push_back ({p.first, p.second->monomorphized_clone ()}); + cloned_params.push_back (std::pair ( + p.first, p.second->monomorphized_clone ())); BaseType *retty = fn->get_return_type ()->monomorphized_clone (); return new FnType (fn->get_ref (), fn->get_ty_ref (), fn->get_id (), @@ -1341,9 +1343,10 @@ VariantDef::variant_type_string (VariantType type) } VariantDef::VariantDef (HirId id, DefId defid, std::string identifier, - RustIdent ident, HIR::Expr *discriminant) + RustIdent ident, + std::unique_ptr &&discriminant) : id (id), defid (defid), identifier (identifier), ident (ident), - discriminant (discriminant) + discriminant (std::move (discriminant)) { type = VariantType::NUM; @@ -1352,34 +1355,15 @@ VariantDef::VariantDef (HirId id, DefId defid, std::string identifier, VariantDef::VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, VariantType type, - HIR::Expr *discriminant, + std::unique_ptr &&discriminant, std::vector fields) : id (id), defid (defid), identifier (identifier), ident (ident), type (type), - discriminant (discriminant), fields (fields) + discriminant (std::move (discriminant)), fields (fields) { rust_assert ((type == VariantType::NUM && fields.empty ()) || (type == VariantType::TUPLE || type == VariantType::STRUCT)); } -VariantDef::VariantDef (const VariantDef &other) - : id (other.id), defid (other.defid), identifier (other.identifier), - ident (other.ident), type (other.type), discriminant (other.discriminant), - fields (other.fields) -{} - -VariantDef & -VariantDef::operator= (const VariantDef &other) -{ - id = other.id; - identifier = other.identifier; - type = other.type; - discriminant = other.discriminant; - fields = other.fields; - ident = other.ident; - - return *this; -} - VariantDef & VariantDef::get_error_node () { @@ -1475,11 +1459,11 @@ VariantDef::lookup_field (const std::string &lookup, return false; } -HIR::Expr * -VariantDef::get_discriminant () const +HIR::Expr & +VariantDef::get_discriminant () { rust_assert (discriminant != nullptr); - return discriminant; + return *discriminant; } std::string @@ -1533,8 +1517,8 @@ VariantDef::clone () const for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->clone ()); - return new VariantDef (id, defid, identifier, ident, type, discriminant, - cloned_fields); + return new VariantDef (id, defid, identifier, ident, type, + discriminant->clone_expr (), cloned_fields); } VariantDef * @@ -1544,8 +1528,8 @@ VariantDef::monomorphized_clone () const for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ()); - return new VariantDef (id, defid, identifier, ident, type, discriminant, - cloned_fields); + return new VariantDef (id, defid, identifier, ident, type, + discriminant->clone_expr (), cloned_fields); } const RustIdent & @@ -1891,7 +1875,7 @@ FnType::as_string () const std::string params_str = ""; for (auto ¶m : params) { - auto pattern = param.first; + auto &pattern = param.first; auto ty = param.second; params_str += pattern->as_string () + " " + ty->as_string (); params_str += ","; @@ -1961,7 +1945,8 @@ FnType::clone () const { std::vector> cloned_params; for (auto &p : params) - cloned_params.push_back ({p.first, p.second->clone ()}); + cloned_params.push_back ( + std::pair (p.first, p.second->clone ())); return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (), ident, flags, abi, std::move (cloned_params), diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 3222e3e86e99..b9cd4ec71fd6 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -28,6 +28,9 @@ #include "rust-tyty-subst.h" #include "rust-tyty-region.h" #include "rust-system.h" +#include "rust-hir.h" + +#include namespace Rust { @@ -567,16 +570,12 @@ class VariantDef static std::string variant_type_string (VariantType type); VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, - HIR::Expr *discriminant); + std::unique_ptr &&discriminant); VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, - VariantType type, HIR::Expr *discriminant, + VariantType type, std::unique_ptr &&discriminant, std::vector fields); - VariantDef (const VariantDef &other); - - VariantDef &operator= (const VariantDef &other); - static VariantDef &get_error_node (); bool is_error () const; @@ -597,7 +596,7 @@ class VariantDef bool lookup_field (const std::string &lookup, StructFieldType **field_lookup, size_t *index) const; - HIR::Expr *get_discriminant () const; + HIR::Expr &get_discriminant (); std::string as_string () const; @@ -616,7 +615,7 @@ class VariantDef RustIdent ident; VariantType type; // can either be a structure or a discriminant value - HIR::Expr *discriminant; + std::unique_ptr discriminant; std::vector fields; }; @@ -787,8 +786,8 @@ class FnType : public CallableTypeInterface, public SubstitutionRef : CallableTypeInterface (ref, ref, TypeKind::FNDEF, ident, refs), SubstitutionRef (std::move (subst_refs), substitution_argument_mappings, region_constraints), - params (std::move (params)), type (type), flags (flags), - identifier (identifier), id (id), abi (abi) + params (params), type (type), flags (flags), identifier (identifier), + id (id), abi (abi) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); @@ -804,8 +803,8 @@ class FnType : public CallableTypeInterface, public SubstitutionRef : CallableTypeInterface (ref, ty_ref, TypeKind::FNDEF, ident, refs), SubstitutionRef (std::move (subst_refs), substitution_argument_mappings, region_constraints), - params (params), type (type), flags (flags), identifier (identifier), - id (id), abi (abi) + params (std::move (params)), type (type), flags (flags), + identifier (identifier), id (id), abi (abi) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 16a838d9c07c..65981095e699 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -459,7 +459,7 @@ Mappings::insert_hir_impl_block (HIR::ImplBlock *item) auto id = item->get_mappings ().get_hirid (); rust_assert (!lookup_hir_impl_block (id)); - HirId impl_type_id = item->get_type ()->get_mappings ().get_hirid (); + HirId impl_type_id = item->get_type ().get_mappings ().get_hirid (); hirImplBlockMappings[id] = item; hirImplBlockTypeMappings[impl_type_id] = item; insert_node_to_hir (item->get_mappings ().get_nodeid (), id);