From patchwork Tue Jan 30 12:07:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892907 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=JArz0/FP; 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 4TPPyv0YJ0z23fD for ; Tue, 30 Jan 2024 23:45:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 014713831E35 for ; Tue, 30 Jan 2024 12:45:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 3F8993857BB8 for ; Tue, 30 Jan 2024 12:11:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F8993857BB8 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 3F8993857BB8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616764; cv=none; b=TR3BjZ2S/HoMQRT5UprmgXF3jKJFDqApSwW8zlKsftIwwmEhSyN7i99qh9FV5nI7Se09VdDrHwK9D3/NNoQ6Bz1Xb2TLXGuxhasi6Jfeyoh/xaYT86kecv1KV8g9AdArw8rLAsCRTfWdMzBmz8beOsTJUy7Q2bcLmAd3bLQQjio= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616764; c=relaxed/simple; bh=Y+kcoDI1zOueopKbI0KEGaxoL7e1q7A4uGA7/RNpdHg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mtztmC4FwyW+GDODLP9JOgRYj66lzXww79LMLfRUvHQ8A5tIrhpwzBANudCYLIqIWwn8AVN/D2SDYscOH4ZA8exrsDoQTa3DY/y9anjb+hhmptuJcDtyBpsxykpAxfHMIrtSjfGA8I8gZg/Ry5vpYD1cmrOwc7zP37mhM/3OIKY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-33aef64f702so1047040f8f.3 for ; Tue, 30 Jan 2024 04:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616711; x=1707221511; darn=gcc.gnu.org; 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=Xed2XFYivzbzeF4tBDYVFzJJNlIXCDve9cqXc60iRa4=; b=JArz0/FPxwrS2k7Rb73fo2Q4wcKOQjPttMvmefghmvYMaM/tDRsKvDmv6kDFGjasab lv1X95E27+i37k2B/mwGq4jQR7hPWWAW01/yIhkoRS8zW2V4pIJJZisIClAGQG2gKguU sPExCgScK+FWcIsk+ZBnz+wt9EanJKcHhTHjOcUlLpXiUlRUvl9zt8AJBD8EP5puTHUi aY9KqLwyycmM4h60l2va3S697INanlY4BG41fvDBiGpVjvINQ6QaESHABCn/tqq2LvHi 2FdzkFAlLft/9fMjSFU8AAE3MZ/8QqlWTpLMKw9VCYQI3VicVv7DSSqHROhWXFnbVu6I aYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616712; x=1707221512; 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=Xed2XFYivzbzeF4tBDYVFzJJNlIXCDve9cqXc60iRa4=; b=QqxPWv3Hdy0qnT8evK9YD8MKUV13opaW7g/yrPA03EVv1wsiWOtizWE26vlz4N9AWj VW25ig5qx8LR+k8KYfggqIAltTgaWwf2tx6aABfHvJ6A0LYs/9LVFU6swD1k4szAgOTH cScdm4c4BoJVOiL+QS75CFvQ1REoOJGjh/rNl2dAedzvGjlRXuwcn4Rdnu8OtWnlyB+S he5Y+8c9hd+vS6TgNZwGM53gVIKtkmgXjvAjavHGnZ12huL/M8aZ8z0ywa9BNL1JhVgz VV9bndx0rCP8x0LY/qgHOfIwKNnABBLhuSmtDqCoMs6MBB1FA5+/wohEN1wPmyQ42BRQ 9oTg== X-Gm-Message-State: AOJu0YyL650dfNsEgzOPdPSegiO7fbxEsvB1dCrlw2fU6nx65v53Gf1Y 7SU6sMgzyzJWj5E4fjlTmYRkoug99UdYDxjJykUEwWph53yntFn+9AaaRbogSlE0A9sALOR2hkL 3XQ== X-Google-Smtp-Source: AGHT+IGStdeb2Ymxnqz2ONlaKH+mY+rxu7O6qI+eJf2N1j1rPyyDZhoN8CZKe9hY7VSYM3QHSUG2/Q== X-Received: by 2002:adf:fc12:0:b0:33a:eda8:3370 with SMTP id i18-20020adffc12000000b0033aeda83370mr4174692wrr.24.1706616711734; Tue, 30 Jan 2024 04:11:51 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:51 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 085/101] gccrs: ast: Infer static lifetime for const and static items Date: Tue, 30 Jan 2024 13:07:41 +0100 Message-ID: <20240130121026.807464-88-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 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, T_SCC_BODY_TEXT_LINE 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: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Jakub Dupak (probably incomplete propagation) gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Propagate static requirement. * hir/rust-ast-lower-base.h: Propagate static requirement. * hir/rust-ast-lower-implitem.h: Propagate static requirement. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Propagate static requirement. * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Propagate static requirement. (ASTLoweringType::visit): Propagate static requirement. * hir/rust-ast-lower-type.h: Propagate static requirement. Signed-off-by: Jakub Dupak --- gcc/rust/hir/rust-ast-lower-base.cc | 14 ++++++++++--- gcc/rust/hir/rust-ast-lower-base.h | 3 ++- gcc/rust/hir/rust-ast-lower-implitem.h | 3 ++- gcc/rust/hir/rust-ast-lower-item.cc | 5 +++-- gcc/rust/hir/rust-ast-lower-type.cc | 28 +++++++++++++++++--------- gcc/rust/hir/rust-ast-lower-type.h | 12 +++++++++-- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index f8438557707..748cec74829 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -530,16 +530,24 @@ ASTLoweringBase::visit (AST::SelfParam ¶m) {} HIR::Lifetime -ASTLoweringBase::lower_lifetime (AST::Lifetime &lifetime) +ASTLoweringBase::lower_lifetime (AST::Lifetime &lifetime, + bool default_to_static_lifetime) { + auto lifetime_type = lifetime.get_lifetime_type (); + if (lifetime_type == AST::Lifetime::WILDCARD && default_to_static_lifetime) + { + // If compiling in a static context. + lifetime_type = AST::Lifetime::STATIC; + } + auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, lifetime.get_node_id (), mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); mappings->insert_node_to_hir (mapping.get_nodeid (), mapping.get_hirid ()); - return HIR::Lifetime (mapping, lifetime.get_lifetime_type (), - lifetime.get_lifetime_name (), lifetime.get_locus ()); + return HIR::Lifetime (mapping, lifetime_type, lifetime.get_lifetime_name (), + lifetime.get_locus ()); } HIR::LoopLabel diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index d52afd3421f..8da11750d18 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -264,7 +264,8 @@ protected: Analysis::Mappings *mappings; Analysis::BuiltinAttributeMappings *attr_mappings; - HIR::Lifetime lower_lifetime (AST::Lifetime &lifetime); + HIR::Lifetime lower_lifetime (AST::Lifetime &lifetime, + bool default_to_static_lifetime = false); HIR::LoopLabel lower_loop_label (AST::LoopLabel &loop_label); diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 6f904dde19f..81dae14cdca 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -88,7 +88,8 @@ public: { HIR::Visibility vis = translate_visibility (constant.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); + HIR::Type *type + = ASTLoweringType::translate (constant.get_type ().get (), true); HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index 2895872f336..7ef556fee0d 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -351,7 +351,7 @@ ASTLoweringItem::visit (AST::StaticItem &var) { HIR::Visibility vis = translate_visibility (var.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (var.get_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (var.get_type ().get (), true); HIR::Expr *expr = ASTLoweringExpr::translate (var.get_expr ().get ()); auto crate_num = mappings->get_current_crate (); @@ -372,7 +372,8 @@ ASTLoweringItem::visit (AST::ConstantItem &constant) { HIR::Visibility vis = translate_visibility (constant.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); + HIR::Type *type + = ASTLoweringType::translate (constant.get_type ().get (), true); HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index 5388f2139ce..5cea71f83a2 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -180,9 +180,9 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) } HIR::Type * -ASTLoweringType::translate (AST::Type *type) +ASTLoweringType::translate (AST::Type *type, bool default_to_static_lifetime) { - ASTLoweringType resolver; + ASTLoweringType resolver (default_to_static_lifetime); type->accept_vis (resolver); rust_assert (resolver.translated != nullptr); @@ -222,7 +222,8 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) } HIR::Type *param_type - = ASTLoweringType::translate (param.get_type ().get ()); + = ASTLoweringType::translate (param.get_type ().get (), + default_to_static_lifetime); HIR::MaybeNamedParam p (param.get_name (), kind, std::unique_ptr (param_type), @@ -234,7 +235,8 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) if (fntype.has_return_type ()) { return_type - = ASTLoweringType::translate (fntype.get_return_type ().get ()); + = ASTLoweringType::translate (fntype.get_return_type ().get (), + default_to_static_lifetime); } auto crate_num = mappings->get_current_crate (); @@ -254,7 +256,8 @@ ASTLoweringType::visit (AST::TupleType &tuple) std::vector> elems; for (auto &e : tuple.get_elems ()) { - HIR::Type *t = ASTLoweringType::translate (e.get ()); + HIR::Type *t + = ASTLoweringType::translate (e.get (), default_to_static_lifetime); elems.push_back (std::unique_ptr (t)); } @@ -283,7 +286,8 @@ void ASTLoweringType::visit (AST::ArrayType &type) { HIR::Type *translated_type - = ASTLoweringType::translate (type.get_elem_type ().get ()); + = ASTLoweringType::translate (type.get_elem_type ().get (), + default_to_static_lifetime); HIR::Expr *array_size = ASTLoweringExpr::translate (type.get_size_expr ().get ()); @@ -301,10 +305,12 @@ ASTLoweringType::visit (AST::ArrayType &type) void ASTLoweringType::visit (AST::ReferenceType &type) { - HIR::Lifetime lifetime = lower_lifetime (type.get_lifetime ()); + HIR::Lifetime lifetime + = lower_lifetime (type.get_lifetime (), default_to_static_lifetime); HIR::Type *base_type - = ASTLoweringType::translate (type.get_base_type ().get ()); + = ASTLoweringType::translate (type.get_base_type ().get (), + default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), @@ -322,7 +328,8 @@ void ASTLoweringType::visit (AST::RawPointerType &type) { HIR::Type *base_type - = ASTLoweringType::translate (type.get_type_pointed_to ().get ()); + = ASTLoweringType::translate (type.get_type_pointed_to ().get (), + default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), @@ -343,7 +350,8 @@ void ASTLoweringType::visit (AST::SliceType &type) { HIR::Type *base_type - = ASTLoweringType::translate (type.get_elem_type ().get ()); + = ASTLoweringType::translate (type.get_elem_type ().get (), + default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h index 8194a9ace5e..ed90c17bb0f 100644 --- a/gcc/rust/hir/rust-ast-lower-type.h +++ b/gcc/rust/hir/rust-ast-lower-type.h @@ -63,7 +63,8 @@ class ASTLoweringType : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Type *translate (AST::Type *type); + static HIR::Type *translate (AST::Type *type, + bool default_to_static_lifetime = false); void visit (AST::BareFunctionType &fntype) override; void visit (AST::TupleType &tuple) override; @@ -79,7 +80,14 @@ public: void visit (AST::TraitObjectType &type) override; private: - ASTLoweringType () : ASTLoweringBase (), translated (nullptr) {} + ASTLoweringType (bool default_to_static_lifetime) + : ASTLoweringBase (), + default_to_static_lifetime (default_to_static_lifetime), + translated (nullptr) + {} + + /** Used when compiling const and static items. */ + bool default_to_static_lifetime; HIR::Type *translated; };