Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a38e983

Browse files
committed
Split out the stable part of smir into its own crate to prevent accidental usage of forever unstable things
1 parent 19f1d78 commit a38e983

File tree

20 files changed

+115
-117
lines changed

20 files changed

+115
-117
lines changed

Cargo.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,7 @@ dependencies = [
32573257
"rustc_driver",
32583258
"rustc_driver_impl",
32593259
"rustc_smir",
3260+
"stable_mir",
32603261
]
32613262

32623263
[[package]]
@@ -4421,7 +4422,7 @@ dependencies = [
44214422
"rustc_session",
44224423
"rustc_span",
44234424
"rustc_target",
4424-
"scoped-tls",
4425+
"stable_mir",
44254426
"tracing",
44264427
]
44274428

@@ -4958,6 +4959,14 @@ version = "1.2.0"
49584959
source = "registry+https://github.com/rust-lang/crates.io-index"
49594960
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
49604961

4962+
[[package]]
4963+
name = "stable_mir"
4964+
version = "0.1.0-preview"
4965+
dependencies = [
4966+
"scoped-tls",
4967+
"tracing",
4968+
]
4969+
49614970
[[package]]
49624971
name = "stacker"
49634972
version = "0.1.15"

compiler/rustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
1313
# Make sure rustc_smir ends up in the sysroot, because this
1414
# crate is intended to be used by stable MIR consumers, which are not in-tree
1515
rustc_smir = { path = "../rustc_smir" }
16+
stable_mir = { path = "../stable_mir" }
1617

1718
[dependencies.jemalloc-sys]
1819
version = "0.5.0"

compiler/rustc_smir/Cargo.toml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,14 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
# Use optional dependencies for rustc_* in order to support building this crate separately.
8-
rustc_hir = { path = "../rustc_hir", optional = true }
9-
rustc_middle = { path = "../rustc_middle", optional = true }
10-
rustc_span = { path = "../rustc_span", optional = true }
11-
rustc_target = { path = "../rustc_target", optional = true }
12-
rustc_driver = { path = "../rustc_driver", optional = true }
13-
rustc_interface = { path = "../rustc_interface", optional = true}
14-
rustc_session = {path = "../rustc_session", optional = true}
7+
rustc_hir = { path = "../rustc_hir" }
8+
rustc_middle = { path = "../rustc_middle" }
9+
rustc_span = { path = "../rustc_span" }
10+
rustc_target = { path = "../rustc_target" }
11+
rustc_driver = { path = "../rustc_driver" }
12+
rustc_interface = { path = "../rustc_interface" }
13+
rustc_session = {path = "../rustc_session" }
1514
tracing = "0.1"
16-
scoped-tls = "1.0"
15+
stable_mir = {path = "../stable_mir" }
1716

1817
[features]
19-
default = [
20-
"rustc_hir",
21-
"rustc_middle",
22-
"rustc_span",
23-
"rustc_target",
24-
"rustc_driver",
25-
"rustc_interface",
26-
"rustc_session",
27-
]

compiler/rustc_smir/src/lib.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,12 @@
1010
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
1111
test(attr(allow(unused_variables), deny(warnings)))
1212
)]
13-
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
13+
#![feature(rustc_private)]
1414
#![feature(ptr_metadata)]
1515
#![feature(type_alias_impl_trait)] // Used to define opaque types.
1616
#![feature(intra_doc_pointers)]
1717

18-
// Declare extern rustc_* crates to enable building this crate separately from the compiler.
19-
#[cfg(not(feature = "default"))]
20-
extern crate rustc_hir;
21-
#[cfg(not(feature = "default"))]
22-
extern crate rustc_middle;
23-
#[cfg(not(feature = "default"))]
24-
extern crate rustc_span;
25-
#[cfg(not(feature = "default"))]
26-
extern crate rustc_target;
27-
2818
pub mod rustc_internal;
29-
pub mod stable_mir;
3019

3120
// Make this module private for now since external users should not call these directly.
3221
mod rustc_smir;
33-
34-
#[macro_use]
35-
extern crate scoped_tls;

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
use std::ops::{ControlFlow, Index};
77

88
use crate::rustc_internal;
9-
use crate::stable_mir::CompilerError;
10-
use crate::{rustc_smir::Tables, stable_mir};
9+
use crate::rustc_smir::Tables;
1110
use rustc_driver::{Callbacks, Compilation, RunCompiler};
1211
use rustc_interface::{interface, Queries};
1312
use rustc_middle::mir::interpret::AllocId;
1413
use rustc_middle::ty::TyCtxt;
1514
pub use rustc_span::def_id::{CrateNum, DefId};
1615
use rustc_span::Span;
16+
use stable_mir::CompilerError;
1717

1818
impl<'tcx> Index<stable_mir::DefId> for Tables<'tcx> {
1919
type Output = DefId;
@@ -129,7 +129,7 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
129129
}
130130

131131
pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
132-
crate::stable_mir::run(
132+
stable_mir::run(
133133
Tables { tcx, def_ids: vec![], alloc_ids: vec![], spans: vec![], types: vec![] },
134134
f,
135135
);

compiler/rustc_smir/src/rustc_smir/alloc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ use rustc_middle::mir::{
33
ConstValue,
44
};
55

6-
use crate::{
7-
rustc_smir::{Stable, Tables},
8-
stable_mir::mir::Mutability,
9-
stable_mir::ty::{Allocation, ProvenanceMap},
10-
};
6+
use crate::rustc_smir::{Stable, Tables};
7+
use stable_mir::mir::Mutability;
8+
use stable_mir::ty::{Allocation, ProvenanceMap};
119

1210
/// Creates new empty `Allocation` from given `Align`.
1311
fn new_empty_allocation(align: rustc_target::abi::Align) -> Allocation {

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
11-
use crate::stable_mir::ty::{
12-
FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
13-
};
14-
use crate::stable_mir::{self, opaque, CompilerError, Context};
1510
use hir::def::DefKind;
1611
use rustc_hir as hir;
1712
use rustc_middle::mir;
1813
use rustc_middle::mir::interpret::{alloc_range, AllocId};
1914
use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
2015
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
21-
use rustc_span::ErrorGuaranteed;
2216
use rustc_target::abi::FieldIdx;
17+
use stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
18+
use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy};
19+
use stable_mir::{self, opaque, Context};
2320
use tracing::debug;
2421

2522
mod alloc;
@@ -112,7 +109,7 @@ impl<'tcx> Context for Tables<'tcx> {
112109
}
113110
}
114111

115-
fn ty_kind(&mut self, ty: crate::stable_mir::ty::Ty) -> TyKind {
112+
fn ty_kind(&mut self, ty: stable_mir::ty::Ty) -> TyKind {
116113
self.types[ty.0].clone().stable(self)
117114
}
118115

@@ -1517,12 +1514,6 @@ impl<'tcx> Stable<'tcx> for rustc_span::Span {
15171514
}
15181515
}
15191516

1520-
impl<T> From<ErrorGuaranteed> for CompilerError<T> {
1521-
fn from(_error: ErrorGuaranteed) -> Self {
1522-
CompilerError::CompilationFailed
1523-
}
1524-
}
1525-
15261517
impl<'tcx> Stable<'tcx> for DefKind {
15271518
type T = stable_mir::DefKind;
15281519

compiler/stable_mir/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "stable_mir"
3+
version = "0.1.0-preview"
4+
edition = "2021"
5+
6+
[dependencies]
7+
tracing = "0.1"
8+
scoped-tls = "1.0"
File renamed without changes.

0 commit comments

Comments
 (0)