From patchwork Tue Jan 31 13:25:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 50863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2751145wrn; Tue, 31 Jan 2023 05:31:41 -0800 (PST) X-Google-Smtp-Source: AK7set/TmqkLtw2f0ULEliEKFcmiYkvlXNiyMjmkeYFHsOmXXbwbu32t+P4UY7r6Fd1Hu13z8KMA X-Received: by 2002:a17:906:1845:b0:805:1e6e:6777 with SMTP id w5-20020a170906184500b008051e6e6777mr3257078eje.23.1675171900894; Tue, 31 Jan 2023 05:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675171900; cv=none; d=google.com; s=arc-20160816; b=AZCp4uFaHCh1NYSSMZKium/vqJ+zdP1Vr0ynAHacO42vQwTO7rJ73isaKPwrfgZpnH jhyH9hiUjifFkZm/oxWOBM0VsJWKbfscsWX2ja5h5nZnH4hCamUyeqFSj5sbxMe6RpKS UtXaRRJZ0KW01X6TkgDjtavf28qmC6nXkCgwQemkl9K1epjMy8Ng/7bcEoS+65PApSxM /1umfuykFIXlYYeKWNI2or54NvE+gZX96T2cunICVqOCK3bIKSBwWpZduu987lgpFUU5 PIuBzHyT14IY3TPFd70hfUOtfXjOzQdcwmwlJ5SHXFCevmQFeDUvL6htkfUc4AW9x+RH /9SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=3hdyFkb1viTE0ucqGlrLZyp1iv0iI76gxF/FUIEptb8=; b=hCoAsoQZF1Jg2hWnvRzcbucZfXHGzJs9juCszYe5SsuYawHcoO3MluZ1ix3p1K1xhw OrLLOIBTs3ThybHHuPhiMZD4UqJFGEPFCIuPau4TXAdkeLbXSnB+CkscqalpMPK+TF9J QJQ2nKdTKBeMba5cIzSPf5dgxjICHsABUZKPpRPbX7JF7VRuWCnYwMx3GB9lMQhVI6F5 giZn7dfDw3s6cjkj7jmVISo916+KdPJINhPoOPZk0dwLQ2g0ba4r2BnhSGxR4sG7Eqcd ucNdoceu2+odq+zVenKP1SqidGmgzH2zWTNuZpcHJdoEfnuOyApRWsiEf5jrfwIBdVYG 85EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=gvboOVYI; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 20-20020a17090600d400b0087039b036ffsi19821988eji.487.2023.01.31.05.31.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:31:40 -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=gvboOVYI; 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 7EAC63853332 for ; Tue, 31 Jan 2023 13:24:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id D220739502ED for ; Tue, 31 Jan 2023 13:22:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D220739502ED 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-x333.google.com with SMTP id c10-20020a05600c0a4a00b003db0636ff84so10603164wmq.0 for ; Tue, 31 Jan 2023 05:22:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=3hdyFkb1viTE0ucqGlrLZyp1iv0iI76gxF/FUIEptb8=; b=gvboOVYIcx/Jy2NzP8Zk02+mZvuviDCuvonMWb0pP4J2fd1geZgmfaOgDLdWgMVVpE 4eTdivM0LyO+uYhf2ZtLhy+X63vm0ljhPoldoI7yAeCbJNT9Aj3DnCN/IeS/REFslSKj VASg1bv1VfgnpXgwDkK9J7yMuzhY2RToKKOSjZMXm8hY7SkzM0jABx99kb0orNzeeG4U OcJjxmxIP/VvRf+rlYtLtv4I6XlcZ28/Fz815kPCdFl8fEh/50s335VvonPxSpCSf89m KDrbUNAQp5RBAOCQa58ACSc0CK4BRXmopmQa44/mtx1/56qbQ73U6tJ67Zm726LOKq2X /XIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3hdyFkb1viTE0ucqGlrLZyp1iv0iI76gxF/FUIEptb8=; b=Jackgouz6ktJM3EzGV1qpMzHwjnPByEkLFHc8NJj2OuFi9bJ+s27vqHQigW+VWqic9 4X5wO6lzS+JN+9fBx3x3k5NHyLpA6kqb/NtvUyoovp87vLyhicoEhF9i7kEqrDKnWizs KOLhZbn6TBCaCUnBBFrQPO6bd7XoYwsHzC6Db9TCM5F0n6BEO5feODASMk4v8vfY/gWT +q3Oa/W5Z1PeF7IKcbW6rZZ9BFFJFKrtwjfcxCK098ud/FyyUMhvY8qENFr5nJm2AGOc e4VrC1q4iUdsPdg17Hra97hpxCHPV1Hf5xRkTHcIEbTHtL/yVMJ0gDdEE7hZpTvf5lb4 EmXg== X-Gm-Message-State: AO0yUKUfvBxCtbOWCXGOOCrpW+tDCrExIMR7KiTIgKhRHtBF8HTRMYFZ jAC6dbmCB9AzIPVeaJGzE5fOPybWIa3zaaLzSw== X-Received: by 2002:a05:600c:5104:b0:3dc:445f:642 with SMTP id o4-20020a05600c510400b003dc445f0642mr3641593wms.37.1675171321441; Tue, 31 Jan 2023 05:22:01 -0800 (PST) Received: from platypus.lan ([2001:861:5e4c:3bb0:6424:328a:1734:3249]) by smtp.gmail.com with ESMTPSA id i1-20020a05600c354100b003dc4050c97bsm2364609wmq.3.2023.01.31.05.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Jan 2023 05:22:01 -0800 (PST) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [COMMITTED] gccrs: Add new check for contains_associated_types Date: Tue, 31 Jan 2023 14:25:46 +0100 Message-Id: <20230131132546.662447-1-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-14.6 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: , 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?1756545051092628995?= X-GMAIL-MSGID: =?utf-8?q?1756545051092628995?= From: Philip Herron We don't need to setup associated types when a trait does not contain any associated types. gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::contains_associated_types): Check if a type bound predicate contains assocated types. * typecheck/rust-tyty.h: Declare the above mentioned function. * typecheck/rust-hir-trait-resolve.cc: Use `contains_associated_types` function. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 3 +++ gcc/rust/typecheck/rust-tyty-bounds.cc | 15 +++++++++++++++ gcc/rust/typecheck/rust-tyty.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index c14a6c3a9be..22398b1fa8a 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -368,6 +368,9 @@ void AssociatedImplTrait::setup_associated_types ( const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound) { + if (!bound.contains_associated_types ()) + return; + // compute the constrained impl block generic arguments based on self and the // higher ranked trait bound TyTy::BaseType *receiver = self->clone (); diff --git a/gcc/rust/typecheck/rust-tyty-bounds.cc b/gcc/rust/typecheck/rust-tyty-bounds.cc index 8dfd692f345..69376aaa373 100644 --- a/gcc/rust/typecheck/rust-tyty-bounds.cc +++ b/gcc/rust/typecheck/rust-tyty-bounds.cc @@ -374,6 +374,21 @@ TypeBoundPredicate::requires_generic_args () const return substitutions.size () > 1; } +bool +TypeBoundPredicate::contains_associated_types () const +{ + auto trait_ref = get (); + for (const auto &trait_item : trait_ref->get_trait_items ()) + { + bool is_associated_type + = trait_item.get_trait_item_type () + == Resolver::TraitItemReference::TraitItemType::TYPE; + if (is_associated_type) + return true; + } + return false; +} + // trait item reference const Resolver::TraitItemReference * diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 14868f2bb81..24efc7aa54c 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1057,6 +1057,8 @@ public: bool requires_generic_args () const; + bool contains_associated_types () const; + private: DefId reference; Location locus;