From patchwork Tue Feb 21 12:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 60079 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1850140wrn; Tue, 21 Feb 2023 05:05:14 -0800 (PST) X-Google-Smtp-Source: AK7set9LfKzlZKDxidEIEtoPYtQpc9UI8Oz7Xf2i6Mt+CpfRAOi1YVKcn/jCAU5+8pGJb+3IRzNY X-Received: by 2002:a17:907:a42a:b0:8b1:730b:a296 with SMTP id sg42-20020a170907a42a00b008b1730ba296mr21611074ejc.15.1676984714688; Tue, 21 Feb 2023 05:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676984714; cv=none; d=google.com; s=arc-20160816; b=bMkoHKRi04Khu9tNLjUiWnuElCBcVCVbL8dvql7YdZaqhFMwkZJZnXnglY7EYhEIDb FBluByasahhGuyA7KNhpO7g6V0UyzjXo8DEux+Wwku+3LVzyfK9QRGWKx0SAuBCjlf1k /GZBQVxThQP7MaRIB5G3aBmgi0MgCNOInVtPajmv2tzntIzUz/62md40sFsjN4KMs3U6 YNeZPwwOugzaN/IOHE4q4S/D7m+LnBzq4TLcPxxtEcyBfI6mTeW2PTUMRR7pvtATrHmV s0/3v6HcGOweNwcR9T+o/caHegjy/wUMNrL81PFOLB+PrzFpVpTGpiLAanw6b3nOGHC9 gSAA== 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=DgbXq+dw7HduszADPLrrkky7+8q8tWS0noGuvtJu09I=; b=Z63CATceZDwMQI26PVjxYk0WrKJy47gGwMVgaxLLQZxUpnscLPrjYaUvzw2NQ+6d+F zjBCZxEqOw8Lch0kg6oHS+dxrYglM4OamBD51d2CSarQNFFDKNuk1WKWbLo9x6ZzsF4+ MbuqlaDioVbSc0zLQgjIjZjKwOB+ThlFp56EwNTqA46e+WA3NNUlYCrVCdxPgtEP+R1S PtigiXDL/swlxCb0zL3NdNwJRbxiPJMOhl9PeKDjSZ7usssOJMNuwVWc6FuLMJ2XThmH AgGugimy/0GGBV4j3Esm/Rlbg0+hvTrRcfulnqkzG206Cns2FhAv2txgdguZnLtJez/J VAAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JBzvBzUJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qn20-20020a170907871400b008c0f56c2b50si10067209ejc.421.2023.02.21.05.05.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 05:05:14 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JBzvBzUJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B7950381BB82 for ; Tue, 21 Feb 2023 12:24:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 2C45F3888C55 for ; Tue, 21 Feb 2023 12:04:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C45F3888C55 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-x430.google.com with SMTP id r7so3993912wrz.6 for ; Tue, 21 Feb 2023 04:04:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; 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=DgbXq+dw7HduszADPLrrkky7+8q8tWS0noGuvtJu09I=; b=JBzvBzUJL7V7p2winSgkFNLluFypgceGh/paFPATjtv2Dfk48HiNQUipgVJ6Tl8gTH d5RoZsMK2iO4t9mFx2+BcJjVWrOeN9OwmPrqWQynhOKmZz62h9GfChYMxJb/6NQAQ+uQ zLv5/RL1HIu6kqrqpSzwtiVhSvUWZrDNYRPHVZbzKax4P0OWYTIYnbrLrr/v9UyLueyh whH6TNPMd9VQBW+Uy57gMExo6szxcTZ8VL/Zybt6wP8+CqyoCSPfUWs+rJZ4y+l/Ewdv Nq77R6pOqerH+jRga9yh+PDiBjlrD/VpJtPsWiSxySiyUnUHLKzt6GBIhLcPqqpBd5/s XLbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=DgbXq+dw7HduszADPLrrkky7+8q8tWS0noGuvtJu09I=; b=H0Lwryc53DzeTRiyJl/UckOkEPUvqGpYFQYAMlhQx+PxBzXk8BqBTkn+KAzFOQbv3L phA5asagPecvbk22pAnxg+VFEKZc1RbAtPZTrXuGvL39Fh84oJ8PR9Ud3iTfV5ZqGhD8 IzgLbS4+1BiXxwEip9mo6Nd5nIJP/XTToMN+Tid2QQ4t41unBlklLHNq83taqrhqjxfQ rMwJrLbx04lTu7pYghWroFGR104KYxmWHNlC3DZxoTu4RXv63i8w7EHxMuCuOD8J9qXT ERUiEeqssz1rdUWFhhpFVTGCF0AEg+6Q/fUG+LUwf/ZFyTPw7yfX3BMjeyfkXNBODseu tSkw== X-Gm-Message-State: AO0yUKWlWSZW9nI3no1HxnS8QtVCrl9O8OjGYCGgvFAExac6y71Hw238 ZIbdS9NC+3CZfXEwo/TW5I650356rK3zencxGA== X-Received: by 2002:adf:ef47:0:b0:2c5:9ed8:7c74 with SMTP id c7-20020adfef47000000b002c59ed87c74mr3685318wrp.19.1676981079537; Tue, 21 Feb 2023 04:04:39 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.04.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:04:39 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 096/103] gccrs: Add capture tracking to the type info for closures Date: Tue, 21 Feb 2023 13:02:26 +0100 Message-Id: <20230221120230.596966-97-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.7 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?1758445924157455177?= X-GMAIL-MSGID: =?utf-8?q?1758445924157455177?= From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Pass captures properly to `TyTy::ClosureType` constructor. * typecheck/rust-tyty.cc (ClosureType::as_string): Fix string representation. (ClosureType::clone): Pass `captures` argument. * typecheck/rust-tyty.h: Add `captures` field. --- gcc/rust/typecheck/rust-hir-type-check-expr.cc | 4 +++- gcc/rust/typecheck/rust-tyty.cc | 5 ++--- gcc/rust/typecheck/rust-tyty.h | 11 +++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 85590630378..0b0db3296a0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1492,8 +1492,10 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr) expr.get_locus ()); // generate the closure type + NodeId closure_node_id = expr.get_mappings ().get_nodeid (); + const std::set &captures = resolver->get_captures (closure_node_id); infered = new TyTy::ClosureType (ref, id, ident, closure_args, result_type, - subst_refs); + subst_refs, captures); // FIXME // all closures automatically inherit the appropriate fn trait. Lets just diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index bdb2d909b86..71f0de1bbab 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -1675,8 +1675,7 @@ std::string ClosureType::as_string () const { std::string params_buf = parameters->as_string (); - return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () - + "} {" + raw_bounds_as_string () + "}"; + return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () + "}"; } BaseType * @@ -1714,7 +1713,7 @@ ClosureType::clone () const { return new ClosureType (get_ref (), get_ty_ref (), ident, id, (TyTy::TupleType *) parameters->clone (), result_type, - clone_substs (), get_combined_refs (), + clone_substs (), captures, get_combined_refs (), specified_bounds); } diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 5eaec352567..b9a1fdfa5c7 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1628,13 +1628,15 @@ public: ClosureType (HirId ref, DefId id, RustIdent ident, TyTy::TupleType *parameters, TyVar result_type, std::vector subst_refs, + std::set captures, std::set refs = std::set (), std::vector specified_bounds = std::vector ()) : BaseType (ref, ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - parameters (parameters), result_type (std::move (result_type)), id (id) + parameters (parameters), result_type (std::move (result_type)), id (id), + captures (captures) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); @@ -1644,13 +1646,15 @@ public: ClosureType (HirId ref, HirId ty_ref, RustIdent ident, DefId id, TyTy::TupleType *parameters, TyVar result_type, std::vector subst_refs, + std::set captures, std::set refs = std::set (), std::vector specified_bounds = std::vector ()) : BaseType (ref, ty_ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), - parameters (parameters), result_type (std::move (result_type)), id (id) + parameters (parameters), result_type (std::move (result_type)), id (id), + captures (captures) { LocalDefId local_def_id = id.localDefId; rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); @@ -1699,10 +1703,13 @@ public: void setup_fn_once_output () const; + const std::set &get_captures () const { return captures; } + private: TyTy::TupleType *parameters; TyVar result_type; DefId id; + std::set captures; }; class ArrayType : public BaseType