public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
From: arthur.cohen@embecosm.com
To: gcc-patches@gcc.gnu.org
Cc: gcc-rust@gcc.gnu.org, Jakub Dupak <dev@jakubdupak.com>
Subject: [COMMITTED 04/25] gccrs: TyTy: Region (lifetime) representation
Date: Wed,  7 Feb 2024 12:43:50 +0100	[thread overview]
Message-ID: <20240207114419.1100894-5-arthur.cohen@embecosm.com> (raw)
In-Reply-To: <20240207114419.1100894-2-arthur.cohen@embecosm.com>

From: Jakub Dupak <dev@jakubdupak.com>

gcc/rust/ChangeLog:

	* typecheck/rust-tyty-region.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
---
 gcc/rust/typecheck/rust-tyty-region.h | 110 ++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 create mode 100644 gcc/rust/typecheck/rust-tyty-region.h

diff --git a/gcc/rust/typecheck/rust-tyty-region.h b/gcc/rust/typecheck/rust-tyty-region.h
new file mode 100644
index 00000000000..b34a2115e7a
--- /dev/null
+++ b/gcc/rust/typecheck/rust-tyty-region.h
@@ -0,0 +1,110 @@
+#ifndef RUST_TYTY_REGION_H
+#define RUST_TYTY_REGION_H
+
+namespace Rust {
+namespace TyTy {
+
+class Region
+{
+  enum Variant : uint8_t
+  {
+    UNRESOLVED,
+    STATIC,
+    EARLY_BOUND,
+    LATE_BOUND,
+    NAMED,
+    ANONYMOUS,
+    ERASED,
+  };
+
+  uint32_t index;
+  uint16_t debruijn_index;
+  Variant variant;
+
+public:
+  Region () : Region (UNRESOLVED) {}
+  Region (const Region &other)
+    : index (other.index), debruijn_index (other.debruijn_index),
+      variant (other.variant)
+  {}
+  Region (Region &&other) noexcept
+    : index (other.index), debruijn_index (other.debruijn_index),
+      variant (other.variant)
+  {}
+  Region &operator= (const Region &other)
+  {
+    if (this == &other)
+      return *this;
+    index = other.index;
+    debruijn_index = other.debruijn_index;
+    variant = other.variant;
+    return *this;
+  }
+  Region &operator= (Region &&other) noexcept
+  {
+    if (this == &other)
+      return *this;
+    index = other.index;
+    debruijn_index = other.debruijn_index;
+    variant = other.variant;
+    return *this;
+  }
+
+  static Region make_static () { return Region (STATIC); }
+  static Region make_early_bound (uint32_t index)
+  {
+    return Region (EARLY_BOUND, index);
+  }
+  static Region make_late_bound (uint32_t index, uint16_t debruijn_index)
+  {
+    return Region (LATE_BOUND, index, debruijn_index);
+  }
+  static Region make_named (uint32_t index) { return Region (NAMED, index); }
+  static Region make_anonymous () { return Region (ANONYMOUS); }
+  static Region make_erased () { return Region (ERASED); }
+
+  size_t get_index () const { return index; }
+
+  bool is_static () const { return variant == STATIC; }
+  bool is_early_bound () const { return variant == EARLY_BOUND; }
+  bool is_late_bound () const { return variant == LATE_BOUND; }
+  bool is_named () const { return variant == NAMED; }
+  bool is_anonymous () const { return variant == ANONYMOUS; }
+
+  void shift_down () { debruijn_index++; }
+
+  WARN_UNUSED_RESULT std::string as_string () const
+  {
+    switch (variant)
+      {
+      case UNRESOLVED:
+	return "'unresolved";
+      case STATIC:
+	return "'static";
+      case EARLY_BOUND:
+	return "'early(" + std::to_string (index) + ")";
+      case LATE_BOUND:
+	return "'late(" + std::to_string (debruijn_index) + ", "
+	       + std::to_string (index) + ")";
+      case NAMED:
+	return "'named(" + std::to_string (index) + "";
+      case ANONYMOUS:
+	return "'_";
+      case ERASED:
+	return "'erased";
+      }
+
+    rust_unreachable ();
+  }
+
+private:
+  explicit Region (Variant variant, uint32_t index = 0,
+		   uint16_t debruijn_index = 0)
+    : index (index), debruijn_index (debruijn_index), variant (variant)
+  {}
+};
+
+} // namespace TyTy
+} // namespace Rust
+
+#endif // RUST_TYTY_REGION_H
-- 
2.42.1


  parent reply	other threads:[~2024-02-07 12:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 11:43 [COMMITTED 01/25] gccrs: Parse normal functions with `self` parameter correctly arthur.cohen
2024-02-07 11:43 ` [COMMITTED 02/25] gccrs: Implement quick-check for Unicode arthur.cohen
2024-02-07 11:43 ` [COMMITTED 03/25] gccrs: Typecheck: lifetime interning and resolution tool arthur.cohen
2024-02-07 11:43 ` arthur.cohen [this message]
2024-02-07 11:43 ` [COMMITTED 05/25] gccrs: HIR: Add mising getter arthur.cohen
2024-02-07 11:43 ` [COMMITTED 06/25] gccrs: Typecheck: add regions (lifetimes) to TyTy arthur.cohen
2024-02-07 11:43 ` [COMMITTED 07/25] gccrs: TyTy: Store region constraints arthur.cohen
2024-02-07 15:26   ` Bernhard Reutner-Fischer
2024-02-07 14:46     ` Arthur Cohen
2024-02-07 11:43 ` [COMMITTED 08/25] gccrs: TyTy: Store reference to type before any substitutions arthur.cohen
2024-02-07 11:43 ` [COMMITTED 09/25] gccrs: Set the default ABI to C for extern blocks and extern functions arthur.cohen
2024-02-07 11:43 ` [COMMITTED 10/25] gccrs: add testcase to prove issue has already been fixed arthur.cohen
2024-02-07 11:43 ` [COMMITTED 11/25] gccrs: add test cases to prove type inference is working arthur.cohen
2024-02-07 11:43 ` [COMMITTED 12/25] gccrs: Fix ICE accessing empty vector without check arthur.cohen
2024-02-07 11:43 ` [COMMITTED 13/25] gccrs: remove old generics hack to reuse generic symbols from previous seg arthur.cohen
2024-02-09 10:03   ` Jakub Jelinek
2024-02-15  9:10     ` [PATCH] gccrs: Avoid *.bak suffixed tests - use dg-skip-if instead Jakub Jelinek
2024-02-15 13:12       ` Arthur Cohen
2024-02-07 11:44 ` [COMMITTED 14/25] gccrs: remove similar hack in type paths as we had in path expressions arthur.cohen
2024-02-07 11:44 ` [COMMITTED 15/25] gccrs: refactor inference variable computation into a seperate method arthur.cohen
2024-02-07 11:44 ` [COMMITTED 16/25] gccrs: Move the Implementation of implitem lowering into its own file arthur.cohen
2024-02-07 11:44 ` [COMMITTED 17/25] gccrs: Add testcase to show issue is already fixed arthur.cohen
2024-02-07 11:44 ` [COMMITTED 18/25] gccrs: fix bug in pattern check for tuples arthur.cohen
2024-02-07 11:44 ` [COMMITTED 19/25] gccrs: Use AssociatedItem in place of TraitItem arthur.cohen
2024-02-07 11:44 ` [COMMITTED 20/25] gccrs: Add checks for Trait functions arthur.cohen
2024-02-07 11:44 ` [COMMITTED 21/25] gccrs: Add missing visitors for AST::Function arthur.cohen
2024-02-07 11:44 ` [COMMITTED 22/25] gccrs: Fix inconsistent formatting arthur.cohen
2024-02-07 11:44 ` [COMMITTED 23/25] gccrs: Parse trait functions as `AST::Function` arthur.cohen
2024-02-07 11:44 ` [COMMITTED 24/25] gccrs: Remove obsolete classes and functions arthur.cohen
2024-02-07 11:44 ` [COMMITTED 25/25] gccrs: Fix macro parsing for trait items arthur.cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240207114419.1100894-5-arthur.cohen@embecosm.com \
    --to=arthur.cohen@embecosm.com \
    --cc=dev@jakubdupak.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc-rust@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).