Skip to content

Commit e991fac

Browse files
authored
Unrolled build for rust-lang#139319
Rollup merge of rust-lang#139319 - makai410:refactor, r=celinval StableMIR: Prepare for refactoring Temporarily make `stable_mir` "parasitic" on the `rustc_smir` crate. It aims to resolve the circular dependency that would arise if we directly invert the dependency order between `rustc_smir` and `stable_mir`. Once the refactoring is complete (`rustc_smir` does not depend on `stable_mir`), we will migrate it back to the `stable_mir` crate. See more details: [here](https://hackmd.io/jBRkZLqAQL2EVgwIIeNMHg).
2 parents 0c478fd + 707d356 commit e991fac

31 files changed

+346
-305
lines changed

Cargo.lock

+2-3
Original file line numberDiff line numberDiff line change
@@ -4432,7 +4432,7 @@ dependencies = [
44324432
"rustc_span",
44334433
"rustc_target",
44344434
"scoped-tls",
4435-
"stable_mir",
4435+
"serde",
44364436
"tracing",
44374437
]
44384438

@@ -4990,8 +4990,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
49904990
name = "stable_mir"
49914991
version = "0.1.0-preview"
49924992
dependencies = [
4993-
"scoped-tls",
4994-
"serde",
4993+
"rustc_smir",
49954994
]
49964995

49974996
[[package]]

compiler/rustc_smir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ rustc_session = { path = "../rustc_session" }
1414
rustc_span = { path = "../rustc_span" }
1515
rustc_target = { path = "../rustc_target" }
1616
scoped-tls = "1.0"
17-
stable_mir = {path = "../stable_mir" }
17+
serde = { version = "1.0.125", features = [ "derive" ] }
1818
tracing = "0.1"
1919
# tidy-alphabetical-end

compiler/rustc_smir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ pub mod rustc_internal;
2222

2323
// Make this module private for now since external users should not call these directly.
2424
mod rustc_smir;
25+
26+
pub mod stable_mir;

compiler/rustc_smir/src/rustc_internal/internal.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use stable_mir::{CrateItem, CrateNum, DefId};
2121

2222
use super::RustcInternal;
2323
use crate::rustc_smir::Tables;
24+
use crate::stable_mir;
2425

