diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/attributes.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/errors.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/const_eval/eval_queries.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/call.rs | 36 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/stack.rs | 38 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/mbe/macro_rules.rs | 50 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/inline/cycle.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_smir/Cargo.toml | 3 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/alloc.rs (renamed from compiler/rustc_smir/src/rustc_smir/alloc.rs) | 6 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/bridge.rs (renamed from compiler/rustc_smir/src/rustc_smir/bridge.rs) | 0 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/builder.rs (renamed from compiler/rustc_smir/src/rustc_smir/builder.rs) | 0 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/context/impls.rs (renamed from compiler/rustc_smir/src/rustc_smir/context/impls.rs) | 11 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/context/mod.rs (renamed from compiler/rustc_smir/src/rustc_smir/context/mod.rs) | 4 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/context/traits.rs (renamed from compiler/rustc_smir/src/rustc_smir/context/traits.rs) | 25 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/lib.rs | 288 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/mod.rs | 286 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/stable_mir/mod.rs | 304 | ||||
| -rw-r--r-- | compiler/stable_mir/Cargo.toml | 11 | ||||
| -rw-r--r-- | compiler/stable_mir/src/abi.rs (renamed from compiler/rustc_smir/src/stable_mir/abi.rs) | 13 | ||||
| -rw-r--r-- | compiler/stable_mir/src/alloc.rs (renamed from compiler/rustc_smir/src/stable_mir/alloc.rs) | 1 | ||||
| -rw-r--r-- | compiler/stable_mir/src/compiler_interface.rs (renamed from compiler/rustc_smir/src/stable_mir/compiler_interface.rs) | 95 | ||||
| -rw-r--r-- | compiler/stable_mir/src/crate_def.rs (renamed from compiler/rustc_smir/src/stable_mir/crate_def.rs) | 5 | ||||
| -rw-r--r-- | compiler/stable_mir/src/error.rs (renamed from compiler/rustc_smir/src/stable_mir/error.rs) | 2 | ||||
| -rw-r--r-- | compiler/stable_mir/src/lib.rs | 301 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir.rs (renamed from compiler/rustc_smir/src/stable_mir/mir.rs) | 0 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir/alloc.rs (renamed from compiler/rustc_smir/src/stable_mir/mir/alloc.rs) | 9 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir/body.rs (renamed from compiler/rustc_smir/src/stable_mir/mir/body.rs) | 13 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir/mono.rs (renamed from compiler/rustc_smir/src/stable_mir/mir/mono.rs) | 19 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir/pretty.rs (renamed from compiler/rustc_smir/src/stable_mir/mir/pretty.rs) | 11 | ||||
| -rw-r--r-- | compiler/stable_mir/src/mir/visit.rs (renamed from compiler/rustc_smir/src/stable_mir/mir/visit.rs) | 8 | ||||
| -rw-r--r-- | compiler/stable_mir/src/rustc_internal/mod.rs (renamed from compiler/rustc_smir/src/rustc_internal/mod.rs) | 17 | ||||
| -rw-r--r-- | compiler/stable_mir/src/rustc_internal/pretty.rs (renamed from compiler/rustc_smir/src/rustc_internal/pretty.rs) | 3 | ||||
| -rw-r--r-- | compiler/stable_mir/src/target.rs (renamed from compiler/rustc_smir/src/stable_mir/target.rs) | 3 | ||||
| -rw-r--r-- | compiler/stable_mir/src/ty.rs (renamed from compiler/rustc_smir/src/stable_mir/ty.rs) | 15 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/convert/internal.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/convert/internal.rs) | 25 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/convert/mod.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/convert/mod.rs) | 3 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/convert/stable/abi.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/convert/stable/abi.rs) | 21 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/convert/stable/mir.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/convert/stable/mir.rs) | 431 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/convert/stable/mod.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/convert/stable/mod.rs) | 37 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/convert/stable/ty.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/convert/stable/ty.rs) | 326 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/internal_cx/mod.rs | 93 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/internal_cx/traits.rs | 31 | ||||
| -rw-r--r-- | compiler/stable_mir/src/unstable/mod.rs (renamed from compiler/rustc_smir/src/stable_mir/unstable/mod.rs) | 94 | ||||
| -rw-r--r-- | compiler/stable_mir/src/visitor.rs (renamed from compiler/rustc_smir/src/stable_mir/visitor.rs) | 6 |
46 files changed, 1320 insertions, 1381 deletions
diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index adb53e0b66c..1ea5a062254 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -370,22 +370,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( }; to_add.extend(inline_attr(cx, inline)); - // The `uwtable` attribute according to LLVM is: - // - // This attribute indicates that the ABI being targeted requires that an - // unwind table entry be produced for this function even if we can show - // that no exceptions passes by it. This is normally the case for the - // ELF x86-64 abi, but it can be disabled for some compilation units. - // - // Typically when we're compiling with `-C panic=abort` (which implies this - // `no_landing_pads` check) we don't need `uwtable` because we can't - // generate any exceptions! On Windows, however, exceptions include other - // events such as illegal instructions, segfaults, etc. This means that on - // Windows we end up still needing the `uwtable` attribute even if the `-C - // panic=abort` flag is passed. - // - // You can also find more info on why Windows always requires uwtables here: - // https://bugzilla.mozilla.org/show_bug.cgi?id=1302078 if cx.sess().must_emit_unwind_tables() { to_add.push(uwtable_attr(cx.llcx, cx.sess().opts.unstable_opts.use_sync_unwind)); } diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 086c069745c..e042fe1f819 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -457,7 +457,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> { } else if arg.as_encoded_bytes().ends_with(b".rlib") { let rlib_path = Path::new(&arg); let dir = rlib_path.parent().unwrap(); - let filename = rlib_path.file_name().unwrap().to_owned(); + let filename = rlib_path.file_stem().unwrap().to_owned(); if let Some(ArgGroup::Rlibs(parent, rlibs)) = args.last_mut() { if parent == dir { rlibs.push(filename); @@ -471,7 +471,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> { args.push(ArgGroup::Regular(arg)); } } - let crate_hash = regex::bytes::Regex::new(r"-[0-9a-f]+\.rlib$").unwrap(); + let crate_hash = regex::bytes::Regex::new(r"-[0-9a-f]+").unwrap(); self.command.args(args.into_iter().map(|arg_group| { match arg_group { // SAFETY: we are only matching on ASCII, not any surrogate pairs, so any replacements we do will still be valid. @@ -494,7 +494,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> { Err(_) => false, }; let mut arg = dir.into_os_string(); - arg.push("/{"); + arg.push("/"); + let needs_braces = rlibs.len() >= 2; + if needs_braces { + arg.push("{"); + } let mut first = true; for mut rlib in rlibs { if !first { @@ -513,7 +517,10 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> { } arg.push(rlib); } - arg.push("}.rlib"); + if needs_braces { + arg.push("}"); + } + arg.push(".rlib"); arg } } diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 08e1877f0eb..4bd4b493009 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -19,7 +19,7 @@ use super::{CanAccessMutGlobal, CompileTimeInterpCx, CompileTimeMachine}; use crate::const_eval::CheckAlignment; use crate::interpret::{ CtfeValidationMode, GlobalId, Immediate, InternKind, InternResult, InterpCx, InterpErrorKind, - InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, StackPopCleanup, create_static_alloc, + InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, ReturnContinuation, create_static_alloc, intern_const_alloc_recursive, interp_ok, throw_exhaust, }; use crate::{CTRL_C_RECEIVED, errors}; @@ -76,7 +76,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>( cid.instance, body, &ret.clone().into(), - StackPopCleanup::Root { cleanup: false }, + ReturnContinuation::Stop { cleanup: false }, )?; ecx.storage_live_for_always_live_locals()?; diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index ebaa5a97a4a..ad3e02580f3 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -15,7 +15,7 @@ use tracing::{info, instrument, trace}; use super::{ CtfeProvenance, FnVal, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, PlaceTy, - Projectable, Provenance, ReturnAction, Scalar, StackPopCleanup, StackPopInfo, interp_ok, + Projectable, Provenance, ReturnAction, ReturnContinuation, Scalar, StackPopInfo, interp_ok, throw_ub, throw_ub_custom, throw_unsup_format, }; use crate::fluent_generated as fluent; @@ -340,7 +340,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { args: &[FnArg<'tcx, M::Provenance>], with_caller_location: bool, destination: &PlaceTy<'tcx, M::Provenance>, - mut stack_pop: StackPopCleanup, + mut cont: ReturnContinuation, ) -> InterpResult<'tcx> { // Compute callee information. // FIXME: for variadic support, do we have to somehow determine callee's extra_args? @@ -365,15 +365,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { if !callee_fn_abi.can_unwind { // The callee cannot unwind, so force the `Unreachable` unwind handling. - match &mut stack_pop { - StackPopCleanup::Root { .. } => {} - StackPopCleanup::Goto { unwind, .. } => { + match &mut cont { + ReturnContinuation::Stop { .. } => {} + ReturnContinuation::Goto { unwind, .. } => { *unwind = mir::UnwindAction::Unreachable; } } } - self.push_stack_frame_raw(instance, body, destination, stack_pop)?; + self.push_stack_frame_raw(instance, body, destination, cont)?; // If an error is raised here, pop the frame again to get an accurate backtrace. // To this end, we wrap it all in a `try` block. @@ -617,7 +617,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { &args, with_caller_location, destination, - StackPopCleanup::Goto { ret: target, unwind }, + ReturnContinuation::Goto { ret: target, unwind }, ) } // `InstanceKind::Virtual` does not have callable MIR. Calls to `Virtual` instances must be @@ -755,8 +755,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // Note that we are using `pop_stack_frame_raw` and not `return_from_current_stack_frame`, // as the latter "executes" the goto to the return block, but we don't want to, // only the tail called function should return to the current return block. - let StackPopInfo { return_action, return_to_block, return_place } = self - .pop_stack_frame_raw(false, |_this, _return_place| { + let StackPopInfo { return_action, return_cont, return_place } = + self.pop_stack_frame_raw(false, |_this, _return_place| { // This function's return value is just discarded, the tail-callee will fill in the return place instead. interp_ok(()) })?; @@ -764,7 +764,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { assert_eq!(return_action, ReturnAction::Normal); // Take the "stack pop cleanup" info, and use that to initiate the next call. - let StackPopCleanup::Goto { ret, unwind } = return_to_block else { + let ReturnContinuation::Goto { ret, unwind } = return_cont else { bug!("can't tailcall as root"); }; @@ -896,23 +896,23 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // Normal return, figure out where to jump. if unwinding { // Follow the unwind edge. - match stack_pop_info.return_to_block { - StackPopCleanup::Goto { unwind, .. } => { + match stack_pop_info.return_cont { + ReturnContinuation::Goto { unwind, .. } => { // This must be the very last thing that happens, since it can in fact push a new stack frame. self.unwind_to_block(unwind) } - StackPopCleanup::Root { .. } => { - panic!("encountered StackPopCleanup::Root when unwinding!") + ReturnContinuation::Stop { .. } => { + panic!("encountered ReturnContinuation::Stop when unwinding!") } } } else { // Follow the normal return edge. - match stack_pop_info.return_to_block { - StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret), - StackPopCleanup::Root { .. } => { + match stack_pop_info.return_cont { + ReturnContinuation::Goto { ret, .. } => self.return_to_block(ret), + ReturnContinuation::Stop { .. } => { assert!( self.stack().is_empty(), - "only the bottommost frame can have StackPopCleanup::Root" + "only the bottommost frame can have ReturnContinuation::Stop" ); interp_ok(()) } diff --git a/compiler/rustc_const_eval/src/interpret/mod.rs b/compiler/rustc_const_eval/src/interpret/mod.rs index f8b3c92debb..8303f891f98 100644 --- a/compiler/rustc_const_eval/src/interpret/mod.rs +++ b/compiler/rustc_const_eval/src/interpret/mod.rs @@ -36,7 +36,7 @@ pub use self::operand::{ImmTy, Immediate, OpTy}; pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable}; use self::place::{MemPlace, Place}; pub use self::projection::{OffsetMode, Projectable}; -pub use self::stack::{Frame, FrameInfo, LocalState, StackPopCleanup, StackPopInfo}; +pub use self::stack::{Frame, FrameInfo, LocalState, ReturnContinuation, StackPopInfo}; pub(crate) use self::util::create_static_alloc; pub use self::validity::{CtfeValidationMode, RangeSet, RefTracking}; pub use self::visitor::ValueVisitor; diff --git a/compiler/rustc_const_eval/src/interpret/stack.rs b/compiler/rustc_const_eval/src/interpret/stack.rs index 543d68d7f45..b6ba069526c 100644 --- a/compiler/rustc_const_eval/src/interpret/stack.rs +++ b/compiler/rustc_const_eval/src/interpret/stack.rs @@ -72,8 +72,8 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> { //////////////////////////////////////////////////////////////////////////////// // Return place and locals //////////////////////////////////////////////////////////////////////////////// - /// Work to perform when returning from this function. - return_to_block: StackPopCleanup, + /// Where to continue when returning from this function. + return_cont: ReturnContinuation, /// The location where the result of the current stack frame should be written to, /// and its layout in the caller. This place is to be interpreted relative to the @@ -106,19 +106,19 @@ pub struct Frame<'tcx, Prov: Provenance = CtfeProvenance, Extra = ()> { pub(super) loc: Either<mir::Location, Span>, } +/// Where and how to continue when returning/unwinding from the current function. #[derive(Clone, Copy, Eq, PartialEq, Debug)] // Miri debug-prints these -pub enum StackPopCleanup { +pub enum ReturnContinuation { /// Jump to the next block in the caller, or cause UB if None (that's a function - /// that may never return). Also store layout of return place so - /// we can validate it at that layout. + /// that may never return). /// `ret` stores the block we jump to on a normal return, while `unwind` /// stores the block used for cleanup during unwinding. Goto { ret: Option<mir::BasicBlock>, unwind: mir::UnwindAction }, - /// The root frame of the stack: nowhere else to jump to. + /// The root frame of the stack: nowhere else to jump to, so we stop. /// `cleanup` says whether locals are deallocated. Static computation /// wants them leaked to intern what they need (and just throw away /// the entire `ecx` when it is done). - Root { cleanup: bool }, + Stop { cleanup: bool }, } /// Return type of [`InterpCx::pop_stack_frame_raw`]. @@ -127,8 +127,8 @@ pub struct StackPopInfo<'tcx, Prov: Provenance> { /// stack frame. pub return_action: ReturnAction, - /// [`return_to_block`](Frame::return_to_block) of the popped stack frame. - pub return_to_block: StackPopCleanup, + /// [`return_cont`](Frame::return_cont) of the popped stack frame. + pub return_cont: ReturnContinuation, /// [`return_place`](Frame::return_place) of the popped stack frame. pub return_place: PlaceTy<'tcx, Prov>, @@ -255,7 +255,7 @@ impl<'tcx, Prov: Provenance> Frame<'tcx, Prov> { Frame { body: self.body, instance: self.instance, - return_to_block: self.return_to_block, + return_cont: self.return_cont, return_place: self.return_place, locals: self.locals, loc: self.loc, @@ -350,20 +350,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// the arguments or local variables. /// /// The high-level version of this is `init_stack_frame`. - #[instrument(skip(self, body, return_place, return_to_block), level = "debug")] + #[instrument(skip(self, body, return_place, return_cont), level = "debug")] pub(crate) fn push_stack_frame_raw( &mut self, instance: ty::Instance<'tcx>, body: &'tcx mir::Body<'tcx>, return_place: &PlaceTy<'tcx, M::Provenance>, - return_to_block: StackPopCleanup, + return_cont: ReturnContinuation, ) -> InterpResult<'tcx> { trace!("body: {:#?}", body); // We can push a `Root` frame if and only if the stack is empty. debug_assert_eq!( self.stack().is_empty(), - matches!(return_to_block, StackPopCleanup::Root { .. }) + matches!(return_cont, ReturnContinuation::Stop { .. }) ); // First push a stack frame so we have access to `instantiate_from_current_frame` and other @@ -373,7 +373,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let pre_frame = Frame { body, loc: Right(body.span), // Span used for errors caused during preamble. - return_to_block, + return_cont, return_place: return_place.clone(), locals, instance, @@ -429,15 +429,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { copy_ret_val(self, &frame.return_place)?; } - let return_to_block = frame.return_to_block; + let return_cont = frame.return_cont; let return_place = frame.return_place.clone(); // Cleanup: deallocate locals. // Usually we want to clean up (deallocate locals), but in a few rare cases we don't. // We do this while the frame is still on the stack, so errors point to the callee. - let cleanup = match return_to_block { - StackPopCleanup::Goto { .. } => true, - StackPopCleanup::Root { cleanup, .. } => cleanup, + let cleanup = match return_cont { + ReturnContinuation::Goto { .. } => true, + ReturnContinuation::Stop { cleanup, .. } => cleanup, }; let return_action = if cleanup { @@ -455,7 +455,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ReturnAction::NoCleanup }; - interp_ok(StackPopInfo { return_action, return_to_block, return_place }) + interp_ok(StackPopInfo { return_action, return_cont, return_place }) } /// In the current stack frame, mark all locals as live that are not arguments and don't have diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 52cdcc5c747..89547088f50 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -373,17 +373,10 @@ pub fn compile_declarative_macro( node_id: NodeId, edition: Edition, ) -> (SyntaxExtension, usize) { + let is_local = node_id != DUMMY_NODE_ID; let mk_syn_ext = |expander| { - SyntaxExtension::new( - sess, - SyntaxExtensionKind::LegacyBang(expander), - span, - Vec::new(), - edition, - ident.name, - attrs, - node_id != DUMMY_NODE_ID, - ) + let kind = SyntaxExtensionKind::LegacyBang(expander); + SyntaxExtension::new(sess, kind, span, Vec::new(), edition, ident.name, attrs, is_local) }; let dummy_syn_ext = |guar| (mk_syn_ext(Arc::new(DummyExpander(guar))), 0); @@ -393,7 +386,8 @@ pub fn compile_declarative_macro( let body = macro_def.body.tokens.clone(); let mut p = Parser::new(&sess.psess, body, rustc_parse::MACRO_ARGUMENTS); - // Don't abort iteration early, so that multiple errors can be reported. + // Don't abort iteration early, so that multiple errors can be reported. We only abort early on + // parse failures we can't recover from. let mut guar = None; let mut check_emission = |ret: Result<(), ErrorGuaranteed>| guar = guar.or(ret.err()); @@ -402,20 +396,11 @@ pub fn compile_declarative_macro( while p.token != token::Eof { let lhs_tt = p.parse_token_tree(); let lhs_tt = parse_one_tt(lhs_tt, RulePart::Pattern, sess, node_id, features, edition); - // We don't handle errors here, the driver will abort after parsing/expansion. We can - // report every error in every macro this way. - check_emission(check_lhs_nt_follows(sess, node_id, &lhs_tt)); - check_emission(check_lhs_no_empty_seq(sess, slice::from_ref(&lhs_tt))); + check_emission(check_lhs(sess, node_id, &lhs_tt)); if let Err(e) = p.expect(exp!(FatArrow)) { return dummy_syn_ext(e.emit()); } - if p.token == token::Eof { - let err_sp = p.token.span.shrink_to_hi(); - let guar = sess - .dcx() - .struct_span_err(err_sp, "macro definition ended unexpectedly") - .with_span_label(err_sp, "expected right-hand side of macro rule") - .emit(); + if let Some(guar) = check_no_eof(sess, &p, "expected right-hand side of macro rule") { return dummy_syn_ext(guar); } let rhs_tt = p.parse_token_tree(); @@ -454,13 +439,32 @@ pub fn compile_declarative_macro( } // Return the number of rules for unused rule linting, if this is a local macro. - let nrules = if node_id != DUMMY_NODE_ID { rules.len() } else { 0 }; + let nrules = if is_local { rules.len() } else { 0 }; let expander = Arc::new(MacroRulesMacroExpander { name: ident, span, node_id, transparency, rules }); (mk_syn_ext(expander), nrules) } +fn check_no_eof(sess: &Session, p: &Parser<'_>, msg: &'static str) -> Option<ErrorGuaranteed> { + if p.token == token::Eof { + let err_sp = p.token.span.shrink_to_hi(); + let guar = sess + .dcx() + .struct_span_err(err_sp, "macro definition ended unexpectedly") + .with_span_label(err_sp, msg) + .emit(); + return Some(guar); + } + None +} + +fn check_lhs(sess: &Session, node_id: NodeId, lhs: &mbe::TokenTree) -> Result<(), ErrorGuaranteed> { + let e1 = check_lhs_nt_follows(sess, node_id, lhs); + let e2 = check_lhs_no_empty_seq(sess, slice::from_ref(lhs)); + e1.and(e2) +} + fn check_lhs_nt_follows( sess: &Session, node_id: NodeId, diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index 08f3ce5fd67..93a81f0dca5 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -155,15 +155,8 @@ pub(crate) fn mir_callgraph_cyclic<'tcx>( let recursion_limit = tcx.recursion_limit() / 2; let mut involved = FxHashSet::default(); let typing_env = ty::TypingEnv::post_analysis(tcx, root); - let Ok(Some(root_instance)) = ty::Instance::try_resolve( - tcx, - typing_env, - root.to_def_id(), - ty::GenericArgs::identity_for_item(tcx, root.to_def_id()), - ) else { - trace!("cannot resolve, skipping"); - return involved.into(); - }; + let root_instance = + ty::Instance::new_raw(root.to_def_id(), ty::GenericArgs::identity_for_item(tcx, root)); if !should_recurse(tcx, root_instance) { trace!("cannot walk, skipping"); return involved.into(); diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 8386fe8dab0..85bd8340c3c 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -776,8 +776,15 @@ impl Session { pub fn must_emit_unwind_tables(&self) -> bool { // This is used to control the emission of the `uwtable` attribute on - // LLVM functions. + // LLVM functions. The `uwtable` attribute according to LLVM is: // + // This attribute indicates that the ABI being targeted requires that an + // unwind table entry be produced for this function even if we can show + // that no exceptions passes by it. This is normally the case for the + // ELF x86-64 abi, but it can be disabled for some compilation units. + // + // Typically when we're compiling with `-C panic=abort` we don't need + // `uwtable` because we can't generate any exceptions! // Unwind tables are needed when compiling with `-C panic=unwind`, but // LLVM won't omit unwind tables unless the function is also marked as // `nounwind`, so users are allowed to disable `uwtable` emission. diff --git a/compiler/rustc_smir/Cargo.toml b/compiler/rustc_smir/Cargo.toml index fc9f411ac3c..b7ea478f731 100644 --- a/compiler/rustc_smir/Cargo.toml +++ b/compiler/rustc_smir/Cargo.toml @@ -13,7 +13,4 @@ rustc_middle = { path = "../rustc_middle" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_target = { path = "../rustc_target" } -scoped-tls = "1.0" -serde = { version = "1.0.125", features = [ "derive" ] } -tracing = "0.1" # tidy-alphabetical-end diff --git a/compiler/rustc_smir/src/rustc_smir/alloc.rs b/compiler/rustc_smir/src/alloc.rs index ecaf3571896..cad643f3709 100644 --- a/compiler/rustc_smir/src/rustc_smir/alloc.rs +++ b/compiler/rustc_smir/src/alloc.rs @@ -11,14 +11,14 @@ use rustc_middle::mir::interpret::{ use rustc_middle::ty::{Ty, layout}; use super::{SmirCtxt, Tables}; -use crate::rustc_smir::bridge::Allocation as _; -use crate::rustc_smir::{Bridge, SmirError}; +use crate::bridge::Allocation as _; +use crate::{Bridge, SmirError}; pub fn create_ty_and_layout<'tcx, B: Bridge>( cx: &SmirCtxt<'tcx, B>, ty: Ty<'tcx>, ) -> Result<TyAndLayout<'tcx, Ty<'tcx>>, &'tcx layout::LayoutError<'tcx>> { - use crate::rustc_smir::context::SmirTypingEnv; + use crate::context::SmirTypingEnv; cx.tcx.layout_of(cx.fully_monomorphized().as_query_input(ty)) } diff --git a/compiler/rustc_smir/src/rustc_smir/bridge.rs b/compiler/rustc_smir/src/bridge.rs index a31eb93d0e8..a31eb93d0e8 100644 --- a/compiler/rustc_smir/src/rustc_smir/bridge.rs +++ b/compiler/rustc_smir/src/bridge.rs diff --git a/compiler/rustc_smir/src/rustc_smir/builder.rs b/compiler/rustc_smir/src/builder.rs index 2141053d09a..2141053d09a 100644 --- a/compiler/rustc_smir/src/rustc_smir/builder.rs +++ b/compiler/rustc_smir/src/builder.rs diff --git a/compiler/rustc_smir/src/rustc_smir/context/impls.rs b/compiler/rustc_smir/src/context/impls.rs index 89ae47143ef..9faadabe489 100644 --- a/compiler/rustc_smir/src/rustc_smir/context/impls.rs +++ b/compiler/rustc_smir/src/context/impls.rs @@ -25,8 +25,8 @@ use rustc_span::{FileNameDisplayPreference, Span, Symbol}; use rustc_target::callconv::FnAbi; use super::{SmirAllocRange, SmirCtxt, SmirTy, SmirTypingEnv}; -use crate::rustc_smir::builder::BodyBuilder; -use crate::rustc_smir::{Bridge, SmirError, Tables, filter_def_ids}; +use crate::builder::BodyBuilder; +use crate::{Bridge, SmirError, Tables, filter_def_ids}; impl<'tcx, B: Bridge> SmirTy<'tcx> for SmirCtxt<'tcx, B> { fn new_foreign(&self, def_id: DefId) -> ty::Ty<'tcx> { @@ -426,7 +426,7 @@ impl<'tcx, B: Bridge> SmirCtxt<'tcx, B> { /// Evaluate constant as a target usize. pub fn eval_target_usize(&self, cnst: MirConst<'tcx>) -> Result<u64, B::Error> { - use crate::rustc_smir::context::SmirTypingEnv; + use crate::context::SmirTypingEnv; cnst.try_eval_target_usize(self.tcx, self.fully_monomorphized()) .ok_or_else(|| B::Error::new(format!("Const `{cnst:?}` cannot be encoded as u64"))) } @@ -436,10 +436,7 @@ impl<'tcx, B: Bridge> SmirCtxt<'tcx, B> { .ok_or_else(|| B::Error::new(format!("Const `{cnst:?}` cannot be encoded as u64"))) } - pub(crate) fn try_new_const_zst( - &self, - ty_internal: Ty<'tcx>, - ) -> Result<MirConst<'tcx>, B::Error> { + pub fn try_new_const_zst(&self, ty_internal: Ty<'tcx>) -> Result<MirConst<'tcx>, B::Error> { let size = self .tcx .layout_of(self.fully_monomorphized().as_query_input(ty_internal)) diff --git a/compiler/rustc_smir/src/rustc_smir/context/mod.rs b/compiler/rustc_smir/src/context/mod.rs index 38743e5f7d3..da20be2a4b3 100644 --- a/compiler/rustc_smir/src/rustc_smir/context/mod.rs +++ b/compiler/rustc_smir/src/context/mod.rs @@ -9,7 +9,7 @@ use rustc_middle::ty; use rustc_middle::ty::layout::{FnAbiOfHelpers, HasTyCtxt, HasTypingEnv, LayoutOfHelpers}; use rustc_middle::ty::{Ty, TyCtxt}; -use crate::rustc_smir::{Bridge, SmirError}; +use crate::{Bridge, SmirError}; mod impls; mod traits; @@ -18,7 +18,7 @@ pub use traits::*; /// Provides direct access to rustc's internal queries. /// -/// The [`crate::stable_mir::compiler_interface::SmirInterface`] must go through +/// `SmirInterface` must go through /// this context to obtain rustc-level information. pub struct SmirCtxt<'tcx, B: Bridge> { pub tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_smir/src/rustc_smir/context/traits.rs b/compiler/rustc_smir/src/context/traits.rs index 19e09016cdd..8483bee4aad 100644 --- a/compiler/rustc_smir/src/rustc_smir/context/traits.rs +++ b/compiler/rustc_smir/src/context/traits.rs @@ -8,31 +8,6 @@ use rustc_middle::ty; use rustc_middle::ty::Ty; use rustc_span::def_id::DefId; -pub trait SmirExistentialProjection<'tcx> { - fn new_from_args( - &self, - def_id: DefId, - args: ty::GenericArgsRef<'tcx>, - term: ty::Term<'tcx>, - ) -> ty::ExistentialProjection<'tcx>; -} - -pub trait SmirExistentialTraitRef<'tcx> { - fn new_from_args( - &self, - trait_def_id: DefId, - args: ty::GenericArgsRef<'tcx>, - ) -> ty::ExistentialTraitRef<'tcx>; -} - -pub trait SmirTraitRef<'tcx> { - fn new_from_args( - &self, - trait_def_id: DefId, - args: ty::GenericArgsRef<'tcx>, - ) -> ty::TraitRef<'tcx>; -} - pub trait SmirTy<'tcx> { fn new_foreign(&self, def_id: DefId) -> Ty<'tcx>; } diff --git a/compiler/rustc_smir/src/lib.rs b/compiler/rustc_smir/src/lib.rs index 067adda791d..fbebf98df7d 100644 --- a/compiler/rustc_smir/src/lib.rs +++ b/compiler/rustc_smir/src/lib.rs @@ -1,4 +1,9 @@ -//! The WIP stable interface to rustc internals. +//! Crate that implements what will become the rustc side of Stable MIR. +//! +//! This crate is responsible for building Stable MIR components from internal components. +//! +//! This crate is not intended to be invoked directly by users. +//! This crate is the public API of rustc that will be invoked by the `stable_mir` crate. //! //! For more information see <https://github.com/rust-lang/project-stable-mir> //! @@ -18,8 +23,283 @@ #![feature(sized_hierarchy)] // tidy-alphabetical-end -pub mod rustc_internal; +use std::cell::RefCell; +use std::fmt::Debug; +use std::hash::Hash; +use std::ops::Index; + +use bridge::*; +use context::SmirCtxt; +use rustc_data_structures::fx::{self, FxIndexMap}; +use rustc_middle::mir; +use rustc_middle::mir::interpret::AllocId; +use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_span::Span; +use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; + +pub mod alloc; +pub mod bridge; +mod builder; +pub mod context; + +#[deprecated(note = "please use `stable_mir::rustc_internal` instead")] +pub mod rustc_internal {} + +/// A container which is used for TLS. +pub struct SmirContainer<'tcx, B: Bridge> { + pub tables: RefCell<Tables<'tcx, B>>, + pub cx: RefCell<SmirCtxt<'tcx, B>>, +} + +pub struct Tables<'tcx, B: Bridge> { + pub def_ids: IndexMap<DefId, B::DefId>, + pub alloc_ids: IndexMap<AllocId, B::AllocId>, + pub spans: IndexMap<rustc_span::Span, B::Span>, + pub types: IndexMap<Ty<'tcx>, B::Ty>, + pub instances: IndexMap<ty::Instance<'tcx>, B::InstanceDef>, + pub ty_consts: IndexMap<ty::Const<'tcx>, B::TyConstId>, + pub mir_consts: IndexMap<mir::Const<'tcx>, B::MirConstId>, + pub layouts: IndexMap<rustc_abi::Layout<'tcx>, B::Layout>, +} + +impl<'tcx, B: Bridge> Default for Tables<'tcx, B> { + fn default() -> Self { + Self { + def_ids: IndexMap::default(), + alloc_ids: IndexMap::default(), + spans: IndexMap::default(), + types: IndexMap::default(), + instances: IndexMap::default(), + ty_consts: IndexMap::default(), + mir_consts: IndexMap::default(), + layouts: IndexMap::default(), + } + } +} + +impl<'tcx, B: Bridge> Index<B::DefId> for Tables<'tcx, B> { + type Output = DefId; + + #[inline(always)] + fn index(&self, index: B::DefId) -> &Self::Output { + &self.def_ids[index] + } +} + +impl<'tcx, B: Bridge> Tables<'tcx, B> { + pub fn intern_ty(&mut self, ty: Ty<'tcx>) -> B::Ty { + self.types.create_or_fetch(ty) + } + + pub fn intern_ty_const(&mut self, ct: ty::Const<'tcx>) -> B::TyConstId { + self.ty_consts.create_or_fetch(ct) + } + + pub fn intern_mir_const(&mut self, constant: mir::Const<'tcx>) -> B::MirConstId { + self.mir_consts.create_or_fetch(constant) + } + + pub fn create_def_id(&mut self, did: DefId) -> B::DefId { + self.def_ids.create_or_fetch(did) + } + + pub fn create_alloc_id(&mut self, aid: AllocId) -> B::AllocId { + self.alloc_ids.create_or_fetch(aid) + } + + pub fn create_span(&mut self, span: Span) -> B::Span { + self.spans.create_or_fetch(span) + } + + pub fn instance_def(&mut self, instance: ty::Instance<'tcx>) -> B::InstanceDef { + self.instances.create_or_fetch(instance) + } + + pub fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> B::Layout { + self.layouts.create_or_fetch(layout) + } + + pub fn crate_item(&mut self, did: rustc_span::def_id::DefId) -> B::CrateItem { + B::CrateItem::new(self.create_def_id(did)) + } + + pub fn adt_def(&mut self, did: rustc_span::def_id::DefId) -> B::AdtDef { + B::AdtDef::new(self.create_def_id(did)) + } + + pub fn foreign_module_def(&mut self, did: rustc_span::def_id::DefId) -> B::ForeignModuleDef { + B::ForeignModuleDef::new(self.create_def_id(did)) + } + + pub fn foreign_def(&mut self, did: rustc_span::def_id::DefId) -> B::ForeignDef { + B::ForeignDef::new(self.create_def_id(did)) + } + + pub fn fn_def(&mut self, did: rustc_span::def_id::DefId) -> B::FnDef { + B::FnDef::new(self.create_def_id(did)) + } + + pub fn closure_def(&mut self, did: rustc_span::def_id::DefId) -> B::ClosureDef { + B::ClosureDef::new(self.create_def_id(did)) + } + + pub fn coroutine_def(&mut self, did: rustc_span::def_id::DefId) -> B::CoroutineDef { + B::CoroutineDef::new(self.create_def_id(did)) + } + + pub fn coroutine_closure_def( + &mut self, + did: rustc_span::def_id::DefId, + ) -> B::CoroutineClosureDef { + B::CoroutineClosureDef::new(self.create_def_id(did)) + } + + pub fn alias_def(&mut self, did: rustc_span::def_id::DefId) -> B::AliasDef { + B::AliasDef::new(self.create_def_id(did)) + } + + pub fn param_def(&mut self, did: rustc_span::def_id::DefId) -> B::ParamDef { + B::ParamDef::new(self.create_def_id(did)) + } + + pub fn br_named_def(&mut self, did: rustc_span::def_id::DefId) -> B::BrNamedDef { + B::BrNamedDef::new(self.create_def_id(did)) + } + + pub fn trait_def(&mut self, did: rustc_span::def_id::DefId) -> B::TraitDef { + B::TraitDef::new(self.create_def_id(did)) + } + + pub fn generic_def(&mut self, did: rustc_span::def_id::DefId) -> B::GenericDef { + B::GenericDef::new(self.create_def_id(did)) + } + + pub fn const_def(&mut self, did: rustc_span::def_id::DefId) -> B::ConstDef { + B::ConstDef::new(self.create_def_id(did)) + } + + pub fn impl_def(&mut self, did: rustc_span::def_id::DefId) -> B::ImplDef { + B::ImplDef::new(self.create_def_id(did)) + } + + pub fn region_def(&mut self, did: rustc_span::def_id::DefId) -> B::RegionDef { + B::RegionDef::new(self.create_def_id(did)) + } + + pub fn coroutine_witness_def( + &mut self, + did: rustc_span::def_id::DefId, + ) -> B::CoroutineWitnessDef { + B::CoroutineWitnessDef::new(self.create_def_id(did)) + } + + pub fn assoc_def(&mut self, did: rustc_span::def_id::DefId) -> B::AssocDef { + B::AssocDef::new(self.create_def_id(did)) + } + + pub fn opaque_def(&mut self, did: rustc_span::def_id::DefId) -> B::OpaqueDef { + B::OpaqueDef::new(self.create_def_id(did)) + } + + pub fn prov(&mut self, aid: rustc_middle::mir::interpret::AllocId) -> B::Prov { + B::Prov::new(self.create_alloc_id(aid)) + } + + pub fn static_def(&mut self, did: rustc_span::def_id::DefId) -> B::StaticDef { + B::StaticDef::new(self.create_def_id(did)) + } +} + +/// A trait defining types that are used to emulate StableMIR components, which is really +/// useful when programming in stable_mir-agnostic settings. +pub trait Bridge: Sized { + type DefId: Copy + Debug + PartialEq + IndexedVal; + type AllocId: Copy + Debug + PartialEq + IndexedVal; + type Span: Copy + Debug + PartialEq + IndexedVal; + type Ty: Copy + Debug + PartialEq + IndexedVal; + type InstanceDef: Copy + Debug + PartialEq + IndexedVal; + type TyConstId: Copy + Debug + PartialEq + IndexedVal; + type MirConstId: Copy + Debug + PartialEq + IndexedVal; + type Layout: Copy + Debug + PartialEq + IndexedVal; + + type Error: SmirError; + type CrateItem: CrateItem<Self>; + type AdtDef: AdtDef<Self>; + type ForeignModuleDef: ForeignModuleDef<Self>; + type ForeignDef: ForeignDef<Self>; + type FnDef: FnDef<Self>; + type ClosureDef: ClosureDef<Self>; + type CoroutineDef: CoroutineDef<Self>; + type CoroutineClosureDef: CoroutineClosureDef<Self>; + type AliasDef: AliasDef<Self>; + type ParamDef: ParamDef<Self>; + type BrNamedDef: BrNamedDef<Self>; + type TraitDef: TraitDef<Self>; + type GenericDef: GenericDef<Self>; + type ConstDef: ConstDef<Self>; + type ImplDef: ImplDef<Self>; + type RegionDef: RegionDef<Self>; + type CoroutineWitnessDef: CoroutineWitnessDef<Self>; + type AssocDef: AssocDef<Self>; + type OpaqueDef: OpaqueDef<Self>; + type Prov: Prov<Self>; + type StaticDef: StaticDef<Self>; + + type Allocation: Allocation<Self>; +} + +pub trait IndexedVal { + fn to_val(index: usize) -> Self; + + fn to_index(&self) -> usize; +} + +/// Similar to rustc's `FxIndexMap`, `IndexMap` with extra +/// safety features added. +pub struct IndexMap<K, V> { + index_map: fx::FxIndexMap<K, V>, +} + +impl<K, V> Default for IndexMap<K, V> { + fn default() -> Self { + Self { index_map: FxIndexMap::default() } + } +} + +impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> IndexMap<K, V> { + pub fn create_or_fetch(&mut self, key: K) -> V { + let len = self.index_map.len(); + let v = self.index_map.entry(key).or_insert(V::to_val(len)); + *v + } +} + +impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> Index<V> + for IndexMap<K, V> +{ + type Output = K; -pub mod rustc_smir; + fn index(&self, index: V) -> &Self::Output { + let (k, v) = self.index_map.get_index(index.to_index()).unwrap(); + assert_eq!(*v, index, "Provided value doesn't match with indexed value"); + k + } +} -pub mod stable_mir; +/// Iterate over the definitions of the given crate. +pub(crate) fn filter_def_ids<F, T>(tcx: TyCtxt<'_>, krate: CrateNum, mut func: F) -> Vec<T> +where + F: FnMut(DefId) -> Option<T>, +{ + if krate == LOCAL_CRATE { + tcx.iter_local_def_id().filter_map(|did| func(did.to_def_id())).collect() + } else { + let num_definitions = tcx.num_extern_def_ids(krate); + (0..num_definitions) + .filter_map(move |i| { + let def_id = DefId { krate, index: rustc_span::def_id::DefIndex::from_usize(i) }; + func(def_id) + }) + .collect() + } +} diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs deleted file mode 100644 index e8b7a3fec09..00000000000 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ /dev/null @@ -1,286 +0,0 @@ -//! Module that implements what will become the rustc side of Stable MIR. - -//! This module is responsible for building Stable MIR components from internal components. -//! -//! This module is not intended to be invoked directly by users. It will eventually -//! become the public API of rustc that will be invoked by the `stable_mir` crate. -//! -//! For now, we are developing everything inside `rustc`, thus, we keep this module private. - -use std::cell::RefCell; -use std::fmt::Debug; -use std::hash::Hash; -use std::ops::Index; - -use bridge::*; -use context::SmirCtxt; -use rustc_data_structures::fx::{self, FxIndexMap}; -use rustc_middle::mir; -use rustc_middle::mir::interpret::AllocId; -use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_span::Span; -use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; - -pub mod alloc; -pub mod bridge; -mod builder; -pub mod context; - -/// A container which is used for TLS. -pub struct SmirContainer<'tcx, B: Bridge> { - pub tables: RefCell<Tables<'tcx, B>>, - pub cx: RefCell<SmirCtxt<'tcx, B>>, -} - -pub struct Tables<'tcx, B: Bridge> { - pub def_ids: IndexMap<DefId, B::DefId>, - pub alloc_ids: IndexMap<AllocId, B::AllocId>, - pub spans: IndexMap<rustc_span::Span, B::Span>, - pub types: IndexMap<Ty<'tcx>, B::Ty>, - pub instances: IndexMap<ty::Instance<'tcx>, B::InstanceDef>, - pub ty_consts: IndexMap<ty::Const<'tcx>, B::TyConstId>, - pub mir_consts: IndexMap<mir::Const<'tcx>, B::MirConstId>, - pub layouts: IndexMap<rustc_abi::Layout<'tcx>, B::Layout>, -} - -impl<'tcx, B: Bridge> Default for Tables<'tcx, B> { - fn default() -> Self { - Self { - def_ids: IndexMap::default(), - alloc_ids: IndexMap::default(), - spans: IndexMap::default(), - types: IndexMap::default(), - instances: IndexMap::default(), - ty_consts: IndexMap::default(), - mir_consts: IndexMap::default(), - layouts: IndexMap::default(), - } - } -} - -impl<'tcx, B: Bridge> Index<B::DefId> for Tables<'tcx, B> { - type Output = DefId; - - #[inline(always)] - fn index(&self, index: B::DefId) -> &Self::Output { - &self.def_ids[index] - } -} - -impl<'tcx, B: Bridge> Tables<'tcx, B> { - pub fn intern_ty(&mut self, ty: Ty<'tcx>) -> B::Ty { - self.types.create_or_fetch(ty) - } - - pub fn intern_ty_const(&mut self, ct: ty::Const<'tcx>) -> B::TyConstId { - self.ty_consts.create_or_fetch(ct) - } - - pub fn intern_mir_const(&mut self, constant: mir::Const<'tcx>) -> B::MirConstId { - self.mir_consts.create_or_fetch(constant) - } - - pub fn create_def_id(&mut self, did: DefId) -> B::DefId { - self.def_ids.create_or_fetch(did) - } - - pub fn create_alloc_id(&mut self, aid: AllocId) -> B::AllocId { - self.alloc_ids.create_or_fetch(aid) - } - - pub fn create_span(&mut self, span: Span) -> B::Span { - self.spans.create_or_fetch(span) - } - - pub fn instance_def(&mut self, instance: ty::Instance<'tcx>) -> B::InstanceDef { - self.instances.create_or_fetch(instance) - } - - pub fn layout_id(&mut self, layout: rustc_abi::Layout<'tcx>) -> B::Layout { - self.layouts.create_or_fetch(layout) - } - - pub fn crate_item(&mut self, did: rustc_span::def_id::DefId) -> B::CrateItem { - B::CrateItem::new(self.create_def_id(did)) - } - - pub fn adt_def(&mut self, did: rustc_span::def_id::DefId) -> B::AdtDef { - B::AdtDef::new(self.create_def_id(did)) - } - - pub fn foreign_module_def(&mut self, did: rustc_span::def_id::DefId) -> B::ForeignModuleDef { - B::ForeignModuleDef::new(self.create_def_id(did)) - } - - pub fn foreign_def(&mut self, did: rustc_span::def_id::DefId) -> B::ForeignDef { - B::ForeignDef::new(self.create_def_id(did)) - } - - pub fn fn_def(&mut self, did: rustc_span::def_id::DefId) -> B::FnDef { - B::FnDef::new(self.create_def_id(did)) - } - - pub fn closure_def(&mut self, did: rustc_span::def_id::DefId) -> B::ClosureDef { - B::ClosureDef::new(self.create_def_id(did)) - } - - pub fn coroutine_def(&mut self, did: rustc_span::def_id::DefId) -> B::CoroutineDef { - B::CoroutineDef::new(self.create_def_id(did)) - } - - pub fn coroutine_closure_def( - &mut self, - did: rustc_span::def_id::DefId, - ) -> B::CoroutineClosureDef { - B::CoroutineClosureDef::new(self.create_def_id(did)) - } - - pub fn alias_def(&mut self, did: rustc_span::def_id::DefId) -> B::AliasDef { - B::AliasDef::new(self.create_def_id(did)) - } - - pub fn param_def(&mut self, did: rustc_span::def_id::DefId) -> B::ParamDef { - B::ParamDef::new(self.create_def_id(did)) - } - - pub fn br_named_def(&mut self, did: rustc_span::def_id::DefId) -> B::BrNamedDef { - B::BrNamedDef::new(self.create_def_id(did)) - } - - pub fn trait_def(&mut self, did: rustc_span::def_id::DefId) -> B::TraitDef { - B::TraitDef::new(self.create_def_id(did)) - } - - pub fn generic_def(&mut self, did: rustc_span::def_id::DefId) -> B::GenericDef { - B::GenericDef::new(self.create_def_id(did)) - } - - pub fn const_def(&mut self, did: rustc_span::def_id::DefId) -> B::ConstDef { - B::ConstDef::new(self.create_def_id(did)) - } - - pub fn impl_def(&mut self, did: rustc_span::def_id::DefId) -> B::ImplDef { - B::ImplDef::new(self.create_def_id(did)) - } - - pub fn region_def(&mut self, did: rustc_span::def_id::DefId) -> B::RegionDef { - B::RegionDef::new(self.create_def_id(did)) - } - - pub fn coroutine_witness_def( - &mut self, - did: rustc_span::def_id::DefId, - ) -> B::CoroutineWitnessDef { - B::CoroutineWitnessDef::new(self.create_def_id(did)) - } - - pub fn assoc_def(&mut self, did: rustc_span::def_id::DefId) -> B::AssocDef { - B::AssocDef::new(self.create_def_id(did)) - } - - pub fn opaque_def(&mut self, did: rustc_span::def_id::DefId) -> B::OpaqueDef { - B::OpaqueDef::new(self.create_def_id(did)) - } - - pub fn prov(&mut self, aid: rustc_middle::mir::interpret::AllocId) -> B::Prov { - B::Prov::new(self.create_alloc_id(aid)) - } - - pub fn static_def(&mut self, did: rustc_span::def_id::DefId) -> B::StaticDef { - B::StaticDef::new(self.create_def_id(did)) - } -} - -/// A trait defining types that are used to emulate StableMIR components, which is really -/// useful when programming in stable_mir-agnostic settings. -pub trait Bridge: Sized { - type DefId: Copy + Debug + PartialEq + IndexedVal; - type AllocId: Copy + Debug + PartialEq + IndexedVal; - type Span: Copy + Debug + PartialEq + IndexedVal; - type Ty: Copy + Debug + PartialEq + IndexedVal; - type InstanceDef: Copy + Debug + PartialEq + IndexedVal; - type TyConstId: Copy + Debug + PartialEq + IndexedVal; - type MirConstId: Copy + Debug + PartialEq + IndexedVal; - type Layout: Copy + Debug + PartialEq + IndexedVal; - - type Error: SmirError; - type CrateItem: CrateItem<Self>; - type AdtDef: AdtDef<Self>; - type ForeignModuleDef: ForeignModuleDef<Self>; - type ForeignDef: ForeignDef<Self>; - type FnDef: FnDef<Self>; - type ClosureDef: ClosureDef<Self>; - type CoroutineDef: CoroutineDef<Self>; - type CoroutineClosureDef: CoroutineClosureDef<Self>; - type AliasDef: AliasDef<Self>; - type ParamDef: ParamDef<Self>; - type BrNamedDef: BrNamedDef<Self>; - type TraitDef: TraitDef<Self>; - type GenericDef: GenericDef<Self>; - type ConstDef: ConstDef<Self>; - type ImplDef: ImplDef<Self>; - type RegionDef: RegionDef<Self>; - type CoroutineWitnessDef: CoroutineWitnessDef<Self>; - type AssocDef: AssocDef<Self>; - type OpaqueDef: OpaqueDef<Self>; - type Prov: Prov<Self>; - type StaticDef: StaticDef<Self>; - - type Allocation: Allocation<Self>; -} - -pub trait IndexedVal { - fn to_val(index: usize) -> Self; - - fn to_index(&self) -> usize; -} - -/// Similar to rustc's `FxIndexMap`, `IndexMap` with extra -/// safety features added. -pub struct IndexMap<K, V> { - index_map: fx::FxIndexMap<K, V>, -} - -impl<K, V> Default for IndexMap<K, V> { - fn default() -> Self { - Self { index_map: FxIndexMap::default() } - } -} - -impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> IndexMap<K, V> { - pub fn create_or_fetch(&mut self, key: K) -> V { - let len = self.index_map.len(); - let v = self.index_map.entry(key).or_insert(V::to_val(len)); - *v - } -} - -impl<K: PartialEq + Hash + Eq, V: Copy + Debug + PartialEq + IndexedVal> Index<V> - for IndexMap<K, V> -{ - type Output = K; - - fn index(&self, index: V) -> &Self::Output { - let (k, v) = self.index_map.get_index(index.to_index()).unwrap(); - assert_eq!(*v, index, "Provided value doesn't match with indexed value"); - k - } -} - -/// Iterate over the definitions of the given crate. -pub(crate) fn filter_def_ids<F, T>(tcx: TyCtxt<'_>, krate: CrateNum, mut func: F) -> Vec<T> -where - F: FnMut(DefId) -> Option<T>, -{ - if krate == LOCAL_CRATE { - tcx.iter_local_def_id().filter_map(|did| func(did.to_def_id())).collect() - } else { - let num_definitions = tcx.num_extern_def_ids(krate); - (0..num_definitions) - .filter_map(move |i| { - let def_id = DefId { krate, index: rustc_span::def_id::DefIndex::from_usize(i) }; - func(def_id) - }) - .collect() - } -} diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs deleted file mode 100644 index 70c09c12854..00000000000 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ /dev/null @@ -1,304 +0,0 @@ -//! Module that is temporarily parasitic on the `rustc_smir` crate, -//! -//! This module is designed to resolve circular dependency that would happen -//! if we gradually invert the dependency order between `rustc_smir` and `stable_mir`. -//! -//! Once refactoring is complete, we will migrate it back to the `stable_mir` crate. - -//! The WIP stable interface to rustc internals. -//! -//! For more information see <https://github.com/rust-lang/project-stable-mir> -//! -//! # Note -//! -//! This API is still completely unstable and subject to change. - -// #![doc( -// html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", -// test(attr(allow(unused_variables), deny(warnings))) -// )] -//! -//! This crate shall contain all type definitions and APIs that we expect third-party tools to invoke to -//! interact with the compiler. -//! -//! The goal is to eventually be published on -//! [crates.io](https://crates.io). - -use std::fmt::Debug; -use std::{fmt, io}; - -pub(crate) use rustc_smir::IndexedVal; -use rustc_smir::Tables; -use rustc_smir::context::SmirCtxt; -use serde::Serialize; -use stable_mir::compiler_interface::with; -pub use stable_mir::crate_def::{CrateDef, CrateDefItems, CrateDefType, DefId}; -pub use stable_mir::error::*; -use stable_mir::mir::mono::StaticDef; -use stable_mir::mir::{Body, Mutability}; -use stable_mir::ty::{ - AssocItem, FnDef, ForeignModuleDef, ImplDef, ProvenanceMap, Span, TraitDef, Ty, -}; -use stable_mir::unstable::Stable; - -use crate::{rustc_smir, stable_mir}; - -pub mod abi; -mod alloc; -pub(crate) mod unstable; -#[macro_use] -pub mod crate_def; -pub mod compiler_interface; -#[macro_use] -pub mod error; -pub mod mir; -pub mod target; -pub mod ty; -pub mod visitor; - -/// Use String for now but we should replace it. -pub type Symbol = String; - -/// The number that identifies a crate. -pub type CrateNum = usize; - -impl Debug for DefId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("DefId").field("id", &self.0).field("name", &self.name()).finish() - } -} - -impl IndexedVal for DefId { - fn to_val(index: usize) -> Self { - DefId(index) - } - - fn to_index(&self) -> usize { - self.0 - } -} - -/// A list of crate items. -pub type CrateItems = Vec<CrateItem>; - -/// A list of trait decls. -pub type TraitDecls = Vec<TraitDef>; - -/// A list of impl trait decls. -pub type ImplTraitDecls = Vec<ImplDef>; - -/// A list of associated items. -pub type AssocItems = Vec<AssocItem>; - -/// Holds information about a crate. -#[derive(Clone, PartialEq, Eq, Debug, Serialize)] -pub struct Crate { - pub id: CrateNum, - pub name: Symbol, - pub is_local: bool, -} - -impl Crate { - /// The list of foreign modules in this crate. - pub fn foreign_modules(&self) -> Vec<ForeignModuleDef> { - with(|cx| cx.foreign_modules(self.id)) - } - - /// The list of traits declared in this crate. - pub fn trait_decls(&self) -> TraitDecls { - with(|cx| cx.trait_decls(self.id)) - } - - /// The list of trait implementations in this crate. - pub fn trait_impls(&self) -> ImplTraitDecls { - with(|cx| cx.trait_impls(self.id)) - } - - /// Return a list of function definitions from this crate independent on their visibility. - pub fn fn_defs(&self) -> Vec<FnDef> { - with(|cx| cx.crate_functions(self.id)) - } - - /// Return a list of static items defined in this crate independent on their visibility. - pub fn statics(&self) -> Vec<StaticDef> { - with(|cx| cx.crate_statics(self.id)) - } -} - -#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Serialize)] -pub enum ItemKind { - Fn, - Static, - Const, - Ctor(CtorKind), -} - -#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Serialize)] -pub enum CtorKind { - Const, - Fn, -} - -pub type Filename = String; - -crate_def_with_ty! { - /// Holds information about an item in a crate. - #[derive(Serialize)] - pub CrateItem; -} - -impl CrateItem { - /// This will return the body of an item or panic if it's not available. - pub fn expect_body(&self) -> mir::Body { - with(|cx| cx.mir_body(self.0)) - } - - /// Return the body of an item if available. - pub fn body(&self) -> Option<mir::Body> { - with(|cx| cx.has_body(self.0).then(|| cx.mir_body(self.0))) - } - - /// Check if a body is available for this item. - pub fn has_body(&self) -> bool { - with(|cx| cx.has_body(self.0)) - } - - pub fn span(&self) -> Span { - with(|cx| cx.span_of_an_item(self.0)) - } - - pub fn kind(&self) -> ItemKind { - with(|cx| cx.item_kind(*self)) - } - - pub fn requires_monomorphization(&self) -> bool { - with(|cx| cx.requires_monomorphization(self.0)) - } - - pub fn ty(&self) -> Ty { - with(|cx| cx.def_ty(self.0)) - } - - pub fn is_foreign_item(&self) -> bool { - with(|cx| cx.is_foreign_item(self.0)) - } - - /// Emit MIR for this item body. - pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> { - self.body() - .ok_or_else(|| io::Error::other(format!("No body found for `{}`", self.name())))? - .dump(w, &self.name()) - } -} - -/// Return the function where execution starts if the current -/// crate defines that. This is usually `main`, but could be -/// `start` if the crate is a no-std crate. -pub fn entry_fn() -> Option<CrateItem> { - with(|cx| cx.entry_fn()) -} - -/// Access to the local crate. -pub fn local_crate() -> Crate { - with(|cx| cx.local_crate()) -} - -/// Try to find a crate or crates if multiple crates exist from given name. -pub fn find_crates(name: &str) -> Vec<Crate> { - with(|cx| cx.find_crates(name)) -} - -/// Try to find a crate with the given name. -pub fn external_crates() -> Vec<Crate> { - with(|cx| cx.external_crates()) -} - -/// Retrieve all items in the local crate that have a MIR associated with them. -pub fn all_local_items() -> CrateItems { - with(|cx| cx.all_local_items()) -} - -pub fn all_trait_decls() -> TraitDecls { - with(|cx| cx.all_trait_decls()) -} - -pub fn all_trait_impls() -> ImplTraitDecls { - with(|cx| cx.all_trait_impls()) -} - -/// A type that provides internal information but that can still be used for debug purpose. -#[derive(Clone, PartialEq, Eq, Hash, Serialize)] -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 fn opaque<T: Debug>(value: &T) -> Opaque { - Opaque(format!("{value:?}")) -} - -macro_rules! bridge_impl { - ($name: ident, $ty: ty) => { - impl rustc_smir::bridge::$name<compiler_interface::BridgeTys> for $ty { - fn new(def: stable_mir::DefId) -> Self { - Self(def) - } - } - }; -} - -bridge_impl!(CrateItem, stable_mir::CrateItem); -bridge_impl!(AdtDef, stable_mir::ty::AdtDef); -bridge_impl!(ForeignModuleDef, stable_mir::ty::ForeignModuleDef); -bridge_impl!(ForeignDef, stable_mir::ty::ForeignDef); -bridge_impl!(FnDef, stable_mir::ty::FnDef); -bridge_impl!(ClosureDef, stable_mir::ty::ClosureDef); -bridge_impl!(CoroutineDef, stable_mir::ty::CoroutineDef); -bridge_impl!(CoroutineClosureDef, stable_mir::ty::CoroutineClosureDef); -bridge_impl!(AliasDef, stable_mir::ty::AliasDef); -bridge_impl!(ParamDef, stable_mir::ty::ParamDef); -bridge_impl!(BrNamedDef, stable_mir::ty::BrNamedDef); -bridge_impl!(TraitDef, stable_mir::ty::TraitDef); -bridge_impl!(GenericDef, stable_mir::ty::GenericDef); -bridge_impl!(ConstDef, stable_mir::ty::ConstDef); -bridge_impl!(ImplDef, stable_mir::ty::ImplDef); -bridge_impl!(RegionDef, stable_mir::ty::RegionDef); -bridge_impl!(CoroutineWitnessDef, stable_mir::ty::CoroutineWitnessDef); -bridge_impl!(AssocDef, stable_mir::ty::AssocDef); -bridge_impl!(OpaqueDef, stable_mir::ty::OpaqueDef); -bridge_impl!(StaticDef, stable_mir::mir::mono::StaticDef); - -impl rustc_smir::bridge::Prov<compiler_interface::BridgeTys> for stable_mir::ty::Prov { - fn new(aid: stable_mir::mir::alloc::AllocId) -> Self { - Self(aid) - } -} - -impl rustc_smir::bridge::Allocation<compiler_interface::BridgeTys> for stable_mir::ty::Allocation { - fn new<'tcx>( - bytes: Vec<Option<u8>>, - ptrs: Vec<(usize, rustc_middle::mir::interpret::AllocId)>, - align: u64, - mutability: rustc_middle::mir::Mutability, - tables: &mut Tables<'tcx, compiler_interface::BridgeTys>, - cx: &SmirCtxt<'tcx, compiler_interface::BridgeTys>, - ) -> Self { - Self { - bytes, - provenance: ProvenanceMap { - ptrs: ptrs.iter().map(|(i, aid)| (*i, tables.prov(*aid))).collect(), - }, - align, - mutability: mutability.stable(tables, cx), - } - } -} diff --git a/compiler/stable_mir/Cargo.toml b/compiler/stable_mir/Cargo.toml index 516c8e9c718..6777abce01d 100644 --- a/compiler/stable_mir/Cargo.toml +++ b/compiler/stable_mir/Cargo.toml @@ -4,7 +4,18 @@ version = "0.1.0-preview" edition = "2024" [dependencies] +# tidy-alphabetical-start +rustc_abi = { path = "../rustc_abi" } +rustc_hir = { path = "../rustc_hir" } +rustc_middle = { path = "../rustc_middle" } +rustc_session = { path = "../rustc_session" } rustc_smir = { path = "../rustc_smir" } +rustc_span = { path = "../rustc_span" } +rustc_target = { path = "../rustc_target" } +scoped-tls = "1.0" +serde = { version = "1.0.125", features = [ "derive" ] } +tracing = "0.1" +# tidy-alphabetical-end [features] # Provides access to APIs that expose internals of the rust compiler. diff --git a/compiler/rustc_smir/src/stable_mir/abi.rs b/compiler/stable_mir/src/abi.rs index 369d08e444e..7b0882caf1b 100644 --- a/compiler/rustc_smir/src/stable_mir/abi.rs +++ b/compiler/stable_mir/src/abi.rs @@ -3,13 +3,12 @@ use std::num::NonZero; use std::ops::RangeInclusive; use serde::Serialize; -use stable_mir::compiler_interface::with; -use stable_mir::mir::FieldIdx; -use stable_mir::target::{MachineInfo, MachineSize as Size}; -use stable_mir::ty::{Align, Ty, VariantIdx}; -use stable_mir::{Error, Opaque, error}; -use crate::stable_mir; +use crate::compiler_interface::with; +use crate::mir::FieldIdx; +use crate::target::{MachineInfo, MachineSize as Size}; +use crate::ty::{Align, Ty, VariantIdx}; +use crate::{Error, Opaque, error}; /// A function ABI definition. #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)] @@ -119,7 +118,7 @@ impl Layout { } } -impl stable_mir::IndexedVal for Layout { +impl crate::IndexedVal for Layout { fn to_val(index: usize) -> Self { Layout(index) } diff --git a/compiler/rustc_smir/src/stable_mir/alloc.rs b/compiler/stable_mir/src/alloc.rs index 120cb4404b9..349b83231e3 100644 --- a/compiler/rustc_smir/src/stable_mir/alloc.rs +++ b/compiler/stable_mir/src/alloc.rs @@ -16,7 +16,6 @@ use super::compiler_interface::BridgeTys; use super::mir::Mutability; use super::ty::{Allocation, ProvenanceMap}; use super::unstable::Stable; -use crate::rustc_smir; /// Creates new empty `Allocation` from given `Align`. fn new_empty_allocation(align: Align) -> Allocation { diff --git a/compiler/rustc_smir/src/stable_mir/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index a19968d2ab7..50c2f02e6ad 100644 --- a/compiler/rustc_smir/src/stable_mir/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -8,68 +8,67 @@ use std::cell::Cell; use rustc_hir::def::DefKind; use rustc_smir::context::SmirCtxt; use rustc_smir::{Bridge, SmirContainer}; -use stable_mir::abi::{FnAbi, Layout, LayoutShape, ReprOptions}; -use stable_mir::crate_def::Attribute; -use stable_mir::mir::alloc::{AllocId, GlobalAlloc}; -use stable_mir::mir::mono::{Instance, InstanceDef, StaticDef}; -use stable_mir::mir::{BinOp, Body, Place, UnOp}; -use stable_mir::target::{MachineInfo, MachineSize}; -use stable_mir::ty::{ +use tracing::debug; + +use crate::abi::{FnAbi, Layout, LayoutShape, ReprOptions}; +use crate::crate_def::Attribute; +use crate::mir::alloc::{AllocId, GlobalAlloc}; +use crate::mir::mono::{Instance, InstanceDef, StaticDef}; +use crate::mir::{BinOp, Body, Place, UnOp}; +use crate::target::{MachineInfo, MachineSize}; +use crate::ty::{ AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, CoroutineDef, Discr, FieldDef, FnDef, ForeignDef, ForeignItemKind, ForeignModule, ForeignModuleDef, GenericArgs, GenericPredicates, Generics, ImplDef, ImplTrait, IntrinsicDef, LineInfo, MirConst, PolyFnSig, RigidTy, Span, TraitDecl, TraitDef, Ty, TyConst, TyConstId, TyKind, UintTy, VariantDef, VariantIdx, }; -use stable_mir::unstable::{RustcInternal, Stable, new_item_kind}; -use stable_mir::{ +use crate::unstable::{RustcInternal, Stable, new_item_kind}; +use crate::{ AssocItems, Crate, CrateDef, CrateItem, CrateItems, CrateNum, DefId, Error, Filename, ImplTraitDecls, ItemKind, Symbol, TraitDecls, alloc, mir, }; -use tracing::debug; - -use crate::{rustc_smir, stable_mir}; pub struct BridgeTys; impl Bridge for BridgeTys { - type DefId = stable_mir::DefId; - type AllocId = stable_mir::mir::alloc::AllocId; - type Span = stable_mir::ty::Span; - type Ty = stable_mir::ty::Ty; - type InstanceDef = stable_mir::mir::mono::InstanceDef; - type TyConstId = stable_mir::ty::TyConstId; - type MirConstId = stable_mir::ty::MirConstId; - type Layout = stable_mir::abi::Layout; - - type Error = stable_mir::Error; - type CrateItem = stable_mir::CrateItem; - type AdtDef = stable_mir::ty::AdtDef; - type ForeignModuleDef = stable_mir::ty::ForeignModuleDef; - type ForeignDef = stable_mir::ty::ForeignDef; - type FnDef = stable_mir::ty::FnDef; - type ClosureDef = stable_mir::ty::ClosureDef; - type CoroutineDef = stable_mir::ty::CoroutineDef; - type CoroutineClosureDef = stable_mir::ty::CoroutineClosureDef; - type AliasDef = stable_mir::ty::AliasDef; - type ParamDef = stable_mir::ty::ParamDef; - type BrNamedDef = stable_mir::ty::BrNamedDef; - type TraitDef = stable_mir::ty::TraitDef; - type GenericDef = stable_mir::ty::GenericDef; - type ConstDef = stable_mir::ty::ConstDef; - type ImplDef = stable_mir::ty::ImplDef; - type RegionDef = stable_mir::ty::RegionDef; - type CoroutineWitnessDef = stable_mir::ty::CoroutineWitnessDef; - type AssocDef = stable_mir::ty::AssocDef; - type OpaqueDef = stable_mir::ty::OpaqueDef; - type Prov = stable_mir::ty::Prov; - type StaticDef = stable_mir::mir::mono::StaticDef; - - type Allocation = stable_mir::ty::Allocation; + type DefId = crate::DefId; + type AllocId = crate::mir::alloc::AllocId; + type Span = crate::ty::Span; + type Ty = crate::ty::Ty; + type InstanceDef = crate::mir::mono::InstanceDef; + type TyConstId = crate::ty::TyConstId; + type MirConstId = crate::ty::MirConstId; + type Layout = crate::abi::Layout; + + type Error = crate::Error; + type CrateItem = crate::CrateItem; + type AdtDef = crate::ty::AdtDef; + type ForeignModuleDef = crate::ty::ForeignModuleDef; + type ForeignDef = crate::ty::ForeignDef; + type FnDef = crate::ty::FnDef; + type ClosureDef = crate::ty::ClosureDef; + type CoroutineDef = crate::ty::CoroutineDef; + type CoroutineClosureDef = crate::ty::CoroutineClosureDef; + type AliasDef = crate::ty::AliasDef; + type ParamDef = crate::ty::ParamDef; + type BrNamedDef = crate::ty::BrNamedDef; + type TraitDef = crate::ty::TraitDef; + type GenericDef = crate::ty::GenericDef; + type ConstDef = crate::ty::ConstDef; + type ImplDef = crate::ty::ImplDef; + type RegionDef = crate::ty::RegionDef; + type CoroutineWitnessDef = crate::ty::CoroutineWitnessDef; + type AssocDef = crate::ty::AssocDef; + type OpaqueDef = crate::ty::OpaqueDef; + type Prov = crate::ty::Prov; + type StaticDef = crate::mir::mono::StaticDef; + + type Allocation = crate::ty::Allocation; } /// Stable public API for querying compiler information. /// -/// All queries are delegated to [`crate::rustc_smir::context::SmirCtxt`] that provides +/// All queries are delegated to [`rustc_smir::context::SmirCtxt`] that provides /// similar APIs but based on internal rustc constructs. /// /// Do not use this directly. This is currently used in the macro expansion. @@ -440,7 +439,7 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> { let cx = &*self.cx.borrow(); let did = tables[def_id]; let (parent, kinds) = cx.predicates_of(did); - stable_mir::ty::GenericPredicates { + crate::ty::GenericPredicates { parent: parent.map(|did| tables.trait_def(did)), predicates: kinds .iter() @@ -454,7 +453,7 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> { let cx = &*self.cx.borrow(); let did = tables[def_id]; let (parent, kinds) = cx.explicit_predicates_of(did); - stable_mir::ty::GenericPredicates { + crate::ty::GenericPredicates { parent: parent.map(|did| tables.trait_def(did)), predicates: kinds .iter() diff --git a/compiler/rustc_smir/src/stable_mir/crate_def.rs b/compiler/stable_mir/src/crate_def.rs index 64f7ef9b314..75228135e4c 100644 --- a/compiler/rustc_smir/src/stable_mir/crate_def.rs +++ b/compiler/stable_mir/src/crate_def.rs @@ -2,10 +2,9 @@ //! such as, a function, a trait, an enum, and any other definitions. use serde::Serialize; -use stable_mir::ty::{GenericArgs, Span, Ty}; -use stable_mir::{AssocItems, Crate, Symbol, with}; -use crate::stable_mir; +use crate::ty::{GenericArgs, Span, Ty}; +use crate::{AssocItems, Crate, Symbol, with}; /// A unique identification number for each item accessible for the current compilation unit. #[derive(Clone, Copy, PartialEq, Eq, Hash, Serialize)] diff --git a/compiler/rustc_smir/src/stable_mir/error.rs b/compiler/stable_mir/src/error.rs index 3f9d67954b9..702134b0c4c 100644 --- a/compiler/rustc_smir/src/stable_mir/error.rs +++ b/compiler/stable_mir/src/error.rs @@ -9,8 +9,6 @@ use std::{fmt, io}; use rustc_smir::bridge::SmirError; -use crate::rustc_smir; - macro_rules! error { ($fmt: literal $(,)?) => { Error(format!($fmt)) }; ($fmt: literal, $($arg:tt)*) => { Error(format!($fmt, $($arg)*)) }; diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs index 688f3936b26..0a2e4e71afc 100644 --- a/compiler/stable_mir/src/lib.rs +++ b/compiler/stable_mir/src/lib.rs @@ -1,11 +1,300 @@ -//! We've temporarily moved the `stable_mir` implementation to [`rustc_smir::stable_mir`], -//! during refactoring to break the circular dependency between `rustc_smir` and `stable_mir`, +//! The WIP stable interface to rustc internals. //! -//! This is a transitional measure as described in [PR #139319](https://github.com/rust-lang/rust/pull/139319). -//! Once the refactoring is complete, the `stable_mir` implementation will be moved back here. +//! For more information see <https://github.com/rust-lang/project-stable-mir> +//! +//! # Note +//! +//! This API is still completely unstable and subject to change. +#![allow(rustc::usage_of_ty_tykind)] +#![doc( + html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", + test(attr(allow(unused_variables), deny(warnings))) +)] +#![feature(sized_hierarchy)] +//! +//! This crate shall contain all type definitions and APIs that we expect third-party tools to invoke to +//! interact with the compiler. +//! +//! The goal is to eventually be published on +//! [crates.io](https://crates.io). + +use std::fmt::Debug; +use std::{fmt, io}; + +pub(crate) use rustc_smir::IndexedVal; +use rustc_smir::Tables; +use rustc_smir::context::SmirCtxt; /// Export the rustc_internal APIs. Note that this module has no stability /// guarantees and it is not taken into account for semver. #[cfg(feature = "rustc_internal")] -pub use rustc_smir::rustc_internal; -pub use rustc_smir::stable_mir::*; +pub mod rustc_internal; +use serde::Serialize; + +use crate::compiler_interface::with; +pub use crate::crate_def::{CrateDef, CrateDefItems, CrateDefType, DefId}; +pub use crate::error::*; +use crate::mir::mono::StaticDef; +use crate::mir::{Body, Mutability}; +use crate::ty::{AssocItem, FnDef, ForeignModuleDef, ImplDef, ProvenanceMap, Span, TraitDef, Ty}; +use crate::unstable::Stable; + +pub mod abi; +mod alloc; +pub(crate) mod unstable; +#[macro_use] +pub mod crate_def; +pub mod compiler_interface; +#[macro_use] +pub mod error; +pub mod mir; +pub mod target; +pub mod ty; +pub mod visitor; + +/// Use String for now but we should replace it. +pub type Symbol = String; + +/// The number that identifies a crate. +pub type CrateNum = usize; + +impl Debug for DefId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("DefId").field("id", &self.0).field("name", &self.name()).finish() + } +} + +impl IndexedVal for DefId { + fn to_val(index: usize) -> Self { + DefId(index) + } + + fn to_index(&self) -> usize { + self.0 + } +} + +/// A list of crate items. +pub type CrateItems = Vec<CrateItem>; + +/// A list of trait decls. +pub type TraitDecls = Vec<TraitDef>; + +/// A list of impl trait decls. +pub type ImplTraitDecls = Vec<ImplDef>; + +/// A list of associated items. +pub type AssocItems = Vec<AssocItem>; + +/// Holds information about a crate. +#[derive(Clone, PartialEq, Eq, Debug, Serialize)] +pub struct Crate { + pub id: CrateNum, + pub name: Symbol, + pub is_local: bool, +} + +impl Crate { + /// The list of foreign modules in this crate. + pub fn foreign_modules(&self) -> Vec<ForeignModuleDef> { + with(|cx| cx.foreign_modules(self.id)) + } + + /// The list of traits declared in this crate. + pub fn trait_decls(&self) -> TraitDecls { + with(|cx| cx.trait_decls(self.id)) + } + + /// The list of trait implementations in this crate. + pub fn trait_impls(&self) -> ImplTraitDecls { + with(|cx| cx.trait_impls(self.id)) + } + + /// Return a list of function definitions from this crate independent on their visibility. + pub fn fn_defs(&self) -> Vec<FnDef> { + with(|cx| cx.crate_functions(self.id)) + } + + /// Return a list of static items defined in this crate independent on their visibility. + pub fn statics(&self) -> Vec<StaticDef> { + with(|cx| cx.crate_statics(self.id)) + } +} + +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Serialize)] +pub enum ItemKind { + Fn, + Static, + Const, + Ctor(CtorKind), +} + +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Serialize)] +pub enum CtorKind { + Const, + Fn, +} + +pub type Filename = String; + +crate_def_with_ty! { + /// Holds information about an item in a crate. + #[derive(Serialize)] + pub CrateItem; +} + +impl CrateItem { + /// This will return the body of an item or panic if it's not available. + pub fn expect_body(&self) -> mir::Body { + with(|cx| cx.mir_body(self.0)) + } + + /// Return the body of an item if available. + pub fn body(&self) -> Option<mir::Body> { + with(|cx| cx.has_body(self.0).then(|| cx.mir_body(self.0))) + } + + /// Check if a body is available for this item. + pub fn has_body(&self) -> bool { + with(|cx| cx.has_body(self.0)) + } + + pub fn span(&self) -> Span { + with(|cx| cx.span_of_an_item(self.0)) + } + + pub fn kind(&self) -> ItemKind { + with(|cx| cx.item_kind(*self)) + } + + pub fn requires_monomorphization(&self) -> bool { + with(|cx| cx.requires_monomorphization(self.0)) + } + + pub fn ty(&self) -> Ty { + with(|cx| cx.def_ty(self.0)) + } + + pub fn is_foreign_item(&self) -> bool { + with(|cx| cx.is_foreign_item(self.0)) + } + + /// Emit MIR for this item body. + pub fn emit_mir<W: io::Write>(&self, w: &mut W) -> io::Result<()> { + self.body() + .ok_or_else(|| io::Error::other(format!("No body found for `{}`", self.name())))? + .dump(w, &self.name()) + } +} + +/// Return the function where execution starts if the current +/// crate defines that. This is usually `main`, but could be +/// `start` if the crate is a no-std crate. +pub fn entry_fn() -> Option<CrateItem> { + with(|cx| cx.entry_fn()) +} + +/// Access to the local crate. +pub fn local_crate() -> Crate { + with(|cx| cx.local_crate()) +} + +/// Try to find a crate or crates if multiple crates exist from given name. +pub fn find_crates(name: &str) -> Vec<Crate> { + with(|cx| cx.find_crates(name)) +} + +/// Try to find a crate with the given name. +pub fn external_crates() -> Vec<Crate> { + with(|cx| cx.external_crates()) +} + +/// Retrieve all items in the local crate that have a MIR associated with them. +pub fn all_local_items() -> CrateItems { + with(|cx| cx.all_local_items()) +} + +pub fn all_trait_decls() -> TraitDecls { + with(|cx| cx.all_trait_decls()) +} + +pub fn all_trait_impls() -> ImplTraitDecls { + with(|cx| cx.all_trait_impls()) +} + +/// A type that provides internal information but that can still be used for debug purpose. +#[derive(Clone, PartialEq, Eq, Hash, Serialize)] +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 fn opaque<T: Debug>(value: &T) -> Opaque { + Opaque(format!("{value:?}")) +} + +macro_rules! bridge_impl { + ($name: ident, $ty: ty) => { + impl rustc_smir::bridge::$name<compiler_interface::BridgeTys> for $ty { + fn new(def: crate::DefId) -> Self { + Self(def) + } + } + }; +} + +bridge_impl!(CrateItem, crate::CrateItem); +bridge_impl!(AdtDef, crate::ty::AdtDef); +bridge_impl!(ForeignModuleDef, crate::ty::ForeignModuleDef); +bridge_impl!(ForeignDef, crate::ty::ForeignDef); +bridge_impl!(FnDef, crate::ty::FnDef); +bridge_impl!(ClosureDef, crate::ty::ClosureDef); +bridge_impl!(CoroutineDef, crate::ty::CoroutineDef); +bridge_impl!(CoroutineClosureDef, crate::ty::CoroutineClosureDef); +bridge_impl!(AliasDef, crate::ty::AliasDef); +bridge_impl!(ParamDef, crate::ty::ParamDef); +bridge_impl!(BrNamedDef, crate::ty::BrNamedDef); +bridge_impl!(TraitDef, crate::ty::TraitDef); +bridge_impl!(GenericDef, crate::ty::GenericDef); +bridge_impl!(ConstDef, crate::ty::ConstDef); +bridge_impl!(ImplDef, crate::ty::ImplDef); +bridge_impl!(RegionDef, crate::ty::RegionDef); +bridge_impl!(CoroutineWitnessDef, crate::ty::CoroutineWitnessDef); +bridge_impl!(AssocDef, crate::ty::AssocDef); +bridge_impl!(OpaqueDef, crate::ty::OpaqueDef); +bridge_impl!(StaticDef, crate::mir::mono::StaticDef); + +impl rustc_smir::bridge::Prov<compiler_interface::BridgeTys> for crate::ty::Prov { + fn new(aid: crate::mir::alloc::AllocId) -> Self { + Self(aid) + } +} + +impl rustc_smir::bridge::Allocation<compiler_interface::BridgeTys> for crate::ty::Allocation { + fn new<'tcx>( + bytes: Vec<Option<u8>>, + ptrs: Vec<(usize, rustc_middle::mir::interpret::AllocId)>, + align: u64, + mutability: rustc_middle::mir::Mutability, + tables: &mut Tables<'tcx, compiler_interface::BridgeTys>, + cx: &SmirCtxt<'tcx, compiler_interface::BridgeTys>, + ) -> Self { + Self { + bytes, + provenance: ProvenanceMap { + ptrs: ptrs.iter().map(|(i, aid)| (*i, tables.prov(*aid))).collect(), + }, + align, + mutability: mutability.stable(tables, cx), + } + } +} diff --git a/compiler/rustc_smir/src/stable_mir/mir.rs b/compiler/stable_mir/src/mir.rs index 413b5152bb3..413b5152bb3 100644 --- a/compiler/rustc_smir/src/stable_mir/mir.rs +++ b/compiler/stable_mir/src/mir.rs diff --git a/compiler/rustc_smir/src/stable_mir/mir/alloc.rs b/compiler/stable_mir/src/mir/alloc.rs index 26f30898a9c..0d45e59885c 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/alloc.rs +++ b/compiler/stable_mir/src/mir/alloc.rs @@ -3,12 +3,11 @@ use std::io::Read; use serde::Serialize; -use stable_mir::mir::mono::{Instance, StaticDef}; -use stable_mir::target::{Endian, MachineInfo}; -use stable_mir::ty::{Allocation, Binder, ExistentialTraitRef, Ty}; -use stable_mir::{Error, IndexedVal, with}; -use crate::stable_mir; +use crate::mir::mono::{Instance, StaticDef}; +use crate::target::{Endian, MachineInfo}; +use crate::ty::{Allocation, Binder, ExistentialTraitRef, Ty}; +use crate::{Error, IndexedVal, with}; /// An allocation in the SMIR global memory can be either a function pointer, /// a static, or a "real" allocation with some data in it. diff --git a/compiler/rustc_smir/src/stable_mir/mir/body.rs b/compiler/stable_mir/src/mir/body.rs index 90d4a06b177..a9fe3607232 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/body.rs +++ b/compiler/stable_mir/src/mir/body.rs @@ -1,15 +1,14 @@ use std::io; use serde::Serialize; -use stable_mir::compiler_interface::with; -use stable_mir::mir::pretty::function_body; -use stable_mir::ty::{ + +use crate::compiler_interface::with; +use crate::mir::pretty::function_body; +use crate::ty::{ AdtDef, ClosureDef, CoroutineClosureDef, CoroutineDef, GenericArgs, MirConst, Movability, Region, RigidTy, Ty, TyConst, TyKind, VariantIdx, }; -use stable_mir::{Error, Opaque, Span, Symbol}; - -use crate::stable_mir; +use crate::{Error, Opaque, Span, Symbol}; /// The SMIR representation of a single function. #[derive(Clone, Debug, Serialize)] @@ -587,7 +586,7 @@ pub enum Rvalue { /// /// **Needs clarification**: Are there weird additional semantics here related to the runtime /// nature of this operation? - ThreadLocalRef(stable_mir::CrateItem), + ThreadLocalRef(crate::CrateItem), /// Computes a value as described by the operation. NullaryOp(NullOp, Ty), diff --git a/compiler/rustc_smir/src/stable_mir/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index 5f177416714..c54fcecac9f 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -3,13 +3,12 @@ use std::io; use rustc_smir::bridge::SmirError; use serde::Serialize; -use stable_mir::abi::FnAbi; -use stable_mir::crate_def::CrateDef; -use stable_mir::mir::Body; -use stable_mir::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, Ty}; -use stable_mir::{CrateItem, DefId, Error, IndexedVal, ItemKind, Opaque, Symbol, with}; -use crate::{rustc_smir, stable_mir}; +use crate::abi::FnAbi; +use crate::crate_def::CrateDef; +use crate::mir::Body; +use crate::ty::{Allocation, ClosureDef, ClosureKind, FnDef, GenericArgs, Ty}; +use crate::{CrateItem, DefId, Error, IndexedVal, ItemKind, Opaque, Symbol, with}; #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)] pub enum MonoItem { @@ -194,7 +193,7 @@ impl Debug for Instance { /// Try to convert a crate item into an instance. /// The item cannot be generic in order to be converted into an instance. impl TryFrom<CrateItem> for Instance { - type Error = stable_mir::Error; + type Error = crate::Error; fn try_from(item: CrateItem) -> Result<Self, Self::Error> { with(|context| { @@ -211,7 +210,7 @@ impl TryFrom<CrateItem> for Instance { /// Try to convert an instance into a crate item. /// Only user defined instances can be converted. impl TryFrom<Instance> for CrateItem { - type Error = stable_mir::Error; + type Error = crate::Error; fn try_from(value: Instance) -> Result<Self, Self::Error> { with(|context| { @@ -258,7 +257,7 @@ crate_def! { } impl TryFrom<CrateItem> for StaticDef { - type Error = stable_mir::Error; + type Error = crate::Error; fn try_from(value: CrateItem) -> Result<Self, Self::Error> { if matches!(value.kind(), ItemKind::Static) { @@ -270,7 +269,7 @@ impl TryFrom<CrateItem> for StaticDef { } impl TryFrom<Instance> for StaticDef { - type Error = stable_mir::Error; + type Error = crate::Error; fn try_from(value: Instance) -> Result<Self, Self::Error> { StaticDef::try_from(CrateItem::try_from(value)?) diff --git a/compiler/rustc_smir/src/stable_mir/mir/pretty.rs b/compiler/stable_mir/src/mir/pretty.rs index a7347e9b021..f496d80053e 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/pretty.rs +++ b/compiler/stable_mir/src/mir/pretty.rs @@ -4,14 +4,13 @@ use std::io::Write; use std::{fmt, io, iter}; use fmt::{Display, Formatter}; -use stable_mir::mir::{ - Operand, Place, RawPtrKind, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents, -}; -use stable_mir::ty::{AdtKind, AssocKind, MirConst, Ty, TyConst}; -use stable_mir::{Body, CrateDef, IndexedVal, Mutability, with}; use super::{AggregateKind, AssertMessage, BinOp, BorrowKind, FakeBorrowKind, TerminatorKind}; -use crate::stable_mir; +use crate::mir::{ + Operand, Place, RawPtrKind, Rvalue, StatementKind, UnwindAction, VarDebugInfoContents, +}; +use crate::ty::{AdtKind, AssocKind, MirConst, Ty, TyConst}; +use crate::{Body, CrateDef, IndexedVal, Mutability, with}; impl Display for Ty { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { diff --git a/compiler/rustc_smir/src/stable_mir/mir/visit.rs b/compiler/stable_mir/src/mir/visit.rs index b7dd433eb09..7dc99d1d1e1 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/visit.rs +++ b/compiler/stable_mir/src/mir/visit.rs @@ -35,11 +35,9 @@ //! The only place that `_` is acceptable is to match a field (or //! variant argument) that does not require visiting. -use stable_mir::mir::*; -use stable_mir::ty::{GenericArgs, MirConst, Region, Ty, TyConst}; -use stable_mir::{Error, Opaque, Span}; - -use crate::stable_mir; +use crate::mir::*; +use crate::ty::{GenericArgs, MirConst, Region, Ty, TyConst}; +use crate::{Error, Opaque, Span}; macro_rules! make_mir_visitor { ($visitor_trait_name:ident, $($mutability:ident)?) => { diff --git a/compiler/rustc_smir/src/rustc_internal/mod.rs b/compiler/stable_mir/src/rustc_internal/mod.rs index dcdc77b76c2..c1ed03ade75 100644 --- a/compiler/rustc_smir/src/rustc_internal/mod.rs +++ b/compiler/stable_mir/src/rustc_internal/mod.rs @@ -6,14 +6,13 @@ use std::cell::{Cell, RefCell}; use rustc_middle::ty::TyCtxt; +use rustc_smir::context::SmirCtxt; +use rustc_smir::{Bridge, SmirContainer, Tables}; use rustc_span::def_id::CrateNum; use scoped_tls::scoped_thread_local; -use stable_mir::Error; -use stable_mir::unstable::{RustcInternal, Stable}; -use crate::rustc_smir::context::SmirCtxt; -use crate::rustc_smir::{Bridge, SmirContainer, Tables}; -use crate::stable_mir; +use crate::Error; +use crate::unstable::{RustcInternal, Stable}; pub mod pretty; @@ -53,7 +52,7 @@ where with_container(|tables, _| item.internal(tables, tcx)) } -pub fn crate_num(item: &stable_mir::Crate) -> CrateNum { +pub fn crate_num(item: &crate::Crate) -> CrateNum { item.id.into() } @@ -93,7 +92,7 @@ where let smir_cx = RefCell::new(SmirCtxt::new(tcx)); let container = SmirContainer { tables: RefCell::new(Tables::default()), cx: smir_cx }; - stable_mir::compiler_interface::run(&container, || init(&container, f)) + crate::compiler_interface::run(&container, || init(&container, f)) } /// Instantiate and run the compiler with the provided arguments and callback. @@ -106,7 +105,6 @@ where /// # extern crate rustc_interface; /// # extern crate rustc_middle; /// # #[macro_use] -/// # extern crate rustc_smir; /// # extern crate stable_mir; /// # /// # fn main() { @@ -127,7 +125,6 @@ where /// # extern crate rustc_interface; /// # extern crate rustc_middle; /// # #[macro_use] -/// # extern crate rustc_smir; /// # extern crate stable_mir; /// # /// # fn main() { @@ -190,7 +187,7 @@ macro_rules! run_driver { use rustc_driver::{Callbacks, Compilation, run_compiler}; use rustc_middle::ty::TyCtxt; use rustc_interface::interface; - use rustc_smir::rustc_internal; + use stable_mir::rustc_internal; use stable_mir::CompilerError; use std::ops::ControlFlow; diff --git a/compiler/rustc_smir/src/rustc_internal/pretty.rs b/compiler/stable_mir/src/rustc_internal/pretty.rs index 0710c18746a..28c5280fe04 100644 --- a/compiler/rustc_smir/src/rustc_internal/pretty.rs +++ b/compiler/stable_mir/src/rustc_internal/pretty.rs @@ -3,7 +3,6 @@ use std::io; use rustc_middle::ty::TyCtxt; use super::run; -use crate::stable_mir; pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io::Result<()> { writeln!( @@ -15,7 +14,7 @@ pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io "// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir." )?; let _ = run(tcx, || { - let items = stable_mir::all_local_items(); + let items = crate::all_local_items(); let _ = items.iter().map(|item| -> io::Result<()> { item.emit_mir(w) }).collect::<Vec<_>>(); }); Ok(()) diff --git a/compiler/rustc_smir/src/stable_mir/target.rs b/compiler/stable_mir/src/target.rs index 6cf1e9feb01..32c3a2a9122 100644 --- a/compiler/rustc_smir/src/stable_mir/target.rs +++ b/compiler/stable_mir/src/target.rs @@ -1,9 +1,8 @@ //! Provide information about the machine that this is being compiled into. use serde::Serialize; -use stable_mir::compiler_interface::with; -use crate::stable_mir; +use crate::compiler_interface::with; /// The properties of the target machine being compiled into. #[derive(Clone, PartialEq, Eq, Serialize)] diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/stable_mir/src/ty.rs index 004a7c02234..87d31cf9713 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/stable_mir/src/ty.rs @@ -2,17 +2,16 @@ use std::fmt::{self, Debug, Display, Formatter}; use std::ops::Range; use serde::Serialize; -use stable_mir::abi::{FnAbi, Layout}; -use stable_mir::crate_def::{CrateDef, CrateDefItems, CrateDefType}; -use stable_mir::mir::alloc::{AllocId, read_target_int, read_target_uint}; -use stable_mir::mir::mono::StaticDef; -use stable_mir::target::MachineInfo; -use stable_mir::{Filename, IndexedVal, Opaque}; use super::abi::ReprOptions; use super::mir::{Body, Mutability, Safety}; use super::{DefId, Error, Symbol, with}; -use crate::stable_mir; +use crate::abi::{FnAbi, Layout}; +use crate::crate_def::{CrateDef, CrateDefItems, CrateDefType}; +use crate::mir::alloc::{AllocId, read_target_int, read_target_uint}; +use crate::mir::mono::StaticDef; +use crate::target::MachineInfo; +use crate::{Filename, IndexedVal, Opaque}; #[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize)] pub struct Ty(usize); @@ -1565,7 +1564,7 @@ pub enum PredicatePolarity { macro_rules! index_impl { ($name:ident) => { - impl stable_mir::IndexedVal for $name { + impl crate::IndexedVal for $name { fn to_val(index: usize) -> Self { $name(index) } diff --git a/compiler/rustc_smir/src/stable_mir/unstable/convert/internal.rs b/compiler/stable_mir/src/unstable/convert/internal.rs index 37c93af392e..04b2e572621 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/convert/internal.rs +++ b/compiler/stable_mir/src/unstable/convert/internal.rs @@ -7,21 +7,20 @@ use rustc_middle::ty::{self as rustc_ty, Const as InternalConst, Ty as InternalTy}; use rustc_smir::Tables; -use stable_mir::abi::Layout; -use stable_mir::compiler_interface::BridgeTys; -use stable_mir::mir::alloc::AllocId; -use stable_mir::mir::mono::{Instance, MonoItem, StaticDef}; -use stable_mir::mir::{BinOp, Mutability, Place, ProjectionElem, RawPtrKind, Safety, UnOp}; -use stable_mir::ty::{ + +use crate::abi::Layout; +use crate::compiler_interface::BridgeTys; +use crate::mir::alloc::AllocId; +use crate::mir::mono::{Instance, MonoItem, StaticDef}; +use crate::mir::{BinOp, Mutability, Place, ProjectionElem, RawPtrKind, Safety, UnOp}; +use crate::ty::{ Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig, GenericArgKind, GenericArgs, IntTy, MirConst, Movability, Pattern, Region, RigidTy, Span, TermKind, TraitRef, Ty, TyConst, UintTy, VariantDef, VariantIdx, }; -use stable_mir::unstable::{InternalCx, RustcInternal}; -use stable_mir::{CrateItem, CrateNum, DefId, IndexedVal}; - -use crate::{rustc_smir, stable_mir}; +use crate::unstable::{InternalCx, RustcInternal}; +use crate::{CrateItem, CrateNum, DefId, IndexedVal}; impl RustcInternal for CrateItem { type T<'tcx> = rustc_span::def_id::DefId; @@ -505,7 +504,7 @@ impl RustcInternal for ExistentialProjection { tables: &mut Tables<'_, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - use rustc_smir::context::SmirExistentialProjection; + use crate::unstable::internal_cx::SmirExistentialProjection; tcx.new_from_args( self.def_id.0.internal(tables, tcx), self.generic_args.internal(tables, tcx), @@ -537,7 +536,7 @@ impl RustcInternal for ExistentialTraitRef { tables: &mut Tables<'_, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - use rustc_smir::context::SmirExistentialTraitRef; + use crate::unstable::internal_cx::SmirExistentialTraitRef; tcx.new_from_args( self.def_id.0.internal(tables, tcx), self.generic_args.internal(tables, tcx), @@ -553,7 +552,7 @@ impl RustcInternal for TraitRef { tables: &mut Tables<'_, BridgeTys>, tcx: impl InternalCx<'tcx>, ) -> Self::T<'tcx> { - use rustc_smir::context::SmirTraitRef; + use crate::unstable::internal_cx::SmirTraitRef; tcx.new_from_args(self.def_id.0.internal(tables, tcx), self.args().internal(tables, tcx)) } } diff --git a/compiler/rustc_smir/src/stable_mir/unstable/convert/mod.rs b/compiler/stable_mir/src/unstable/convert/mod.rs index 6e1b85671f8..aad92325861 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/convert/mod.rs +++ b/compiler/stable_mir/src/unstable/convert/mod.rs @@ -10,10 +10,9 @@ use std::ops::RangeInclusive; use rustc_smir::Tables; use rustc_smir::context::SmirCtxt; -use stable_mir::compiler_interface::BridgeTys; use super::Stable; -use crate::{rustc_smir, stable_mir}; +use crate::compiler_interface::BridgeTys; mod internal; mod stable; diff --git a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/abi.rs b/compiler/stable_mir/src/unstable/convert/stable/abi.rs index d8823a0d10c..8fdaa69c305 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/abi.rs +++ b/compiler/stable_mir/src/unstable/convert/stable/abi.rs @@ -7,18 +7,17 @@ use rustc_middle::ty; use rustc_smir::Tables; use rustc_smir::context::SmirCtxt; use rustc_target::callconv; -use stable_mir::abi::{ + +use crate::abi::{ AddressSpace, ArgAbi, CallConvention, FieldsShape, FloatLength, FnAbi, IntegerLength, IntegerType, Layout, LayoutShape, PassMode, Primitive, ReprFlags, ReprOptions, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape, WrappingRange, }; -use stable_mir::compiler_interface::BridgeTys; -use stable_mir::target::MachineSize as Size; -use stable_mir::ty::{Align, VariantIdx}; -use stable_mir::unstable::Stable; -use stable_mir::{IndexedVal, opaque}; - -use crate::{rustc_smir, stable_mir}; +use crate::compiler_interface::BridgeTys; +use crate::target::MachineSize as Size; +use crate::ty::{Align, VariantIdx}; +use crate::unstable::Stable; +use crate::{IndexedVal, opaque}; impl<'tcx> Stable<'tcx> for rustc_abi::VariantIdx { type T = VariantIdx; @@ -28,12 +27,12 @@ impl<'tcx> Stable<'tcx> for rustc_abi::VariantIdx { } impl<'tcx> Stable<'tcx> for rustc_abi::Endian { - type T = stable_mir::target::Endian; + type T = crate::target::Endian; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { match self { - rustc_abi::Endian::Little => stable_mir::target::Endian::Little, - rustc_abi::Endian::Big => stable_mir::target::Endian::Big, + rustc_abi::Endian::Little => crate::target::Endian::Little, + rustc_abi::Endian::Big => crate::target::Endian::Big, } } } diff --git a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/mir.rs b/compiler/stable_mir/src/unstable/convert/stable/mir.rs index 99f9f456567..f6f4706e40b 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/mir.rs +++ b/compiler/stable_mir/src/unstable/convert/stable/mir.rs @@ -5,27 +5,26 @@ use rustc_middle::{bug, mir}; use rustc_smir::Tables; use rustc_smir::bridge::SmirError; use rustc_smir::context::SmirCtxt; -use stable_mir::compiler_interface::BridgeTys; -use stable_mir::mir::alloc::GlobalAlloc; -use stable_mir::mir::{ConstOperand, Statement, UserTypeProjection, VarDebugInfoFragment}; -use stable_mir::ty::{Allocation, ConstantKind, MirConst}; -use stable_mir::unstable::Stable; -use stable_mir::{Error, alloc, opaque}; -use crate::{rustc_smir, stable_mir}; +use crate::compiler_interface::BridgeTys; +use crate::mir::alloc::GlobalAlloc; +use crate::mir::{ConstOperand, Statement, UserTypeProjection, VarDebugInfoFragment}; +use crate::ty::{Allocation, ConstantKind, MirConst}; +use crate::unstable::Stable; +use crate::{Error, alloc, opaque}; impl<'tcx> Stable<'tcx> for mir::Body<'tcx> { - type T = stable_mir::mir::Body; + type T = crate::mir::Body; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::mir::Body::new( + crate::mir::Body::new( self.basic_blocks .iter() - .map(|block| stable_mir::mir::BasicBlock { + .map(|block| crate::mir::BasicBlock { terminator: block.terminator().stable(tables, cx), statements: block .statements @@ -36,7 +35,7 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> { .collect(), self.local_decls .iter() - .map(|decl| stable_mir::mir::LocalDecl { + .map(|decl| crate::mir::LocalDecl { ty: decl.ty.stable(tables, cx), span: decl.source_info.span.stable(tables, cx), mutability: decl.mutability.stable(tables, cx), @@ -51,13 +50,13 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> { } impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> { - type T = stable_mir::mir::VarDebugInfo; + type T = crate::mir::VarDebugInfo; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::mir::VarDebugInfo { + crate::mir::VarDebugInfo { name: self.name.to_string(), source_info: self.source_info.stable(tables, cx), composite: self.composite.as_ref().map(|composite| composite.stable(tables, cx)), @@ -68,7 +67,7 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfo<'tcx> { } impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> { - type T = stable_mir::mir::Statement; + type T = crate::mir::Statement; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -82,18 +81,18 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> { } impl<'tcx> Stable<'tcx> for mir::SourceInfo { - type T = stable_mir::mir::SourceInfo; + type T = crate::mir::SourceInfo; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::mir::SourceInfo { span: self.span.stable(tables, cx), scope: self.scope.into() } + crate::mir::SourceInfo { span: self.span.stable(tables, cx), scope: self.scope.into() } } } impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> { - type T = stable_mir::mir::VarDebugInfoFragment; + type T = crate::mir::VarDebugInfoFragment; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -107,7 +106,7 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoFragment<'tcx> { } impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> { - type T = stable_mir::mir::VarDebugInfoContents; + type T = crate::mir::VarDebugInfoContents; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -115,7 +114,7 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> { ) -> Self::T { match self { mir::VarDebugInfoContents::Place(place) => { - stable_mir::mir::VarDebugInfoContents::Place(place.stable(tables, cx)) + crate::mir::VarDebugInfoContents::Place(place.stable(tables, cx)) } mir::VarDebugInfoContents::Const(const_operand) => { let op = ConstOperand { @@ -123,81 +122,76 @@ impl<'tcx> Stable<'tcx> for mir::VarDebugInfoContents<'tcx> { user_ty: const_operand.user_ty.map(|index| index.as_usize()), const_: const_operand.const_.stable(tables, cx), }; - stable_mir::mir::VarDebugInfoContents::Const(op) + crate::mir::VarDebugInfoContents::Const(op) } } } } impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> { - type T = stable_mir::mir::StatementKind; + type T = crate::mir::StatementKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { match self { - mir::StatementKind::Assign(assign) => stable_mir::mir::StatementKind::Assign( + mir::StatementKind::Assign(assign) => crate::mir::StatementKind::Assign( assign.0.stable(tables, cx), assign.1.stable(tables, cx), ), - mir::StatementKind::FakeRead(fake_read_place) => { - stable_mir::mir::StatementKind::FakeRead( - fake_read_place.0.stable(tables, cx), - fake_read_place.1.stable(tables, cx), - ) - } + mir::StatementKind::FakeRead(fake_read_place) => crate::mir::StatementKind::FakeRead( + fake_read_place.0.stable(tables, cx), + fake_read_place.1.stable(tables, cx), + ), mir::StatementKind::SetDiscriminant { place, variant_index } => { - stable_mir::mir::StatementKind::SetDiscriminant { + crate::mir::StatementKind::SetDiscriminant { place: place.as_ref().stable(tables, cx), variant_index: variant_index.stable(tables, cx), } } mir::StatementKind::Deinit(place) => { - stable_mir::mir::StatementKind::Deinit(place.stable(tables, cx)) + crate::mir::StatementKind::Deinit(place.stable(tables, cx)) } mir::StatementKind::StorageLive(place) => { - stable_mir::mir::StatementKind::StorageLive(place.stable(tables, cx)) + crate::mir::StatementKind::StorageLive(place.stable(tables, cx)) } mir::StatementKind::StorageDead(place) => { - stable_mir::mir::StatementKind::StorageDead(place.stable(tables, cx)) + crate::mir::StatementKind::StorageDead(place.stable(tables, cx)) + } + mir::StatementKind::Retag(retag, place) => { + crate::mir::StatementKind::Retag(retag.stable(tables, cx), place.stable(tables, cx)) } - mir::StatementKind::Retag(retag, place) => stable_mir::mir::StatementKind::Retag( - retag.stable(tables, cx), - place.stable(tables, cx), - ), mir::StatementKind::PlaceMention(place) => { - stable_mir::mir::StatementKind::PlaceMention(place.stable(tables, cx)) + crate::mir::StatementKind::PlaceMention(place.stable(tables, cx)) } mir::StatementKind::AscribeUserType(place_projection, variance) => { - stable_mir::mir::StatementKind::AscribeUserType { + crate::mir::StatementKind::AscribeUserType { place: place_projection.as_ref().0.stable(tables, cx), projections: place_projection.as_ref().1.stable(tables, cx), variance: variance.stable(tables, cx), } } mir::StatementKind::Coverage(coverage) => { - stable_mir::mir::StatementKind::Coverage(opaque(coverage)) + crate::mir::StatementKind::Coverage(opaque(coverage)) } mir::StatementKind::Intrinsic(intrinstic) => { - stable_mir::mir::StatementKind::Intrinsic(intrinstic.stable(tables, cx)) - } - mir::StatementKind::ConstEvalCounter => { - stable_mir::mir::StatementKind::ConstEvalCounter + crate::mir::StatementKind::Intrinsic(intrinstic.stable(tables, cx)) } + mir::StatementKind::ConstEvalCounter => crate::mir::StatementKind::ConstEvalCounter, // BackwardIncompatibleDropHint has no semantics, so it is translated to Nop. mir::StatementKind::BackwardIncompatibleDropHint { .. } => { - stable_mir::mir::StatementKind::Nop + crate::mir::StatementKind::Nop } - mir::StatementKind::Nop => stable_mir::mir::StatementKind::Nop, + mir::StatementKind::Nop => crate::mir::StatementKind::Nop, } } } impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> { - type T = stable_mir::mir::Rvalue; + type T = crate::mir::Rvalue; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -205,91 +199,89 @@ impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> { ) -> Self::T { use rustc_middle::mir::Rvalue::*; match self { - Use(op) => stable_mir::mir::Rvalue::Use(op.stable(tables, cx)), + Use(op) => crate::mir::Rvalue::Use(op.stable(tables, cx)), Repeat(op, len) => { let len = len.stable(tables, cx); - stable_mir::mir::Rvalue::Repeat(op.stable(tables, cx), len) + crate::mir::Rvalue::Repeat(op.stable(tables, cx), len) } - Ref(region, kind, place) => stable_mir::mir::Rvalue::Ref( + Ref(region, kind, place) => crate::mir::Rvalue::Ref( region.stable(tables, cx), kind.stable(tables, cx), place.stable(tables, cx), ), ThreadLocalRef(def_id) => { - stable_mir::mir::Rvalue::ThreadLocalRef(tables.crate_item(*def_id)) + crate::mir::Rvalue::ThreadLocalRef(tables.crate_item(*def_id)) } - RawPtr(mutability, place) => stable_mir::mir::Rvalue::AddressOf( + RawPtr(mutability, place) => crate::mir::Rvalue::AddressOf( mutability.stable(tables, cx), place.stable(tables, cx), ), - Len(place) => stable_mir::mir::Rvalue::Len(place.stable(tables, cx)), - Cast(cast_kind, op, ty) => stable_mir::mir::Rvalue::Cast( + Len(place) => crate::mir::Rvalue::Len(place.stable(tables, cx)), + Cast(cast_kind, op, ty) => crate::mir::Rvalue::Cast( cast_kind.stable(tables, cx), op.stable(tables, cx), ty.stable(tables, cx), ), BinaryOp(bin_op, ops) => { if let Some(bin_op) = bin_op.overflowing_to_wrapping() { - stable_mir::mir::Rvalue::CheckedBinaryOp( + crate::mir::Rvalue::CheckedBinaryOp( bin_op.stable(tables, cx), ops.0.stable(tables, cx), ops.1.stable(tables, cx), ) } else { - stable_mir::mir::Rvalue::BinaryOp( + crate::mir::Rvalue::BinaryOp( bin_op.stable(tables, cx), ops.0.stable(tables, cx), ops.1.stable(tables, cx), ) } } - NullaryOp(null_op, ty) => stable_mir::mir::Rvalue::NullaryOp( - null_op.stable(tables, cx), - ty.stable(tables, cx), - ), + NullaryOp(null_op, ty) => { + crate::mir::Rvalue::NullaryOp(null_op.stable(tables, cx), ty.stable(tables, cx)) + } UnaryOp(un_op, op) => { - stable_mir::mir::Rvalue::UnaryOp(un_op.stable(tables, cx), op.stable(tables, cx)) + crate::mir::Rvalue::UnaryOp(un_op.stable(tables, cx), op.stable(tables, cx)) } - Discriminant(place) => stable_mir::mir::Rvalue::Discriminant(place.stable(tables, cx)), + Discriminant(place) => crate::mir::Rvalue::Discriminant(place.stable(tables, cx)), Aggregate(agg_kind, operands) => { let operands = operands.iter().map(|op| op.stable(tables, cx)).collect(); - stable_mir::mir::Rvalue::Aggregate(agg_kind.stable(tables, cx), operands) + crate::mir::Rvalue::Aggregate(agg_kind.stable(tables, cx), operands) } - ShallowInitBox(op, ty) => stable_mir::mir::Rvalue::ShallowInitBox( - op.stable(tables, cx), - ty.stable(tables, cx), - ), - CopyForDeref(place) => stable_mir::mir::Rvalue::CopyForDeref(place.stable(tables, cx)), + ShallowInitBox(op, ty) => { + crate::mir::Rvalue::ShallowInitBox(op.stable(tables, cx), ty.stable(tables, cx)) + } + CopyForDeref(place) => crate::mir::Rvalue::CopyForDeref(place.stable(tables, cx)), WrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"), } } } impl<'tcx> Stable<'tcx> for mir::Mutability { - type T = stable_mir::mir::Mutability; + type T = crate::mir::Mutability; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_hir::Mutability::*; match *self { - Not => stable_mir::mir::Mutability::Not, - Mut => stable_mir::mir::Mutability::Mut, + Not => crate::mir::Mutability::Not, + Mut => crate::mir::Mutability::Mut, } } } impl<'tcx> Stable<'tcx> for mir::RawPtrKind { - type T = stable_mir::mir::RawPtrKind; + type T = crate::mir::RawPtrKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use mir::RawPtrKind::*; match *self { - Const => stable_mir::mir::RawPtrKind::Const, - Mut => stable_mir::mir::RawPtrKind::Mut, - FakeForPtrMetadata => stable_mir::mir::RawPtrKind::FakeForPtrMetadata, + Const => crate::mir::RawPtrKind::Const, + Mut => crate::mir::RawPtrKind::Mut, + FakeForPtrMetadata => crate::mir::RawPtrKind::FakeForPtrMetadata, } } } impl<'tcx> Stable<'tcx> for mir::BorrowKind { - type T = stable_mir::mir::BorrowKind; + type T = crate::mir::BorrowKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -297,38 +289,38 @@ impl<'tcx> Stable<'tcx> for mir::BorrowKind { ) -> Self::T { use rustc_middle::mir::BorrowKind::*; match *self { - Shared => stable_mir::mir::BorrowKind::Shared, - Fake(kind) => stable_mir::mir::BorrowKind::Fake(kind.stable(tables, cx)), - Mut { kind } => stable_mir::mir::BorrowKind::Mut { kind: kind.stable(tables, cx) }, + Shared => crate::mir::BorrowKind::Shared, + Fake(kind) => crate::mir::BorrowKind::Fake(kind.stable(tables, cx)), + Mut { kind } => crate::mir::BorrowKind::Mut { kind: kind.stable(tables, cx) }, } } } impl<'tcx> Stable<'tcx> for mir::MutBorrowKind { - type T = stable_mir::mir::MutBorrowKind; + type T = crate::mir::MutBorrowKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::MutBorrowKind::*; match *self { - Default => stable_mir::mir::MutBorrowKind::Default, - TwoPhaseBorrow => stable_mir::mir::MutBorrowKind::TwoPhaseBorrow, - ClosureCapture => stable_mir::mir::MutBorrowKind::ClosureCapture, + Default => crate::mir::MutBorrowKind::Default, + TwoPhaseBorrow => crate::mir::MutBorrowKind::TwoPhaseBorrow, + ClosureCapture => crate::mir::MutBorrowKind::ClosureCapture, } } } impl<'tcx> Stable<'tcx> for mir::FakeBorrowKind { - type T = stable_mir::mir::FakeBorrowKind; + type T = crate::mir::FakeBorrowKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::FakeBorrowKind::*; match *self { - Deep => stable_mir::mir::FakeBorrowKind::Deep, - Shallow => stable_mir::mir::FakeBorrowKind::Shallow, + Deep => crate::mir::FakeBorrowKind::Deep, + Shallow => crate::mir::FakeBorrowKind::Shallow, } } } impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> { - type T = stable_mir::mir::NullOp; + type T = crate::mir::NullOp; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -336,19 +328,19 @@ impl<'tcx> Stable<'tcx> for mir::NullOp<'tcx> { ) -> Self::T { use rustc_middle::mir::NullOp::*; match self { - SizeOf => stable_mir::mir::NullOp::SizeOf, - AlignOf => stable_mir::mir::NullOp::AlignOf, - OffsetOf(indices) => stable_mir::mir::NullOp::OffsetOf( + SizeOf => crate::mir::NullOp::SizeOf, + AlignOf => crate::mir::NullOp::AlignOf, + OffsetOf(indices) => crate::mir::NullOp::OffsetOf( indices.iter().map(|idx| idx.stable(tables, cx)).collect(), ), - UbChecks => stable_mir::mir::NullOp::UbChecks, - ContractChecks => stable_mir::mir::NullOp::ContractChecks, + UbChecks => crate::mir::NullOp::UbChecks, + ContractChecks => crate::mir::NullOp::ContractChecks, } } } impl<'tcx> Stable<'tcx> for mir::CastKind { - type T = stable_mir::mir::CastKind; + type T = crate::mir::CastKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -356,40 +348,38 @@ impl<'tcx> Stable<'tcx> for mir::CastKind { ) -> Self::T { use rustc_middle::mir::CastKind::*; match self { - PointerExposeProvenance => stable_mir::mir::CastKind::PointerExposeAddress, - PointerWithExposedProvenance => stable_mir::mir::CastKind::PointerWithExposedProvenance, - PointerCoercion(c, _) => { - stable_mir::mir::CastKind::PointerCoercion(c.stable(tables, cx)) - } - IntToInt => stable_mir::mir::CastKind::IntToInt, - FloatToInt => stable_mir::mir::CastKind::FloatToInt, - FloatToFloat => stable_mir::mir::CastKind::FloatToFloat, - IntToFloat => stable_mir::mir::CastKind::IntToFloat, - PtrToPtr => stable_mir::mir::CastKind::PtrToPtr, - FnPtrToPtr => stable_mir::mir::CastKind::FnPtrToPtr, - Transmute => stable_mir::mir::CastKind::Transmute, + PointerExposeProvenance => crate::mir::CastKind::PointerExposeAddress, + PointerWithExposedProvenance => crate::mir::CastKind::PointerWithExposedProvenance, + PointerCoercion(c, _) => crate::mir::CastKind::PointerCoercion(c.stable(tables, cx)), + IntToInt => crate::mir::CastKind::IntToInt, + FloatToInt => crate::mir::CastKind::FloatToInt, + FloatToFloat => crate::mir::CastKind::FloatToFloat, + IntToFloat => crate::mir::CastKind::IntToFloat, + PtrToPtr => crate::mir::CastKind::PtrToPtr, + FnPtrToPtr => crate::mir::CastKind::FnPtrToPtr, + Transmute => crate::mir::CastKind::Transmute, } } } impl<'tcx> Stable<'tcx> for mir::FakeReadCause { - type T = stable_mir::mir::FakeReadCause; + type T = crate::mir::FakeReadCause; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::FakeReadCause::*; match self { - ForMatchGuard => stable_mir::mir::FakeReadCause::ForMatchGuard, + ForMatchGuard => crate::mir::FakeReadCause::ForMatchGuard, ForMatchedPlace(local_def_id) => { - stable_mir::mir::FakeReadCause::ForMatchedPlace(opaque(local_def_id)) + crate::mir::FakeReadCause::ForMatchedPlace(opaque(local_def_id)) } - ForGuardBinding => stable_mir::mir::FakeReadCause::ForGuardBinding, - ForLet(local_def_id) => stable_mir::mir::FakeReadCause::ForLet(opaque(local_def_id)), - ForIndex => stable_mir::mir::FakeReadCause::ForIndex, + ForGuardBinding => crate::mir::FakeReadCause::ForGuardBinding, + ForLet(local_def_id) => crate::mir::FakeReadCause::ForLet(opaque(local_def_id)), + ForIndex => crate::mir::FakeReadCause::ForIndex, } } } impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> { - type T = stable_mir::mir::Operand; + type T = crate::mir::Operand; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -397,22 +387,22 @@ impl<'tcx> Stable<'tcx> for mir::Operand<'tcx> { ) -> Self::T { use rustc_middle::mir::Operand::*; match self { - Copy(place) => stable_mir::mir::Operand::Copy(place.stable(tables, cx)), - Move(place) => stable_mir::mir::Operand::Move(place.stable(tables, cx)), - Constant(c) => stable_mir::mir::Operand::Constant(c.stable(tables, cx)), + Copy(place) => crate::mir::Operand::Copy(place.stable(tables, cx)), + Move(place) => crate::mir::Operand::Move(place.stable(tables, cx)), + Constant(c) => crate::mir::Operand::Constant(c.stable(tables, cx)), } } } impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> { - type T = stable_mir::mir::ConstOperand; + type T = crate::mir::ConstOperand; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::mir::ConstOperand { + crate::mir::ConstOperand { span: self.span.stable(tables, cx), user_ty: self.user_ty.map(|u| u.as_usize()).or(None), const_: self.const_.stable(tables, cx), @@ -421,13 +411,13 @@ impl<'tcx> Stable<'tcx> for mir::ConstOperand<'tcx> { } impl<'tcx> Stable<'tcx> for mir::Place<'tcx> { - type T = stable_mir::mir::Place; + type T = crate::mir::Place; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::mir::Place { + crate::mir::Place { local: self.local.as_usize(), projection: self.projection.iter().map(|e| e.stable(tables, cx)).collect(), } @@ -435,7 +425,7 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> { } impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> { - type T = stable_mir::mir::ProjectionElem; + type T = crate::mir::ProjectionElem; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -443,39 +433,36 @@ impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> { ) -> Self::T { use rustc_middle::mir::ProjectionElem::*; match self { - Deref => stable_mir::mir::ProjectionElem::Deref, - Field(idx, ty) => stable_mir::mir::ProjectionElem::Field( - idx.stable(tables, cx), - ty.stable(tables, cx), - ), - Index(local) => stable_mir::mir::ProjectionElem::Index(local.stable(tables, cx)), + Deref => crate::mir::ProjectionElem::Deref, + Field(idx, ty) => { + crate::mir::ProjectionElem::Field(idx.stable(tables, cx), ty.stable(tables, cx)) + } + Index(local) => crate::mir::ProjectionElem::Index(local.stable(tables, cx)), ConstantIndex { offset, min_length, from_end } => { - stable_mir::mir::ProjectionElem::ConstantIndex { + crate::mir::ProjectionElem::ConstantIndex { offset: *offset, min_length: *min_length, from_end: *from_end, } } - Subslice { from, to, from_end } => stable_mir::mir::ProjectionElem::Subslice { - from: *from, - to: *to, - from_end: *from_end, - }, + Subslice { from, to, from_end } => { + crate::mir::ProjectionElem::Subslice { from: *from, to: *to, from_end: *from_end } + } // MIR includes an `Option<Symbol>` argument for `Downcast` that is the name of the // variant, used for printing MIR. However this information should also be accessible // via a lookup using the `VariantIdx`. The `Option<Symbol>` argument is therefore // dropped when converting to Stable MIR. A brief justification for this decision can be // found at https://github.com/rust-lang/rust/pull/117517#issuecomment-1811683486 - Downcast(_, idx) => stable_mir::mir::ProjectionElem::Downcast(idx.stable(tables, cx)), - OpaqueCast(ty) => stable_mir::mir::ProjectionElem::OpaqueCast(ty.stable(tables, cx)), - Subtype(ty) => stable_mir::mir::ProjectionElem::Subtype(ty.stable(tables, cx)), + Downcast(_, idx) => crate::mir::ProjectionElem::Downcast(idx.stable(tables, cx)), + OpaqueCast(ty) => crate::mir::ProjectionElem::OpaqueCast(ty.stable(tables, cx)), + Subtype(ty) => crate::mir::ProjectionElem::Subtype(ty.stable(tables, cx)), UnwrapUnsafeBinder(..) => todo!("FIXME(unsafe_binders):"), } } } impl<'tcx> Stable<'tcx> for mir::UserTypeProjection { - type T = stable_mir::mir::UserTypeProjection; + type T = crate::mir::UserTypeProjection; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { UserTypeProjection { base: self.base.as_usize(), projection: opaque(&self.projs) } @@ -483,40 +470,40 @@ impl<'tcx> Stable<'tcx> for mir::UserTypeProjection { } impl<'tcx> Stable<'tcx> for mir::Local { - type T = stable_mir::mir::Local; + type T = crate::mir::Local; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { self.as_usize() } } impl<'tcx> Stable<'tcx> for mir::RetagKind { - type T = stable_mir::mir::RetagKind; + type T = crate::mir::RetagKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::RetagKind; match self { - RetagKind::FnEntry => stable_mir::mir::RetagKind::FnEntry, - RetagKind::TwoPhase => stable_mir::mir::RetagKind::TwoPhase, - RetagKind::Raw => stable_mir::mir::RetagKind::Raw, - RetagKind::Default => stable_mir::mir::RetagKind::Default, + RetagKind::FnEntry => crate::mir::RetagKind::FnEntry, + RetagKind::TwoPhase => crate::mir::RetagKind::TwoPhase, + RetagKind::Raw => crate::mir::RetagKind::Raw, + RetagKind::Default => crate::mir::RetagKind::Default, } } } impl<'tcx> Stable<'tcx> for mir::UnwindAction { - type T = stable_mir::mir::UnwindAction; + type T = crate::mir::UnwindAction; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::UnwindAction; match self { - UnwindAction::Continue => stable_mir::mir::UnwindAction::Continue, - UnwindAction::Unreachable => stable_mir::mir::UnwindAction::Unreachable, - UnwindAction::Terminate(_) => stable_mir::mir::UnwindAction::Terminate, - UnwindAction::Cleanup(bb) => stable_mir::mir::UnwindAction::Cleanup(bb.as_usize()), + UnwindAction::Continue => crate::mir::UnwindAction::Continue, + UnwindAction::Unreachable => crate::mir::UnwindAction::Unreachable, + UnwindAction::Terminate(_) => crate::mir::UnwindAction::Terminate, + UnwindAction::Cleanup(bb) => crate::mir::UnwindAction::Cleanup(bb.as_usize()), } } } impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> { - type T = stable_mir::mir::NonDivergingIntrinsic; + type T = crate::mir::NonDivergingIntrinsic; fn stable<'cx>( &self, @@ -524,13 +511,14 @@ impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { use rustc_middle::mir::NonDivergingIntrinsic; - use stable_mir::mir::CopyNonOverlapping; + + use crate::mir::CopyNonOverlapping; match self { NonDivergingIntrinsic::Assume(op) => { - stable_mir::mir::NonDivergingIntrinsic::Assume(op.stable(tables, cx)) + crate::mir::NonDivergingIntrinsic::Assume(op.stable(tables, cx)) } NonDivergingIntrinsic::CopyNonOverlapping(copy_non_overlapping) => { - stable_mir::mir::NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping { + crate::mir::NonDivergingIntrinsic::CopyNonOverlapping(CopyNonOverlapping { src: copy_non_overlapping.src.stable(tables, cx), dst: copy_non_overlapping.dst.stable(tables, cx), count: copy_non_overlapping.count.stable(tables, cx), @@ -541,7 +529,7 @@ impl<'tcx> Stable<'tcx> for mir::NonDivergingIntrinsic<'tcx> { } impl<'tcx> Stable<'tcx> for mir::AssertMessage<'tcx> { - type T = stable_mir::mir::AssertMessage; + type T = crate::mir::AssertMessage; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -549,98 +537,96 @@ impl<'tcx> Stable<'tcx> for mir::AssertMessage<'tcx> { ) -> Self::T { use rustc_middle::mir::AssertKind; match self { - AssertKind::BoundsCheck { len, index } => stable_mir::mir::AssertMessage::BoundsCheck { + AssertKind::BoundsCheck { len, index } => crate::mir::AssertMessage::BoundsCheck { len: len.stable(tables, cx), index: index.stable(tables, cx), }, - AssertKind::Overflow(bin_op, op1, op2) => stable_mir::mir::AssertMessage::Overflow( + AssertKind::Overflow(bin_op, op1, op2) => crate::mir::AssertMessage::Overflow( bin_op.stable(tables, cx), op1.stable(tables, cx), op2.stable(tables, cx), ), AssertKind::OverflowNeg(op) => { - stable_mir::mir::AssertMessage::OverflowNeg(op.stable(tables, cx)) + crate::mir::AssertMessage::OverflowNeg(op.stable(tables, cx)) } AssertKind::DivisionByZero(op) => { - stable_mir::mir::AssertMessage::DivisionByZero(op.stable(tables, cx)) + crate::mir::AssertMessage::DivisionByZero(op.stable(tables, cx)) } AssertKind::RemainderByZero(op) => { - stable_mir::mir::AssertMessage::RemainderByZero(op.stable(tables, cx)) + crate::mir::AssertMessage::RemainderByZero(op.stable(tables, cx)) } AssertKind::ResumedAfterReturn(coroutine) => { - stable_mir::mir::AssertMessage::ResumedAfterReturn(coroutine.stable(tables, cx)) + crate::mir::AssertMessage::ResumedAfterReturn(coroutine.stable(tables, cx)) } AssertKind::ResumedAfterPanic(coroutine) => { - stable_mir::mir::AssertMessage::ResumedAfterPanic(coroutine.stable(tables, cx)) + crate::mir::AssertMessage::ResumedAfterPanic(coroutine.stable(tables, cx)) } AssertKind::ResumedAfterDrop(coroutine) => { - stable_mir::mir::AssertMessage::ResumedAfterDrop(coroutine.stable(tables, cx)) + crate::mir::AssertMessage::ResumedAfterDrop(coroutine.stable(tables, cx)) } AssertKind::MisalignedPointerDereference { required, found } => { - stable_mir::mir::AssertMessage::MisalignedPointerDereference { + crate::mir::AssertMessage::MisalignedPointerDereference { required: required.stable(tables, cx), found: found.stable(tables, cx), } } - AssertKind::NullPointerDereference => { - stable_mir::mir::AssertMessage::NullPointerDereference - } + AssertKind::NullPointerDereference => crate::mir::AssertMessage::NullPointerDereference, AssertKind::InvalidEnumConstruction(source) => { - stable_mir::mir::AssertMessage::InvalidEnumConstruction(source.stable(tables, cx)) + crate::mir::AssertMessage::InvalidEnumConstruction(source.stable(tables, cx)) } } } } impl<'tcx> Stable<'tcx> for mir::BinOp { - type T = stable_mir::mir::BinOp; + type T = crate::mir::BinOp; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::BinOp; match self { - BinOp::Add => stable_mir::mir::BinOp::Add, - BinOp::AddUnchecked => stable_mir::mir::BinOp::AddUnchecked, + BinOp::Add => crate::mir::BinOp::Add, + BinOp::AddUnchecked => crate::mir::BinOp::AddUnchecked, BinOp::AddWithOverflow => bug!("AddWithOverflow should have been translated already"), - BinOp::Sub => stable_mir::mir::BinOp::Sub, - BinOp::SubUnchecked => stable_mir::mir::BinOp::SubUnchecked, + BinOp::Sub => crate::mir::BinOp::Sub, + BinOp::SubUnchecked => crate::mir::BinOp::SubUnchecked, BinOp::SubWithOverflow => bug!("AddWithOverflow should have been translated already"), - BinOp::Mul => stable_mir::mir::BinOp::Mul, - BinOp::MulUnchecked => stable_mir::mir::BinOp::MulUnchecked, + BinOp::Mul => crate::mir::BinOp::Mul, + BinOp::MulUnchecked => crate::mir::BinOp::MulUnchecked, BinOp::MulWithOverflow => bug!("AddWithOverflow should have been translated already"), - BinOp::Div => stable_mir::mir::BinOp::Div, - BinOp::Rem => stable_mir::mir::BinOp::Rem, - BinOp::BitXor => stable_mir::mir::BinOp::BitXor, - BinOp::BitAnd => stable_mir::mir::BinOp::BitAnd, - BinOp::BitOr => stable_mir::mir::BinOp::BitOr, - BinOp::Shl => stable_mir::mir::BinOp::Shl, - BinOp::ShlUnchecked => stable_mir::mir::BinOp::ShlUnchecked, - BinOp::Shr => stable_mir::mir::BinOp::Shr, - BinOp::ShrUnchecked => stable_mir::mir::BinOp::ShrUnchecked, - BinOp::Eq => stable_mir::mir::BinOp::Eq, - BinOp::Lt => stable_mir::mir::BinOp::Lt, - BinOp::Le => stable_mir::mir::BinOp::Le, - BinOp::Ne => stable_mir::mir::BinOp::Ne, - BinOp::Ge => stable_mir::mir::BinOp::Ge, - BinOp::Gt => stable_mir::mir::BinOp::Gt, - BinOp::Cmp => stable_mir::mir::BinOp::Cmp, - BinOp::Offset => stable_mir::mir::BinOp::Offset, + BinOp::Div => crate::mir::BinOp::Div, + BinOp::Rem => crate::mir::BinOp::Rem, + BinOp::BitXor => crate::mir::BinOp::BitXor, + BinOp::BitAnd => crate::mir::BinOp::BitAnd, + BinOp::BitOr => crate::mir::BinOp::BitOr, + BinOp::Shl => crate::mir::BinOp::Shl, + BinOp::ShlUnchecked => crate::mir::BinOp::ShlUnchecked, + BinOp::Shr => crate::mir::BinOp::Shr, + BinOp::ShrUnchecked => crate::mir::BinOp::ShrUnchecked, + BinOp::Eq => crate::mir::BinOp::Eq, + BinOp::Lt => crate::mir::BinOp::Lt, + BinOp::Le => crate::mir::BinOp::Le, + BinOp::Ne => crate::mir::BinOp::Ne, + BinOp::Ge => crate::mir::BinOp::Ge, + BinOp::Gt => crate::mir::BinOp::Gt, + BinOp::Cmp => crate::mir::BinOp::Cmp, + BinOp::Offset => crate::mir::BinOp::Offset, } } } impl<'tcx> Stable<'tcx> for mir::UnOp { - type T = stable_mir::mir::UnOp; + type T = crate::mir::UnOp; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::mir::UnOp; match self { - UnOp::Not => stable_mir::mir::UnOp::Not, - UnOp::Neg => stable_mir::mir::UnOp::Neg, - UnOp::PtrMetadata => stable_mir::mir::UnOp::PtrMetadata, + UnOp::Not => crate::mir::UnOp::Not, + UnOp::Neg => crate::mir::UnOp::Neg, + UnOp::PtrMetadata => crate::mir::UnOp::PtrMetadata, } } } impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { - type T = stable_mir::mir::AggregateKind; + type T = crate::mir::AggregateKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -648,11 +634,11 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { ) -> Self::T { match self { mir::AggregateKind::Array(ty) => { - stable_mir::mir::AggregateKind::Array(ty.stable(tables, cx)) + crate::mir::AggregateKind::Array(ty.stable(tables, cx)) } - mir::AggregateKind::Tuple => stable_mir::mir::AggregateKind::Tuple, + mir::AggregateKind::Tuple => crate::mir::AggregateKind::Tuple, mir::AggregateKind::Adt(def_id, var_idx, generic_arg, user_ty_index, field_idx) => { - stable_mir::mir::AggregateKind::Adt( + crate::mir::AggregateKind::Adt( tables.adt_def(*def_id), var_idx.stable(tables, cx), generic_arg.stable(tables, cx), @@ -660,26 +646,24 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { field_idx.map(|idx| idx.index()), ) } - mir::AggregateKind::Closure(def_id, generic_arg) => { - stable_mir::mir::AggregateKind::Closure( - tables.closure_def(*def_id), - generic_arg.stable(tables, cx), - ) - } + mir::AggregateKind::Closure(def_id, generic_arg) => crate::mir::AggregateKind::Closure( + tables.closure_def(*def_id), + generic_arg.stable(tables, cx), + ), mir::AggregateKind::Coroutine(def_id, generic_arg) => { - stable_mir::mir::AggregateKind::Coroutine( + crate::mir::AggregateKind::Coroutine( tables.coroutine_def(*def_id), generic_arg.stable(tables, cx), cx.coroutine_movability(*def_id).stable(tables, cx), ) } mir::AggregateKind::CoroutineClosure(def_id, generic_args) => { - stable_mir::mir::AggregateKind::CoroutineClosure( + crate::mir::AggregateKind::CoroutineClosure( tables.coroutine_closure_def(*def_id), generic_args.stable(tables, cx), ) } - mir::AggregateKind::RawPtr(ty, mutability) => stable_mir::mir::AggregateKind::RawPtr( + mir::AggregateKind::RawPtr(ty, mutability) => crate::mir::AggregateKind::RawPtr( ty.stable(tables, cx), mutability.stable(tables, cx), ), @@ -688,7 +672,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { } impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> { - type T = stable_mir::mir::InlineAsmOperand; + type T = crate::mir::InlineAsmOperand; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -710,18 +694,18 @@ impl<'tcx> Stable<'tcx> for mir::InlineAsmOperand<'tcx> { | InlineAsmOperand::Label { .. } => (None, None), }; - stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{self:?}") } + crate::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{self:?}") } } } impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { - type T = stable_mir::mir::Terminator; + type T = crate::mir::Terminator; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::mir::Terminator; + use crate::mir::Terminator; Terminator { kind: self.kind.stable(tables, cx), span: self.source_info.span.stable(tables, cx), @@ -730,13 +714,13 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { } impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> { - type T = stable_mir::mir::TerminatorKind; + type T = crate::mir::TerminatorKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::mir::TerminatorKind; + use crate::mir::TerminatorKind; match self { mir::TerminatorKind::Goto { target } => { TerminatorKind::Goto { target: target.as_usize() } @@ -745,7 +729,7 @@ impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> { discr: discr.stable(tables, cx), targets: { let branches = targets.iter().map(|(val, target)| (val, target.as_usize())); - stable_mir::mir::SwitchTargets::new( + crate::mir::SwitchTargets::new( branches.collect(), targets.otherwise().as_usize(), ) @@ -830,7 +814,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ConstAllocation<'tcx> { } impl<'tcx> Stable<'tcx> for mir::interpret::Allocation { - type T = stable_mir::ty::Allocation; + type T = crate::ty::Allocation; fn stable<'cx>( &self, @@ -848,7 +832,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::Allocation { } impl<'tcx> Stable<'tcx> for mir::interpret::AllocId { - type T = stable_mir::mir::alloc::AllocId; + type T = crate::mir::alloc::AllocId; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -885,7 +869,7 @@ impl<'tcx> Stable<'tcx> for mir::interpret::GlobalAlloc<'tcx> { } impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { - type T = stable_mir::ty::MirConst; + type T = crate::ty::MirConst; fn stable<'cx>( &self, @@ -895,17 +879,16 @@ impl<'tcx> Stable<'tcx> for rustc_middle::mir::Const<'tcx> { let id = tables.intern_mir_const(cx.lift(*self).unwrap()); match *self { mir::Const::Ty(ty, c) => MirConst::new( - stable_mir::ty::ConstantKind::Ty(c.stable(tables, cx)), + crate::ty::ConstantKind::Ty(c.stable(tables, cx)), ty.stable(tables, cx), id, ), mir::Const::Unevaluated(unev_const, ty) => { - let kind = - stable_mir::ty::ConstantKind::Unevaluated(stable_mir::ty::UnevaluatedConst { - def: tables.const_def(unev_const.def), - args: unev_const.args.stable(tables, cx), - promoted: unev_const.promoted.map(|u| u.as_u32()), - }); + let kind = crate::ty::ConstantKind::Unevaluated(crate::ty::UnevaluatedConst { + def: tables.const_def(unev_const.def), + args: unev_const.args.stable(tables, cx), + promoted: unev_const.promoted.map(|u| u.as_u32()), + }); let ty = ty.stable(tables, cx); MirConst::new(kind, ty, id) } @@ -933,14 +916,14 @@ impl<'tcx> Stable<'tcx> for mir::interpret::ErrorHandled { } impl<'tcx> Stable<'tcx> for MonoItem<'tcx> { - type T = stable_mir::mir::mono::MonoItem; + type T = crate::mir::mono::MonoItem; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::mir::mono::MonoItem as StableMonoItem; + use crate::mir::mono::MonoItem as StableMonoItem; match self { MonoItem::Fn(instance) => StableMonoItem::Fn(instance.stable(tables, cx)), MonoItem::Static(def_id) => StableMonoItem::Static(tables.static_def(*def_id)), diff --git a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/mod.rs b/compiler/stable_mir/src/unstable/convert/stable/mod.rs index 799917c6e17..e7f14bbdfc8 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/mod.rs +++ b/compiler/stable_mir/src/unstable/convert/stable/mod.rs @@ -3,21 +3,20 @@ use rustc_abi::FieldIdx; use rustc_smir::Tables; use rustc_smir::context::SmirCtxt; -use stable_mir::compiler_interface::BridgeTys; use super::Stable; -use crate::{rustc_smir, stable_mir}; +use crate::compiler_interface::BridgeTys; mod abi; mod mir; mod ty; impl<'tcx> Stable<'tcx> for rustc_hir::Safety { - type T = stable_mir::mir::Safety; + type T = crate::mir::Safety; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { match self { - rustc_hir::Safety::Unsafe => stable_mir::mir::Safety::Unsafe, - rustc_hir::Safety::Safe => stable_mir::mir::Safety::Safe, + rustc_hir::Safety::Unsafe => crate::mir::Safety::Unsafe, + rustc_hir::Safety::Safe => crate::mir::Safety::Safe, } } } @@ -30,19 +29,19 @@ impl<'tcx> Stable<'tcx> for FieldIdx { } impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineSource { - type T = stable_mir::mir::CoroutineSource; + type T = crate::mir::CoroutineSource; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_hir::CoroutineSource; match self { - CoroutineSource::Block => stable_mir::mir::CoroutineSource::Block, - CoroutineSource::Closure => stable_mir::mir::CoroutineSource::Closure, - CoroutineSource::Fn => stable_mir::mir::CoroutineSource::Fn, + CoroutineSource::Block => crate::mir::CoroutineSource::Block, + CoroutineSource::Closure => crate::mir::CoroutineSource::Closure, + CoroutineSource::Fn => crate::mir::CoroutineSource::Fn, } } } impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind { - type T = stable_mir::mir::CoroutineKind; + type T = crate::mir::CoroutineKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -51,23 +50,23 @@ impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind { use rustc_hir::{CoroutineDesugaring, CoroutineKind}; match *self { CoroutineKind::Desugared(CoroutineDesugaring::Async, source) => { - stable_mir::mir::CoroutineKind::Desugared( - stable_mir::mir::CoroutineDesugaring::Async, + crate::mir::CoroutineKind::Desugared( + crate::mir::CoroutineDesugaring::Async, source.stable(tables, cx), ) } CoroutineKind::Desugared(CoroutineDesugaring::Gen, source) => { - stable_mir::mir::CoroutineKind::Desugared( - stable_mir::mir::CoroutineDesugaring::Gen, + crate::mir::CoroutineKind::Desugared( + crate::mir::CoroutineDesugaring::Gen, source.stable(tables, cx), ) } CoroutineKind::Coroutine(movability) => { - stable_mir::mir::CoroutineKind::Coroutine(movability.stable(tables, cx)) + crate::mir::CoroutineKind::Coroutine(movability.stable(tables, cx)) } CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, source) => { - stable_mir::mir::CoroutineKind::Desugared( - stable_mir::mir::CoroutineDesugaring::AsyncGen, + crate::mir::CoroutineKind::Desugared( + crate::mir::CoroutineDesugaring::AsyncGen, source.stable(tables, cx), ) } @@ -76,7 +75,7 @@ impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind { } impl<'tcx> Stable<'tcx> for rustc_span::Symbol { - type T = stable_mir::Symbol; + type T = crate::Symbol; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { self.to_string() @@ -84,7 +83,7 @@ impl<'tcx> Stable<'tcx> for rustc_span::Symbol { } impl<'tcx> Stable<'tcx> for rustc_span::Span { - type T = stable_mir::ty::Span; + type T = crate::ty::Span; fn stable<'cx>( &self, diff --git a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/ty.rs b/compiler/stable_mir/src/unstable/convert/stable/ty.rs index 596c8b96bfc..366f7ea01d4 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/convert/stable/ty.rs +++ b/compiler/stable_mir/src/unstable/convert/stable/ty.rs @@ -4,73 +4,69 @@ use rustc_middle::ty::Ty; use rustc_middle::{bug, mir, ty}; use rustc_smir::Tables; use rustc_smir::context::SmirCtxt; -use stable_mir::alloc; -use stable_mir::compiler_interface::BridgeTys; -use stable_mir::ty::{ + +use crate::alloc; +use crate::compiler_interface::BridgeTys; +use crate::ty::{ AdtKind, FloatTy, GenericArgs, GenericParamDef, IntTy, Region, RigidTy, TyKind, UintTy, }; -use stable_mir::unstable::Stable; - -use crate::{rustc_smir, stable_mir}; +use crate::unstable::Stable; impl<'tcx> Stable<'tcx> for ty::AliasTyKind { - type T = stable_mir::ty::AliasKind; + type T = crate::ty::AliasKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { match self { - ty::Projection => stable_mir::ty::AliasKind::Projection, - ty::Inherent => stable_mir::ty::AliasKind::Inherent, - ty::Opaque => stable_mir::ty::AliasKind::Opaque, - ty::Free => stable_mir::ty::AliasKind::Free, + ty::Projection => crate::ty::AliasKind::Projection, + ty::Inherent => crate::ty::AliasKind::Inherent, + ty::Opaque => crate::ty::AliasKind::Opaque, + ty::Free => crate::ty::AliasKind::Free, } } } impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> { - type T = stable_mir::ty::AliasTy; + type T = crate::ty::AliasTy; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::AliasTy { args, def_id, .. } = self; - stable_mir::ty::AliasTy { def_id: tables.alias_def(*def_id), args: args.stable(tables, cx) } + crate::ty::AliasTy { def_id: tables.alias_def(*def_id), args: args.stable(tables, cx) } } } impl<'tcx> Stable<'tcx> for ty::AliasTerm<'tcx> { - type T = stable_mir::ty::AliasTerm; + type T = crate::ty::AliasTerm; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::AliasTerm { args, def_id, .. } = self; - stable_mir::ty::AliasTerm { - def_id: tables.alias_def(*def_id), - args: args.stable(tables, cx), - } + crate::ty::AliasTerm { def_id: tables.alias_def(*def_id), args: args.stable(tables, cx) } } } impl<'tcx> Stable<'tcx> for ty::DynKind { - type T = stable_mir::ty::DynKind; + type T = crate::ty::DynKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { match self { - ty::Dyn => stable_mir::ty::DynKind::Dyn, + ty::Dyn => crate::ty::DynKind::Dyn, } } } impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> { - type T = stable_mir::ty::ExistentialPredicate; + type T = crate::ty::ExistentialPredicate; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::ExistentialPredicate::*; + use crate::ty::ExistentialPredicate::*; match self { ty::ExistentialPredicate::Trait(existential_trait_ref) => { Trait(existential_trait_ref.stable(tables, cx)) @@ -84,7 +80,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> { } impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> { - type T = stable_mir::ty::ExistentialTraitRef; + type T = crate::ty::ExistentialTraitRef; fn stable<'cx>( &self, @@ -92,7 +88,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::ExistentialTraitRef { def_id, args, .. } = self; - stable_mir::ty::ExistentialTraitRef { + crate::ty::ExistentialTraitRef { def_id: tables.trait_def(*def_id), generic_args: args.stable(tables, cx), } @@ -100,14 +96,14 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> { } impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> { - type T = stable_mir::ty::TermKind; + type T = crate::ty::TermKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::TermKind; + use crate::ty::TermKind; match self { ty::TermKind::Ty(ty) => TermKind::Type(ty.stable(tables, cx)), ty::TermKind::Const(cnst) => { @@ -119,7 +115,7 @@ impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> { } impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> { - type T = stable_mir::ty::ExistentialProjection; + type T = crate::ty::ExistentialProjection; fn stable<'cx>( &self, @@ -127,7 +123,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::ExistentialProjection { def_id, args, term, .. } = self; - stable_mir::ty::ExistentialProjection { + crate::ty::ExistentialProjection { def_id: tables.trait_def(*def_id), generic_args: args.stable(tables, cx), term: term.kind().stable(tables, cx), @@ -136,7 +132,7 @@ impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> { } impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion { - type T = stable_mir::mir::PointerCoercion; + type T = crate::mir::PointerCoercion; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -144,16 +140,14 @@ impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion { ) -> Self::T { use rustc_middle::ty::adjustment::PointerCoercion; match self { - PointerCoercion::ReifyFnPointer => stable_mir::mir::PointerCoercion::ReifyFnPointer, - PointerCoercion::UnsafeFnPointer => stable_mir::mir::PointerCoercion::UnsafeFnPointer, + PointerCoercion::ReifyFnPointer => crate::mir::PointerCoercion::ReifyFnPointer, + PointerCoercion::UnsafeFnPointer => crate::mir::PointerCoercion::UnsafeFnPointer, PointerCoercion::ClosureFnPointer(safety) => { - stable_mir::mir::PointerCoercion::ClosureFnPointer(safety.stable(tables, cx)) + crate::mir::PointerCoercion::ClosureFnPointer(safety.stable(tables, cx)) } - PointerCoercion::MutToConstPointer => { - stable_mir::mir::PointerCoercion::MutToConstPointer - } - PointerCoercion::ArrayToPointer => stable_mir::mir::PointerCoercion::ArrayToPointer, - PointerCoercion::Unsize => stable_mir::mir::PointerCoercion::Unsize, + PointerCoercion::MutToConstPointer => crate::mir::PointerCoercion::MutToConstPointer, + PointerCoercion::ArrayToPointer => crate::mir::PointerCoercion::ArrayToPointer, + PointerCoercion::Unsize => crate::mir::PointerCoercion::Unsize, } } } @@ -178,14 +172,14 @@ impl<'tcx> Stable<'tcx> for ty::AdtKind { } impl<'tcx> Stable<'tcx> for ty::FieldDef { - type T = stable_mir::ty::FieldDef; + type T = crate::ty::FieldDef; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::ty::FieldDef { + crate::ty::FieldDef { def: tables.create_def_id(self.did), name: self.name.stable(tables, cx), } @@ -193,7 +187,7 @@ impl<'tcx> Stable<'tcx> for ty::FieldDef { } impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> { - type T = stable_mir::ty::GenericArgs; + type T = crate::ty::GenericArgs; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -204,14 +198,14 @@ impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> { } impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> { - type T = stable_mir::ty::GenericArgKind; + type T = crate::ty::GenericArgKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::GenericArgKind; + use crate::ty::GenericArgKind; match self { ty::GenericArgKind::Lifetime(region) => { GenericArgKind::Lifetime(region.stable(tables, cx)) @@ -226,14 +220,14 @@ impl<'tcx, S, V> Stable<'tcx> for ty::Binder<'tcx, S> where S: Stable<'tcx, T = V>, { - type T = stable_mir::ty::Binder<V>; + type T = crate::ty::Binder<V>; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::Binder; + use crate::ty::Binder; Binder { value: self.as_ref().skip_binder().stable(tables, cx), @@ -250,27 +244,27 @@ impl<'tcx, S, V> Stable<'tcx> for ty::EarlyBinder<'tcx, S> where S: Stable<'tcx, T = V>, { - type T = stable_mir::ty::EarlyBinder<V>; + type T = crate::ty::EarlyBinder<V>; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::EarlyBinder; + use crate::ty::EarlyBinder; EarlyBinder { value: self.as_ref().skip_binder().stable(tables, cx) } } } impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> { - type T = stable_mir::ty::FnSig; + type T = crate::ty::FnSig; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::FnSig; + use crate::ty::FnSig; FnSig { inputs_and_output: self @@ -286,14 +280,14 @@ impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> { } impl<'tcx> Stable<'tcx> for ty::BoundTyKind { - type T = stable_mir::ty::BoundTyKind; + type T = crate::ty::BoundTyKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::BoundTyKind; + use crate::ty::BoundTyKind; match self { ty::BoundTyKind::Anon => BoundTyKind::Anon, @@ -305,14 +299,14 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind { } impl<'tcx> Stable<'tcx> for ty::BoundRegionKind { - type T = stable_mir::ty::BoundRegionKind; + type T = crate::ty::BoundRegionKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::BoundRegionKind; + use crate::ty::BoundRegionKind; match self { ty::BoundRegionKind::Anon => BoundRegionKind::BrAnon, @@ -327,14 +321,14 @@ impl<'tcx> Stable<'tcx> for ty::BoundRegionKind { } impl<'tcx> Stable<'tcx> for ty::BoundVariableKind { - type T = stable_mir::ty::BoundVariableKind; + type T = crate::ty::BoundVariableKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::BoundVariableKind; + use crate::ty::BoundVariableKind; match self { ty::BoundVariableKind::Ty(bound_ty_kind) => { @@ -392,7 +386,7 @@ impl<'tcx> Stable<'tcx> for ty::FloatTy { } impl<'tcx> Stable<'tcx> for Ty<'tcx> { - type T = stable_mir::ty::Ty; + type T = crate::ty::Ty; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -403,7 +397,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> { } impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { - type T = stable_mir::ty::TyKind; + type T = crate::ty::TyKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, @@ -488,7 +482,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { } impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> { - type T = stable_mir::ty::Pattern; + type T = crate::ty::Pattern; fn stable<'cx>( &self, @@ -496,7 +490,7 @@ impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { match **self { - ty::PatternKind::Range { start, end } => stable_mir::ty::Pattern::Range { + ty::PatternKind::Range { start, end } => crate::ty::Pattern::Range { // FIXME(SMIR): update data structures to not have an Option here anymore start: Some(start.stable(tables, cx)), end: Some(end.stable(tables, cx)), @@ -508,7 +502,7 @@ impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> { } impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { - type T = stable_mir::ty::TyConst; + type T = crate::ty::TyConst; fn stable<'cx>( &self, @@ -520,18 +514,16 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { ty::ConstKind::Value(cv) => { let const_val = cx.valtree_to_const_val(cv); if matches!(const_val, mir::ConstValue::ZeroSized) { - stable_mir::ty::TyConstKind::ZSTValue(cv.ty.stable(tables, cx)) + crate::ty::TyConstKind::ZSTValue(cv.ty.stable(tables, cx)) } else { - stable_mir::ty::TyConstKind::Value( + crate::ty::TyConstKind::Value( cv.ty.stable(tables, cx), alloc::new_allocation(cv.ty, const_val, tables, cx), ) } } - ty::ConstKind::Param(param) => { - stable_mir::ty::TyConstKind::Param(param.stable(tables, cx)) - } - ty::ConstKind::Unevaluated(uv) => stable_mir::ty::TyConstKind::Unevaluated( + ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)), + ty::ConstKind::Unevaluated(uv) => crate::ty::TyConstKind::Unevaluated( tables.const_def(uv.def), uv.args.stable(tables, cx), ), @@ -542,42 +534,42 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { ty::ConstKind::Expr(_) => unimplemented!(), }; let id = tables.intern_ty_const(ct); - stable_mir::ty::TyConst::new(kind, id) + crate::ty::TyConst::new(kind, id) } } impl<'tcx> Stable<'tcx> for ty::ParamConst { - type T = stable_mir::ty::ParamConst; + type T = crate::ty::ParamConst; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { - use stable_mir::ty::ParamConst; + use crate::ty::ParamConst; ParamConst { index: self.index, name: self.name.to_string() } } } impl<'tcx> Stable<'tcx> for ty::ParamTy { - type T = stable_mir::ty::ParamTy; + type T = crate::ty::ParamTy; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { - use stable_mir::ty::ParamTy; + use crate::ty::ParamTy; ParamTy { index: self.index, name: self.name.to_string() } } } impl<'tcx> Stable<'tcx> for ty::BoundTy { - type T = stable_mir::ty::BoundTy; + type T = crate::ty::BoundTy; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::BoundTy; + use crate::ty::BoundTy; BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables, cx) } } } impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind { - type T = stable_mir::ty::TraitSpecializationKind; + type T = crate::ty::TraitSpecializationKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { - use stable_mir::ty::TraitSpecializationKind; + use crate::ty::TraitSpecializationKind; match self { ty::trait_def::TraitSpecializationKind::None => TraitSpecializationKind::None, @@ -590,14 +582,14 @@ impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind { } impl<'tcx> Stable<'tcx> for ty::TraitDef { - type T = stable_mir::ty::TraitDecl; + type T = crate::ty::TraitDecl; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::opaque; - use stable_mir::ty::TraitDecl; + use crate::opaque; + use crate::ty::TraitDecl; TraitDecl { def_id: tables.trait_def(self.def_id), @@ -620,27 +612,27 @@ impl<'tcx> Stable<'tcx> for ty::TraitDef { } impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> { - type T = stable_mir::ty::TraitRef; + type T = crate::ty::TraitRef; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::TraitRef; + use crate::ty::TraitRef; TraitRef::try_new(tables.trait_def(self.def_id), self.args.stable(tables, cx)).unwrap() } } impl<'tcx> Stable<'tcx> for ty::Generics { - type T = stable_mir::ty::Generics; + type T = crate::ty::Generics; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::Generics; + use crate::ty::Generics; let params: Vec<_> = self.own_params.iter().map(|param| param.stable(tables, cx)).collect(); let param_def_id_to_index = @@ -661,10 +653,10 @@ impl<'tcx> Stable<'tcx> for ty::Generics { } impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind { - type T = stable_mir::ty::GenericParamDefKind; + type T = crate::ty::GenericParamDefKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { - use stable_mir::ty::GenericParamDefKind; + use crate::ty::GenericParamDefKind; match self { ty::GenericParamDefKind::Lifetime => GenericParamDefKind::Lifetime, ty::GenericParamDefKind::Type { has_default, synthetic } => { @@ -678,7 +670,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind { } impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef { - type T = stable_mir::ty::GenericParamDef; + type T = crate::ty::GenericParamDef; fn stable<'cx>( &self, @@ -696,7 +688,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef { } impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> { - type T = stable_mir::ty::PredicateKind; + type T = crate::ty::PredicateKind; fn stable<'cx>( &self, @@ -706,25 +698,24 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> { use rustc_middle::ty::PredicateKind; match self { PredicateKind::Clause(clause_kind) => { - stable_mir::ty::PredicateKind::Clause(clause_kind.stable(tables, cx)) + crate::ty::PredicateKind::Clause(clause_kind.stable(tables, cx)) } PredicateKind::DynCompatible(did) => { - stable_mir::ty::PredicateKind::DynCompatible(tables.trait_def(*did)) + crate::ty::PredicateKind::DynCompatible(tables.trait_def(*did)) } PredicateKind::Subtype(subtype_predicate) => { - stable_mir::ty::PredicateKind::SubType(subtype_predicate.stable(tables, cx)) + crate::ty::PredicateKind::SubType(subtype_predicate.stable(tables, cx)) } PredicateKind::Coerce(coerce_predicate) => { - stable_mir::ty::PredicateKind::Coerce(coerce_predicate.stable(tables, cx)) + crate::ty::PredicateKind::Coerce(coerce_predicate.stable(tables, cx)) } - PredicateKind::ConstEquate(a, b) => stable_mir::ty::PredicateKind::ConstEquate( - a.stable(tables, cx), - b.stable(tables, cx), - ), - PredicateKind::Ambiguous => stable_mir::ty::PredicateKind::Ambiguous, + PredicateKind::ConstEquate(a, b) => { + crate::ty::PredicateKind::ConstEquate(a.stable(tables, cx), b.stable(tables, cx)) + } + PredicateKind::Ambiguous => crate::ty::PredicateKind::Ambiguous, PredicateKind::NormalizesTo(_pred) => unimplemented!(), PredicateKind::AliasRelate(a, b, alias_relation_direction) => { - stable_mir::ty::PredicateKind::AliasRelate( + crate::ty::PredicateKind::AliasRelate( a.kind().stable(tables, cx), b.kind().stable(tables, cx), alias_relation_direction.stable(tables, cx), @@ -735,7 +726,7 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> { } impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> { - type T = stable_mir::ty::ClauseKind; + type T = crate::ty::ClauseKind; fn stable<'cx>( &self, @@ -745,30 +736,30 @@ impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> { use rustc_middle::ty::ClauseKind; match *self { ClauseKind::Trait(trait_object) => { - stable_mir::ty::ClauseKind::Trait(trait_object.stable(tables, cx)) + crate::ty::ClauseKind::Trait(trait_object.stable(tables, cx)) } ClauseKind::RegionOutlives(region_outlives) => { - stable_mir::ty::ClauseKind::RegionOutlives(region_outlives.stable(tables, cx)) + crate::ty::ClauseKind::RegionOutlives(region_outlives.stable(tables, cx)) } ClauseKind::TypeOutlives(type_outlives) => { let ty::OutlivesPredicate::<_, _>(a, b) = type_outlives; - stable_mir::ty::ClauseKind::TypeOutlives(stable_mir::ty::OutlivesPredicate( + crate::ty::ClauseKind::TypeOutlives(crate::ty::OutlivesPredicate( a.stable(tables, cx), b.stable(tables, cx), )) } ClauseKind::Projection(projection_predicate) => { - stable_mir::ty::ClauseKind::Projection(projection_predicate.stable(tables, cx)) + crate::ty::ClauseKind::Projection(projection_predicate.stable(tables, cx)) } - ClauseKind::ConstArgHasType(const_, ty) => stable_mir::ty::ClauseKind::ConstArgHasType( + ClauseKind::ConstArgHasType(const_, ty) => crate::ty::ClauseKind::ConstArgHasType( const_.stable(tables, cx), ty.stable(tables, cx), ), ClauseKind::WellFormed(term) => { - stable_mir::ty::ClauseKind::WellFormed(term.kind().stable(tables, cx)) + crate::ty::ClauseKind::WellFormed(term.kind().stable(tables, cx)) } ClauseKind::ConstEvaluatable(const_) => { - stable_mir::ty::ClauseKind::ConstEvaluatable(const_.stable(tables, cx)) + crate::ty::ClauseKind::ConstEvaluatable(const_.stable(tables, cx)) } ClauseKind::HostEffect(..) => { todo!() @@ -778,20 +769,20 @@ impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> { } impl<'tcx> Stable<'tcx> for ty::ClosureKind { - type T = stable_mir::ty::ClosureKind; + type T = crate::ty::ClosureKind; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::ty::ClosureKind::*; match self { - Fn => stable_mir::ty::ClosureKind::Fn, - FnMut => stable_mir::ty::ClosureKind::FnMut, - FnOnce => stable_mir::ty::ClosureKind::FnOnce, + Fn => crate::ty::ClosureKind::Fn, + FnMut => crate::ty::ClosureKind::FnMut, + FnOnce => crate::ty::ClosureKind::FnOnce, } } } impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> { - type T = stable_mir::ty::SubtypePredicate; + type T = crate::ty::SubtypePredicate; fn stable<'cx>( &self, @@ -799,12 +790,12 @@ impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::SubtypePredicate { a, b, a_is_expected: _ } = self; - stable_mir::ty::SubtypePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) } + crate::ty::SubtypePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) } } } impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> { - type T = stable_mir::ty::CoercePredicate; + type T = crate::ty::CoercePredicate; fn stable<'cx>( &self, @@ -812,24 +803,24 @@ impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::CoercePredicate { a, b } = self; - stable_mir::ty::CoercePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) } + crate::ty::CoercePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) } } } impl<'tcx> Stable<'tcx> for ty::AliasRelationDirection { - type T = stable_mir::ty::AliasRelationDirection; + type T = crate::ty::AliasRelationDirection; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::ty::AliasRelationDirection::*; match self { - Equate => stable_mir::ty::AliasRelationDirection::Equate, - Subtype => stable_mir::ty::AliasRelationDirection::Subtype, + Equate => crate::ty::AliasRelationDirection::Equate, + Subtype => crate::ty::AliasRelationDirection::Subtype, } } } impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> { - type T = stable_mir::ty::TraitPredicate; + type T = crate::ty::TraitPredicate; fn stable<'cx>( &self, @@ -837,7 +828,7 @@ impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::TraitPredicate { trait_ref, polarity } = self; - stable_mir::ty::TraitPredicate { + crate::ty::TraitPredicate { trait_ref: trait_ref.stable(tables, cx), polarity: polarity.stable(tables, cx), } @@ -848,7 +839,7 @@ impl<'tcx, T> Stable<'tcx> for ty::OutlivesPredicate<'tcx, T> where T: Stable<'tcx>, { - type T = stable_mir::ty::OutlivesPredicate<T::T, Region>; + type T = crate::ty::OutlivesPredicate<T::T, Region>; fn stable<'cx>( &self, @@ -856,12 +847,12 @@ where cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::OutlivesPredicate(a, b) = self; - stable_mir::ty::OutlivesPredicate(a.stable(tables, cx), b.stable(tables, cx)) + crate::ty::OutlivesPredicate(a.stable(tables, cx), b.stable(tables, cx)) } } impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> { - type T = stable_mir::ty::ProjectionPredicate; + type T = crate::ty::ProjectionPredicate; fn stable<'cx>( &self, @@ -869,7 +860,7 @@ impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> { cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { let ty::ProjectionPredicate { projection_term, term } = self; - stable_mir::ty::ProjectionPredicate { + crate::ty::ProjectionPredicate { projection_term: projection_term.stable(tables, cx), term: term.kind().stable(tables, cx), } @@ -877,32 +868,32 @@ impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> { } impl<'tcx> Stable<'tcx> for ty::ImplPolarity { - type T = stable_mir::ty::ImplPolarity; + type T = crate::ty::ImplPolarity; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::ty::ImplPolarity::*; match self { - Positive => stable_mir::ty::ImplPolarity::Positive, - Negative => stable_mir::ty::ImplPolarity::Negative, - Reservation => stable_mir::ty::ImplPolarity::Reservation, + Positive => crate::ty::ImplPolarity::Positive, + Negative => crate::ty::ImplPolarity::Negative, + Reservation => crate::ty::ImplPolarity::Reservation, } } } impl<'tcx> Stable<'tcx> for ty::PredicatePolarity { - type T = stable_mir::ty::PredicatePolarity; + type T = crate::ty::PredicatePolarity; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_middle::ty::PredicatePolarity::*; match self { - Positive => stable_mir::ty::PredicatePolarity::Positive, - Negative => stable_mir::ty::PredicatePolarity::Negative, + Positive => crate::ty::PredicatePolarity::Positive, + Negative => crate::ty::PredicatePolarity::Negative, } } } impl<'tcx> Stable<'tcx> for ty::Region<'tcx> { - type T = stable_mir::ty::Region; + type T = crate::ty::Region; fn stable<'cx>( &self, @@ -914,14 +905,14 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> { } impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> { - type T = stable_mir::ty::RegionKind; + type T = crate::ty::RegionKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::{BoundRegion, EarlyParamRegion, RegionKind}; + use crate::ty::{BoundRegion, EarlyParamRegion, RegionKind}; match self { ty::ReEarlyParam(early_reg) => RegionKind::ReEarlyParam(EarlyParamRegion { index: early_reg.index, @@ -935,15 +926,13 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> { }, ), ty::ReStatic => RegionKind::ReStatic, - ty::RePlaceholder(place_holder) => { - RegionKind::RePlaceholder(stable_mir::ty::Placeholder { - universe: place_holder.universe.as_u32(), - bound: BoundRegion { - var: place_holder.bound.var.as_u32(), - kind: place_holder.bound.kind.stable(tables, cx), - }, - }) - } + ty::RePlaceholder(place_holder) => RegionKind::RePlaceholder(crate::ty::Placeholder { + universe: place_holder.universe.as_u32(), + bound: BoundRegion { + var: place_holder.bound.var.as_u32(), + kind: place_holder.bound.kind.stable(tables, cx), + }, + }), ty::ReErased => RegionKind::ReErased, _ => unreachable!("{self:?}"), } @@ -951,7 +940,7 @@ impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> { } impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> { - type T = stable_mir::mir::mono::Instance; + type T = crate::mir::mono::Instance; fn stable<'cx>( &self, @@ -960,10 +949,10 @@ impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> { ) -> Self::T { let def = tables.instance_def(cx.lift(*self).unwrap()); let kind = match self.def { - ty::InstanceKind::Item(..) => stable_mir::mir::mono::InstanceKind::Item, - ty::InstanceKind::Intrinsic(..) => stable_mir::mir::mono::InstanceKind::Intrinsic, + ty::InstanceKind::Item(..) => crate::mir::mono::InstanceKind::Item, + ty::InstanceKind::Intrinsic(..) => crate::mir::mono::InstanceKind::Intrinsic, ty::InstanceKind::Virtual(_def_id, idx) => { - stable_mir::mir::mono::InstanceKind::Virtual { idx } + crate::mir::mono::InstanceKind::Virtual { idx } } ty::InstanceKind::VTableShim(..) | ty::InstanceKind::ReifyShim(..) @@ -976,43 +965,42 @@ impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> { | ty::InstanceKind::FnPtrShim(..) | ty::InstanceKind::FutureDropPollShim(..) | ty::InstanceKind::AsyncDropGlue(..) - | ty::InstanceKind::AsyncDropGlueCtorShim(..) => { - stable_mir::mir::mono::InstanceKind::Shim - } + | ty::InstanceKind::AsyncDropGlueCtorShim(..) => crate::mir::mono::InstanceKind::Shim, }; - stable_mir::mir::mono::Instance { def, kind } + crate::mir::mono::Instance { def, kind } } } impl<'tcx> Stable<'tcx> for ty::Variance { - type T = stable_mir::mir::Variance; + type T = crate::mir::Variance; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { match self { - ty::Bivariant => stable_mir::mir::Variance::Bivariant, - ty::Contravariant => stable_mir::mir::Variance::Contravariant, - ty::Covariant => stable_mir::mir::Variance::Covariant, - ty::Invariant => stable_mir::mir::Variance::Invariant, + ty::Bivariant => crate::mir::Variance::Bivariant, + ty::Contravariant => crate::mir::Variance::Contravariant, + ty::Covariant => crate::mir::Variance::Covariant, + ty::Invariant => crate::mir::Variance::Invariant, } } } impl<'tcx> Stable<'tcx> for ty::Movability { - type T = stable_mir::ty::Movability; + type T = crate::ty::Movability; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { match self { - ty::Movability::Static => stable_mir::ty::Movability::Static, - ty::Movability::Movable => stable_mir::ty::Movability::Movable, + ty::Movability::Static => crate::ty::Movability::Static, + ty::Movability::Movable => crate::ty::Movability::Movable, } } } impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi { - type T = stable_mir::ty::Abi; + type T = crate::ty::Abi; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { use rustc_abi::ExternAbi; - use stable_mir::ty::Abi; + + use crate::ty::Abi; match *self { ExternAbi::Rust => Abi::Rust, ExternAbi::C { unwind } => Abi::C { unwind }, @@ -1046,14 +1034,14 @@ impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi { } impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule { - type T = stable_mir::ty::ForeignModule; + type T = crate::ty::ForeignModule; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::ty::ForeignModule { + crate::ty::ForeignModule { def_id: tables.foreign_module_def(self.def_id), abi: self.abi.stable(tables, cx), } @@ -1061,14 +1049,14 @@ impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule { } impl<'tcx> Stable<'tcx> for ty::AssocKind { - type T = stable_mir::ty::AssocKind; + type T = crate::ty::AssocKind; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::{AssocKind, AssocTypeData}; + use crate::ty::{AssocKind, AssocTypeData}; match *self { ty::AssocKind::Const { name } => AssocKind::Const { name: name.to_string() }, ty::AssocKind::Fn { name, has_self } => { @@ -1087,10 +1075,10 @@ impl<'tcx> Stable<'tcx> for ty::AssocKind { } impl<'tcx> Stable<'tcx> for ty::AssocItemContainer { - type T = stable_mir::ty::AssocItemContainer; + type T = crate::ty::AssocItemContainer; fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &SmirCtxt<'_, BridgeTys>) -> Self::T { - use stable_mir::ty::AssocItemContainer; + use crate::ty::AssocItemContainer; match self { ty::AssocItemContainer::Trait => AssocItemContainer::Trait, ty::AssocItemContainer::Impl => AssocItemContainer::Impl, @@ -1099,14 +1087,14 @@ impl<'tcx> Stable<'tcx> for ty::AssocItemContainer { } impl<'tcx> Stable<'tcx> for ty::AssocItem { - type T = stable_mir::ty::AssocItem; + type T = crate::ty::AssocItem; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::ty::AssocItem { + crate::ty::AssocItem { def_id: tables.assoc_def(self.def_id), kind: self.kind.stable(tables, cx), container: self.container.stable(tables, cx), @@ -1116,14 +1104,14 @@ impl<'tcx> Stable<'tcx> for ty::AssocItem { } impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData { - type T = stable_mir::ty::ImplTraitInTraitData; + type T = crate::ty::ImplTraitInTraitData; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, _: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - use stable_mir::ty::ImplTraitInTraitData; + use crate::ty::ImplTraitInTraitData; match self { ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id } => { ImplTraitInTraitData::Trait { @@ -1139,13 +1127,13 @@ impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData { } impl<'tcx> Stable<'tcx> for rustc_middle::ty::util::Discr<'tcx> { - type T = stable_mir::ty::Discr; + type T = crate::ty::Discr; fn stable<'cx>( &self, tables: &mut Tables<'cx, BridgeTys>, cx: &SmirCtxt<'cx, BridgeTys>, ) -> Self::T { - stable_mir::ty::Discr { val: self.val, ty: self.ty.stable(tables, cx) } + crate::ty::Discr { val: self.val, ty: self.ty.stable(tables, cx) } } } diff --git a/compiler/stable_mir/src/unstable/internal_cx/mod.rs b/compiler/stable_mir/src/unstable/internal_cx/mod.rs new file mode 100644 index 00000000000..6b0a06e304c --- /dev/null +++ b/compiler/stable_mir/src/unstable/internal_cx/mod.rs @@ -0,0 +1,93 @@ +//! Implementation of InternalCx. + +use rustc_middle::ty::{List, Ty, TyCtxt}; +use rustc_middle::{mir, ty}; +pub(crate) use traits::*; + +use super::InternalCx; + +pub(crate) mod traits; + +impl<'tcx, T: InternalCx<'tcx>> SmirExistentialProjection<'tcx> for T { + fn new_from_args( + &self, + def_id: rustc_span::def_id::DefId, + args: ty::GenericArgsRef<'tcx>, + term: ty::Term<'tcx>, + ) -> ty::ExistentialProjection<'tcx> { + ty::ExistentialProjection::new_from_args(self.tcx(), def_id, args, term) + } +} + +impl<'tcx, T: InternalCx<'tcx>> SmirExistentialTraitRef<'tcx> for T { + fn new_from_args( + &self, + trait_def_id: rustc_span::def_id::DefId, + args: ty::GenericArgsRef<'tcx>, + ) -> ty::ExistentialTraitRef<'tcx> { + ty::ExistentialTraitRef::new_from_args(self.tcx(), trait_def_id, args) + } +} + +impl<'tcx, T: InternalCx<'tcx>> SmirTraitRef<'tcx> for T { + fn new_from_args( + &self, + trait_def_id: rustc_span::def_id::DefId, + args: ty::GenericArgsRef<'tcx>, + ) -> ty::TraitRef<'tcx> { + ty::TraitRef::new_from_args(self.tcx(), trait_def_id, args) + } +} + +impl<'tcx> InternalCx<'tcx> for TyCtxt<'tcx> { + fn tcx(self) -> TyCtxt<'tcx> { + self + } + + fn lift<T: ty::Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> { + TyCtxt::lift(self, value) + } + + fn mk_args_from_iter<I, T>(self, iter: I) -> T::Output + where + I: Iterator<Item = T>, + T: ty::CollectAndApply<ty::GenericArg<'tcx>, ty::GenericArgsRef<'tcx>>, + { + TyCtxt::mk_args_from_iter(self, iter) + } + + fn mk_pat(self, v: ty::PatternKind<'tcx>) -> ty::Pattern<'tcx> { + TyCtxt::mk_pat(self, v) + } + + fn mk_poly_existential_predicates( + self, + eps: &[ty::PolyExistentialPredicate<'tcx>], + ) -> &'tcx List<ty::PolyExistentialPredicate<'tcx>> { + TyCtxt::mk_poly_existential_predicates(self, eps) + } + + fn mk_type_list(self, v: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> { + TyCtxt::mk_type_list(self, v) + } + + fn lifetimes_re_erased(self) -> ty::Region<'tcx> { + self.lifetimes.re_erased + } + + fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output + where + I: Iterator<Item = T>, + T: ty::CollectAndApply<ty::BoundVariableKind, &'tcx List<ty::BoundVariableKind>>, + { + TyCtxt::mk_bound_variable_kinds_from_iter(self, iter) + } + + fn mk_place_elems(self, v: &[mir::PlaceElem<'tcx>]) -> &'tcx List<mir::PlaceElem<'tcx>> { + TyCtxt::mk_place_elems(self, v) + } + + fn adt_def(self, def_id: rustc_hir::def_id::DefId) -> ty::AdtDef<'tcx> { + self.adt_def(def_id) + } +} diff --git a/compiler/stable_mir/src/unstable/internal_cx/traits.rs b/compiler/stable_mir/src/unstable/internal_cx/traits.rs new file mode 100644 index 00000000000..da443cd78f1 --- /dev/null +++ b/compiler/stable_mir/src/unstable/internal_cx/traits.rs @@ -0,0 +1,31 @@ +//! A set of traits that define a stable interface to rustc's internals. +//! +//! These traits are primarily used to clarify the behavior of different +//! functions that share the same name across various contexts. + +use rustc_middle::ty; + +pub(crate) trait SmirExistentialProjection<'tcx> { + fn new_from_args( + &self, + def_id: rustc_span::def_id::DefId, + args: ty::GenericArgsRef<'tcx>, + term: ty::Term<'tcx>, + ) -> ty::ExistentialProjection<'tcx>; +} + +pub(crate) trait SmirExistentialTraitRef<'tcx> { + fn new_from_args( + &self, + trait_def_id: rustc_span::def_id::DefId, + args: ty::GenericArgsRef<'tcx>, + ) -> ty::ExistentialTraitRef<'tcx>; +} + +pub(crate) trait SmirTraitRef<'tcx> { + fn new_from_args( + &self, + trait_def_id: rustc_span::def_id::DefId, + args: ty::GenericArgsRef<'tcx>, + ) -> ty::TraitRef<'tcx>; +} diff --git a/compiler/rustc_smir/src/stable_mir/unstable/mod.rs b/compiler/stable_mir/src/unstable/mod.rs index 77a772019eb..51c31e212f5 100644 --- a/compiler/rustc_smir/src/stable_mir/unstable/mod.rs +++ b/compiler/stable_mir/src/unstable/mod.rs @@ -10,104 +10,18 @@ use rustc_hir::def::DefKind; use rustc_middle::ty::{List, Ty, TyCtxt}; use rustc_middle::{mir, ty}; use rustc_smir::Tables; -use rustc_smir::context::{ - SmirCtxt, SmirExistentialProjection, SmirExistentialTraitRef, SmirTraitRef, -}; -use stable_mir::{CtorKind, ItemKind}; +use rustc_smir::context::SmirCtxt; use super::compiler_interface::BridgeTys; -use crate::{rustc_smir, stable_mir}; +use crate::{CtorKind, ItemKind}; pub(crate) mod convert; - -impl<'tcx, T: InternalCx<'tcx>> SmirExistentialProjection<'tcx> for T { - fn new_from_args( - &self, - def_id: rustc_span::def_id::DefId, - args: ty::GenericArgsRef<'tcx>, - term: ty::Term<'tcx>, - ) -> ty::ExistentialProjection<'tcx> { - ty::ExistentialProjection::new_from_args(self.tcx(), def_id, args, term) - } -} - -impl<'tcx, T: InternalCx<'tcx>> SmirExistentialTraitRef<'tcx> for T { - fn new_from_args( - &self, - trait_def_id: rustc_span::def_id::DefId, - args: ty::GenericArgsRef<'tcx>, - ) -> ty::ExistentialTraitRef<'tcx> { - ty::ExistentialTraitRef::new_from_args(self.tcx(), trait_def_id, args) - } -} - -impl<'tcx, T: InternalCx<'tcx>> SmirTraitRef<'tcx> for T { - fn new_from_args( - &self, - trait_def_id: rustc_span::def_id::DefId, - args: ty::GenericArgsRef<'tcx>, - ) -> ty::TraitRef<'tcx> { - ty::TraitRef::new_from_args(self.tcx(), trait_def_id, args) - } -} - -impl<'tcx> InternalCx<'tcx> for TyCtxt<'tcx> { - fn tcx(self) -> TyCtxt<'tcx> { - self - } - - fn lift<T: ty::Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> { - TyCtxt::lift(self, value) - } - - fn mk_args_from_iter<I, T>(self, iter: I) -> T::Output - where - I: Iterator<Item = T>, - T: ty::CollectAndApply<ty::GenericArg<'tcx>, ty::GenericArgsRef<'tcx>>, - { - TyCtxt::mk_args_from_iter(self, iter) - } - - fn mk_pat(self, v: ty::PatternKind<'tcx>) -> ty::Pattern<'tcx> { - TyCtxt::mk_pat(self, v) - } - - fn mk_poly_existential_predicates( - self, - eps: &[ty::PolyExistentialPredicate<'tcx>], - ) -> &'tcx List<ty::PolyExistentialPredicate<'tcx>> { - TyCtxt::mk_poly_existential_predicates(self, eps) - } - - fn mk_type_list(self, v: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>> { - TyCtxt::mk_type_list(self, v) - } - - fn lifetimes_re_erased(self) -> ty::Region<'tcx> { - self.lifetimes.re_erased - } - - fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output - where - I: Iterator<Item = T>, - T: ty::CollectAndApply<ty::BoundVariableKind, &'tcx List<ty::BoundVariableKind>>, - { - TyCtxt::mk_bound_variable_kinds_from_iter(self, iter) - } - - fn mk_place_elems(self, v: &[mir::PlaceElem<'tcx>]) -> &'tcx List<mir::PlaceElem<'tcx>> { - TyCtxt::mk_place_elems(self, v) - } - - fn adt_def(self, def_id: rustc_hir::def_id::DefId) -> ty::AdtDef<'tcx> { - self.adt_def(def_id) - } -} +mod internal_cx; /// Trait that defines the methods that are fine to call from [`RustcInternal`]. /// /// This trait is only for [`RustcInternal`]. Any other other access to rustc's internals -/// should go through [`crate::rustc_smir::context::SmirCtxt`]. +/// should go through [`rustc_smir::context::SmirCtxt`]. pub trait InternalCx<'tcx>: Copy + Clone { fn tcx(self) -> TyCtxt<'tcx>; diff --git a/compiler/rustc_smir/src/stable_mir/visitor.rs b/compiler/stable_mir/src/visitor.rs index 31a53d1b19d..45e2a815470 100644 --- a/compiler/rustc_smir/src/stable_mir/visitor.rs +++ b/compiler/stable_mir/src/visitor.rs @@ -1,13 +1,11 @@ use std::ops::ControlFlow; -use stable_mir::Opaque; -use stable_mir::ty::TyConst; - use super::ty::{ Allocation, Binder, ConstDef, ExistentialPredicate, FnSig, GenericArgKind, GenericArgs, MirConst, Promoted, Region, RigidTy, TermKind, Ty, UnevaluatedConst, }; -use crate::stable_mir; +use crate::Opaque; +use crate::ty::TyConst; pub trait Visitor: Sized { type Break; |
