From patchwork Thu Aug 1 14:57:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=AL0F0xu5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZYFG1zrjz1ybX for ; Fri, 2 Aug 2024 01:45:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 734323864825 for ; Thu, 1 Aug 2024 15:45:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id AB4C7386100D for ; Thu, 1 Aug 2024 15:00:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB4C7386100D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AB4C7386100D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524509; cv=none; b=kdyUy++oIUWTXsZTUdWCZy6ASqD+RwMnppA9Sg37+IS9Bch7GE2qJ68Fe6MpwEWi2lwZKjThBtBeJ9nYQxOtUXhl89kP1rRj5LVFV2gOMdgezJqxmG95rE1O/IoXjsh4qc/cCrD7aBto/M4h/Z2op0dZaXmAmgH8cGiM/2vV8CM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524509; c=relaxed/simple; bh=vsiHZmkyd95rnWmWCqQwwKSqmYGDN7Pu+Hz6HUcUmaM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uEF3barkEceHV+1YjxivaxW4XtchrFWTz5itayJsCf9R8B8bavoBPQXHoZHb/jW8J58q+5US7EM8jYr7dz0oWoGgBOfa5ADVQYSmb+tFeAx8ozr7ril6M5S71/53Fao4ZvdbA6PMK7/rCfRaTrhbi9SFw/9D3qqAPZ/0FooXrkE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52f01afa11cso10559398e87.0 for ; Thu, 01 Aug 2024 08:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524456; x=1723129256; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3s66JSbpDkhpFs6d4SYceCTuIWNW4s/E6XzRHoW9xR8=; b=AL0F0xu5IxLmAHqxO/VJKSbHaNQ4LJWxCYOQCHSZT4reWLsqoC1MGFUvKitOAj04ho CO/ElmfeKb+OOxJPEeaRU15eJxq78JVhrcmWBJvbuqW/jgDrVrGWdfazGuZmdkIkVfF9 mdORKGCNBcdamUD6T+y5hmp1ymc3ishW3nqmJhKeiYvBnqRYoCY13RRbHHiI1Jt0LL0s 1zNMiNAwzRgwrLhBa/RRrxwzDxCS2Mw/s7MLyJGqbuzlXM6WxomCsaz8E0RqlwlV17hC WcF/9VsPe7mf5uirWd6WTA+GDI9tPnxTSTUw39txfiR6YI9w+aPoydu2w8mDumKc2Cer Vf8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524456; x=1723129256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3s66JSbpDkhpFs6d4SYceCTuIWNW4s/E6XzRHoW9xR8=; b=RlkBKlG/g1GOFohelWIkZhQEqYjw62JjDH8hCkCmr5SteMo3xmJiMVYpMW2IGmiB9N clSy7myISyVNT1cdmhGtDMhtuFgIbmBvuBUovXayBx/Pfh0wycxA+/hIgY5BiQOuKq6L pdbnhHUn712rxgmKR2Nyool0Kj3UfIYB1toykKJX2ABichHelAdX/bDogqv9nkQq9z38 VlozjkWNSRUnWgsnUqO62/4AhDvlw8uzRmPJeYnh84Hr4yijrk7qIenxpcJFCA2rbA8a kZ409RLFbf/AOg6SsKNHVLWbjaYs4c3oLWPVVab3EGTelQbuzSzWl/1fG2vjHBCpCgna JkVA== X-Gm-Message-State: AOJu0Yz2lQP0niuunbsxyqFiqCqV4tcjw1L4klA/9KlO38s5MhnNE2dc 4AbegXG0ZXf6SKya461gRLXli62Kg6y7d4Ai2mDiLvSOCLDVvdCPeKR+leOM8a/NWyS91Hojf67 /UF/k X-Google-Smtp-Source: AGHT+IErE52PM10792yIiWXfKAFn0KYHRO4ZRLbYTRJ6AUziN8Yyue99R7SfCCrP/KzNml1cag0vCQ== X-Received: by 2002:a05:6512:a8d:b0:52e:a68a:6076 with SMTP id 2adb3069b0e04-530bb3b42d7mr105087e87.49.1722524455618; Thu, 01 Aug 2024 08:00:55 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.08.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:00:55 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [PATCH 122/125] gccrs: borrowck: Remove block braces to satisfy GNU style Date: Thu, 1 Aug 2024 16:57:58 +0200 Message-ID: <20240801145809.366388-124-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Jakub Dupak gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-dump.cc (renumber_places): Remove unecessary braces. (Dump::go): Remove unecessary braces. (Dump::visit): Remove unecessary braces. (Dump::visit_scope): Remove unecessary braces. * checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector): Remove unecessary braces. (points): Remove unecessary braces. * checks/errors/borrowck/rust-bir-free-region.h: Remove unecessary braces. * checks/errors/borrowck/rust-bir-place.h: Remove unecessary braces. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Remove unecessary braces. * checks/errors/borrowck/rust-function-collector.h: Remove unecessary braces. Signed-off-by: Jakub Dupak --- .../checks/errors/borrowck/rust-bir-dump.cc | 47 ++++------ .../errors/borrowck/rust-bir-fact-collector.h | 87 ++++++------------- .../errors/borrowck/rust-bir-free-region.h | 16 +--- .../checks/errors/borrowck/rust-bir-place.h | 17 ++-- .../errors/borrowck/rust-borrow-checker.cc | 6 +- .../errors/borrowck/rust-function-collector.h | 4 +- 6 files changed, 56 insertions(+), 121 deletions(-) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc index 51dd1436350..a39f145f8f9 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc +++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc @@ -42,13 +42,9 @@ renumber_places (const Function &func, std::vector &place_map) { const Place &place = func.place_db[in_id]; if (place.kind == Place::VARIABLE || place.kind == Place::TEMPORARY) - { - place_map[in_id] = next_out_id++; - } + place_map[in_id] = next_out_id++; else - { - place_map[in_id] = INVALID_PLACE; - } + place_map[in_id] = INVALID_PLACE; } } @@ -138,10 +134,9 @@ Dump::go (bool enable_simplify_cfg) stream << ";\n"; } if (!bb_terminated) - { - stream << indentation << indentation << "goto -> bb" - << bb_fold_map[bb.successors.at (0)] << ";\t\t" << i++ << "\n"; - } + stream << indentation << indentation << "goto -> bb" + << bb_fold_map[bb.successors.at (0)] << ";\t\t" << i++ << "\n"; + stream << indentation << "}\n"; } @@ -276,15 +271,13 @@ void Dump::visit (const CallExpr &expr) { stream << "Call("; - if (auto fn_type - = func.place_db[expr.get_callable ()].tyty->try_as ()) - { - stream << fn_type->get_identifier (); - } + auto maybe_fn_type + = func.place_db[expr.get_callable ()].tyty->try_as (); + if (maybe_fn_type) + stream << maybe_fn_type->get_identifier (); else - { - visit_move_place (expr.get_callable ()); - } + visit_move_place (expr.get_callable ()); + stream << ")("; print_comma_separated (stream, expr.get_arguments (), [this] (PlaceId place_id) { @@ -321,13 +314,9 @@ void Dump::visit (const Assignment &expr) { if (func.place_db[expr.get_rhs ()].is_rvalue ()) - { - visit_move_place (expr.get_rhs ()); - } + visit_move_place (expr.get_rhs ()); else - { - visit_place (expr.get_rhs ()); - } + visit_place (expr.get_rhs ()); } std::ostream & @@ -346,9 +335,8 @@ Dump::visit_scope (ScopeId id, size_t depth) return; if (id > 1) - { - indent (depth) << "scope " << id - 1 << " {\n"; - } + indent (depth) << "scope " << id - 1 << " {\n"; + for (auto &local : scope.locals) { indent (depth + 1) << "let _"; @@ -357,9 +345,8 @@ Dump::visit_scope (ScopeId id, size_t depth) stream << ";\n"; } for (auto &child : scope.children) - { - visit_scope (child, (id >= 1) ? depth + 1 : depth); - } + visit_scope (child, (id >= 1) ? depth + 1 : depth); + if (id > 1) indent (depth) << "}\n"; } diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h index 17c198e0fa7..527ae65606c 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-fact-collector.h @@ -67,9 +67,8 @@ class FactCollector : public Visitor { std::vector free_regions; for (size_t i = 0; i < size; i++) - { - free_regions.push_back (region_binder.get_next_free_region ()); - } + free_regions.push_back (region_binder.get_next_free_region ()); + return FreeRegions (std::move (free_regions)); } @@ -129,9 +128,8 @@ protected: // Main collection entry points (for different categories). case Place::TEMPORARY: facts.path_is_var.emplace_back (place_id, place_id); for (auto ®ion : place.regions) - { - facts.use_of_var_derefs_origin.emplace_back (place_id, region); - } + facts.use_of_var_derefs_origin.emplace_back (place_id, region); + // TODO: drop_of_var_derefs_origin break; case Place::FIELD: @@ -154,10 +152,9 @@ protected: // Main collection entry points (for different categories). } for (PlaceId arg = FIRST_VARIABLE_PLACE + 1; arg < first_local; ++arg) - { - facts.path_assigned_at_base.emplace_back ( - arg, get_point (0, 0, PointPosition::START)); - } + facts.path_assigned_at_base.emplace_back ( + arg, get_point (0, 0, PointPosition::START)); + for (PlaceId place = first_local; place < place_db.size (); ++place) { if (place_db[place].is_var ()) @@ -560,17 +557,13 @@ protected: // Generic BIR operations. { place_db.for_each_path_segment (place_id, [&] (PlaceId id) { for (auto loan : place_db[id].borrowed_by) - { - facts.loan_invalidated_at.emplace_back (get_current_point_start (), - loan); - } + facts.loan_invalidated_at.emplace_back (get_current_point_start (), + loan); }); place_db.for_each_path_from_root (place_id, [&] (PlaceId id) { for (auto loan : place_db[id].borrowed_by) - { - facts.loan_invalidated_at.emplace_back (get_current_point_start (), - loan); - } + facts.loan_invalidated_at.emplace_back (get_current_point_start (), + loan); }); } @@ -583,14 +576,10 @@ protected: // Generic BIR operations. if (mutability == Mutability::Imm && place_db.get_loans ()[other_loan].mutability == Mutability::Imm) - { - continue; - } + continue; else - { - facts.loan_invalidated_at.emplace_back ( - get_current_point_start (), other_loan); - } + facts.loan_invalidated_at.emplace_back (get_current_point_start (), + other_loan); } }); @@ -600,14 +589,10 @@ protected: // Generic BIR operations. if (mutability == Mutability::Imm && place_db.get_loans ()[other_loan].mutability == Mutability::Imm) - { - continue; - } + continue; else - { - facts.loan_invalidated_at.emplace_back ( - get_current_point_start (), other_loan); - } + facts.loan_invalidated_at.emplace_back (get_current_point_start (), + other_loan); } }); } @@ -618,9 +603,7 @@ protected: // Generic BIR operations. if (id == place_id) return; if (place_db[id].kind == Place::DEREF) - { - rust_error_at (location, "Cannot move from behind a reference."); - } + rust_error_at (location, "Cannot move from behind a reference."); }); } @@ -654,13 +637,9 @@ protected: // Subset helpers. void push_subset (Variance variance, FreeRegion lhs, FreeRegion rhs) { if (variance.is_covariant ()) - { - push_subset (lhs, rhs); - } + push_subset (lhs, rhs); else if (variance.is_contravariant ()) - { - push_subset (rhs, lhs); - } + push_subset (rhs, lhs); else if (variance.is_invariant ()) { push_subset (lhs, rhs); @@ -671,13 +650,9 @@ protected: // Subset helpers. void push_subset_all (Variance variance, FreeRegion lhs, FreeRegion rhs) { if (variance.is_covariant ()) - { - push_subset_all (lhs, rhs); - } + push_subset_all (lhs, rhs); else if (variance.is_contravariant ()) - { - push_subset_all (rhs, lhs); - } + push_subset_all (rhs, lhs); else if (variance.is_invariant ()) { push_subset_all (lhs, rhs); @@ -701,9 +676,7 @@ protected: // Subset helpers. rust_assert (lhs.size () == rhs.size ()); rust_assert (lhs.size () == variances.size ()); for (size_t i = 0; i < lhs.size (); ++i) - { - push_subset (variances[i], lhs[i], rhs[i]); - } + push_subset (variances[i], lhs[i], rhs[i]); } void push_subset_all (TyTy::BaseType *type, FreeRegions lhs, FreeRegions rhs) @@ -714,9 +687,7 @@ protected: // Subset helpers. rust_assert (lhs.size () == rhs.size ()); rust_assert (lhs.size () == variances.size ()); for (size_t i = 0; i < lhs.size (); ++i) - { - push_subset_all (variances[i], lhs[i], rhs[i]); - } + push_subset_all (variances[i], lhs[i], rhs[i]); } void push_subset_user (TyTy::BaseType *type, FreeRegions free_regions, @@ -731,18 +702,14 @@ protected: // Subset helpers. for (size_t i = 0; i < free_regions.size (); ++i) { if (user_regions[i].is_named ()) - { - push_subset (variances[i], free_regions[i], - {Polonius::Origin (user_regions[i].get_index ())}); - } + push_subset (variances[i], free_regions[i], + {Polonius::Origin (user_regions[i].get_index ())}); else if (user_regions[i].is_anonymous ()) { // IGNORE } else - { - rust_internal_error_at (UNKNOWN_LOCATION, "Unexpected region type"); - } + rust_internal_error_at (UNKNOWN_LOCATION, "Unexpected region type"); } } diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h index 0560a894ab0..e5d6ef3c98b 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-free-region.h @@ -75,21 +75,13 @@ public: for (auto ®ion : regions) { if (region.is_early_bound ()) - { - free_regions.push_back (parent_free_regions[region.get_index ()]); - } + free_regions.push_back (parent_free_regions[region.get_index ()]); else if (region.is_static ()) - { - free_regions.push_back (0); - } + free_regions.push_back (0); else if (region.is_anonymous ()) - { - free_regions.push_back (get_next_free_region ()); - } + free_regions.push_back (get_next_free_region ()); else if (region.is_named ()) - { - rust_unreachable (); // FIXME - } + rust_unreachable (); // FIXME else { rust_sorry_at (UNKNOWN_LOCATION, "Unimplemented"); diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h index f22ab112b3e..752c8f42c00 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h @@ -233,28 +233,21 @@ public: PlaceId new_place = places.size () - 1; Place &new_place_ref = places[new_place]; // Intentional shadowing. if (last_sibling == 0) - { - places[new_place_ref.path.parent].path.first_child = new_place; - } + places[new_place_ref.path.parent].path.first_child = new_place; else - { - places[last_sibling].path.next_sibling = new_place; - } + places[last_sibling].path.next_sibling = new_place; if (new_place_ref.kind == Place::VARIABLE || new_place_ref.kind == Place::TEMPORARY) - { - scopes[current_scope].locals.push_back (new_place); - } + scopes[current_scope].locals.push_back (new_place); auto variances = Resolver::TypeCheckContext::get () ->get_variance_analysis_ctx () .query_type_variances (new_place_ref.tyty); std::vector regions; for (size_t i = 0; i < variances.size (); i++) - { - regions.push_back (next_free_region++); - } + regions.push_back (next_free_region++); + new_place_ref.regions.set_from (std::move (regions)); return new_place; diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc index 77726eb1c26..ae06aadaa5b 100644 --- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc +++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc @@ -92,10 +92,8 @@ BorrowChecker::go (HIR::Crate &crate) } for (auto closure ATTRIBUTE_UNUSED : collector.get_closures ()) - { - rust_sorry_at (closure->get_locus (), - "Closure borrow checking is not implemented yet."); - } + rust_sorry_at (closure->get_locus (), + "Closure borrow checking is not implemented yet."); } } // namespace HIR diff --git a/gcc/rust/checks/errors/borrowck/rust-function-collector.h b/gcc/rust/checks/errors/borrowck/rust-function-collector.h index 272f20d5f93..7058451f2b5 100644 --- a/gcc/rust/checks/errors/borrowck/rust-function-collector.h +++ b/gcc/rust/checks/errors/borrowck/rust-function-collector.h @@ -50,9 +50,7 @@ protected: template void visit_all (std::vector> &items) { for (std::unique_ptr &item : items) - { - item->accept_vis (*this); - } + item->accept_vis (*this); } void visit (HIR::Function &function) override