From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id E35B93888C53 for ; Tue, 21 Feb 2023 12:04:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E35B93888C53 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-x42f.google.com with SMTP id c12so4165456wrw.1 for ; Tue, 21 Feb 2023 04:04:39 -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=hx68Evlvk5HoHhjRxDBfbiO9hj51MmLCehPDgM/IGvSEk1MxsllTxcUIuDYXxF/GzW OFJ1AXK047sxmfHmCEAYwzKZDqTHPa4sw3F57iQliERYJgTtWS8LoI6iaVo1w9X+ScqY 7GmhNArvVpkNZeLL7gjmCbCprXMj1eMjNXPa+sD4TF1YCef7m/H40yOzsx9seChmwFOE mBoWOdfiApxwhSFsqpFghPF1awHaFXmzdnX4pCKhJEv09fzHR6UWNDNhogVC3OXdH7nG cbD4Rg9a/ONkF9U1FfdghW8/I29UVMszwM1tZeV+QrHH1o3fhZoNb34QvraI+f/KPMBS /ghA== X-Gm-Message-State: AO0yUKU0NqcOIVufZjisgDveCLSWa8okoQ2jzql6NPlgXzNeybRBW20e 6wT7QhkWJbWfyNw1cKAU41nj X-Google-Smtp-Source: AK7set+Gh9kdyG9Bci0lih8kaglAnLIVBOyyVMMjLqbxyDMrU04LMcNKdb8q8iAqMTY+PxQxl3SI0w== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 -- 2.39.1