From 19f1d782d51d980ccb5c448e6a415188323b30ce Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 18 Sep 2023 14:47:39 +0000 Subject: [PATCH] Move `Opaque` to `stable_mir` --- compiler/rustc_smir/src/rustc_internal/mod.rs | 21 ------------------ compiler/rustc_smir/src/rustc_smir/mod.rs | 3 +-- compiler/rustc_smir/src/stable_mir/fold.rs | 11 +++++----- .../rustc_smir/src/stable_mir/mir/body.rs | 2 +- compiler/rustc_smir/src/stable_mir/mod.rs | 22 +++++++++++++++++-- compiler/rustc_smir/src/stable_mir/ty.rs | 3 +-- compiler/rustc_smir/src/stable_mir/visitor.rs | 11 +++++----- 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/rustc_smir/src/rustc_internal/mod.rs index f60332fc226..6d55676c645 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/rustc_smir/src/rustc_internal/mod.rs @@ -3,7 +3,6 @@ //! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs //! until stable MIR is complete. -use std::fmt::Debug; use std::ops::{ControlFlow, Index}; use crate::rustc_internal; @@ -136,26 +135,6 @@ pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) { ); } -/// A type that provides internal information but that can still be used for debug purpose. -#[derive(Clone)] -pub struct Opaque(String); - -impl std::fmt::Display for Opaque { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - -impl std::fmt::Debug for Opaque { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } -} - -pub(crate) fn opaque(value: &T) -> Opaque { - Opaque(format!("{value:?}")) -} - pub struct StableMir where B: Send, diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 3c6442396a8..690cc97c748 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -7,12 +7,11 @@ //! //! For now, we are developing everything inside `rustc`, thus, we keep this module private. -use crate::rustc_internal::opaque; use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx}; use crate::stable_mir::ty::{ FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy, }; -use crate::stable_mir::{self, CompilerError, Context}; +use crate::stable_mir::{self, opaque, CompilerError, Context}; use hir::def::DefKind; use rustc_hir as hir; use rustc_middle::mir; diff --git a/compiler/rustc_smir/src/stable_mir/fold.rs b/compiler/rustc_smir/src/stable_mir/fold.rs index 831cfb40a15..d09386cff3a 100644 --- a/compiler/rustc_smir/src/stable_mir/fold.rs +++ b/compiler/rustc_smir/src/stable_mir/fold.rs @@ -1,10 +1,11 @@ use std::ops::ControlFlow; -use crate::rustc_internal::Opaque; - -use super::ty::{ - Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, GenericArgKind, - GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst, +use super::{ + ty::{ + Allocation, Binder, Const, ConstDef, ConstantKind, ExistentialPredicate, FnSig, + GenericArgKind, GenericArgs, Promoted, RigidTy, TermKind, Ty, TyKind, UnevaluatedConst, + }, + Opaque, }; pub trait Folder: Sized { diff --git a/compiler/rustc_smir/src/stable_mir/mir/body.rs b/compiler/rustc_smir/src/stable_mir/mir/body.rs index 449ca4b8145..c288df3c2b6 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/body.rs +++ b/compiler/rustc_smir/src/stable_mir/mir/body.rs @@ -1,7 +1,7 @@ -use crate::rustc_internal::Opaque; use crate::stable_mir::ty::{ AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region, }; +use crate::stable_mir::Opaque; use crate::stable_mir::{self, ty::Ty, Span}; #[derive(Clone, Debug)] diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 312cb9ec0b2..3679a20a72d 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -15,8 +15,6 @@ use std::cell::Cell; use std::fmt; use std::fmt::Debug; -use crate::rustc_internal::Opaque; - use self::ty::{ GenericPredicates, Generics, ImplDef, ImplTrait, Span, TraitDecl, TraitDef, Ty, TyKind, }; @@ -210,3 +208,23 @@ pub(crate) fn with(f: impl FnOnce(&mut dyn Context) -> R) -> R { f(unsafe { *(ptr as *mut &mut dyn Context) }) }) } + +/// A type that provides internal information but that can still be used for debug purpose. +#[derive(Clone)] +pub struct Opaque(String); + +impl std::fmt::Display for Opaque { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + +impl std::fmt::Debug for Opaque { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self.0) + } +} + +pub(crate) fn opaque(value: &T) -> Opaque { + Opaque(format!("{value:?}")) +} diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 3f665212f26..92ff4711408 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -1,9 +1,8 @@ use super::{ mir::Safety, mir::{Body, Mutability}, - with, AllocId, DefId, + with, AllocId, DefId, Opaque, }; -use crate::rustc_internal::Opaque; use std::fmt::{self, Debug, Formatter}; #[derive(Copy, Clone)] diff --git a/compiler/rustc_smir/src/stable_mir/visitor.rs b/compiler/rustc_smir/src/stable_mir/visitor.rs index c86063d2ed6..d6a31c99c1e 100644 --- a/compiler/rustc_smir/src/stable_mir/visitor.rs +++ b/compiler/rustc_smir/src/stable_mir/visitor.rs @@ -1,10 +1,11 @@ use std::ops::ControlFlow; -use crate::rustc_internal::Opaque; - -use super::ty::{ - Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs, - Promoted, RigidTy, TermKind, Ty, UnevaluatedConst, +use super::{ + ty::{ + Allocation, Binder, Const, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, + GenericArgs, Promoted, RigidTy, TermKind, Ty, UnevaluatedConst, + }, + Opaque, }; pub trait Visitor: Sized {