Revert changes to internal method for now
- Move fix to a separate PR
This commit is contained in:
parent
2564811e7b
commit
6a573cbc60
3 changed files with 6 additions and 31 deletions
|
@ -24,35 +24,11 @@ use std::ops::Index;
|
||||||
mod internal;
|
mod internal;
|
||||||
pub mod pretty;
|
pub mod pretty;
|
||||||
|
|
||||||
/// Convert an internal Rust compiler item into its stable counterpart, if one exists.
|
|
||||||
///
|
|
||||||
/// # Warning
|
|
||||||
///
|
|
||||||
/// This function is unstable, and its behavior may change at any point.
|
|
||||||
/// E.g.: Items that were previously supported, may no longer be supported, or its translation may
|
|
||||||
/// change.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This function will panic if StableMIR has not been properly initialized.
|
|
||||||
pub fn stable<'tcx, S: Stable<'tcx>>(item: S) -> S::T {
|
pub fn stable<'tcx, S: Stable<'tcx>>(item: S) -> S::T {
|
||||||
with_tables(|tables| item.stable(tables))
|
with_tables(|tables| item.stable(tables))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert a stable item into its internal Rust compiler counterpart, if one exists.
|
pub fn internal<'tcx, S: RustcInternal<'tcx>>(item: S) -> S::T {
|
||||||
///
|
|
||||||
/// # Warning
|
|
||||||
///
|
|
||||||
/// This function is unstable, and it's behavior may change at any point.
|
|
||||||
/// Not every stable item can be converted to an internal one.
|
|
||||||
/// Furthermore, items that were previously supported, may no longer be supported in newer versions.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This function will panic if StableMIR has not been properly initialized.
|
|
||||||
pub fn internal<'tcx, S: RustcInternal<'tcx>>(tcx: TyCtxt<'tcx>, item: S) -> S::T {
|
|
||||||
// The tcx argument ensures that the item won't outlive the type context.
|
|
||||||
let _ = tcx;
|
|
||||||
with_tables(|tables| item.internal(tables))
|
with_tables(|tables| item.internal(tables))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +269,7 @@ macro_rules! optional {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prefer using [run] and [run_with_tcx] instead.
|
/// Prefer using [run!] and [run_with_tcx] instead.
|
||||||
///
|
///
|
||||||
/// This macro implements the instantiation of a StableMIR driver, and it will invoke
|
/// This macro implements the instantiation of a StableMIR driver, and it will invoke
|
||||||
/// the given callback after the compiler analyses.
|
/// the given callback after the compiler analyses.
|
||||||
|
|
|
@ -29,7 +29,7 @@ use stable_mir::{Crate, CrateItem, CrateNum, DefId, Error, Filename, ItemKind, S
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use crate::rustc_internal::RustcInternal;
|
use crate::rustc_internal::{internal, RustcInternal};
|
||||||
use crate::rustc_smir::builder::BodyBuilder;
|
use crate::rustc_smir::builder::BodyBuilder;
|
||||||
use crate::rustc_smir::{alloc, new_item_kind, smir_crate, Stable, Tables};
|
use crate::rustc_smir::{alloc, new_item_kind, smir_crate, Stable, Tables};
|
||||||
|
|
||||||
|
@ -322,8 +322,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
|
fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
|
||||||
let mut tables = self.0.borrow_mut();
|
internal(cnst).to_string()
|
||||||
cnst.internal(&mut *tables).to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
|
fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
|
||||||
|
|
|
@ -26,11 +26,11 @@ use std::ops::ControlFlow;
|
||||||
|
|
||||||
const CRATE_NAME: &str = "input";
|
const CRATE_NAME: &str = "input";
|
||||||
|
|
||||||
fn test_translation(tcx: TyCtxt) -> ControlFlow<()> {
|
fn test_translation(_tcx: TyCtxt) -> ControlFlow<()> {
|
||||||
let main_fn = stable_mir::entry_fn().unwrap();
|
let main_fn = stable_mir::entry_fn().unwrap();
|
||||||
let body = main_fn.body();
|
let body = main_fn.body();
|
||||||
let orig_ty = body.locals()[0].ty;
|
let orig_ty = body.locals()[0].ty;
|
||||||
let rustc_ty = rustc_internal::internal(tcx, &orig_ty);
|
let rustc_ty = rustc_internal::internal(&orig_ty);
|
||||||
assert!(rustc_ty.is_unit());
|
assert!(rustc_ty.is_unit());
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue