From ca9f57f55171329972d86ca7dba6fc372f55609d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?O=C4=9Fuz=20A=C4=9Fcayaz=C4=B1?= <ouz.agz@gmail.com>
Date: Mon, 16 Oct 2023 20:40:21 +0300
Subject: [PATCH] move rustc_smir to driver

---
 Cargo.lock                                    | 18 +----------------
 compiler/rustc/Cargo.toml                     |  5 +----
 compiler/rustc_driver_impl/Cargo.toml         |  1 +
 compiler/rustc_driver_impl/src/lib.rs         |  2 ++
 .../src/rustc_internal/mod.rs                 |  4 ++--
 .../src/rustc_smir/alloc.rs                   |  0
 .../src/rustc_smir/mod.rs                     |  8 ++++++++
 compiler/rustc_smir/.gitignore                |  1 -
 compiler/rustc_smir/Cargo.toml                | 17 ----------------
 compiler/rustc_smir/src/lib.rs                | 20 -------------------
 .../stable-mir/compilation-result.rs          |  4 ++--
 tests/ui-fulldeps/stable-mir/crate-info.rs    |  4 ++--
 12 files changed, 19 insertions(+), 65 deletions(-)
 rename compiler/{rustc_smir => rustc_driver_impl}/src/rustc_internal/mod.rs (97%)
 rename compiler/{rustc_smir => rustc_driver_impl}/src/rustc_smir/alloc.rs (100%)
 rename compiler/{rustc_smir => rustc_driver_impl}/src/rustc_smir/mod.rs (99%)
 delete mode 100644 compiler/rustc_smir/.gitignore
 delete mode 100644 compiler/rustc_smir/Cargo.toml
 delete mode 100644 compiler/rustc_smir/src/lib.rs

diff --git a/Cargo.lock b/Cargo.lock
index 5cfb7feb6f545..741e571935bd1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3346,8 +3346,6 @@ dependencies = [
  "rustc_codegen_ssa",
  "rustc_driver",
  "rustc_driver_impl",
- "rustc_smir",
- "stable_mir",
 ]
 
 [[package]]
