From patchwork Thu Aug 1 14:57:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=b3AUULkJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZXnF2YBtz1ydq for ; Fri, 2 Aug 2024 01:24:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D9AA3865487 for ; Thu, 1 Aug 2024 15:24:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 7145F3861009 for ; Thu, 1 Aug 2024 15:00:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7145F3861009 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7145F3861009 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524460; cv=none; b=X7PREz4wKnsUyk0lO0Sd/IP7D8pCGlg38ra8eY1p611HcrN/XiacJwGQi76Amfw0yJAF2KMiROdOlJlpBlBcoCKTYPyII7ZZY2eU4lhYRzKZBoD2pGWeR/2Espoyq3943pIYeQ/1NCEdE/gO8KU9QMDa8XTzIfF6BznladGAqcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524460; c=relaxed/simple; bh=eVQeOjoeLDJtH6ApK7FZP5CmoldaAq7lT83Vb/OkVqw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jE+eJdTTt2kMTiWLA0wJYyOwob5MRnhJeVWYU5o5eAODBy5wAKTrDEKrbLOiGYrqyYvEjJ1jjA/RkihwH1bf+rVNmQ87ObhRFXTiyYaNDpw39vmdbzL6b0KA/4TEJQT5m/M3lXdbG1vdsY1WIjv1SUp8yIEK5WwMsl623giv5bc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5a1c49632deso9487145a12.2 for ; Thu, 01 Aug 2024 08:00:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524410; x=1723129210; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6r7jaZTDFdibhZurnnM0NTr42tU2MiI9tCOM3f1Hkmg=; b=b3AUULkJSNYaWYmh+mUnFRVI+GkqSYYn9MYzsS8Yh9I6D6DMPOO41R3RbAIOCnInAo ovkUsDEEj3NCGOGgEVl24osOj7cV/R50Ic2KoDhkuJBuSrAUuWExa2qVaGSZXQjyqY5P tGIwgaB3DhXQThtYIOyAni3c9AKyVUSllwDeMB08Nm9kwjwcpHK/1dUAyvthyhF+5fO/ 3LYxfjvXQHzf5rfWCzDtoWq4BS4PwDhs2fDzt5Oic79hShb5mGRsZobX8qh5xiF+vwNo 1aP4KQ4sfNjxgqNHaQXUwkQPT2qdGROalAPS34SQirXOumyE3C0pzbIVzs2udHJ5+LjM r/xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524410; x=1723129210; h=content-transfer-encoding:mime-version: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=6r7jaZTDFdibhZurnnM0NTr42tU2MiI9tCOM3f1Hkmg=; b=bma/bcl8lTM3kTcQp23PmyZPXGa3s/z5gQ3ty6J/+LeIdDm8wiR/DORL1EEe2UD/85 ZhpABygnljMugD+WxZdgSYqf/Gk2+PZvUATBMnBzYa9i/8R0tu6N5nvUkDAs03eM6iJ4 nudwm5cIJ10dg4Ba0rA+C4teyOPGUR9ujssvJh1Qh44c/If43MOuk+HlPv/DpH1Pg/rB sUVa+wBtXOOrX6+H+LG5kli1XLAkFz4EizwFfxKvhMQAKbAVQ2CvGl8Ym7Z5WPr8wIsM meob9PxySmHszyXX3yhYLzI6Ho/sdjW8vfp5/l0oxuo1GrRjIgmWwsM0taAwqRcsfHXd 7FYA== X-Gm-Message-State: AOJu0Ywit7iqcAg6GM47qDDzlhtn3frQ85qYZdD/EhBSEm7zSCB+mh5W wsNkVPiXb29t2uzNwoQD3Ej5UeGR5ANk7GATQ07oY57NXYq+VRmCWdu+R9Y1hLTpM3muMYET8dK QdcEd X-Google-Smtp-Source: AGHT+IGmNeINuGE4mfgsfGh1V/mrk1ftQEH1YXLhwWkHOaKaj/YXsodCKY9BGWDHwAoAYXz4RAsLWg== X-Received: by 2002:a05:6402:60f:b0:5a3:a9f8:cf20 with SMTP id 4fb4d7f45d1cf-5b7f58eb70dmr366407a12.34.1722524409877; Thu, 01 Aug 2024 08:00:09 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.08.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 08:00:09 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [PATCH 095/125] gccrs: Prevent getting immutable context with classic nr Date: Thu, 1 Aug 2024 16:57:31 +0200 Message-ID: <20240801145809.366388-97-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Pierre-Emmanuel Patry Immutable name resolution context is not initialized when the classic name resolution is in use. It can therefore not be used, the getter would error out. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Only get immutable name resolution context when name resolution 2.0 is used. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/typecheck/rust-hir-type-check-path.cc | 14 ++++++++------ gcc/rust/typecheck/rust-hir-type-check-type.cc | 17 +++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index b0e52c454e9..dd6ab03a362 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -199,16 +199,18 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, bool is_root = *offset == 0; NodeId ast_node_id = seg.get_mappings ().get_nodeid (); - auto nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); - // then lookup the reference_node_id NodeId ref_node_id = UNKNOWN_NODEID; if (flag_name_resolution_2_0) - // assign the ref_node_id if we've found something - nr_ctx.lookup (expr.get_mappings ().get_nodeid ()) - .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; }); + { + auto nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + // assign the ref_node_id if we've found something + nr_ctx.lookup (expr.get_mappings ().get_nodeid ()) + .map ([&ref_node_id] (NodeId resolved) { ref_node_id = resolved; }); + } else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) resolver->lookup_resolved_type (ast_node_id, &ref_node_id); diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 588e5bce88e..44ebc159b23 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -341,19 +341,20 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, bool is_root = *offset == 0; NodeId ast_node_id = seg->get_mappings ().get_nodeid (); - auto nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); - // then lookup the reference_node_id NodeId ref_node_id = UNKNOWN_NODEID; // FIXME: HACK: ARTHUR: Remove this if (flag_name_resolution_2_0) - // assign the ref_node_id if we've found something - nr_ctx.lookup (path.get_mappings ().get_nodeid ()) - .map ([&ref_node_id, &path] (NodeId resolved) { - ref_node_id = resolved; - }); + { + auto nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + // assign the ref_node_id if we've found something + nr_ctx.lookup (path.get_mappings ().get_nodeid ()) + .map ([&ref_node_id, &path] (NodeId resolved) { + ref_node_id = resolved; + }); + } else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) resolver->lookup_resolved_type (ast_node_id, &ref_node_id);