From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 3D7FA3898513; Mon, 5 Dec 2022 09:53:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D7FA3898513 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670233992; bh=TJuK58fK0KG2h+ZzToSft1PzV5PltffPcTjGFvAJCfw=; h=From:To:Subject:Date:From; b=J1ifWgdyQ5I1A+oB7PlLoE7xGwKM/0Xq56H9tWYZ57HL/2Y5IWhu2k3NGyHY9oHvj hbTu7sph0AtpPMwet1cCH4wgLLzyzonAgYw0kVNY9bz4DCBYtPUKKtNUr/OqErsQPE SYLyBk5xxaJ3DJL13GBcLHL+R7phaTib/nbkurKk= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Add capture tracking to the type info for closures X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: b5c354de73ddccb7738778c1e013d42b96aeb048 X-Git-Newrev: 3573ec082f12440a42fa1bf6fdafc578d280870c Message-Id: <20221205095312.3D7FA3898513@sourceware.org> Date: Mon, 5 Dec 2022 09:53:12 +0000 (GMT) List-Id: https://gcc.gnu.org/g:3573ec082f12440a42fa1bf6fdafc578d280870c commit 3573ec082f12440a42fa1bf6fdafc578d280870c Author: Philip Herron Date: Fri Oct 21 15:39:52 2022 +0100 Add capture tracking to the type info for closures Diff: --- 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 8911a1d99f7..7ea1bd900ba 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 e56bdd17b87..86f40af0fbe 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 9a9f0aa915e..8b39e5138fb 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