From 7e213fe42835b4fe828426271de220f0bf9a97e5 Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Mon, 18 Dec 2023 22:21:37 +1100
Subject: [PATCH 1/3] Remove `Session` methods that duplicate `DiagCtxt`
 methods.

Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
---
 src/abi/mod.rs                 | 18 +++++++++---------
 src/base.rs                    |  8 ++++----
 src/common.rs                  |  9 ++++++---
 src/constant.rs                |  8 ++++----
 src/driver/aot.rs              |  8 ++++----
 src/driver/jit.rs              |  8 ++++----
 src/global_asm.rs              |  4 ++--
 src/inline_asm.rs              |  6 +++---
 src/intrinsics/llvm.rs         |  2 +-
 src/intrinsics/llvm_aarch64.rs |  2 +-
 src/intrinsics/llvm_x86.rs     | 14 +++++++++-----
 src/intrinsics/mod.rs          | 10 +++++-----
 src/intrinsics/simd.rs         | 18 +++++++++---------
 src/lib.rs                     | 19 +++++++++++--------
 src/main_shim.rs               |  4 ++--
 src/value_and_place.rs         |  2 +-
 16 files changed, 75 insertions(+), 65 deletions(-)

diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index 2c194f6d6d3..795c8daec6a 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -47,12 +47,12 @@ pub(crate) fn conv_to_call_conv(sess: &Session, c: Conv, default_call_conv: Call
         }
 
         Conv::X86Intr | Conv::RiscvInterrupt { .. } => {
-            sess.fatal(format!("interrupt call conv {c:?} not yet implemented"))
+            sess.dcx().fatal(format!("interrupt call conv {c:?} not yet implemented"))
         }
 
-        Conv::ArmAapcs => sess.fatal("aapcs call conv not yet implemented"),
+        Conv::ArmAapcs => sess.dcx().fatal("aapcs call conv not yet implemented"),
         Conv::CCmseNonSecureCall => {
-            sess.fatal("C-cmse-nonsecure-call call conv is not yet implemented");
+            sess.dcx().fatal("C-cmse-nonsecure-call call conv is not yet implemented");
         }
 
         Conv::Msp430Intr
