From patchwork Tue Feb 21 12:01:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59973 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1827853wrn; Tue, 21 Feb 2023 04:15:00 -0800 (PST) X-Google-Smtp-Source: AK7set+Xpp6smsu+oVZLsGE3fQvn9B51obUMO20xuS75x0s8tFr/SDV/ItMqffxsTgrQiyBHRXzS X-Received: by 2002:a17:906:1d45:b0:884:930:b014 with SMTP id o5-20020a1709061d4500b008840930b014mr9925110ejh.6.1676981700607; Tue, 21 Feb 2023 04:15:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981700; cv=none; d=google.com; s=arc-20160816; b=igu6/2uLLr7418B1gl644kjPn7uMa6bFI5PZynadfHJ3IVCE+2TMbMF0/XRhfTyrl5 8SHSTpGWbtdGC6s/cMiHke2+9dgZleEKgBWhVb4RcVrDTFUck4eoPr41S/84W6LXOkW8 0g1bOPtJtqWKtAKBGlv5cKNxQ2osoZPojyrciaixsBM9ijxuTHG727F+HxkDNS+RYKur qMlDK9f0rxgBHC+5T3oi9cKU19KgLGx2d0oX8+MP6Kvj8jpIURUAxcHR4y/mhNcF5fYN cpHkwbOMJTN6paEJuGTcZkZ5lVF4KkOBianOpXs7yMWs4mn9IdN7/EoEXr0up1iEOj6W D2IA== 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=ZwW22c3vcHXu7MbxASXuWQFb4wPjX3d85Vq6Q7E0s0Y=; b=TEvXULZDqT8DhuZRKZ7MkH0rBfUPu9ClOBHAn88l3sIhUEp2fALaChNoMDCmlh4kxm 35pDAvaIIh22mM6DH26b5yfv9lAeZfM2FAwFFccaLWJ8FkHakuD73c8LUoSQOWy2tDZA nc+1lMgnUKRgMKmzx9cEjeCCHbkFCz6/31moqZ+DB7i0L8BTj+9qIonUzejjCjsGpGWm Jd1+cT1TKxd29CK1auF5cx8lhzSqdxWCFrM2gVNFW6cGUkSBZUqFsgZdQIBX12SRK9V1 S4UhYay+0JihfogpLXMJvllMJiyIcFC91EdMthT0dC1FWt8CdfjYVGS2kkzDbHpwQW02 Nv4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Bn2QQhkj; 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 16-20020a170906015000b008bc21b16e15si14898042ejh.993.2023.02.21.04.15.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:15:00 -0800 (PST) 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=Bn2QQhkj; 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 1A9BF395B46C for ; Tue, 21 Feb 2023 12:07:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id E5E91384476D for ; Tue, 21 Feb 2023 12:03:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5E91384476D 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-wm1-x332.google.com with SMTP id p3-20020a05600c358300b003e206711347so2928165wmq.0 for ; Tue, 21 Feb 2023 04:03:42 -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=ZwW22c3vcHXu7MbxASXuWQFb4wPjX3d85Vq6Q7E0s0Y=; b=Bn2QQhkjgNFbB9qDfD8HQYl11INgh+oiV3oQ/2itCGY9QvRw2jRzHHdj8rHvGYcwd2 5ZAPzkpe9tli8P+g96F/0gNWHQGkALU3NAnHDkE4xS8+sOWu4bNq5cMqN1P6/2GPOrsj eN+J8P2xfHtvsLtO9qzyrFFeocJiwaznbbK2BDRUiWOBoAO+JECu1/TaTGprfq4KW1m8 BB+rPtpKuC65efpQ58iTbjU+TYt/GYQocXoWFleqVdKpp5XsBVh7nOPbnRFozwuSHQy8 Ingkbz7MdPogd/tocYwymV4vQAawh1VfnENN8jTTVLDlATlJ+kwysH2oAQU2OXX4OEFN o2Qg== 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=ZwW22c3vcHXu7MbxASXuWQFb4wPjX3d85Vq6Q7E0s0Y=; b=HbtcgaLtN2Brde7h+RBTXJxiSxtCxcSm9xBmEj/mDsgs6A4kPh2cY3kw1o9w+EYswy mOsk+DShx5YX2ac6cPJ8S2xl9URxEwImwZTUv+lQsIsB477+q/NzqgwoMEuMadXyWVCA 1PuACKAgzHJqGXQKsR02TUUAaEO3BMahGWFqIvpLjA7WPlqJaqAOh7cWDdTCIj/RyYa/ 84rs+TaGF424gPEXtFenrOoDUBnUGKYCyEBe+cukRiagk4UMsTO53qhsfybJLK17Wwo3 Z6Co1tvo8qgUXd2Ie8WBT+HgI1TLPMYfsrjzlENnAqTIuxfTSCFC3ZjlL3mkRx0e6z8U tIRw== X-Gm-Message-State: AO0yUKUHHk7t7Oc3iVIJQ0kLxGbWWhQ0+NHGCHQ2FldalMpsN3KmilEC foPqjYRs9CGwZu9wXhQObJAGKhIN1l2maZ9ECw== X-Received: by 2002:a05:600c:3084:b0:3dd:97d6:8f2e with SMTP id g4-20020a05600c308400b003dd97d68f2emr3295229wmn.17.1676981021266; Tue, 21 Feb 2023 04:03:41 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:40 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 021/103] gccrs: Support type resolution on super traits on dyn objects Date: Tue, 21 Feb 2023 13:01:11 +0100 Message-Id: <20230221120230.596966-22-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.9 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.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?1758442763483055819?= X-GMAIL-MSGID: =?utf-8?q?1758442763483055819?= From: Philip Herron When checking if specified bounds satisfy other bounds we must lookup the super traits. To finish the support for super traits we need to redo the computation of method addresses to support super traits. Addresses #914 gcc/rust/ChangeLog: * backend/rust-compile.cc: Add note about missing support for super traits. * typecheck/rust-tyty.cc (BaseType::satisfies_bound): New function. (BaseType::bounds_compatible): New function. (DynamicObjectType::get_object_items): New function. * typecheck/rust-hir-trait-ref.h: Use new API to perform type resolution on dyn objects. --- gcc/rust/backend/rust-compile.cc | 2 ++ gcc/rust/typecheck/rust-hir-trait-ref.h | 24 +++++++++++++++++ gcc/rust/typecheck/rust-tyty.cc | 35 ++++++++----------------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 13f42438b56..db08b3d595b 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -247,6 +247,8 @@ HIRCompileBase::compute_address_for_trait_item ( // Algo: // check if there is an impl-item for this trait-item-ref first // else assert that the trait-item-ref has an implementation + // + // FIXME this does not support super traits TyTy::TypeBoundPredicateItem predicate_item = predicate->lookup_associated_item (ref->get_identifier ()); diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-ref.h index 7eeb3300387..0df35265959 100644 --- a/gcc/rust/typecheck/rust-hir-trait-ref.h +++ b/gcc/rust/typecheck/rust-hir-trait-ref.h @@ -380,6 +380,16 @@ public: return item_refs; } + void get_trait_items_and_supers ( + std::vector &result) const + { + for (const auto &item : item_refs) + result.push_back (&item); + + for (const auto &super_trait : super_traits) + super_trait->get_trait_items_and_supers (result); + } + void on_resolved () { for (auto &item : item_refs) @@ -451,6 +461,20 @@ public: return trait_substs; } + bool satisfies_bound (const TraitReference &reference) const + { + if (is_equal (reference)) + return true; + + for (const auto &super_trait : super_traits) + { + if (super_trait->satisfies_bound (reference)) + return true; + } + + return false; + } + private: const HIR::Trait *hir_trait_ref; std::vector item_refs; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 64fe0f6cfb0..e2f79971337 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -136,22 +136,18 @@ bool BaseType::satisfies_bound (const TypeBoundPredicate &predicate) const { const Resolver::TraitReference *query = predicate.get (); - for (auto &bound : specified_bounds) + for (const auto &bound : specified_bounds) { const Resolver::TraitReference *item = bound.get (); - bool found = item->get_mappings ().get_defid () - == query->get_mappings ().get_defid (); - if (found) + if (item->satisfies_bound (*query)) return true; } auto probed = Resolver::TypeBoundsProbe::Probe (this); - for (auto &b : probed) + for (const auto &b : probed) { const Resolver::TraitReference *bound = b.first; - bool found = bound->get_mappings ().get_defid () - == query->get_mappings ().get_defid (); - if (found) + if (bound->satisfies_bound (*query)) return true; } @@ -191,7 +187,6 @@ BaseType::bounds_compatible (const BaseType &other, Location locus, rust_error_at (r, "bounds not satisfied for %s %<%s%> is not satisfied", other.get_name ().c_str (), missing_preds.c_str ()); - // rust_assert (!emit_error); } } @@ -2956,23 +2951,15 @@ DynamicObjectType::get_object_items () const for (auto &bound : get_specified_bounds ()) { const Resolver::TraitReference *trait = bound.get (); - for (auto &item : trait->get_trait_items ()) - { - if (item.get_trait_item_type () - == Resolver::TraitItemReference::TraitItemType::FN - && item.is_object_safe ()) - items.push_back ({&item, &bound}); - } + std::vector trait_items; + trait->get_trait_items_and_supers (trait_items); - for (auto &super_trait : trait->get_super_traits ()) + for (auto &item : trait_items) { - for (auto &item : super_trait->get_trait_items ()) - { - if (item.get_trait_item_type () - == Resolver::TraitItemReference::TraitItemType::FN - && item.is_object_safe ()) - items.push_back ({&item, &bound}); - } + if (item->get_trait_item_type () + == Resolver::TraitItemReference::TraitItemType::FN + && item->is_object_safe ()) + items.push_back ({item, &bound}); } } return items;