From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 8BF9F38A90A2 for ; Tue, 31 Jan 2023 13:22:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BF9F38A90A2 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-x336.google.com with SMTP id n28-20020a05600c3b9c00b003ddca7a2bcbso585340wms.3 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=0BrTYkgifDCirn2+63CHpGKPJmaLSiRFLqIu8IWpGrSdOY2DcNXO3Cus+iXfZdRUNk p6wh79idoe93ZqAc5U+XMR6MK2eCK9/qh+l+vQujK52eNii6KvxqlCUDCtx1+eBU+Xsd VodeqPVvw0G0xbH86uuS8KThuJ7sl+oxKgl6mJhbSYa4vydDKMc6XNd1X+CcwkBvOzpC UwN7hKtLFjdlYc7nlUH0Fx35CEph0ExpT5APyUgqTABNcxeJyAo4ovlZzykEiCZkpDCx loisJBoqj9i5FP5Feb2xLXjf1HIQ7Qtfeny0a19+0QyPbiDczBW1JuVhbfDt9vgyXJGk g8bQ== X-Gm-Message-State: AO0yUKVYdhuuF09QmEVbcwWHstnQAaxOD2lI8iY8reR3UH+8JZxr4hQ2 UMAXQ5bQFeHlhGTzteSGLRWx/PuxaX/g6TNSFA== X-Google-Smtp-Source: AK7set9/X5K6EDf8DCBoKoAoUVv1JIU7ROuiCrlycVZVLJRzqvJhiXRrTwmtF8HrBsr23SV4Y6eXTA== 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-15.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=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 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; -- 2.39.1