From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 8DC03385EC59 for ; Thu, 1 Aug 2024 14:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DC03385EC59 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 8DC03385EC59 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::129 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524398; cv=none; b=b5baZG/fmR587izBWpzWozlhZZcBujfDQiwN7Fxmt1qCNVaoy2S+x5210aH53KPr4lzloiPaa7eIgDt84bwlXhT2VoygGss6huukYgsq8rz4gzg84uHc8aqSmvtHgXucjXNANUw2ATyNTv1F/DBPJiX7FgbjkJO/ebYGCn68G5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524398; c=relaxed/simple; bh=W/jiORpcebK01Yjuunn/YhLdbv69a0gXM3p4eWATsGk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iw/wHdsxEHAjGIx4w93Mo/365Td4dzl2i5ivSeMJgwgQMQO2TqTymCFxXZsggOK4NkhatPfx8tDE14rDeaFTRwp/7+ez7pEBmihDFmKNimmmz/rKY87KcIxgYQSBjXPchfF9KtnSGSO3LIht7oLKhCWF+CnGbb5/ULciE3n49I4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-52ed741fe46so8078493e87.0 for ; Thu, 01 Aug 2024 07:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524368; x=1723129168; 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=FO1vJxUBzX00RzRsNLBkbQe7e2SQFiI+3oJRr7JyM3g=; b=Ei/3TZw+tToTKlE3JxNpKprt8Z1bFXLKGrrbRSsN5t2GtLvgPeWLJA/rpYnUSuS/EK b5WNx3yszzh7sfHK69SlsqUDOkWzOfDyubgLFTVvjzT8r0U31t+hplQir2yPl3aHIk8h EXtplvrnU/hegxtK651xxVbTNlgkDPxJYt4DKgR9wMRH4gISOJNN9qDsGTDocAJ0k7uS YfHDeu8UnPb/u6FHDYK1KH+6vT6AjuWUSRKodgvlwBN14nRd5Iu/gLQdW6RkjcyLDAl3 dZ1ZqAbEt0O887ZF13pBCLL0KWw2nflF7wIdhtbEJApTBXjNXesBITRp+GBMPDEReldq nSHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524368; x=1723129168; 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=FO1vJxUBzX00RzRsNLBkbQe7e2SQFiI+3oJRr7JyM3g=; b=WBcYsWbBT8t+9rY2p1BO9VrBnEPz9TgOQno6fX/hCvogGvbHLUqt5mnVp3ppxCvpUI 4dvKimNKFExP6oa5WzrngnLixqmBNouMZFPTESie6GxWrlZLwqGKXnVEdpoziWg8Xya2 Sl5s3yBUxfCTt+5LcQjlpYDx6V/SonX99IK3yb/kEBpmjLV60xdcRlPdBCG6wEsDrlY4 lDughw9InCq7S927TsoC5PKHXvPzh23H+JJZzE+tuCgB1S8pMBKhSOL+9Ox7kT3uRkHj 6B/GsifnPh3J/Pcben8BZeaYhwYFva3K7vOEjavVYzwx6sQ3VXyWq7l2+FaC3e8rN6FB 4zFg== X-Gm-Message-State: AOJu0YydDGo10s/OsFHJhlhXSMK4ypUB8Tn0sgA6+HBmE3Ia/sY+bsRR DFE12ol6d/ZSM23Cf8cFFOvPzWiINiVDcsYWI+AeauOD0jR+cJjKLBdbM6GWRz1JKWuBjCQ8Y7e gKE0u X-Google-Smtp-Source: AGHT+IHMxZxjeYAxUdixwgz5b07YJblfTF2ymuXiZaGMS2FbKWIqc65kpbGWnpAHkeXw0on1uVJ6pQ== X-Received: by 2002:a05:6512:12d1:b0:530:b7ef:9f6a with SMTP id 2adb3069b0e04-530bb3b8234mr96647e87.36.1722524367668; Thu, 01 Aug 2024 07:59:27 -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.07.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:59:27 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH 059/125] gccrs: nr2.0: Add new ImmutableNameResolutionCtx class. Date: Thu, 1 Aug 2024 16:56:55 +0200 Message-ID: <20240801145809.366388-61-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 Content-Transfer-Encoding: 8bit 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,KAM_SHORT,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: gcc/rust/ChangeLog: * Make-lang.in: Compile it. * resolve/rust-immutable-name-resolution-context.cc: New file. * resolve/rust-immutable-name-resolution-context.h: New file. --- gcc/rust/Make-lang.in | 1 + .../rust-immutable-name-resolution-context.cc | 56 +++++++++++++++++++ .../rust-immutable-name-resolution-context.h | 55 ++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 gcc/rust/resolve/rust-immutable-name-resolution-context.cc create mode 100644 gcc/rust/resolve/rust-immutable-name-resolution-context.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 10af0814372..24229c02770 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -134,6 +134,7 @@ GRS_OBJS = \ rust/rust-toplevel-name-resolver-2.0.o \ rust/rust-early-name-resolver-2.0.o \ rust/rust-late-name-resolver-2.0.o \ + rust/rust-immutable-name-resolution-context.o \ rust/rust-early-name-resolver.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.cc b/gcc/rust/resolve/rust-immutable-name-resolution-context.cc new file mode 100644 index 00000000000..3894e27cd20 --- /dev/null +++ b/gcc/rust/resolve/rust-immutable-name-resolution-context.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#include "rust-immutable-name-resolution-context.h" + +namespace Rust { +namespace Resolver2_0 { + +static ImmutableNameResolutionContext *instance = nullptr; + +const ImmutableNameResolutionContext & +ImmutableNameResolutionContext::init (const NameResolutionContext &ctx) +{ + rust_assert (!instance); + + instance = new ImmutableNameResolutionContext (ctx); + + return *instance; +} + +const ImmutableNameResolutionContext & +ImmutableNameResolutionContext::get () +{ + rust_assert (instance); + + return *instance; +} + +const NameResolutionContext & +ImmutableNameResolutionContext::resolver () const +{ + return ctx; +} + +ImmutableNameResolutionContext::ImmutableNameResolutionContext ( + const NameResolutionContext &ctx) + : ctx (ctx) +{} + +} // namespace Resolver2_0 +} // namespace Rust diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.h b/gcc/rust/resolve/rust-immutable-name-resolution-context.h new file mode 100644 index 00000000000..9f9e7764cd2 --- /dev/null +++ b/gcc/rust/resolve/rust-immutable-name-resolution-context.h @@ -0,0 +1,55 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#ifndef RUST_IMMUTABLE_NRCTX_H +#define RUST_IMMUTABLE_NRCTX_H + +#include "rust-name-resolution-context.h" + +namespace Rust { +namespace Resolver2_0 { + +/** + * Once the name resolution pass is complete, the typechecker can access it + * + * FIXME: More documentation + */ +class ImmutableNameResolutionContext +{ +public: + /** FIXME: Documentation */ + static const ImmutableNameResolutionContext & + init (const NameResolutionContext &ctx); + + /** FIXME: Documentation */ + static const ImmutableNameResolutionContext &get (); + + const NameResolutionContext &resolver () const; + +private: + ImmutableNameResolutionContext (const NameResolutionContext &ctx); + ImmutableNameResolutionContext (const ImmutableNameResolutionContext &other) + = default; + + const NameResolutionContext &ctx; +}; + +} // namespace Resolver2_0 +} // namespace Rust + +#endif //! RUST_IMMUTABLE_NRCTX_H -- 2.45.2