@@ -3770,6 +3768,7 @@ dependencies = [
  "rustc_trait_selection",
  "rustc_ty_utils",
  "serde_json",
+ "stable_mir",
  "time",
  "tracing",
  "windows",
@@ -4500,21 +4499,6 @@ dependencies = [
  "windows",
 ]
 
-[[package]]
-name = "rustc_smir"
-version = "0.0.0"
-dependencies = [
- "rustc_data_structures",
- "rustc_driver",
- "rustc_hir",
- "rustc_interface",
- "rustc_middle",
- "rustc_span",
- "rustc_target",
- "stable_mir",
- "tracing",
-]
-
 [[package]]
 name = "rustc_span"
 version = "0.0.0"
diff --git a/compiler/rustc/Cargo.toml b/compiler/rustc/Cargo.toml
index dcb165f9fdbf7..e98ee309c76f4 100644
--- a/compiler/rustc/Cargo.toml
+++ b/compiler/rustc/Cargo.toml
@@ -10,10 +10,7 @@ rustc_driver_impl = { path = "../rustc_driver_impl" }
 # Make sure rustc_codegen_ssa ends up in the sysroot, because this
 # crate is intended to be used by codegen backends, which may not be in-tree.
 rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
-# Make sure rustc_smir ends up in the sysroot, because this
-# crate is intended to be used by stable MIR consumers, which are not in-tree
-rustc_smir = { path = "../rustc_smir" }
-stable_mir = { path = "../stable_mir" }
+
 
 [dependencies.jemalloc-sys]
 version = "0.5.0"
diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml
index a7b01618ade39..5e3dd848ff981 100644
--- a/compiler/rustc_driver_impl/Cargo.toml
+++ b/compiler/rustc_driver_impl/Cargo.toml
@@ -53,6 +53,7 @@ rustc_ast = { path = "../rustc_ast" }
 rustc_span = { path = "../rustc_span" }
 rustc_hir_analysis = { path = "../rustc_hir_analysis" }
 rustc_mir_transform = { path = "../rustc_mir_transform" }
+stable_mir = {path = "../stable_mir"}
 
 [target.'cfg(unix)'.dependencies]
 libc = "0.2"
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index 5bb7c41677cd1..8d1678ecbeebc 100644
--- a/compiler/rustc_driver_impl/src/lib.rs
+++ b/compiler/rustc_driver_impl/src/lib.rs
@@ -85,6 +85,8 @@ use {do_not_use_print as print, do_not_use_print as println};
 
 pub mod args;
 pub mod pretty;
+pub mod rustc_internal;
+pub mod rustc_smir;
 #[macro_use]
 mod print;
 mod session_diagnostics;
diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_driver_impl/src/rustc_internal/mod.rs
similarity index 97%
rename from compiler/rustc_smir/src/rustc_internal/mod.rs
rename to compiler/rustc_driver_impl/src/rustc_internal/mod.rs
index e3c84f06543ed..c5bb0611cab7d 100644
--- a/compiler/rustc_smir/src/rustc_internal/mod.rs
+++ b/compiler/rustc_driver_impl/src/rustc_internal/mod.rs
@@ -5,8 +5,8 @@
 
 use crate::rustc_internal;
 use crate::rustc_smir::Tables;
+use crate::{catch_fatal_errors, Callbacks, Compilation, RunCompiler};
 use rustc_data_structures::fx;
-use rustc_driver::{Callbacks, Compilation, RunCompiler};
 use rustc_interface::{interface, Queries};
 use rustc_middle::mir::interpret::AllocId;
 use rustc_middle::ty::TyCtxt;
@@ -150,7 +150,7 @@ where
     /// Runs the compiler against given target and tests it with `test_function`
     pub fn run(&mut self) -> Result<C, CompilerError<B>> {
         let compiler_result =
-            rustc_driver::catch_fatal_errors(|| RunCompiler::new(&self.args.clone(), self).run());
+            catch_fatal_errors(|| RunCompiler::new(&self.args.clone(), self).run());
         match (compiler_result, self.result.take()) {
             (Ok(Ok(())), Some(ControlFlow::Continue(value))) => Ok(value),
             (Ok(Ok(())), Some(ControlFlow::Break(value))) => Err(CompilerError::Interrupted(value)),
diff --git a/compiler/rustc_smir/src/rustc_smir/alloc.rs b/compiler/rustc_driver_impl/src/rustc_smir/alloc.rs
similarity index 100%
rename from compiler/rustc_smir/src/rustc_smir/alloc.rs
rename to compiler/rustc_driver_impl/src/rustc_smir/alloc.rs
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_driver_impl/src/rustc_smir/mod.rs
similarity index 99%
rename from compiler/rustc_smir/src/rustc_smir/mod.rs
rename to compiler/rustc_driver_impl/src/rustc_smir/mod.rs
index f26d18ad38f23..776a340a67809 100644
--- a/compiler/rustc_smir/src/rustc_smir/mod.rs
+++ b/compiler/rustc_driver_impl/src/rustc_smir/mod.rs
@@ -1,3 +1,11 @@
+//! The WIP stable interface to rustc internals.
+//!
+//! For more information see <https://github.com/rust-lang/project-stable-mir>
+//!
+//! # Note
+//!
+//! This API is still completely unstable and subject to change.
+
 //! Module that implements what will become the rustc side of Stable MIR.
 
 //! This module is responsible for building Stable MIR components from internal components.
diff --git a/compiler/rustc_smir/.gitignore b/compiler/rustc_smir/.gitignore
deleted file mode 100644
index eb5a316cbd195..0000000000000
--- a/compiler/rustc_smir/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-target
diff --git a/compiler/rustc_smir/Cargo.toml b/compiler/rustc_smir/Cargo.toml
deleted file mode 100644
index 2b77044d6bfc7..0000000000000
--- a/compiler/rustc_smir/Cargo.toml
+++ /dev/null
@@ -1,17 +0,0 @@
-[package]
-name = "rustc_smir"
-version = "0.0.0"
-edition = "2021"
-
-[dependencies]
-rustc_data_structures = { path = "../rustc_data_structures" }
-rustc_driver = { path = "../rustc_driver" }
-rustc_hir = { path = "../rustc_hir" }
-rustc_interface = { path = "../rustc_interface" }
-rustc_middle = { path = "../rustc_middle" }
-rustc_span = { path = "../rustc_span" }
-rustc_target = { path = "../rustc_target" }
-stable_mir = {path = "../stable_mir" }
-tracing = "0.1"
-
-[features]
diff --git a/compiler/rustc_smir/src/lib.rs b/compiler/rustc_smir/src/lib.rs
deleted file mode 100644
index c24b9efe86545..0000000000000
--- a/compiler/rustc_smir/src/lib.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-//! The WIP stable interface to rustc internals.
-//!
-//! For more information see <https://github.com/rust-lang/project-stable-mir>
-//!
-//! # Note
-//!
-//! This API is still completely unstable and subject to change.
-
-#![doc(
-    html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
-    test(attr(allow(unused_variables), deny(warnings)))
-)]
-#![cfg_attr(not(bootstrap), doc(rust_logo))]
-#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
-#![cfg_attr(not(bootstrap), allow(internal_features))]
-
-pub mod rustc_internal;
-
-// Make this module private for now since external users should not call these directly.
-mod rustc_smir;
diff --git a/tests/ui-fulldeps/stable-mir/compilation-result.rs b/tests/ui-fulldeps/stable-mir/compilation-result.rs
index 3ec1519fb13c4..eb0f6859a0448 100644
--- a/tests/ui-fulldeps/stable-mir/compilation-result.rs
+++ b/tests/ui-fulldeps/stable-mir/compilation-result.rs
@@ -10,11 +10,11 @@
 #![feature(assert_matches)]
 
 extern crate rustc_middle;
-extern crate rustc_smir;
+extern crate rustc_driver;
 extern crate stable_mir;
 
 use rustc_middle::ty::TyCtxt;
-use rustc_smir::rustc_internal;
+use rustc_driver::rustc_internal;
 use std::io::Write;
 use std::ops::ControlFlow;
 
diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs
index 8a812bd3265a1..e1e97cb333ae4 100644
--- a/tests/ui-fulldeps/stable-mir/crate-info.rs
+++ b/tests/ui-fulldeps/stable-mir/crate-info.rs
@@ -12,12 +12,12 @@
 
 extern crate rustc_hir;
 extern crate rustc_middle;
-extern crate rustc_smir;
+extern crate rustc_driver;
 extern crate stable_mir;
 
 use rustc_hir::def::DefKind;
 use rustc_middle::ty::TyCtxt;
-use rustc_smir::rustc_internal;
+use rustc_driver::rustc_internal;
 
 use stable_mir::fold::Foldable;
 use std::assert_matches::assert_matches;