]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
borrowck: Add CLI option for borrowck
authorJakub Dupak <dev@jakubdupak.com>
Thu, 19 Oct 2023 08:59:54 +0000 (10:59 +0200)
committerCohenArthur <arthur.cohen@embecosm.com>
Thu, 26 Oct 2023 15:05:49 +0000 (15:05 +0000)
gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::BorrowChecker): Opt dump.
(BorrowChecker::go): Opt dump.
* checks/errors/borrowck/rust-borrow-checker.h (class BorrowChecker): Opt dump.
* lang.opt: Add compile until borrowcheck.
* rust-session-manager.cc (Session::enable_dump): Add BIR.
(Session::compile_crate): Handle new options.
* rust-session-manager.h (struct CompileOptions): Add BIR.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
gcc/rust/checks/errors/borrowck/rust-borrow-checker.cc
gcc/rust/checks/errors/borrowck/rust-borrow-checker.h
gcc/rust/lang.opt
gcc/rust/rust-session-manager.cc
gcc/rust/rust-session-manager.h

index a6086b8a69567e5bc6e11d5e5c99b2b23bbce2f3..6c292231042312a0f2afe6a6fe4b4132ea905eb9 100644 (file)
@@ -22,8 +22,6 @@
 namespace Rust {
 namespace HIR {
 
-BorrowChecker::BorrowChecker () = default;
-
 void
 BorrowChecker::go (HIR::Crate &crate)
 {
index 7df5fe788a0bcc32d6050730e929689e7a7f67f6..549af3560e9b92534d17473f5d63806077e98a3a 100644 (file)
@@ -26,8 +26,11 @@ namespace HIR {
 
 class BorrowChecker
 {
+  bool enable_dump_bir;
+
 public:
-  BorrowChecker ();
+  explicit BorrowChecker (bool enable_dump_bir)
+    : enable_dump_bir (enable_dump_bir){};
 
   /** Perform borrow-checking using polonius on an entire crate */
   void go (HIR::Crate &crate);
index a77c0a903947b4aea193a5baadeaf3fc1b135b32..67285a6d92b2995aafb9a3a5a0b02524753216f9 100644 (file)
@@ -190,10 +190,13 @@ EnumValue
 Enum(frust_compile_until) String(const) Value(8)
 
 EnumValue
-Enum(frust_compile_until) String(compilation) Value(9)
+Enum(frust_compile_until) String(borrowcheck) Value(9)
 
 EnumValue
-Enum(frust_compile_until) String(end) Value(10)
+Enum(frust_compile_until) String(compilation) Value(10)
+
+EnumValue
+Enum(frust_compile_until) String(end) Value(11)
 
 frust-name-resolution-2.0
 Rust Var(flag_name_resolution_2_0)
index c674a18d1c92360178e8e22bb04dcb94761e4024..2843b7d25cf21c45dccafde254f02ae094d4c6d0 100644 (file)
@@ -51,6 +51,7 @@
 #include "selftest.h"
 #include "tm.h"
 #include "rust-target.h"
+#include "rust-borrow-checker.h"
 
 extern bool
 saw_errors (void);
@@ -313,7 +314,7 @@ Session::enable_dump (std::string arg)
        "dump option was not given a name. choose %<lex%>, %<ast-pretty%>, "
        "%<register_plugins%>, %<injection%>, "
        "%<expansion%>, %<resolution%>, %<target_options%>, %<hir%>, "
-       "%<hir-pretty%>, or %<all%>");
+       "%<hir-pretty%>, %<bir%> or %<all%>");
       return false;
     }
 
@@ -357,6 +358,10 @@ Session::enable_dump (std::string arg)
     {
       options.enable_dump_option (CompileOptions::HIR_DUMP_PRETTY);
     }
+  else if (arg == "bir")
+    {
+      options.enable_dump_option (CompileOptions::BIR_DUMP);
+    }
   else
     {
       rust_error_at (
@@ -659,6 +664,13 @@ Session::compile_crate (const char *filename)
 
   HIR::ConstChecker ().go (hir);
 
+  if (last_step == CompileOptions::CompileStep::BorrowCheck)
+    return;
+
+  const bool dump_bir
+    = options.dump_option_enabled (CompileOptions::DumpOption::BIR_DUMP);
+  HIR::BorrowChecker (dump_bir).go (hir);
+
   if (saw_errors ())
     return;
 
index 7e82291f95f9e91733b9aca19494bb4ec1356044..2b1f6d00d9c91d9206cc299218c2c5cd60861d6b 100644 (file)
@@ -221,6 +221,7 @@ struct CompileOptions
     TARGET_OPTION_DUMP,
     HIR_DUMP,
     HIR_DUMP_PRETTY,
+    BIR_DUMP,
   };
 
   std::set<DumpOption> dump_options;
@@ -254,6 +255,7 @@ struct CompileOptions
     Privacy,
     Unsafety,
     Const,
+    BorrowCheck,
     Compilation,
     End,
   } compile_until
@@ -277,6 +279,7 @@ struct CompileOptions
     enable_dump_option (DumpOption::TARGET_OPTION_DUMP);
     enable_dump_option (DumpOption::HIR_DUMP);
     enable_dump_option (DumpOption::HIR_DUMP_PRETTY);
+    enable_dump_option (DumpOption::BIR_DUMP);
   }
 
   void set_crate_name (std::string name)