Skip to content

Commit c42a9ac

Browse files
committed
move stable_mir back to its own crate and move rustc_internal to thestable_mir crate
As part of this reorganization, some traits need to be moved from `rustc_smir::context::traits` to `stable_mir::unstable::internal_cx`. These traits are specifically designed for `InternalCx` to clarify the behavior of different functions that share the same name. This move is necessary to avoid orphan rule violations.
1 parent fd9ca71 commit c42a9ac

File tree

38 files changed

+1241
-1291
lines changed

38 files changed

+1241
-1291
lines changed

Cargo.lock

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,9 +4540,6 @@ dependencies = [
45404540
"rustc_session",
45414541
"rustc_span",
45424542
"rustc_target",
4543-
"scoped-tls",
4544-
"serde",
4545-
"tracing",
45464543
]
45474544

45484545
[[package]]
@@ -5095,7 +5092,16 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
50955092
name = "stable_mir"
50965093
version = "0.1.0-preview"
50975094
dependencies = [
5095+
"rustc_abi",
5096+
"rustc_hir",
5097+
"rustc_middle",
5098+
"rustc_session",
50985099
"rustc_smir",
5100+
"rustc_span",
5101+
"rustc_target",
5102+
"scoped-tls",
5103+
"serde",
5104+
"tracing",
50995105
]
51005106

51015107
[[package]]

compiler/rustc_smir/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,4 @@ rustc_middle = { path = "../rustc_middle" }
1313
rustc_session = { path = "../rustc_session" }
1414
rustc_span = { path = "../rustc_span" }
1515
rustc_target = { path = "../rustc_target" }
16-
scoped-tls = "1.0"
17-
serde = { version = "1.0.125", features = [ "derive" ] }
18-
tracing = "0.1"
1916
# tidy-alphabetical-end

compiler/rustc_smir/src/rustc_smir/alloc.rs renamed to compiler/rustc_smir/src/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ use rustc_middle::mir::interpret::{
1111
use rustc_middle::ty::{Ty, layout};
1212

1313
use super::{SmirCtxt, Tables};
14-
use crate::rustc_smir::bridge::Allocation as _;
15-
use crate::rustc_smir::{Bridge, SmirError};
14+
use crate::bridge::Allocation as _;
15+
use crate::{Bridge, SmirError};
1616

1717
pub fn create_ty_and_layout<'tcx, B: Bridge>(
1818
cx: &SmirCtxt<'tcx, B>,
1919
ty: Ty<'tcx>,
2020
) -> Result<TyAndLayout<'tcx, Ty<'tcx>>, &'tcx layout::LayoutError<'tcx>> {
21-
use crate::rustc_smir::context::SmirTypingEnv;
21+
use crate::context::SmirTypingEnv;
2222
cx.tcx.layout_of(cx.fully_monomorphized().as_query_input(ty))
2323
}
2424

compiler/rustc_smir/src/rustc_smir/context/impls.rs renamed to compiler/rustc_smir/src/context/impls.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ use rustc_span::{FileNameDisplayPreference, Span, Symbol};
2525
use rustc_target::callconv::FnAbi;
2626

2727
use super::{SmirAllocRange, SmirCtxt, SmirTy, SmirTypingEnv};
28-
use crate::rustc_smir::builder::BodyBuilder;
29-
use crate::rustc_smir::{Bridge, SmirError, Tables, filter_def_ids};
28+
use crate::builder::BodyBuilder;
29+
use crate::{Bridge, SmirError, Tables, filter_def_ids};
3030

3131
impl<'tcx, B: Bridge> SmirTy<'tcx> for SmirCtxt<'tcx, B> {
3232
fn new_foreign(&self, def_id: DefId) -> ty::Ty<'tcx> {
@@ -426,7 +426,7 @@ impl<'tcx, B: Bridge> SmirCtxt<'tcx, B> {
426426

427427
/// Evaluate constant as a target usize.
428428
pub fn eval_target_usize(&self, cnst: MirConst<'tcx>) -> Result<u64, B::Error> {
429-
use crate::rustc_smir::context::SmirTypingEnv;
429+
use crate::context::SmirTypingEnv;
430430
cnst.try_eval_target_usize(self.tcx, self.fully_monomorphized())
431431
.ok_or_else(|| B::Error::new(format!("Const `{cnst:?}` cannot be encoded as u64")))
432432
}
@@ -436,10 +436,7 @@ impl<'tcx, B: Bridge> SmirCtxt<'tcx, B> {
436436
.ok_or_else(|| B::Error::new(format!("Const `{cnst:?}` cannot be encoded as u64")))
437437
}
438438

439-
pub(crate) fn try_new_const_zst(
440-
&self,
441-
ty_internal: Ty<'tcx>,
442-
) -> Result<MirConst<'tcx>, B::Error> {
439+
pub fn try_new_const_zst(&self, ty_internal: Ty<'tcx>) -> Result<MirConst<'tcx>, B::Error> {
443440
let size = self
444441
.tcx
445442
.layout_of(self.fully_monomorphized().as_query_input(ty_internal))

compiler/rustc_smir/src/rustc_smir/context/mod.rs renamed to compiler/rustc_smir/src/context/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::ty;
99
use rustc_middle::ty::layout::{FnAbiOfHelpers, HasTyCtxt, HasTypingEnv, LayoutOfHelpers};
1010
use rustc_middle::ty::{Ty, TyCtxt};
1111

12-
use crate::rustc_smir::{Bridge, SmirError};
12+
use crate::{Bridge, SmirError};
1313

1414
mod impls;
1515
mod traits;
@@ -18,7 +18,7 @@ pub use traits::*;
1818

1919
/// Provides direct access to rustc's internal queries.
2020
///
21-
/// The [`crate::stable_mir::compiler_interface::SmirInterface`] must go through
21+
/// `SmirInterface` must go through
2222
/// this context to obtain rustc-level information.
2323
pub struct SmirCtxt<'tcx, B: Bridge> {
2424
pub tcx: TyCtxt<'tcx>,

compiler/rustc_smir/src/rustc_smir/context/traits.rs renamed to compiler/rustc_smir/src/context/traits.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,6 @@ use rustc_middle::ty;
88
use rustc_middle::ty::Ty;
99
use rustc_span::def_id::DefId;
1010

11-
pub trait SmirExistentialProjection<'tcx> {
12-
fn new_from_args(
13-
&self,
14-
def_id: DefId,
15-
args: ty::GenericArgsRef<'tcx>,
16-
term: ty::Term<'tcx>,
17-
) -> ty::ExistentialProjection<'tcx>;
18-
}
19-
20-
pub trait SmirExistentialTraitRef<'tcx> {
21-
fn new_from_args(
22-
&self,
23-
trait_def_id: DefId,
24-
args: ty::GenericArgsRef<'tcx>,
25-
) -> ty::ExistentialTraitRef<'tcx>;
26-
}
27-
28-
pub trait SmirTraitRef<'tcx> {
29-
fn new_from_args(
30-
&self,
31-
trait_def_id: DefId,
32-
args: ty::GenericArgsRef<'tcx>,
33-
) -> ty::TraitRef<'tcx>;
34-
}
35-
3611
pub trait SmirTy<'tcx> {
3712
fn new_foreign(&self, def_id: DefId) -> Ty<'tcx>;
3813
}

0 commit comments

Comments
 (0)