Skip to content

Commit 663e2b7

Browse files
committed
refactor: move convert module to stable_mir
note that this commit delete `convert/error.rs`, we would use `SmirError::from_internal` instead. **Unresolved questions:** - There are still a few direct calls to rustc's internals scattered across `impl Stable`s, but most of them appear to be relatively stable, e.g., `mir::interpret::ConstAllocation::inner(self)` and `mir::syntax::SwitchTargets::otherwise(self)`.
1 parent 0f6f683 commit 663e2b7

File tree

11 files changed

+1225
-668
lines changed

11 files changed

+1225
-668
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ 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::convert::{RustcInternal, Stable};
2021

2122
use crate::rustc_smir::context::SmirCtxt;
22-
use crate::rustc_smir::{Stable, Tables};
2323
use crate::rustc_smir::{Bridge, IndexedVal, SmirContainer, Tables};
2424
use crate::stable_mir;
2525

26-
mod internal;
2726
pub mod pretty;
2827

2928
/// Convert an internal Rust compiler item into its stable counterpart, if one exists.
@@ -340,11 +339,3 @@ impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> Index<V
340339
k
341340
}
342341
}
343-
344-
/// Trait used to translate a stable construct to its rustc counterpart.
345-
///
346-
/// This is basically a mirror of [crate::rustc_smir::Stable].
347-
pub trait RustcInternal {
348-
type T<'tcx>;
349-
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx>;
350-
}

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

Lines changed: 0 additions & 25 deletions
This file was deleted.

compiler/rustc_smir/src/rustc_smir/mod.rs

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

@@ -23,7 +22,6 @@ use crate::rustc_internal::IndexMap;
2322
pub mod alloc;
2423
mod builder;
2524
pub mod context;
26-
mod convert;
2725

2826
/// A container which is used for TLS.
2927
pub struct SmirContainer<'tcx, B: Bridge> {
@@ -155,79 +153,3 @@ where
155153
.collect()
156154
}
157155
}
158-
159-
/// Trait used to convert between an internal MIR type to a Stable MIR type.
160-
pub trait Stable<'cx>: PointeeSized {
161-
/// The stable representation of the type implementing Stable.
162-
type T;
163-
/// Converts an object to the equivalent Stable MIR representation.
164-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T;
165-
}
166-
167-
impl<'tcx, T> Stable<'tcx> for &T
168-
where
169-
T: Stable<'tcx>,
170-
{
171-
type T = T::T;
172-
173-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
174-
(*self).stable(tables)
175-
}
176-
}
177-
178-
impl<'tcx, T> Stable<'tcx> for Option<T>
179-
where
180-
T: Stable<'tcx>,
181-
{
182-
type T = Option<T::T>;
183-
184-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
185-
self.as_ref().map(|value| value.stable(tables))
186-
}
187-
}
188-
189-
impl<'tcx, T, E> Stable<'tcx> for Result<T, E>
190-
where
191-
T: Stable<'tcx>,
192-
E: Stable<'tcx>,
193-
{
194-
type T = Result<T::T, E::T>;
195-
196-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
197-
match self {
198-
Ok(val) => Ok(val.stable(tables)),
199-
Err(error) => Err(error.stable(tables)),
200-
}
201-
}
202-
}
203-
204-
impl<'tcx, T> Stable<'tcx> for &[T]
205-
where
206-
T: Stable<'tcx>,
207-
{
208-
type T = Vec<T::T>;
209-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
210-
self.iter().map(|e| e.stable(tables)).collect()
211-
}
212-
}
213-
214-
impl<'tcx, T, U> Stable<'tcx> for (T, U)
215-
where
216-
T: Stable<'tcx>,
217-
U: Stable<'tcx>,
218-
{
219-
type T = (T::T, U::T);
220-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
221-
(self.0.stable(tables), self.1.stable(tables))
222-
}
223-
}
224-
225-
impl<'tcx, T> Stable<'tcx> for RangeInclusive<T>
226-
where
227-
T: Stable<'tcx>,
228-
{
229-
type T = RangeInclusive<T::T>;
230-
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
231-
RangeInclusive::new(self.start().stable(tables), self.end().stable(tables))
232-
}
233-
}

compiler/rustc_smir/src/stable_mir/compiler_interface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::cell::Cell;
88
use rustc_hir::def::DefKind;
99
use rustc_smir::{Bridge, SmirContainer, Tables};
1010
use stable_mir::abi::{FnAbi, Layout, LayoutShape, ReprOptions};
11+
use stable_mir::convert::{RustcInternal, Stable};
1112
use stable_mir::crate_def::Attribute;
1213
use stable_mir::mir::alloc::{AllocId, GlobalAlloc};
1314
use stable_mir::mir::mono::{Instance, InstanceDef, StaticDef};

0 commit comments

Comments
 (0)