Skip to content

Commit bc01bf9

Browse files
committed
use TypingEnv when no infcx is available
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
1 parent e8c42a8 commit bc01bf9

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{cmp, mem};
1212
use rustc_abi::{BackendRepr, Size};
1313
use rustc_data_structures::fx::FxHashSet;
1414
use rustc_middle::mir::{Mutability, RetagKind};
15-
use rustc_middle::ty::layout::HasParamEnv;
15+
use rustc_middle::ty::layout::HasTypingEnv;
1616
use rustc_middle::ty::{self, Ty};
1717

1818
use self::diagnostics::{RetagCause, RetagInfo};

src/borrow_tracker/tree_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_abi::{BackendRepr, Size};
22
use rustc_middle::mir::{Mutability, RetagKind};
3-
use rustc_middle::ty::layout::HasParamEnv;
3+
use rustc_middle::ty::layout::HasTypingEnv;
44
use rustc_middle::ty::{self, Ty};
55
use rustc_span::def_id::DefId;
66

src/eval.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,14 @@ pub fn create_ecx<'tcx>(
268268
entry_type: EntryFnType,
269269
config: &MiriConfig,
270270
) -> InterpResult<'tcx, InterpCx<'tcx, MiriMachine<'tcx>>> {
271-
let param_env = ty::ParamEnv::reveal_all();
272-
let layout_cx = LayoutCx::new(tcx, param_env);
273-
let mut ecx =
274-
InterpCx::new(tcx, rustc_span::DUMMY_SP, param_env, MiriMachine::new(config, layout_cx));
271+
let typing_env = ty::TypingEnv::fully_monomorphized();
272+
let layout_cx = LayoutCx::new(tcx, typing_env);
273+
let mut ecx = InterpCx::new(
274+
tcx,
275+
rustc_span::DUMMY_SP,
276+
typing_env.param_env,
277+
MiriMachine::new(config, layout_cx)
278+
);
275279

276280
// Some parts of initialization require a full `InterpCx`.
277281
MiriMachine::late_init(&mut ecx, config, {
@@ -376,7 +380,7 @@ pub fn create_ecx<'tcx>(
376380
let main_ret_ty = main_ret_ty.no_bound_vars().unwrap();
377381
let start_instance = ty::Instance::try_resolve(
378382
tcx,
379-
ty::ParamEnv::reveal_all(),
383+
typing_env,
380384
start_id,
381385
tcx.mk_args(&[ty::GenericArg::from(main_ret_ty)]),
382386
)

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ pub fn resolve_path<'tcx>(
116116
/// Gets the layout of a type at a path.
117117
#[track_caller]
118118
pub fn path_ty_layout<'tcx>(cx: &impl LayoutOf<'tcx>, path: &[&str]) -> TyAndLayout<'tcx> {
119-
let ty =
120-
resolve_path(cx.tcx(), path, Namespace::TypeNS).ty(cx.tcx(), ty::ParamEnv::reveal_all());
119+
let ty = resolve_path(cx.tcx(), path, Namespace::TypeNS)
120+
.ty(cx.tcx(), cx.typing_env());
121121
cx.layout_of(ty).to_result().ok().unwrap()
122122
}
123123

src/machine.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,9 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11271127
};
11281128
let info = ecx.get_alloc_info(alloc_id);
11291129
let def_ty = ecx.tcx.type_of(def_id).instantiate_identity();
1130-
let extern_decl_layout = ecx.tcx.layout_of(ty::ParamEnv::empty().and(def_ty)).unwrap();
1130+
let extern_decl_layout = ecx.tcx.layout_of(
1131+
ecx.typing_env().as_query_input(def_ty)
1132+
).unwrap();
11311133
if extern_decl_layout.size != info.size || extern_decl_layout.align.abi != info.align {
11321134
throw_unsup_format!(
11331135
"extern static `{link_name}` has been declared as `{krate}::{name}` \

0 commit comments

Comments
 (0)