use "helper" as a more descriptive name

This commit is contained in:
Makai
2025-07-15 13:51:55 +00:00
parent 7f22e88fab
commit ad0de062b5
10 changed files with 26 additions and 26 deletions

View File

@@ -59,7 +59,7 @@ pub(crate) fn try_new_allocation<'tcx>(
}
ConstValue::Indirect { alloc_id, offset } => {
let alloc = alloc::try_new_indirect(alloc_id, cx);
use rustc_public_bridge::context::SmirAllocRange;
use rustc_public_bridge::context::AllocRangeHelpers;
Ok(allocation_filter(&alloc.0, cx.alloc_range(offset, layout.size), tables, cx))
}
}

View File

@@ -567,7 +567,7 @@ impl<'tcx> CompilerInterface for Container<'tcx, BridgeTys> {
DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)),
DefKind::Static { .. } => ForeignItemKind::Static(tables.static_def(def_id)),
DefKind::ForeignTy => {
use rustc_public_bridge::context::SmirTy;
use rustc_public_bridge::context::TyHelpers;
ForeignItemKind::Type(tables.intern_ty(cx.new_foreign(def_id)))
}
def_kind => unreachable!("Unexpected kind for a foreign item: {:?}", def_kind),

View File

@@ -504,7 +504,7 @@ impl RustcInternal for ExistentialProjection {
tables: &mut Tables<'_, BridgeTys>,
tcx: impl InternalCx<'tcx>,
) -> Self::T<'tcx> {
use crate::unstable::internal_cx::SmirExistentialProjection;
use crate::unstable::internal_cx::ExistentialProjectionHelpers;
tcx.new_from_args(
self.def_id.0.internal(tables, tcx),
self.generic_args.internal(tables, tcx),
@@ -536,7 +536,7 @@ impl RustcInternal for ExistentialTraitRef {
tables: &mut Tables<'_, BridgeTys>,
tcx: impl InternalCx<'tcx>,
) -> Self::T<'tcx> {
use crate::unstable::internal_cx::SmirExistentialTraitRef;
use crate::unstable::internal_cx::ExistentialTraitRefHelpers;
tcx.new_from_args(
self.def_id.0.internal(tables, tcx),
self.generic_args.internal(tables, tcx),
@@ -552,7 +552,7 @@ impl RustcInternal for TraitRef {
tables: &mut Tables<'_, BridgeTys>,
tcx: impl InternalCx<'tcx>,
) -> Self::T<'tcx> {
use crate::unstable::internal_cx::SmirTraitRef;
use crate::unstable::internal_cx::TraitRefHelpers;
tcx.new_from_args(self.def_id.0.internal(tables, tcx), self.args().internal(tables, tcx))
}
}

View File

@@ -821,7 +821,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
tables: &mut Tables<'cx, BridgeTys>,
cx: &CompilerCtxt<'cx, BridgeTys>,
) -> Self::T {
use rustc_public_bridge::context::SmirAllocRange;
use rustc_public_bridge::context::AllocRangeHelpers;
alloc::allocation_filter(
self,
cx.alloc_range(rustc_abi::Size::ZERO, self.size()),

View File

@@ -5,7 +5,7 @@
use rustc_middle::ty;
pub(crate) trait SmirExistentialProjection<'tcx> {
pub(crate) trait ExistentialProjectionHelpers<'tcx> {
fn new_from_args(
&self,
def_id: rustc_span::def_id::DefId,
@@ -14,7 +14,7 @@ pub(crate) trait SmirExistentialProjection<'tcx> {
) -> ty::ExistentialProjection<'tcx>;
}
pub(crate) trait SmirExistentialTraitRef<'tcx> {
pub(crate) trait ExistentialTraitRefHelpers<'tcx> {
fn new_from_args(
&self,
trait_def_id: rustc_span::def_id::DefId,
@@ -22,7 +22,7 @@ pub(crate) trait SmirExistentialTraitRef<'tcx> {
) -> ty::ExistentialTraitRef<'tcx>;
}
pub(crate) trait SmirTraitRef<'tcx> {
pub(crate) trait TraitRefHelpers<'tcx> {
fn new_from_args(
&self,
trait_def_id: rustc_span::def_id::DefId,

View File

@@ -2,13 +2,13 @@
use rustc_middle::ty::{List, Ty, TyCtxt};
use rustc_middle::{mir, ty};
pub(crate) use traits::*;
pub(crate) use helpers::*;
use super::InternalCx;
pub(crate) mod traits;
pub(crate) mod helpers;
impl<'tcx, T: InternalCx<'tcx>> SmirExistentialProjection<'tcx> for T {
impl<'tcx, T: InternalCx<'tcx>> ExistentialProjectionHelpers<'tcx> for T {
fn new_from_args(
&self,
def_id: rustc_span::def_id::DefId,
@@ -19,7 +19,7 @@ impl<'tcx, T: InternalCx<'tcx>> SmirExistentialProjection<'tcx> for T {
}
}
impl<'tcx, T: InternalCx<'tcx>> SmirExistentialTraitRef<'tcx> for T {
impl<'tcx, T: InternalCx<'tcx>> ExistentialTraitRefHelpers<'tcx> for T {
fn new_from_args(
&self,
trait_def_id: rustc_span::def_id::DefId,
@@ -29,7 +29,7 @@ impl<'tcx, T: InternalCx<'tcx>> SmirExistentialTraitRef<'tcx> for T {
}
}
impl<'tcx, T: InternalCx<'tcx>> SmirTraitRef<'tcx> for T {
impl<'tcx, T: InternalCx<'tcx>> TraitRefHelpers<'tcx> for T {
fn new_from_args(
&self,
trait_def_id: rustc_span::def_id::DefId,

View File

@@ -18,7 +18,7 @@ pub fn create_ty_and_layout<'tcx, B: Bridge>(
cx: &CompilerCtxt<'tcx, B>,
ty: Ty<'tcx>,
) -> Result<TyAndLayout<'tcx, Ty<'tcx>>, &'tcx layout::LayoutError<'tcx>> {
use crate::context::SmirTypingEnv;
use crate::context::TypingEnvHelpers;
cx.tcx.layout_of(cx.fully_monomorphized().as_query_input(ty))
}

