Skip to content

Commit 1bc8681

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

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
@@ -3194,6 +3194,7 @@ dependencies = [
31943194
"rustc_driver",
31953195
"rustc_driver_impl",
31963196
"rustc_smir",
3197+
"stable_mir",
31973198
]
31983199

31993200
[[package]]
@@ -4358,7 +4359,7 @@ dependencies = [
43584359
"rustc_session",
43594360
"rustc_span",
43604361
"rustc_target",
4361-
"scoped-tls",
4362+
"stable_mir",
43624363
"tracing",
43634364
]
43644365

@@ -4909,6 +4910,14 @@ version = "1.2.0"
49094910
source = "registry+https://github.com/rust-lang/crates.io-index"
49104911
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
49114912

4913+
[[package]]
4914+
name = "stable_mir"
4915+
version = "0.1.0-preview"
4916+
dependencies = [
4917+
"scoped-tls",
4918+
"tracing",
4919+
]
4920+
49124921
[[package]]
49134922
name = "stacker"
49144923
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
@@ -1,10 +1,8 @@
11
use rustc_middle::mir::interpret::{alloc_range, AllocRange, ConstValue, Pointer};
22

3-
use crate::{
4-
rustc_smir::{Stable, Tables},
5-
stable_mir::mir::Mutability,
6-
stable_mir::ty::{Allocation, ProvenanceMap},
7-
};
3+
use crate::rustc_smir::{Stable, Tables};
4+
use stable_mir::mir::Mutability;
5+
use stable_mir::ty::{Allocation, ProvenanceMap};
86

97
/// Creates new empty `Allocation` from given `Align`.
108
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::interpret::{alloc_range, AllocId};
1813
use rustc_middle::mir::{self, ConstantKind};
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

@@ -1523,12 +1520,6 @@ impl<'tcx> Stable<'tcx> for rustc_span::Span {
15231520
}
15241521
}
15251522

1526-
impl<T> From<ErrorGuaranteed> for CompilerError<T> {
1527-
fn from(_error: ErrorGuaranteed) -> Self {
1528-
CompilerError::CompilationFailed
1529-
}
1530-
}
1531-
15321523
impl<'tcx> Stable<'tcx> for DefKind {
15331524
type T = stable_mir::DefKind;
15341525

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)