@@ -88,10 +88,10 @@ pub(crate) fn import_function<'tcx>(
     let sig = get_function_sig(tcx, module.target_config().default_call_conv, inst);
     match module.declare_function(name, Linkage::Import, &sig) {
         Ok(func_id) => func_id,
-        Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!(
+        Err(ModuleError::IncompatibleDeclaration(_)) => tcx.dcx().fatal(format!(
             "attempt to declare `{name}` as function, but it was already declared as static"
         )),
-        Err(ModuleError::IncompatibleSignature(_, prev_sig, new_sig)) => tcx.sess.fatal(format!(
+        Err(ModuleError::IncompatibleSignature(_, prev_sig, new_sig)) => tcx.dcx().fatal(format!(
             "attempt to declare `{name}` with signature {new_sig:?}, \
              but it was already declared with signature {prev_sig:?}"
         )),
@@ -181,7 +181,7 @@ fn make_local_place<'tcx>(
     is_ssa: bool,
 ) -> CPlace<'tcx> {
     if layout.is_unsized() {
-        fx.tcx.sess.span_fatal(
+        fx.tcx.dcx().span_fatal(
             fx.mir.local_decls[local].source_info.span,
             "unsized locals are not yet supported",
         );
@@ -226,7 +226,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
 
     // FIXME implement variadics in cranelift
     if fn_abi.c_variadic {
-        fx.tcx.sess.span_fatal(
+        fx.tcx.dcx().span_fatal(
             fx.mir.span,
             "Defining variadic functions is not yet supported by Cranelift",
         );
@@ -543,7 +543,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
         // FIXME find a cleaner way to support varargs
         if fn_sig.c_variadic() {
             if !matches!(fn_sig.abi(), Abi::C { .. }) {
-                fx.tcx.sess.span_fatal(
+                fx.tcx.dcx().span_fatal(
                     source_info.span,
                     format!("Variadic call for non-C abi {:?}", fn_sig.abi()),
                 );
@@ -555,7 +555,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
                     let ty = fx.bcx.func.dfg.value_type(arg);
                     if !ty.is_int() {
                         // FIXME set %al to upperbound on float args once floats are supported
-                        fx.tcx.sess.span_fatal(
+                        fx.tcx.dcx().span_fatal(
                             source_info.span,
                             format!("Non int ty {:?} for variadic call", ty),
                         );
diff --git a/src/base.rs b/src/base.rs
index 8d3be19839e..881c0c0b56b 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -236,13 +236,13 @@ pub(crate) fn verify_func(
         match cranelift_codegen::verify_function(&func, &flags) {
             Ok(_) => {}
             Err(err) => {
-                tcx.sess.err(format!("{:?}", err));
+                tcx.dcx().err(format!("{:?}", err));
                 let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
                     &func,
                     Some(Box::new(writer)),
                     err,
                 );
-                tcx.sess.fatal(format!("cranelift verify error:\n{}", pretty_error));
+                tcx.dcx().fatal(format!("cranelift verify error:\n{}", pretty_error));
             }
         }
     });
@@ -450,7 +450,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
                 unwind: _,
             } => {
                 if options.contains(InlineAsmOptions::MAY_UNWIND) {
-                    fx.tcx.sess.span_fatal(
+                    fx.tcx.dcx().span_fatal(
                         source_info.span,
                         "cranelift doesn't support unwinding from inline assembly.",
                     );
@@ -812,7 +812,7 @@ fn codegen_stmt<'tcx>(
         | StatementKind::PlaceMention(..)
         | StatementKind::AscribeUserType(..) => {}
 
-        StatementKind::Coverage { .. } => fx.tcx.sess.fatal("-Zcoverage is unimplemented"),
+        StatementKind::Coverage { .. } => fx.tcx.dcx().fatal("-Zcoverage is unimplemented"),
         StatementKind::Intrinsic(ref intrinsic) => match &**intrinsic {
             // We ignore `assume` intrinsics, they are only useful for optimizations
             NonDivergingIntrinsic::Assume(_) => {}
diff --git a/src/common.rs b/src/common.rs
index bd19a7ed059..1e37825b548 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -465,9 +465,12 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
     #[inline]
     fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
         if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
-            self.0.sess.span_fatal(span, err.to_string())
+            self.0.sess.dcx().span_fatal(span, err.to_string())
         } else {
-            self.0.sess.span_fatal(span, format!("failed to get layout for `{}`: {}", ty, err))
+            self.0
+                .sess
+                .dcx()
+                .span_fatal(span, format!("failed to get layout for `{}`: {}", ty, err))
         }
     }
 }
@@ -483,7 +486,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
         fn_abi_request: FnAbiRequest<'tcx>,
     ) -> ! {
         if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
-            self.0.sess.emit_fatal(Spanned { span, node: err })
+            self.0.sess.dcx().emit_fatal(Spanned { span, node: err })
         } else {
             match fn_abi_request {
                 FnAbiRequest::OfFnPtr { sig, extra_args } => {
diff --git a/src/constant.rs b/src/constant.rs
index 9ffa006e59b..b6de688130c 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -263,7 +263,7 @@ fn data_id_for_static(
             attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
         ) {
             Ok(data_id) => data_id,
-            Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!(
+            Err(ModuleError::IncompatibleDeclaration(_)) => tcx.dcx().fatal(format!(
                 "attempt to declare `{symbol_name}` as static, but it was already declared as function"
             )),
             Err(err) => Err::<_, _>(err).unwrap(),
@@ -311,7 +311,7 @@ fn data_id_for_static(
         attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
     ) {
         Ok(data_id) => data_id,
-        Err(ModuleError::IncompatibleDeclaration(_)) => tcx.sess.fatal(format!(
+        Err(ModuleError::IncompatibleDeclaration(_)) => tcx.dcx().fatal(format!(
             "attempt to declare `{symbol_name}` as static, but it was already declared as function"
         )),
         Err(err) => Err::<_, _>(err).unwrap(),
@@ -360,7 +360,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
                 if let Some(names) = section_name.split_once(',') {
                     names
                 } else {
-                    tcx.sess.fatal(format!(
+                    tcx.dcx().fatal(format!(
                         "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma",
                         section_name
                     ));
@@ -406,7 +406,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
                 GlobalAlloc::Static(def_id) => {
                     if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)
                     {
-                        tcx.sess.fatal(format!(
+                        tcx.dcx().fatal(format!(
                             "Allocation {:?} contains reference to TLS value {:?}",
                             alloc_id, def_id
                         ));
diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index b3ab533df3d..df457b16085 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -69,7 +69,7 @@ impl OngoingCodegen {
 
             let module_codegen_result = match module_codegen_result {
                 Ok(module_codegen_result) => module_codegen_result,
-                Err(err) => sess.fatal(err),
+                Err(err) => sess.dcx().fatal(err),
             };
             let ModuleCodegenResult { module_regular, module_global_asm, existing_work_product } =
                 module_codegen_result;
@@ -422,7 +422,7 @@ pub(crate) fn run_aot(
                                     backend_config.clone(),
                                     global_asm_config.clone(),
                                     cgu.name(),
-                                    concurrency_limiter.acquire(tcx.sess.dcx()),
+                                    concurrency_limiter.acquire(tcx.dcx()),
                                 ),
                                 module_codegen,
                                 Some(rustc_middle::dep_graph::hash_result),
@@ -455,7 +455,7 @@ pub(crate) fn run_aot(
             "allocator_shim".to_owned(),
         ) {
             Ok(allocator_module) => Some(allocator_module),
-            Err(err) => tcx.sess.fatal(err),
+            Err(err) => tcx.dcx().fatal(err),
         }
     } else {
         None
@@ -478,7 +478,7 @@ pub(crate) fn run_aot(
             let obj = create_compressed_metadata_file(tcx.sess, &metadata, &symbol_name);
 
             if let Err(err) = std::fs::write(&tmp_file, obj) {
-                tcx.sess.fatal(format!("error writing metadata object file: {}", err));
+                tcx.dcx().fatal(format!("error writing metadata object file: {}", err));
             }
 
             (metadata_cgu_name, tmp_file)
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index 6ee65d12c73..63fa89d79bc 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -94,11 +94,11 @@ fn create_jit_module(
 
 pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
     if !tcx.sess.opts.output_types.should_codegen() {
-        tcx.sess.fatal("JIT mode doesn't work with `cargo check`");
+        tcx.dcx().fatal("JIT mode doesn't work with `cargo check`");
     }
 
     if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
-        tcx.sess.fatal("can't jit non-executable crate");
+        tcx.dcx().fatal("can't jit non-executable crate");
     }
 
     let (mut jit_module, mut cx) = create_jit_module(
@@ -141,14 +141,14 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
                 }
                 MonoItem::GlobalAsm(item_id) => {
                     let item = tcx.hir().item(item_id);
-                    tcx.sess.span_fatal(item.span, "Global asm is not supported in JIT mode");
+                    tcx.dcx().span_fatal(item.span, "Global asm is not supported in JIT mode");
                 }
             }
         }
     });
 
     if !cx.global_asm.is_empty() {
-        tcx.sess.fatal("Inline asm is not supported in JIT mode");
+        tcx.dcx().fatal("Inline asm is not supported in JIT mode");
     }
 
     tcx.sess.abort_if_errors();
diff --git a/src/global_asm.rs b/src/global_asm.rs
index b14007f4e52..af99239d815 100644
--- a/src/global_asm.rs
+++ b/src/global_asm.rs
@@ -47,7 +47,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
                         }
                         InlineAsmOperand::SymFn { anon_const } => {
                             if cfg!(not(feature = "inline_asm_sym")) {
-                                tcx.sess.span_err(
+                                tcx.dcx().span_err(
                                     item.span,
                                     "asm! and global_asm! sym operands are not yet supported",
                                 );
@@ -65,7 +65,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String,
                         }
                         InlineAsmOperand::SymStatic { path: _, def_id } => {
                             if cfg!(not(feature = "inline_asm_sym")) {
-                                tcx.sess.span_err(
+                                tcx.dcx().span_err(
                                     item.span,
                                     "asm! and global_asm! sym operands are not yet supported",
                                 );
diff --git a/src/inline_asm.rs b/src/inline_asm.rs
index 73f4bc7c151..6b9cec39d70 100644
--- a/src/inline_asm.rs
+++ b/src/inline_asm.rs
@@ -84,7 +84,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
             InlineAsmOperand::SymFn { ref value } => {
                 if cfg!(not(feature = "inline_asm_sym")) {
                     fx.tcx
-                        .sess
+                        .dcx()
                         .span_err(span, "asm! and global_asm! sym operands are not yet supported");
                 }
 
@@ -455,7 +455,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
             }
             _ => self
                 .tcx
-                .sess
+                .dcx()
                 .fatal(format!("Unsupported binary format for inline asm: {binary_format:?}")),
         }
 
@@ -563,7 +563,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
             BinaryFormat::Macho | BinaryFormat::Coff => {}
             _ => self
                 .tcx
-                .sess
+                .dcx()
                 .fatal(format!("Unsupported binary format for inline asm: {binary_format:?}")),
         }
 
diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs
index dbd5db87511..a38a728c926 100644
--- a/src/intrinsics/llvm.rs
+++ b/src/intrinsics/llvm.rs
@@ -68,7 +68,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
 
         _ => {
             fx.tcx
-                .sess
+                .dcx()
                 .warn(format!("unsupported llvm intrinsic {}; replacing with trap", intrinsic));
             crate::trap::trap_unimplemented(fx, intrinsic);
             return;
diff --git a/src/intrinsics/llvm_aarch64.rs b/src/intrinsics/llvm_aarch64.rs
index e1e514dca44..c8f9c3997a6 100644
--- a/src/intrinsics/llvm_aarch64.rs
+++ b/src/intrinsics/llvm_aarch64.rs
@@ -309,7 +309,7 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
         }
         */
         _ => {
-            fx.tcx.sess.warn(format!(
+            fx.tcx.dcx().warn(format!(
                 "unsupported AArch64 llvm intrinsic {}; replacing with trap",
                 intrinsic
             ));
diff --git a/src/intrinsics/llvm_x86.rs b/src/intrinsics/llvm_x86.rs
index 99bb5c4eae2..81114cbf40d 100644
--- a/src/intrinsics/llvm_x86.rs
+++ b/src/intrinsics/llvm_x86.rs
@@ -960,7 +960,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
             {
                 imm8
             } else {
-                fx.tcx.sess.span_fatal(span, "Index argument for `_mm_cmpestri` is not a constant");
+                fx.tcx
+                    .dcx()
+                    .span_fatal(span, "Index argument for `_mm_cmpestri` is not a constant");
             };
 
             let imm8 = imm8.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", imm8));
@@ -1011,7 +1013,9 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
             {
                 imm8
             } else {
-                fx.tcx.sess.span_fatal(span, "Index argument for `_mm_cmpestrm` is not a constant");
+                fx.tcx
+                    .dcx()
+                    .span_fatal(span, "Index argument for `_mm_cmpestrm` is not a constant");
             };
 
             let imm8 = imm8.try_to_u8().unwrap_or_else(|_| panic!("kind not scalar: {:?}", imm8));
@@ -1056,7 +1060,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
             {
                 imm8
             } else {
-                fx.tcx.sess.span_fatal(
+                fx.tcx.dcx().span_fatal(
                     span,
                     "Index argument for `_mm_clmulepi64_si128` is not a constant",
                 );
@@ -1093,7 +1097,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
             {
                 imm8
             } else {
-                fx.tcx.sess.span_fatal(
+                fx.tcx.dcx().span_fatal(
                     span,
                     "Index argument for `_mm_aeskeygenassist_si128` is not a constant",
                 );
@@ -1361,7 +1365,7 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
 
         _ => {
             fx.tcx
-                .sess
+                .dcx()
                 .warn(format!("unsupported x86 llvm intrinsic {}; replacing with trap", intrinsic));
             crate::trap::trap_unimplemented(fx, intrinsic);
             return;
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs
index 68126f12424..15249402a63 100644
--- a/src/intrinsics/mod.rs
+++ b/src/intrinsics/mod.rs
@@ -37,7 +37,7 @@ fn report_atomic_type_validation_error<'tcx>(
     span: Span,
     ty: Ty<'tcx>,
 ) {
-    fx.tcx.sess.span_err(
+    fx.tcx.dcx().span_err(
         span,
         format!(
             "`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`",
@@ -785,7 +785,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
                         return;
                     } else {
                         fx.tcx
-                            .sess
+                            .dcx()
                             .span_fatal(source_info.span, "128bit atomics not yet supported");
                     }
                 }
@@ -816,7 +816,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
                         return;
                     } else {
                         fx.tcx
-                            .sess
+                            .dcx()
                             .span_fatal(source_info.span, "128bit atomics not yet supported");
                     }
                 }
@@ -1245,7 +1245,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
 
         // FIXME implement variadics in cranelift
         sym::va_copy | sym::va_arg | sym::va_end => {
-            fx.tcx.sess.span_fatal(
+            fx.tcx.dcx().span_fatal(
                 source_info.span,
                 "Defining variadic functions is not yet supported by Cranelift",
             );
@@ -1253,7 +1253,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
 
         _ => {
             fx.tcx
-                .sess
+                .dcx()
                 .span_fatal(source_info.span, format!("unsupported intrinsic {}", intrinsic));
         }
     }
diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs
index fe4f073f799..16a550f45b8 100644
--- a/src/intrinsics/simd.rs
+++ b/src/intrinsics/simd.rs
@@ -12,7 +12,7 @@ fn report_simd_type_validation_error(
     span: Span,
     ty: Ty<'_>,
 ) {
-    fx.tcx.sess.span_err(span, format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty));
+    fx.tcx.dcx().span_err(span, format!("invalid monomorphization of `{}` intrinsic: expected SIMD input type, found non-SIMD `{}`", intrinsic, ty));
     // Prevent verifier error
     fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
 }
@@ -192,7 +192,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                     .try_into()
                     .unwrap(),
                 _ => {
-                    fx.tcx.sess.span_err(
+                    fx.tcx.dcx().span_err(
                         span,
                         format!("simd_shuffle index must be an array of `u32`, got `{}`", idx_ty),
                     );
@@ -278,7 +278,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
             {
                 idx_const
             } else {
-                fx.tcx.sess.span_fatal(span, "Index argument for `simd_insert` is not a constant");
+                fx.tcx.dcx().span_fatal(span, "Index argument for `simd_insert` is not a constant");
             };
 
             let idx: u32 = idx_const
@@ -286,7 +286,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                 .unwrap_or_else(|_| panic!("kind not scalar: {:?}", idx_const));
             let (lane_count, _lane_ty) = base.layout().ty.simd_size_and_type(fx.tcx);
             if u64::from(idx) >= lane_count {
-                fx.tcx.sess.span_fatal(
+                fx.tcx.dcx().span_fatal(
                     fx.mir.span,
                     format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count),
                 );
@@ -316,7 +316,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
             {
                 idx_const
             } else {
-                fx.tcx.sess.span_warn(span, "Index argument for `simd_extract` is not a constant");
+                fx.tcx.dcx().span_warn(span, "Index argument for `simd_extract` is not a constant");
                 let trap_block = fx.bcx.create_block();
                 let true_ = fx.bcx.ins().iconst(types::I8, 1);
                 let ret_block = fx.get_block(target);
@@ -334,7 +334,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                 .unwrap_or_else(|_| panic!("kind not scalar: {:?}", idx_const));
             let (lane_count, _lane_ty) = v.layout().ty.simd_size_and_type(fx.tcx);
             if u64::from(idx) >= lane_count {
-                fx.tcx.sess.span_fatal(
+                fx.tcx.dcx().span_fatal(
                     fx.mir.span,
                     format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count),
                 );
@@ -859,7 +859,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
             match lane_ty.kind() {
                 ty::Int(_) | ty::Uint(_) => {}
                 _ => {
-                    fx.tcx.sess.span_fatal(
+                    fx.tcx.dcx().span_fatal(
                         span,
                         format!(
                             "invalid monomorphization of `simd_bitmask` intrinsic: \
@@ -899,7 +899,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
                         && len.try_eval_target_usize(fx.tcx, ty::ParamEnv::reveal_all())
                             == Some(expected_bytes) => {}
                 _ => {
-                    fx.tcx.sess.span_fatal(
+                    fx.tcx.dcx().span_fatal(
                         span,
                         format!(
                             "invalid monomorphization of `simd_bitmask` intrinsic: \
@@ -1086,7 +1086,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
         }
 
         _ => {
-            fx.tcx.sess.span_err(span, format!("Unknown SIMD intrinsic {}", intrinsic));
+            fx.tcx.dcx().span_err(span, format!("Unknown SIMD intrinsic {}", intrinsic));
             // Prevent verifier error
             fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
             return;
diff --git a/src/lib.rs b/src/lib.rs
index d0ce209be44..b9e02587fbc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -177,13 +177,15 @@ impl CodegenBackend for CraneliftCodegenBackend {
         use rustc_session::config::Lto;
         match sess.lto() {
             Lto::No | Lto::ThinLocal => {}
-            Lto::Thin | Lto::Fat => sess.warn("LTO is not supported. You may get a linker error."),
+            Lto::Thin | Lto::Fat => {
+                sess.dcx().warn("LTO is not supported. You may get a linker error.")
+            }
         }
 
         let mut config = self.config.borrow_mut();
         if config.is_none() {
             let new_config = BackendConfig::from_opts(&sess.opts.cg.llvm_args)
-                .unwrap_or_else(|err| sess.fatal(err));
+                .unwrap_or_else(|err| sess.dcx().fatal(err));
             *config = Some(new_config);
         }
     }
@@ -211,7 +213,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
                 driver::jit::run_jit(tcx, config);
 
                 #[cfg(not(feature = "jit"))]
-                tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift");
+                tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
             }
         }
     }
@@ -243,7 +245,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
 fn target_triple(sess: &Session) -> target_lexicon::Triple {
     match sess.target.llvm_target.parse() {
         Ok(triple) => triple,
-        Err(err) => sess.fatal(format!("target not recognized: {}", err)),
+        Err(err) => sess.dcx().fatal(format!("target not recognized: {}", err)),
     }
 }
 
@@ -310,17 +312,18 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::Tar
         Some(value) => {
             let mut builder =
                 cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| {
-                    sess.fatal(format!("can't compile for {}: {}", target_triple, err));
+                    sess.dcx().fatal(format!("can't compile for {}: {}", target_triple, err));
                 });
             if let Err(_) = builder.enable(value) {
-                sess.fatal("the specified target cpu isn't currently supported by Cranelift.");
+                sess.dcx()
+                    .fatal("the specified target cpu isn't currently supported by Cranelift.");
             }
             builder
         }
         None => {
             let mut builder =
                 cranelift_codegen::isa::lookup(target_triple.clone()).unwrap_or_else(|err| {
-                    sess.fatal(format!("can't compile for {}: {}", target_triple, err));
+                    sess.dcx().fatal(format!("can't compile for {}: {}", target_triple, err));
                 });
             if target_triple.architecture == target_lexicon::Architecture::X86_64 {
                 // Don't use "haswell" as the default, as it implies `has_lzcnt`.
@@ -333,7 +336,7 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Arc<dyn isa::Tar
 
     match isa_builder.finish(flags) {
         Ok(target_isa) => target_isa,
-        Err(err) => sess.fatal(format!("failed to build TargetIsa: {}", err)),
+        Err(err) => sess.dcx().fatal(format!("failed to build TargetIsa: {}", err)),
     }
 }
 
diff --git a/src/main_shim.rs b/src/main_shim.rs
index b5efe44d8b3..6535c3a367b 100644
--- a/src/main_shim.rs
+++ b/src/main_shim.rs
@@ -74,7 +74,7 @@ pub(crate) fn maybe_create_entry_wrapper(
         let cmain_func_id = match m.declare_function(entry_name, Linkage::Export, &cmain_sig) {
             Ok(func_id) => func_id,
             Err(err) => {
-                tcx.sess
+                tcx.dcx()
                     .fatal(format!("entry symbol `{entry_name}` declared multiple times: {err}"));
             }
         };
@@ -171,7 +171,7 @@ pub(crate) fn maybe_create_entry_wrapper(
         }
 
         if let Err(err) = m.define_function(cmain_func_id, &mut ctx) {
-            tcx.sess.fatal(format!("entry symbol `{entry_name}` defined multiple times: {err}"));
+            tcx.dcx().fatal(format!("entry symbol `{entry_name}` defined multiple times: {err}"));
         }
 
         unwind_context.add_function(cmain_func_id, &ctx, m.isa());
diff --git a/src/value_and_place.rs b/src/value_and_place.rs
index 567a5669d49..838c73fa213 100644
--- a/src/value_and_place.rs
+++ b/src/value_and_place.rs
@@ -397,7 +397,7 @@ impl<'tcx> CPlace<'tcx> {
 
         if layout.size.bytes() >= u64::from(u32::MAX - 16) {
             fx.tcx
-                .sess
+                .dcx()
                 .fatal(format!("values of type {} are too big to store on the stack", layout.ty));
         }
 

From 93c86f78b2e04b5a8c60f48d97fe5623638f0c00 Mon Sep 17 00:00:00 2001
From: Nicholas Nethercote <n.nethercote@gmail.com>
Date: Thu, 21 Dec 2023 16:26:09 +1100
Subject: [PATCH 2/3] Remove more `Session` methods that duplicate `DiagCtxt`
 methods.

---
 src/driver/aot.rs | 2 +-
 src/driver/jit.rs | 4 ++--
 src/lib.rs        | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/driver/aot.rs b/src/driver/aot.rs
index df457b16085..e77b0cd0721 100644
--- a/src/driver/aot.rs
+++ b/src/driver/aot.rs
@@ -108,7 +108,7 @@ impl OngoingCodegen {
 
         self.concurrency_limiter.finished();
 
-        sess.abort_if_errors();
+        sess.dcx().abort_if_errors();
 
         (
             CodegenResults {
diff --git a/src/driver/jit.rs b/src/driver/jit.rs
index 63fa89d79bc..7905ec8402d 100644
--- a/src/driver/jit.rs
+++ b/src/driver/jit.rs
@@ -151,7 +151,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
         tcx.dcx().fatal("Inline asm is not supported in JIT mode");
     }
 
-    tcx.sess.abort_if_errors();
+    tcx.dcx().abort_if_errors();
 
     jit_module.finalize_definitions().unwrap();
     unsafe { cx.unwind_context.register_jit(&jit_module) };
@@ -338,7 +338,7 @@ fn dep_symbol_lookup_fn(
             .collect::<Box<[_]>>(),
     );
 
-    sess.abort_if_errors();
+    sess.dcx().abort_if_errors();
 
     Box::new(move |sym_name| {
         for dylib in &*imported_dylibs {
diff --git a/src/lib.rs b/src/lib.rs
index b9e02587fbc..b482f0dd2f0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -204,7 +204,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
         metadata: EncodedMetadata,
         need_metadata_module: bool,
     ) -> Box<dyn Any> {
-        tcx.sess.abort_if_errors();
+        tcx.dcx().abort_if_errors();
         let config = self.config.borrow().clone().unwrap();
         match config.codegen_mode {
             CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),

From 653121cd38433cd1e697b2af5196a3a8c7fbb894 Mon Sep 17 00:00:00 2001
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Date: Sun, 24 Dec 2023 14:38:37 +0000
Subject: [PATCH 3/3] Fix borked subtree syncs

---
 example/mini_core_hello_world.rs | 287 ++++---------------------------
 src/intrinsics/simd.rs           |   2 +-
 2 files changed, 33 insertions(+), 256 deletions(-)

diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs
index 1d51b499c8b..a1cdf31c68a 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -538,261 +538,38 @@ pub enum E1 {
 pub enum E2<X> {
     V1 { f: bool },
 
-    /*_00*/ _01(X),
-    _02(X),
-    _03(X),
-    _04(X),
-    _05(X),
-    _06(X),
-    _07(X),
-    _08(X),
-    _09(X),
-    _0A(X),
-    _0B(X),
-    _0C(X),
-    _0D(X),
-    _0E(X),
-    _0F(X),
-    _10(X),
-    _11(X),
-    _12(X),
-    _13(X),
-    _14(X),
-    _15(X),
-    _16(X),
-    _17(X),
-    _18(X),
-    _19(X),
-    _1A(X),
-    _1B(X),
-    _1C(X),
-    _1D(X),
-    _1E(X),
-    _1F(X),
-    _20(X),
-    _21(X),
-    _22(X),
-    _23(X),
-    _24(X),
-    _25(X),
-    _26(X),
-    _27(X),
-    _28(X),
-    _29(X),
-    _2A(X),
-    _2B(X),
-    _2C(X),
-    _2D(X),
-    _2E(X),
-    _2F(X),
-    _30(X),
-    _31(X),
-    _32(X),
-    _33(X),
-    _34(X),
-    _35(X),
-    _36(X),
-    _37(X),
-    _38(X),
-    _39(X),
-    _3A(X),
-    _3B(X),
-    _3C(X),
-    _3D(X),
-    _3E(X),
-    _3F(X),
-    _40(X),
-    _41(X),
-    _42(X),
-    _43(X),
-    _44(X),
-    _45(X),
-    _46(X),
-    _47(X),
-    _48(X),
-    _49(X),
-    _4A(X),
-    _4B(X),
-    _4C(X),
-    _4D(X),
-    _4E(X),
-    _4F(X),
-    _50(X),
-    _51(X),
-    _52(X),
-    _53(X),
-    _54(X),
-    _55(X),
-    _56(X),
-    _57(X),
-    _58(X),
-    _59(X),
-    _5A(X),
-    _5B(X),
-    _5C(X),
-    _5D(X),
-    _5E(X),
-    _5F(X),
-    _60(X),
-    _61(X),
-    _62(X),
-    _63(X),
-    _64(X),
-    _65(X),
-    _66(X),
-    _67(X),
-    _68(X),
-    _69(X),
-    _6A(X),
-    _6B(X),
-    _6C(X),
-    _6D(X),
-    _6E(X),
-    _6F(X),
-    _70(X),
-    _71(X),
-    _72(X),
-    _73(X),
-    _74(X),
-    _75(X),
-    _76(X),
-    _77(X),
-    _78(X),
-    _79(X),
-    _7A(X),
-    _7B(X),
-    _7C(X),
-    _7D(X),
-    _7E(X),
-    _7F(X),
-    _80(X),
-    _81(X),
-    _82(X),
-    _83(X),
-    _84(X),
-    _85(X),
-    _86(X),
-    _87(X),
-    _88(X),
-    _89(X),
-    _8A(X),
-    _8B(X),
-    _8C(X),
-    _8D(X),
-    _8E(X),
-    _8F(X),
-    _90(X),
-    _91(X),
-    _92(X),
-    _93(X),
-    _94(X),
-    _95(X),
-    _96(X),
-    _97(X),
-    _98(X),
-    _99(X),
-    _9A(X),
-    _9B(X),
-    _9C(X),
-    _9D(X),
-    _9E(X),
-    _9F(X),
-    _A0(X),
-    _A1(X),
-    _A2(X),
-    _A3(X),
-    _A4(X),
-    _A5(X),
-    _A6(X),
-    _A7(X),
-    _A8(X),
-    _A9(X),
-    _AA(X),
-    _AB(X),
-    _AC(X),
-    _AD(X),
-    _AE(X),
-    _AF(X),
-    _B0(X),
-    _B1(X),
-    _B2(X),
-    _B3(X),
-    _B4(X),
-    _B5(X),
-    _B6(X),
-    _B7(X),
-    _B8(X),
-    _B9(X),
-    _BA(X),
-    _BB(X),
-    _BC(X),
-    _BD(X),
-    _BE(X),
-    _BF(X),
-    _C0(X),
-    _C1(X),
-    _C2(X),
-    _C3(X),
-    _C4(X),
-    _C5(X),
-    _C6(X),
-    _C7(X),
-    _C8(X),
-    _C9(X),
-    _CA(X),
-    _CB(X),
-    _CC(X),
-    _CD(X),
-    _CE(X),
-    _CF(X),
-    _D0(X),
-    _D1(X),
-    _D2(X),
-    _D3(X),
-    _D4(X),
-    _D5(X),
-    _D6(X),
-    _D7(X),
-    _D8(X),
-    _D9(X),
-    _DA(X),
-    _DB(X),
-    _DC(X),
-    _DD(X),
-    _DE(X),
-    _DF(X),
-    _E0(X),
-    _E1(X),
-    _E2(X),
-    _E3(X),
-    _E4(X),
-    _E5(X),
-    _E6(X),
-    _E7(X),
-    _E8(X),
-    _E9(X),
-    _EA(X),
-    _EB(X),
-    _EC(X),
-    _ED(X),
-    _EE(X),
-    _EF(X),
-    _F0(X),
-    _F1(X),
-    _F2(X),
-    _F3(X),
-    _F4(X),
-    _F5(X),
-    _F6(X),
-    _F7(X),
-    _F8(X),
-    _F9(X),
-    _FA(X),
-    _FB(X),
-    _FC(X),
-    _FD(X),
-    _FE(X),
-    _FF(X),
+    /*_00*/ _01(X), _02(X), _03(X), _04(X), _05(X), _06(X), _07(X),
+    _08(X), _09(X), _0A(X), _0B(X), _0C(X), _0D(X), _0E(X), _0F(X),
+    _10(X), _11(X), _12(X), _13(X), _14(X), _15(X), _16(X), _17(X),
+    _18(X), _19(X), _1A(X), _1B(X), _1C(X), _1D(X), _1E(X), _1F(X),
+    _20(X), _21(X), _22(X), _23(X), _24(X), _25(X), _26(X), _27(X),
+    _28(X), _29(X), _2A(X), _2B(X), _2C(X), _2D(X), _2E(X), _2F(X),
+    _30(X), _31(X), _32(X), _33(X), _34(X), _35(X), _36(X), _37(X),
+    _38(X), _39(X), _3A(X), _3B(X), _3C(X), _3D(X), _3E(X), _3F(X),
+    _40(X), _41(X), _42(X), _43(X), _44(X), _45(X), _46(X), _47(X),
+    _48(X), _49(X), _4A(X), _4B(X), _4C(X), _4D(X), _4E(X), _4F(X),
+    _50(X), _51(X), _52(X), _53(X), _54(X), _55(X), _56(X), _57(X),
+    _58(X), _59(X), _5A(X), _5B(X), _5C(X), _5D(X), _5E(X), _5F(X),
+    _60(X), _61(X), _62(X), _63(X), _64(X), _65(X), _66(X), _67(X),
+    _68(X), _69(X), _6A(X), _6B(X), _6C(X), _6D(X), _6E(X), _6F(X),
+    _70(X), _71(X), _72(X), _73(X), _74(X), _75(X), _76(X), _77(X),
+    _78(X), _79(X), _7A(X), _7B(X), _7C(X), _7D(X), _7E(X), _7F(X),
+    _80(X), _81(X), _82(X), _83(X), _84(X), _85(X), _86(X), _87(X),
+    _88(X), _89(X), _8A(X), _8B(X), _8C(X), _8D(X), _8E(X), _8F(X),
+    _90(X), _91(X), _92(X), _93(X), _94(X), _95(X), _96(X), _97(X),
+    _98(X), _99(X), _9A(X), _9B(X), _9C(X), _9D(X), _9E(X), _9F(X),
+    _A0(X), _A1(X), _A2(X), _A3(X), _A4(X), _A5(X), _A6(X), _A7(X),
+    _A8(X), _A9(X), _AA(X), _AB(X), _AC(X), _AD(X), _AE(X), _AF(X),
+    _B0(X), _B1(X), _B2(X), _B3(X), _B4(X), _B5(X), _B6(X), _B7(X),
+    _B8(X), _B9(X), _BA(X), _BB(X), _BC(X), _BD(X), _BE(X), _BF(X),
+    _C0(X), _C1(X), _C2(X), _C3(X), _C4(X), _C5(X), _C6(X), _C7(X),
+    _C8(X), _C9(X), _CA(X), _CB(X), _CC(X), _CD(X), _CE(X), _CF(X),
+    _D0(X), _D1(X), _D2(X), _D3(X), _D4(X), _D5(X), _D6(X), _D7(X),
+    _D8(X), _D9(X), _DA(X), _DB(X), _DC(X), _DD(X), _DE(X), _DF(X),
+    _E0(X), _E1(X), _E2(X), _E3(X), _E4(X), _E5(X), _E6(X), _E7(X),
+    _E8(X), _E9(X), _EA(X), _EB(X), _EC(X), _ED(X), _EE(X), _EF(X),
+    _F0(X), _F1(X), _F2(X), _F3(X), _F4(X), _F5(X), _F6(X), _F7(X),
+    _F8(X), _F9(X), _FA(X), _FB(X), _FC(X), _FD(X), _FE(X), _FF(X),
 
     V3,
     V4,
diff --git a/src/intrinsics/simd.rs b/src/intrinsics/simd.rs
index 9242021ce2e..d06237f8d91 100644
--- a/src/intrinsics/simd.rs
+++ b/src/intrinsics/simd.rs
@@ -1088,7 +1088,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
         }
 
         sym::simd_scatter => {
-            intrinsic_args!(fx, args => (mask, ptr, val); intrinsic);
+            intrinsic_args!(fx, args => (val, ptr, mask); intrinsic);
 
             let (val_lane_count, _val_lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx);
             let (ptr_lane_count, _ptr_lane_ty) = ptr.layout().ty.simd_size_and_type(fx.tcx);