View File

@@ -1,6 +1,6 @@
//! A set of traits that define a stable interface to rustc's internals.
//!
//! These traits abstract rustc's internal APIs, allowing StableMIR to maintain a stable
//! These traits abstract rustc's internal APIs, allowing rustc_public to maintain a stable
//! interface regardless of internal compiler changes.
use rustc_middle::mir::interpret::AllocRange;
@@ -8,14 +8,14 @@ use rustc_middle::ty;
use rustc_middle::ty::Ty;
use rustc_span::def_id::DefId;
pub trait SmirTy<'tcx> {
pub trait TyHelpers<'tcx> {
fn new_foreign(&self, def_id: DefId) -> Ty<'tcx>;
}
pub trait SmirTypingEnv<'tcx> {
pub trait TypingEnvHelpers<'tcx> {
fn fully_monomorphized(&self) -> ty::TypingEnv<'tcx>;
}
pub trait SmirAllocRange<'tcx> {
pub trait AllocRangeHelpers<'tcx> {
fn alloc_range(&self, offset: rustc_abi::Size, size: rustc_abi::Size) -> AllocRange;
}

View File

@@ -24,23 +24,23 @@ use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_span::{FileNameDisplayPreference, Span, Symbol};
use rustc_target::callconv::FnAbi;
use super::{SmirAllocRange, CompilerCtxt, SmirTy, SmirTypingEnv};
use super::{AllocRangeHelpers, CompilerCtxt, TyHelpers, TypingEnvHelpers};
use crate::builder::BodyBuilder;
use crate::{Bridge, SmirError, Tables, filter_def_ids};
impl<'tcx, B: Bridge> SmirTy<'tcx> for CompilerCtxt<'tcx, B> {
impl<'tcx, B: Bridge> TyHelpers<'tcx> for CompilerCtxt<'tcx, B> {
fn new_foreign(&self, def_id: DefId) -> ty::Ty<'tcx> {
ty::Ty::new_foreign(self.tcx, def_id)
}
}
impl<'tcx, B: Bridge> SmirTypingEnv<'tcx> for CompilerCtxt<'tcx, B> {
impl<'tcx, B: Bridge> TypingEnvHelpers<'tcx> for CompilerCtxt<'tcx, B> {
fn fully_monomorphized(&self) -> ty::TypingEnv<'tcx> {
ty::TypingEnv::fully_monomorphized()
}
}
impl<'tcx, B: Bridge> SmirAllocRange<'tcx> for CompilerCtxt<'tcx, B> {
impl<'tcx, B: Bridge> AllocRangeHelpers<'tcx> for CompilerCtxt<'tcx, B> {
fn alloc_range(
&self,
offset: rustc_abi::Size,
@@ -426,7 +426,7 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> {
/// Evaluate constant as a target usize.
pub fn eval_target_usize(&self, cnst: MirConst<'tcx>) -> Result<u64, B::Error> {
use crate::context::SmirTypingEnv;
use crate::context::TypingEnvHelpers;
cnst.try_eval_target_usize(self.tcx, self.fully_monomorphized())
.ok_or_else(|| B::Error::new(format!("Const `{cnst:?}` cannot be encoded as u64")))
}

View File

@@ -12,9 +12,9 @@ use rustc_middle::ty::{Ty, TyCtxt};
use crate::{Bridge, SmirError};
mod impls;
mod traits;
mod helpers;
pub use traits::*;
pub use helpers::*;
/// Provides direct access to rustc's internal queries.
///