2526
impl RustcInternal for CrateItem {
2627
type T<'tcx> = rustc_span::def_id::DefId;

compiler/rustc_smir/src/rustc_internal/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use stable_mir::ty::IndexedVal;
2222

2323
use crate::rustc_smir::context::TablesWrapper;
2424
use crate::rustc_smir::{Stable, Tables};
25+
use crate::stable_mir;
2526

2627
mod internal;
2728
pub mod pretty;

compiler/rustc_smir/src/rustc_internal/pretty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::io;
33
use rustc_middle::ty::TyCtxt;
44

55
use super::run;
6+
use crate::stable_mir;
67

78
pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io::Result<()> {
89
writeln!(

compiler/rustc_smir/src/rustc_smir/alloc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use stable_mir::mir::Mutability;
66
use stable_mir::ty::{Allocation, ProvenanceMap};
77

88
use crate::rustc_smir::{Stable, Tables};
9+
use crate::stable_mir;
910

1011
/// Creates new empty `Allocation` from given `Align`.
1112
fn new_empty_allocation(align: Align) -> Allocation {

compiler/rustc_smir/src/rustc_smir/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::mir::visit::MutVisitor;
1010
use rustc_middle::ty::{self, TyCtxt};
1111

1212
use crate::rustc_smir::{Stable, Tables};
13+
use crate::stable_mir;
1314

1415
/// Builds a monomorphic body for a given instance.
1516
pub(crate) struct BodyBuilder<'tcx> {

compiler/rustc_smir/src/rustc_smir/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use stable_mir::{Crate, CrateDef, CrateItem, CrateNum, DefId, Error, Filename, I
3535
use crate::rustc_internal::RustcInternal;
3636
use crate::rustc_smir::builder::BodyBuilder;
3737
use crate::rustc_smir::{Stable, Tables, alloc, filter_def_ids, new_item_kind, smir_crate};
38+
use crate::stable_mir;
3839

3940
impl<'tcx> Context for TablesWrapper<'tcx> {
4041
fn target_info(&self) -> MachineInfo {

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use stable_mir::target::MachineSize as Size;
1414
use stable_mir::ty::{Align, IndexedVal, VariantIdx};
1515

1616
use crate::rustc_smir::{Stable, Tables};
17+
use crate::stable_mir;
1718

1819
impl<'tcx> Stable<'tcx> for rustc_abi::VariantIdx {
1920
type T = VariantIdx;

compiler/rustc_smir/src/rustc_smir/convert/error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_middle::mir::interpret::AllocError;
66
use rustc_middle::ty::layout::LayoutError;
77

88
use crate::rustc_smir::{Stable, Tables};
9+
use crate::stable_mir;
910

1011
impl<'tcx> Stable<'tcx> for LayoutError<'tcx> {
1112
type T = stable_mir::Error;

compiler/rustc_smir/src/rustc_smir/convert/mir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use stable_mir::ty::{Allocation, ConstantKind, MirConst};
99
use stable_mir::{Error, opaque};
1010

1111
use crate::rustc_smir::{Stable, Tables, alloc};
12+
use crate::stable_mir;
1213

1314
impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
1415
type T = stable_mir::mir::Body;

compiler/rustc_smir/src/rustc_smir/convert/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use rustc_abi::FieldIdx;
44

55
use crate::rustc_smir::{Stable, Tables};
6+
use crate::stable_mir;
67

78
mod abi;
89
mod error;

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use stable_mir::ty::{
77
};
88

99
use crate::rustc_smir::{Stable, Tables, alloc};
10+
use crate::stable_mir;
1011

1112
impl<'tcx> Stable<'tcx> for ty::AliasTyKind {
1213
type T = stable_mir::ty::AliasKind;

compiler/rustc_smir/src/rustc_smir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use stable_mir::{CtorKind, ItemKind};
2121
use tracing::debug;
2222

2323
use crate::rustc_internal::IndexMap;
24+
use crate::stable_mir;
2425

2526
mod alloc;
2627
mod builder;

compiler/stable_mir/src/abi.rs compiler/rustc_smir/src/stable_mir/abi.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::num::NonZero;
33
use std::ops::RangeInclusive;
44

55
use serde::Serialize;
6+
use stable_mir::compiler_interface::with;
7+
use stable_mir::mir::FieldIdx;
8+
use stable_mir::target::{MachineInfo, MachineSize as Size};
9+
use stable_mir::ty::{Align, IndexedVal, Ty, VariantIdx};
10+
use stable_mir::{Error, Opaque, error};
611

7-
use crate::compiler_interface::with;
8-
use crate::mir::FieldIdx;
9-
use crate::target::{MachineInfo, MachineSize as Size};
10-
use crate::ty::{Align, IndexedVal, Ty, VariantIdx};
11-
use crate::{Error, Opaque, error};
12+
use crate::stable_mir;
1213

1314
/// A function ABI definition.
1415
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
@@ -149,7 +150,7 @@ pub enum FieldsShape {
149150
Arbitrary {
150151
/// Offsets for the first byte of each field,
151152
/// ordered to match the source definition order.
152-
/// I.e.: It follows the same order as [crate::ty::VariantDef::fields()].
153+
/// I.e.: It follows the same order as [super::ty::VariantDef::fields()].
153154
/// This vector does not go in increasing order.
154155
offsets: Vec<Size>,
155156
},

compiler/stable_mir/src/compiler_interface.rs compiler/rustc_smir/src/stable_mir/compiler_interface.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
66
use std::cell::Cell;
77

8-
use crate::abi::{FnAbi, Layout, LayoutShape};
9-
use crate::crate_def::Attribute;
10-
use crate::mir::alloc::{AllocId, GlobalAlloc};
11-
use crate::mir::mono::{Instance, InstanceDef, StaticDef};
12-
use crate::mir::{BinOp, Body, Place, UnOp};
13-
use crate::target::MachineInfo;
14-
use crate::ty::{
8+
use stable_mir::abi::{FnAbi, Layout, LayoutShape};
9+
use stable_mir::crate_def::Attribute;
10+
use stable_mir::mir::alloc::{AllocId, GlobalAlloc};
11+
use stable_mir::mir::mono::{Instance, InstanceDef, StaticDef};
12+
use stable_mir::mir::{BinOp, Body, Place, UnOp};
13+
use stable_mir::target::MachineInfo;
14+
use stable_mir::ty::{
1515
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, FieldDef, FnDef, ForeignDef,
1616
ForeignItemKind, ForeignModule, ForeignModuleDef, GenericArgs, GenericPredicates, Generics,
1717
ImplDef, ImplTrait, IntrinsicDef, LineInfo, MirConst, PolyFnSig, RigidTy, Span, TraitDecl,
1818
TraitDef, Ty, TyConst, TyConstId, TyKind, UintTy, VariantDef,
1919
};
20-
use crate::{
20+
use stable_mir::{
2121
AssocItems, Crate, CrateItem, CrateItems, CrateNum, DefId, Error, Filename, ImplTraitDecls,
2222
ItemKind, Symbol, TraitDecls, mir,
2323
};
2424

25+
use crate::stable_mir;
26+
2527
/// This trait defines the interface between stable_mir and the Rust compiler.
2628
/// Do not use this directly.
2729
pub trait Context {

compiler/stable_mir/src/crate_def.rs compiler/rustc_smir/src/stable_mir/crate_def.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
//! such as, a function, a trait, an enum, and any other definitions.
33
44
use serde::Serialize;
5+
use stable_mir::ty::{GenericArgs, Span, Ty};
6+
use stable_mir::{AssocItems, Crate, Symbol, with};
57

6-
use crate::ty::{GenericArgs, Span, Ty};
7-
use crate::{AssocItems, Crate, Symbol, with};
8+
use crate::stable_mir;
89

910
/// A unique identification number for each item accessible for the current compilation unit.
1011
#[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)]
File renamed without changes.
File renamed without changes.

compiler/stable_mir/src/mir/alloc.rs compiler/rustc_smir/src/stable_mir/mir/alloc.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
use std::io::Read;
44

55
use serde::Serialize;
6+
use stable_mir::mir::mono::{Instance, StaticDef};
7+
use stable_mir::target::{Endian, MachineInfo};
8+
use stable_mir::ty::{Allocation, Binder, ExistentialTraitRef, IndexedVal, Ty};
9+
use stable_mir::{Error, with};
610

7-
use crate::mir::mono::{Instance, StaticDef};
8-
use crate::target::{Endian, MachineInfo};
9-
use crate::ty::{Allocation, Binder, ExistentialTraitRef, IndexedVal, Ty};
10-
use crate::{Error, with};
11+
use crate::stable_mir;
1112

1213
/// An allocation in the SMIR global memory can be either a function pointer,
1314
/// a static, or a "real" allocation with some data in it.

compiler/stable_mir/src/mir/body.rs compiler/rustc_smir/src/stable_mir/mir/body.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use std::io;
22

33
use serde::Serialize;
4-
5-
use crate::compiler_interface::with;
6-
use crate::mir::pretty::function_body;
7-
use crate::ty::{
4+
use stable_mir::compiler_interface::with;
5+
use stable_mir::mir::pretty::function_body;
6+
use stable_mir::ty::{
87
AdtDef, ClosureDef, CoroutineClosureDef, CoroutineDef, GenericArgs, MirConst, Movability,
98
Region, RigidTy, Ty, TyConst, TyKind, VariantIdx,
109
};
11-
use crate::{Error, Opaque, Span, Symbol};
10+
use stable_mir::{Error, Opaque, Span, Symbol};
11+
12+
use crate::stable_mir;
1213

1314
/// The SMIR representation of a single function.
1415
#[derive(Clone, Debug, Serialize)]
@@ -565,7 +566,7 @@ pub enum Rvalue {
565566
///
566567
/// **Needs clarification**: Are there weird additional semantics here related to the runtime
567568
/// nature of this operation?
568-
ThreadLocalRef(crate::CrateItem),
569+
ThreadLocalRef(stable_mir::CrateItem),
569570

570571
/// Computes a value as described by the operation.
571572
NullaryOp(NullOp, Ty),

compiler/stable_mir/src/mir/mono.rs compiler/rustc_smir/src/stable_mir/mir/mono.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use std::fmt::{Debug, Formatter};
22
use std::io;
33

44
use serde::Serialize;
5+
use stable_mir::abi::FnAbi;
6+
use stable_mir::crate_def::CrateDef;
7+
use stable_mir::mir::Body;
8+
use stable_mir::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty};
9+
use stable_mir::{CrateItem, DefId, Error, ItemKind, Opaque, Symbol, with};
510

6-
use crate::abi::FnAbi;
7-
use crate::crate_def::CrateDef;
8-
use crate::mir::Body;
9-
use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, IndexedVal, Ty};
10-
use crate::{CrateItem, DefId, Error, ItemKind, Opaque, Symbol, with};
11+
use crate::stable_mir;
1112

1213
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
1314
pub enum MonoItem {
@@ -117,11 +118,11 @@ impl Instance {
117118
}
118119

119120
/// Resolve an instance starting from a function definition and generic arguments.
120-
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, crate::Error> {
121+
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
121122
with(|context| {
122-
context.resolve_instance(def, args).ok_or_else(|| {
123-
crate::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
124-
})
123+
context
124+
.resolve_instance(def, args)
125+
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
125126
})
126127
}
127128

@@ -131,11 +132,11 @@ impl Instance {
131132
}
132133

133134
/// Resolve an instance for a given function pointer.
134-
pub fn resolve_for_fn_ptr(def: FnDef, args: &GenericArgs) -> Result<Instance, crate::Error> {
135+
pub fn resolve_for_fn_ptr(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
135136
with(|context| {
136-
context.resolve_for_fn_ptr(def, args).ok_or_else(|| {
137-
crate::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
138-
})
137+
context
138+
.resolve_for_fn_ptr(def, args)
139+
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
139140
})
140141
}
141142

@@ -144,11 +145,11 @@ impl Instance {
144145
def: ClosureDef,
145146
args: &GenericArgs,
146147
kind: ClosureKind,
147-
) -> Result<Instance, crate::Error> {
148+
) -> Result<Instance, Error> {
148149
with(|context| {
149-
context.resolve_closure(def, args, kind).ok_or_else(|| {
150-
crate::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
151-
})
150+
context
151+
.resolve_closure(def, args, kind)
152+
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
152153
})
153154
}
154155

@@ -195,7 +196,7 @@ impl Debug for Instance {
195196
/// Try to convert a crate item into an instance.
196197
/// The item cannot be generic in order to be converted into an instance.
197198
impl TryFrom<CrateItem> for Instance {
198-
type Error = crate::Error;
199+
type Error = stable_mir::Error;
199200

200201
fn try_from(item: CrateItem) -> Result<Self, Self::Error> {
201202
with(|context| {
@@ -212,7 +213,7 @@ impl TryFrom<CrateItem> for Instance {
212213
/// Try to convert an instance into a crate item.
213214
/// Only user defined instances can be converted.
214215
impl TryFrom<Instance> for CrateItem {
215-
type Error = crate::Error;
216+
type Error = stable_mir::Error;
216217

217218
fn try_from(value: Instance) -> Result<Self, Self::Error> {
218219
with(|context| {
@@ -259,7 +260,7 @@ crate_def! {
259260
}
260261

261262
impl TryFrom<CrateItem> for StaticDef {
262-
type Error = crate::Error;
263+
type Error = stable_mir::Error;
263264

264265
fn try_from(value: CrateItem) -> Result<Self, Self::Error> {
265266
if matches!(value.kind(), ItemKind::Static) {
@@ -271,7 +272,7 @@ impl TryFrom<CrateItem> for StaticDef {
271272
}
272273

273274
impl TryFrom<Instance> for StaticDef {
274-
type Error = crate::Error;
275+
type Error = stable_mir::Error;
275276

276277
fn try_from(value: Instance) -> Result<Self, Self::Error> {
277278
StaticDef::try_from(CrateItem::try_from(value)?)

compiler/stable_mir/src/mir/pretty.rs compiler/rustc_smir/src/stable_mir/mir/pretty.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ use std::io::Write;
44
use std::{fmt, io, iter};
55

66
use fmt::{Display, Formatter};
7-
8-
use super::{AggregateKind, AssertMessage, BinOp, BorrowKind, FakeBorrowKind, TerminatorKind};
9-
use crate::mir::{
7+
use stable_mir::mir::{
108
Operand, Place, RawPtrKind, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents,
119
};
12-
use crate::ty::{AdtKind, AssocKind, IndexedVal, MirConst, Ty, TyConst};
13-
use crate::{Body, CrateDef, Mutability, with};
10+
use stable_mir::ty::{AdtKind, AssocKind, IndexedVal, MirConst, Ty, TyConst};
11+
use stable_mir::{Body, CrateDef, Mutability, with};
12+
13+
use super::{AggregateKind, AssertMessage, BinOp, BorrowKind, FakeBorrowKind, TerminatorKind};
14+
use crate::stable_mir;
1415

1516
impl Display for Ty {
1617
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {

compiler/stable_mir/src/mir/visit.rs compiler/rustc_smir/src/stable_mir/mir/visit.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
//! The only place that `_` is acceptable is to match a field (or
3636
//! variant argument) that does not require visiting.
3737
38-
use crate::mir::*;
39-
use crate::ty::{GenericArgs, MirConst, Region, Ty, TyConst};
40-
use crate::{Error, Opaque, Span};
38+
use stable_mir::mir::*;
39+
use stable_mir::ty::{GenericArgs, MirConst, Region, Ty, TyConst};
40+
use stable_mir::{Error, Opaque, Span};
41+
42+
use crate::stable_mir;
4143

4244
macro_rules! make_mir_visitor {
4345
($visitor_trait_name:ident, $($mutability:ident)?) => {

0 commit comments

Comments
 (0)