From patchwork Wed Apr 5 14:03:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 79694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp356086vqo; Wed, 5 Apr 2023 07:37:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Zl2TJAiod/6Rl4Mpe6Q6jkcldwF5eeM76QhTxve6k/TGslvV35Qd7YTSaafSgcjf1nwvjM X-Received: by 2002:a17:906:a409:b0:92b:f8ce:4e75 with SMTP id l9-20020a170906a40900b0092bf8ce4e75mr3257669ejz.72.1680705420395; Wed, 05 Apr 2023 07:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705420; cv=none; d=google.com; s=arc-20160816; b=prsEGj/kLJtrVy8osSpwgiOt0AymcIGp9sl/0uhk7RqZ61W7QRMdreb85ZW9finexE fQSZy+xSPvw+kftH44ohHkxAztHZPob14BqB/+xSDcKl4lwhdAr8KeO5XQT+9Q1vY+/1 IPhisHSEdTVNznCkpGMbzNrjvcHuEdN3QQOJMCrxQygNFEAgnQn6DaVLK0hIbWdC/j80 TgCt86PGYKGezOTgWmUqdQ71tDQUpvcIJj89aCF1nVWt1VRqmkbWXnoXaMZIaiun43AW RVPPwcGKloniJ9yWBMMKfk2NNsnyTXShGEY01F0DXWKGxUH+LhEBreXlrHI6DrT+/H9W Jlgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=iXqjus6/FsO2Nkxo1n686g5RhNiMOGUPKH7j5mkojD4=; b=lbSUDIBpR6FonrT8mxtoirDIFgix8Tc19hCxdL5GKxqMC6P/SJ6qrYII3QvGPNyAP5 fVZkn4kfZI6kQGBbS+2EMzat9LUg7yK5i+TMKzuXfBbKJmMJM3wDOSNT99VOpCv6+Kmj IEYIhyyIFOA7mQOcOSZvB8p6bm/qMEdCAmqwwnt/OV0P1K56eLnmxXDhEL90gIQkjVqO XOrrqiSEzhqpPGaL840YHVYl0IxwLv+qddSPIUDHwCjnigFekvX+45JjuwwqF2CRMkKq BK0rM3lU9g+RDA2vXtMSSIRomfn0PoUT6DChsACArBuBEvEwb4pTdcTXgwvIQKAlv5Dg vCOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WD5rm9Ta; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id rl3-20020a170907216300b00946f79be789si4141882ejb.985.2023.04.05.07.37.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:37:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=WD5rm9Ta; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 71EA83952017 for ; Wed, 5 Apr 2023 14:14:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 8309038708F1 for ; Wed, 5 Apr 2023 14:06:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8309038708F1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x435.google.com with SMTP id l12so36316149wrm.10 for ; Wed, 05 Apr 2023 07:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1680703561; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=iXqjus6/FsO2Nkxo1n686g5RhNiMOGUPKH7j5mkojD4=; b=WD5rm9TajimmNg+zYV1xppepWtId6Qc1jyvv3JUXoWL2BMKO5mviMmKlTCeSGVydSO W0Gtkm1x2+nnAqPqniPC0PAESMgdRMASZ/sahXxM5DNrDlCb1Y9HgJBFlUL+met+Ymvg 3KdO9wHXV7SVgxqNrMSpxhrsQvFgpCOOSz0JP6xqKfAa37yhf1SQGeNlcAtTgwpYQh0v N1vooHcwkYBtiXHj5DY0TSWBdeQZqMHY+TvP+a836VMy0ilxUofXcB2ZAS9c7Dg4PLr7 cDXNf+XeuqLkfjzdMjKCZWUeebXU3MCXyiIMz1TVIJ9OMm1SaSiaXS65QvpHWeLj3M0V S0OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680703561; h=content-transfer-encoding:mime-version:reply-to: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=iXqjus6/FsO2Nkxo1n686g5RhNiMOGUPKH7j5mkojD4=; b=Hc4HuN11EtsZu32aLW0TlXtEVk51U9J6EPemKGReNLQ05sA+zPkjUItXS0tVQO0UU4 7Onlva2k5vKG1IeTptqbDglEgDI64oWjksOicO/gFDbLAKiOnbV2Qzn84jTyXnpvJ6dp PH6uF6y9Mbgwjfpb9gdHcnjSbDbKo62E20ud+7iq/sE3sz+Qar/+Rzx8pBHD0Ph2xhU0 nBl2nxDj76eOmDWLDBNrH1OVQ0KQUbU4SyEDupTOhPxisFhmJ0Ggp4ZnMJSaX8d2ayaI Se+A+TzuQizPqfMuEQJ5cAb8wT1+4iFNyfnbs21Q2th7Yuxlx9EEgTw+n5HB5lvDDZ97 UKKQ== X-Gm-Message-State: AAQBX9fEGcp5Stg1kR+6pauf4ubHPOG8B+M1RfibaK3PofDkdcw7sFfK 2TDRSFq9/k0kMdhA1rUl+v69eptbWu5t8OMwcw== X-Received: by 2002:a05:6000:11ce:b0:2e6:bff9:2634 with SMTP id i14-20020a05600011ce00b002e6bff92634mr3928628wrx.56.1680703561022; Wed, 05 Apr 2023 07:06:01 -0700 (PDT) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id ay8-20020a05600c1e0800b003edddae1068sm2330150wmb.9.2023.04.05.07.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:06:00 -0700 (PDT) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 46/88] gccrs: Refactor handle_substitutions to take a reference Date: Wed, 5 Apr 2023 16:03:30 +0200 Message-Id: <20230405140411.3016563-47-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com> References: <20230405140411.3016563-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.3 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=unavailable 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762347367088086492?= X-GMAIL-MSGID: =?utf-8?q?1762347367088086492?= From: Philip Herron This patch changes the recusive substitution code to take a reference instead of a copy. This is important as the callback field is going to be made non-copyable in a future patch and this pipeline is for recursive substitutions so its ok to reuse the same mappings here. Signed-off-by: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc: refactor to take a reference * typecheck/rust-tyty-subst.cc: likewise (SubstitutionRef::get_substitution_arguments): likewise (SubstitutionRef::infer_substitions): likewise * typecheck/rust-tyty-subst.h: likewise * typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise (TupleType::handle_substitions): likewise (FnType::handle_substitions): likewise (ClosureType::handle_substitions): likewise (ArrayType::handle_substitions): likewise (SliceType::handle_substitions): likewise (ReferenceType::handle_substitions): likewise (PointerType::handle_substitions): likewise (ParamType::handle_substitions): likewise (ProjectionType::handle_substitions): likewise * typecheck/rust-tyty.h: likewise --- gcc/rust/typecheck/rust-tyty-bounds.cc | 2 +- gcc/rust/typecheck/rust-tyty-subst.cc | 10 ++++++++-- gcc/rust/typecheck/rust-tyty-subst.h | 5 +++-- gcc/rust/typecheck/rust-tyty.cc | 21 +++++++++++---------- gcc/rust/typecheck/rust-tyty.h | 22 +++++++++++----------- 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index e7eb9a760f5..b14e0c68e5a 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -444,7 +444,7 @@ TypeBoundPredicate::is_error () const BaseType * TypeBoundPredicate::handle_substitions ( - SubstitutionArgumentMappings subst_mappings) + SubstitutionArgumentMappings &subst_mappings) { for (auto &sub : get_substs ()) { diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc index aceed29ff03..a5d738744fc 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.cc +++ b/gcc/rust/typecheck/rust-tyty-subst.cc @@ -488,7 +488,13 @@ SubstitutionRef::was_substituted () const return !needs_substitution (); } -SubstitutionArgumentMappings +SubstitutionArgumentMappings & +SubstitutionRef::get_substitution_arguments () +{ + return used_arguments; +} + +const SubstitutionArgumentMappings & SubstitutionRef::get_substitution_arguments () const { return used_arguments; @@ -697,7 +703,7 @@ SubstitutionRef::infer_substitions (Location locus) SubstitutionArgumentMappings infer_arguments (std::move (args), {} /* binding_arguments */, locus); - return handle_substitions (std::move (infer_arguments)); + return handle_substitions (infer_arguments); } SubstitutionArgumentMappings diff --git a/gcc/rust/typecheck/rust-tyty-subst.h b/gcc/rust/typecheck/rust-tyty-subst.h index 4d09a3013e7..039eb36589e 100644 --- a/gcc/rust/typecheck/rust-tyty-subst.h +++ b/gcc/rust/typecheck/rust-tyty-subst.h @@ -199,7 +199,8 @@ public: bool was_substituted () const; - SubstitutionArgumentMappings get_substitution_arguments () const; + SubstitutionArgumentMappings &get_substitution_arguments (); + const SubstitutionArgumentMappings &get_substitution_arguments () const; // this is the count of type params that are not substituted fuly size_t num_required_substitutions () const; @@ -301,7 +302,7 @@ public: bool monomorphize (); // TODO comment - virtual BaseType *handle_substitions (SubstitutionArgumentMappings mappings) + virtual BaseType *handle_substitions (SubstitutionArgumentMappings &mappings) = 0; SubstitutionArgumentMappings get_used_arguments () const; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 4c324c66c16..a3271eb0d1a 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1148,7 +1148,7 @@ handle_substitions (SubstitutionArgumentMappings &subst_mappings, } ADTType * -ADTType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +ADTType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) { ADTType *adt = static_cast (clone ()); adt->set_ty_ref (mappings->get_next_hir_id ()); @@ -1333,7 +1333,7 @@ TupleType::monomorphized_clone () const } TupleType * -TupleType::handle_substitions (SubstitutionArgumentMappings mappings) +TupleType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -1474,7 +1474,7 @@ FnType::monomorphized_clone () const } FnType * -FnType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) { FnType *fn = static_cast (clone ()); fn->set_ty_ref (mappings->get_next_hir_id ()); @@ -1742,7 +1742,7 @@ ClosureType::monomorphized_clone () const } ClosureType * -ClosureType::handle_substitions (SubstitutionArgumentMappings mappings) +ClosureType::handle_substitions (SubstitutionArgumentMappings &mappings) { gcc_unreachable (); return nullptr; @@ -1862,7 +1862,7 @@ ArrayType::monomorphized_clone () const } ArrayType * -ArrayType::handle_substitions (SubstitutionArgumentMappings mappings) +ArrayType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -1945,7 +1945,7 @@ SliceType::monomorphized_clone () const } SliceType * -SliceType::handle_substitions (SubstitutionArgumentMappings mappings) +SliceType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -2704,7 +2704,7 @@ ReferenceType::monomorphized_clone () const } ReferenceType * -ReferenceType::handle_substitions (SubstitutionArgumentMappings mappings) +ReferenceType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -2870,7 +2870,7 @@ PointerType::monomorphized_clone () const } PointerType * -PointerType::handle_substitions (SubstitutionArgumentMappings mappings) +PointerType::handle_substitions (SubstitutionArgumentMappings &mappings) { auto mappings_table = Analysis::Mappings::get (); @@ -3047,7 +3047,7 @@ ParamType::is_equal (const BaseType &other) const } ParamType * -ParamType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +ParamType::handle_substitions (SubstitutionArgumentMappings &subst_mappings) { SubstitutionArg arg = SubstitutionArg::error (); bool ok = subst_mappings.get_argument_for_symbol (this, &arg); @@ -3492,7 +3492,8 @@ ProjectionType::monomorphized_clone () const } ProjectionType * -ProjectionType::handle_substitions (SubstitutionArgumentMappings subst_mappings) +ProjectionType::handle_substitions ( + SubstitutionArgumentMappings &subst_mappings) { // // do we really need to substitute this? // if (base->needs_generic_substitutions () || base->contains_type_parameters diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 85b3a3b7abc..1cf7131c1cb 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -304,7 +304,7 @@ public: bool is_concrete () const override final; - ParamType *handle_substitions (SubstitutionArgumentMappings mappings); + ParamType *handle_substitions (SubstitutionArgumentMappings &mappings); private: std::string symbol; @@ -379,7 +379,7 @@ public: std::string get_name () const override final; - TupleType *handle_substitions (SubstitutionArgumentMappings mappings); + TupleType *handle_substitions (SubstitutionArgumentMappings &mappings); private: std::vector fields; @@ -427,7 +427,7 @@ public: // WARNING THIS WILL ALWAYS RETURN NULLPTR BaseType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; bool is_error () const; @@ -682,7 +682,7 @@ public: } ADTType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; private: std::string identifier; @@ -815,7 +815,7 @@ public: } FnType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; ABI get_abi () const { return abi; } @@ -965,7 +965,7 @@ public: } ClosureType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; TyTy::TupleType &get_parameters () const { return *parameters; } TyTy::BaseType &get_result_type () const { return *result_type.get_tyty (); } @@ -1024,7 +1024,7 @@ public: HIR::Expr &get_capacity_expr () const { return capacity_expr; } - ArrayType *handle_substitions (SubstitutionArgumentMappings mappings); + ArrayType *handle_substitions (SubstitutionArgumentMappings &mappings); private: TyVar element_type; @@ -1070,7 +1070,7 @@ public: return get_element_type ()->is_concrete (); } - SliceType *handle_substitions (SubstitutionArgumentMappings mappings); + SliceType *handle_substitions (SubstitutionArgumentMappings &mappings); private: TyVar element_type; @@ -1321,7 +1321,7 @@ public: bool is_concrete () const override final; - ReferenceType *handle_substitions (SubstitutionArgumentMappings mappings); + ReferenceType *handle_substitions (SubstitutionArgumentMappings &mappings); Mutability mutability () const; @@ -1364,7 +1364,7 @@ public: bool is_concrete () const override final; - PointerType *handle_substitions (SubstitutionArgumentMappings mappings); + PointerType *handle_substitions (SubstitutionArgumentMappings &mappings); Mutability mutability () const; bool is_mutable () const; @@ -1500,7 +1500,7 @@ public: bool is_concrete () const override final; ProjectionType * - handle_substitions (SubstitutionArgumentMappings mappings) override final; + handle_substitions (SubstitutionArgumentMappings &mappings) override final; private: BaseType *base;