Skip to content

Commit 7ec653e

Browse files
committed
Auto merge of #113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errors
Move `TyCtxt::mk_x` to `Ty::new_x` where applicable Part of rust-lang/compiler-team#616 turns out there's a lot of places we construct `Ty` this is a ridiculously huge PR :S r? `@oli-obk`
2 parents 6f4b04c + cdeb2e7 commit 7ec653e

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

src/borrow_tracker/stacked_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10081008

10091009
// We have to turn the place into a pointer to use the existing code.
10101010
// (The pointer type does not matter, so we use a raw pointer.)
1011-
let ptr_layout = this.layout_of(this.tcx.mk_mut_ptr(return_place.layout.ty))?;
1011+
let ptr_layout = this.layout_of(Ty::new_mut_ptr(this.tcx.tcx,return_place.layout.ty))?;
10121012
let val = ImmTy::from_immediate(return_place.to_ref(this), ptr_layout);
10131013
// Reborrow it. With protection! That is part of the point.
10141014
let new_perm = NewPermission::Uniform {

src/borrow_tracker/tree_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
509509

510510
// We have to turn the place into a pointer to use the existing code.
511511
// (The pointer type does not matter, so we use a raw pointer.)
512-
let ptr_layout = this.layout_of(this.tcx.mk_mut_ptr(return_place.layout.ty))?;
512+
let ptr_layout = this.layout_of(Ty::new_mut_ptr(this.tcx.tcx,return_place.layout.ty))?;
513513
let val = ImmTy::from_immediate(return_place.to_ref(this), ptr_layout);
514514
// Reborrow it. With protection! That is part of the point.
515515
// FIXME: do we truly want a 2phase borrow here?

src/eval.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::task::Poll;
88
use std::thread;
99

1010
use log::info;
11+
use rustc_middle::ty::Ty;
1112

1213
use crate::borrow_tracker::RetagFields;
1314
use crate::diagnostics::report_leaks;
@@ -304,7 +305,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
304305
for arg in config.args.iter() {
305306
// Make space for `0` terminator.
306307
let size = u64::try_from(arg.len()).unwrap().checked_add(1).unwrap();
307-
let arg_type = tcx.mk_array(tcx.types.u8, size);
308+
let arg_type = Ty::new_array(tcx,tcx.types.u8, size);
308309
let arg_place =
309310
ecx.allocate(ecx.layout_of(arg_type)?, MiriMemoryKind::Machine.into())?;
310311
ecx.write_os_str_to_c_str(OsStr::new(arg), arg_place.ptr, size)?;
@@ -313,7 +314,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
313314
}
314315
// Make an array with all these pointers, in the Miri memory.
315316
let argvs_layout = ecx.layout_of(
316-
tcx.mk_array(tcx.mk_imm_ptr(tcx.types.u8), u64::try_from(argvs.len()).unwrap()),
317+
Ty::new_array(tcx,Ty::new_imm_ptr(tcx,tcx.types.u8), u64::try_from(argvs.len()).unwrap()),
317318
)?;
318319
let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Machine.into())?;
319320
for (idx, arg) in argvs.into_iter().enumerate() {
@@ -332,7 +333,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
332333
ecx.machine.argc = Some(*argc_place);
333334

334335
let argv_place = ecx.allocate(
335-
ecx.layout_of(tcx.mk_imm_ptr(tcx.types.unit))?,
336+
ecx.layout_of(Ty::new_imm_ptr(tcx,tcx.types.unit))?,
336337
MiriMemoryKind::Machine.into(),
337338
)?;
338339
ecx.write_immediate(argv, &argv_place.into())?;
@@ -344,7 +345,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
344345
// Construct a command string with all the arguments.
345346
let cmd_utf16: Vec<u16> = args_to_utf16_command_string(config.args.iter());
346347

347-
let cmd_type = tcx.mk_array(tcx.types.u16, u64::try_from(cmd_utf16.len()).unwrap());
348+
let cmd_type = Ty::new_array(tcx,tcx.types.u16, u64::try_from(cmd_utf16.len()).unwrap());
348349
let cmd_place =
349350
ecx.allocate(ecx.layout_of(cmd_type)?, MiriMemoryKind::Machine.into())?;
350351
ecx.machine.cmd_line = Some(*cmd_place);

src/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ pub struct PrimitiveLayouts<'tcx> {
313313
impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
314314
fn new(layout_cx: LayoutCx<'tcx, TyCtxt<'tcx>>) -> Result<Self, &'tcx LayoutError<'tcx>> {
315315
let tcx = layout_cx.tcx;
316-
let mut_raw_ptr = tcx.mk_ptr(TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Mut });
317-
let const_raw_ptr = tcx.mk_ptr(TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
316+
let mut_raw_ptr = Ty::new_ptr(tcx,TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Mut });
317+
let const_raw_ptr = Ty::new_ptr(tcx,TypeAndMut { ty: tcx.types.unit, mutbl: Mutability::Not });
318318
Ok(Self {
319-
unit: layout_cx.layout_of(tcx.mk_unit())?,
319+
unit: layout_cx.layout_of(Ty::new_unit(tcx,))?,
320320
i8: layout_cx.layout_of(tcx.types.i8)?,
321321
i16: layout_cx.layout_of(tcx.types.i16)?,
322322
i32: layout_cx.layout_of(tcx.types.i32)?,

src/shims/backtrace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::*;
22
use rustc_ast::ast::Mutability;
33
use rustc_middle::ty::layout::LayoutOf as _;
4-
use rustc_middle::ty::{self, Instance};
4+
use rustc_middle::ty::{self, Instance, Ty};
55
use rustc_span::{BytePos, Loc, Symbol};
66
use rustc_target::{abi::Size, spec::abi::Abi};
77

@@ -71,7 +71,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7171
let len: u64 = ptrs.len().try_into().unwrap();
7272

7373
let ptr_ty = this.machine.layouts.mut_raw_ptr.ty;
74-
let array_layout = this.layout_of(tcx.mk_array(ptr_ty, len)).unwrap();
74+
let array_layout = this.layout_of(Ty::new_array(tcx.tcx,ptr_ty, len)).unwrap();
7575

7676
match flags {
7777
// storage for pointers is allocated by miri

src/shims/env.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::mem;
55

66
use rustc_const_eval::interpret::Pointer;
77
use rustc_data_structures::fx::FxHashMap;
8+
use rustc_middle::ty::Ty;
89
use rustc_middle::ty::layout::LayoutOf;
910
use rustc_target::abi::Size;
1011

@@ -449,7 +450,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
449450
// Make an array with all these pointers inside Miri.
450451
let tcx = this.tcx;
451452
let vars_layout = this.layout_of(
452-
tcx.mk_array(this.machine.layouts.mut_raw_ptr.ty, u64::try_from(vars.len()).unwrap()),
453+
Ty::new_array(tcx.tcx,this.machine.layouts.mut_raw_ptr.ty, u64::try_from(vars.len()).unwrap()),
453454
)?;
454455
let vars_place = this.allocate(vars_layout, MiriMemoryKind::Runtime.into())?;
455456
for (idx, var) in vars.into_iter().enumerate() {

src/shims/os_str.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::os::unix::ffi::{OsStrExt, OsStringExt};
77
#[cfg(windows)]
88
use std::os::windows::ffi::{OsStrExt, OsStringExt};
99

10+
use rustc_middle::ty::Ty;
1011
use rustc_middle::ty::layout::LayoutOf;
1112

1213
use crate::*;
@@ -140,7 +141,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
140141
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator.
141142
let this = self.eval_context_mut();
142143

143-
let arg_type = this.tcx.mk_array(this.tcx.types.u8, size);
144+
let arg_type = Ty::new_array(this.tcx.tcx,this.tcx.types.u8, size);
144145
let arg_place = this.allocate(this.layout_of(arg_type).unwrap(), memkind)?;
145146
let (written, _) = self.write_os_str_to_c_str(os_str, arg_place.ptr, size).unwrap();
146147
assert!(written);
@@ -156,7 +157,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
156157
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator.
157158
let this = self.eval_context_mut();
158159

159-
let arg_type = this.tcx.mk_array(this.tcx.types.u16, size);
160+
let arg_type = Ty::new_array(this.tcx.tcx,this.tcx.types.u16, size);
160161
let arg_place = this.allocate(this.layout_of(arg_type).unwrap(), memkind)?;
161162
let (written, _) =
162163
self.write_os_str_to_wide_str(os_str, arg_place.ptr, size, /*truncate*/ false).unwrap();

0 commit comments

Comments
 (0)