Skip to content

Commit 7f5e382

Browse files
committed
refactor: make SmirInterface a trait and impl it for SmirContainer
- rewrite all `SmirInterface` apis. - add `BridgeTys` to impl those associated types in `Bridge`. - move `**_def()` stuffs living in `impl Tables` from `rustc_internal` to `stable_mir`.
1 parent d0130ae commit 7f5e382

File tree

5 files changed

+912
-255
lines changed

5 files changed

+912
-255
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use rustc_span::Span;
1717
use rustc_span::def_id::{CrateNum, DefId};
1818
use scoped_tls::scoped_thread_local;
1919
use stable_mir::Error;
20-
use stable_mir::compiler_interface::SmirInterface;
2120
use stable_mir::ty::IndexedVal;
2221

2322
use crate::rustc_smir::context::SmirCtxt;

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010
use std::marker::PointeeSized;
11-
use std::ops::RangeInclusive;
1211
use std::cell::RefCell;
1312
use std::fmt::Debug;
1413

@@ -18,8 +17,6 @@ use rustc_middle::mir;
1817
use rustc_middle::mir::interpret::AllocId;
1918
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2019
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
21-
use stable_mir::{CtorKind, ItemKind};
22-
use tracing::debug;
2320

2421
use crate::rustc_internal::IndexMap;
2522
use crate::stable_mir;
@@ -154,51 +151,6 @@ where
154151
}
155152
}
156153

157-
/// Build a stable mir crate from a given crate number.
158-
pub(crate) fn smir_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> stable_mir::Crate {
159-
let crate_name = tcx.crate_name(crate_num).to_string();
160-
let is_local = crate_num == LOCAL_CRATE;
161-
debug!(?crate_name, ?crate_num, "smir_crate");
162-
stable_mir::Crate { id: crate_num.into(), name: crate_name, is_local }
163-
}
164-
165-
pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
166-
match kind {
167-
DefKind::Mod
168-
| DefKind::Struct
169-
| DefKind::Union
170-
| DefKind::Enum
171-
| DefKind::Variant
172-
| DefKind::Trait
173-
| DefKind::TyAlias
174-
| DefKind::ForeignTy
175-
| DefKind::TraitAlias
176-
| DefKind::AssocTy
177-
| DefKind::TyParam
178-
| DefKind::ConstParam
179-
| DefKind::Macro(_)
180-
| DefKind::ExternCrate
181-
| DefKind::Use
182-
| DefKind::ForeignMod
183-
| DefKind::OpaqueTy
184-
| DefKind::Field
185-
| DefKind::LifetimeParam
186-
| DefKind::Impl { .. }
187-
| DefKind::GlobalAsm => {
188-
unreachable!("Not a valid item kind: {kind:?}");
189-
}
190-
DefKind::Closure | DefKind::AssocFn | DefKind::Fn | DefKind::SyntheticCoroutineBody => {
191-
ItemKind::Fn
192-
}
193-
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
194-
ItemKind::Const
195-
}
196-
DefKind::Static { .. } => ItemKind::Static,
197-
DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
198-
DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),
199-
}
200-
}
201-
202154
/// Trait used to convert between an internal MIR type to a Stable MIR type.
203155
pub trait Stable<'cx>: PointeeSized {
204156
/// The stable representation of the type implementing Stable.

0 commit comments

Comments
 (0)