Message ID | 20230221120230.596966-40-arthur.cohen@embecosm.com |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1837515wrn; Tue, 21 Feb 2023 04:38:27 -0800 (PST) X-Google-Smtp-Source: AK7set/0JHNCzxM8F5HPFHp5xrzf5e2iJhIrCyXjVFYYAay1otsVxjxWoPNLz3OYbvNjG1+9FfK9 X-Received: by 2002:a05:6402:355:b0:4ae:e547:e563 with SMTP id r21-20020a056402035500b004aee547e563mr5761209edw.36.1676983107079; Tue, 21 Feb 2023 04:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676983107; cv=none; d=google.com; s=arc-20160816; b=Fa6xK5GjiUn3654N+OG93wOuAkTT5BQAQmaK21E1MXKL6xx0ElRX1rF/7dKOuJCC1s AHheLMU6ddNXhMglPNa6APOvIUsFwJlrAFwFcnxgUuMZcNqbISHX/tLwtVvm5GArzhkV FSiFdiU7V7eI2DOyFIKVJdr7nSPMufChkLSsnbl0Ov5EgUEcv08nR4yd2RZ7BOXDMbjW /aVcnjbTOFbu/JCehoUPsxIA6MEHUpDkw4krZuS6OvIlzndDRqt7ib8u3CTtyADmg4KG tNqZ++2O8nCexhYvq1qQUhxa/36OtL/HObIUWtmMTmJfzR09wsBR2mbnaE4424GsOoCq 9NRw== 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=88inREnYvEbMuVb0RenaQ3Q8ZlW4nBvnKzDWMJtXKHs=; b=AzAn9fIj7xO24WK7Z6TYVHEv9SBqixm1xAu0E4gaWgavG0HNabjNtN4ZVIdPPewDxl ZVaLdtr++3ouXgwqv2jM2QO1ASubf65P9XFwW2Bd2OyHaLR0BPR+xYsMmDJIKCZpCsrv WYJ2E6O05iCZIWRtzv0rqx1Un/uhrgLBJY/XOfPw5zd245j0GbftX8bm9+cd1nOiYH7o fzHs00soEu8cuYeCzHPSo/fWxppLuPJpgiaACmvdAGtZgIQ/EpgCp8pLPmMsh4s4ayt/ iZRJFY1Dw9wCgIe82ItQNQdAeMNsVp1y50Mp4XVElhumH3D7923JYn3owZ780Azo28ir K2Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b="N4jPaJ/a"; 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 f13-20020aa7d84d000000b004acc81d5053si19615154eds.616.2023.02.21.04.38.26 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:38:27 -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="N4jPaJ/a"; 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 4ADD938323D3 for <ouuuleilei@gmail.com>; Tue, 21 Feb 2023 12:13:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 438C6385B50C for <gcc-patches@gcc.gnu.org>; Tue, 21 Feb 2023 12:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 438C6385B50C 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-x430.google.com with SMTP id r7so3991373wrz.6 for <gcc-patches@gcc.gnu.org>; Tue, 21 Feb 2023 04:03:55 -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=88inREnYvEbMuVb0RenaQ3Q8ZlW4nBvnKzDWMJtXKHs=; b=N4jPaJ/aD4/FPoA+w0JLttZnE7Mc1iKw//BO9nAui48UlRaudm/ifGrXO44vd1YTF8 vtC4NSYYWHT4dV8zky9u6sKil1zvVKAuKQPK9jpgHa5bHJfuLNq4cdLfDjJLQ/P4wpTV RX83/oMDBgq6wpVAhmScUsi7BidsD17DZ7zJCZ/u3PrDsLGXGx30SNNGjQEQgZ2d0gkv 3F4VvprwzJmbNnvZULzdm/2xG9yB75cR9Fleu6LMx/L0BlH6mJc3nwLXYqAcM/E8hiqG r17wkTcbReVrfDUq15+yjD4FCyPnlyqekjs+bWPzRfM0qZN1MWYoQKLeccY+QE2umDh5 sIdQ== 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=88inREnYvEbMuVb0RenaQ3Q8ZlW4nBvnKzDWMJtXKHs=; b=ADeRBs5VMO5VpbcUVT4br6DpOxwXUvMOHk/eEmWCwJ4j4dkXCV5WCfiCEOdgZUo8F+ CamEKrgshtuk5jr+uSCCk0+OLNF0l5MflbJOS1ZANkgb7+C9c9RpyhKdIyrHy986QDeK NBBObbubgobdbaTc81DDniRiZ6Z3Yrm2AwRjxsXXPR2URAqCSxEahrqFK8RXj/Ja6ZyC uP+DHWKn8hm96b4XLWe+V+GdLbmBYybjYlZcW6JLk7VJzar1cBRZ4BRE2sE8zZ5UVXPY qgTFIjVFnVIzes7vsBIHUH7tJ+Vsk3M+svnxJlDSqmof4EuBq7NDeF1DOMWQGv2e3Njj kKHA== X-Gm-Message-State: AO0yUKXSucwN1kWuBWlcqdirD8c8h4eqFuK8mpL/xKh3CissTc+q9b8C px7I29S046n+BP6v2uBr87MFvAuUDTTJJ847WQ== X-Received: by 2002:a5d:5387:0:b0:2c5:455b:4cd2 with SMTP id d7-20020a5d5387000000b002c5455b4cd2mr5103370wrv.57.1676981033833; Tue, 21 Feb 2023 04:03:53 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:53 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron <philip.herron@embecosm.com> Subject: [committed 039/103] gccrs: Add check for recursive trait cycles Date: Tue, 21 Feb 2023 13:01:29 +0100 Message-Id: <20230221120230.596966-40-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 Content-Transfer-Encoding: 8bit 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=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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758444238011994955?= X-GMAIL-MSGID: =?utf-8?q?1758444238011994955?= |
Series |
[committed,001/103] gccrs: Fix missing dead code analysis ICE on local enum definition
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Arthur Cohen
Feb. 21, 2023, 12:01 p.m. UTC
From: Philip Herron <philip.herron@embecosm.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Check if a
trait query is currently in progress.
* typecheck/rust-hir-type-check.h (class TraitQueryGuard): Add helpers around
checking for trait queries and inserting them.
gcc/testsuite/ChangeLog:
* rust/compile/issue-1589.rs: New test.
---
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 12 +++++++-
gcc/rust/typecheck/rust-hir-type-check.h | 29 ++++++++++++++++++++
gcc/testsuite/rust/compile/issue-1589.rs | 5 ++++
3 files changed, 45 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/issue-1589.rs
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 1b0bcaac79d..2ec9b2ef83e 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -141,6 +141,14 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) return tref; } + DefId trait_id = trait_reference->get_mappings ().get_defid (); + if (context->trait_query_in_progress (trait_id)) + { + rust_error_at (trait_reference->get_locus (), "trait cycle detected"); + return &TraitReference::error_node (); + } + + TraitQueryGuard guard (trait_id); TyTy::BaseType *self = nullptr; std::vector<TyTy::SubstitutionParamMapping> substitutions; for (auto &generic_param : trait_reference->get_generic_params ()) @@ -201,8 +209,10 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference) HIR::TraitBound *b = static_cast<HIR::TraitBound *> (bound.get ()); - // FIXME this might be recursive we need a check for that auto predicate = get_predicate_from_bound (b->get_path ()); + if (predicate.is_error ()) + return &TraitReference::error_node (); + specified_bounds.push_back (predicate); super_traits.push_back (predicate.get ()); } diff --git a/gcc/rust/typecheck/rust-hir-type-check.h b/gcc/rust/typecheck/rust-hir-type-check.h index a1dd8052246..2b47c6738b5 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.h +++ b/gcc/rust/typecheck/rust-hir-type-check.h @@ -381,6 +381,19 @@ public: return querys_in_progress.find (id) != querys_in_progress.end (); } + void insert_trait_query (DefId id) { trait_queries_in_progress.insert (id); } + + void trait_query_completed (DefId id) + { + trait_queries_in_progress.erase (id); + } + + bool trait_query_in_progress (DefId id) const + { + return trait_queries_in_progress.find (id) + != trait_queries_in_progress.end (); + } + private: TypeCheckContext (); @@ -418,6 +431,7 @@ private: // query context lookups std::set<HirId> querys_in_progress; + std::set<DefId> trait_queries_in_progress; }; class TypeResolution @@ -426,6 +440,21 @@ public: static void Resolve (HIR::Crate &crate); }; +class TraitQueryGuard +{ +public: + TraitQueryGuard (DefId id) : id (id), ctx (*TypeCheckContext::get ()) + { + ctx.insert_trait_query (id); + } + + ~TraitQueryGuard () { ctx.trait_query_completed (id); } + +private: + DefId id; + TypeCheckContext &ctx; +}; + } // namespace Resolver } // namespace Rust diff --git a/gcc/testsuite/rust/compile/issue-1589.rs b/gcc/testsuite/rust/compile/issue-1589.rs new file mode 100644 index 00000000000..79a5866e4af --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1589.rs @@ -0,0 +1,5 @@ +pub trait A: B {} +// { dg-error "trait cycle detected" "" { target *-*-* } .-1 } + +pub trait B: A {} +// { dg-error "trait cycle detected" "" { target *-*-* } .-1 }