Skip to content

Commit

Permalink
use TypingEnv when no infcx is available
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
lcnr committed Nov 18, 2024
1 parent e8c42a8 commit bc01bf9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/borrow_tracker/stacked_borrows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{cmp, mem};
use rustc_abi::{BackendRepr, Size};
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::mir::{Mutability, RetagKind};
use rustc_middle::ty::layout::HasParamEnv;
use rustc_middle::ty::layout::HasTypingEnv;
use rustc_middle::ty::{self, Ty};

use self::diagnostics::{RetagCause, RetagInfo};
Expand Down
2 changes: 1 addition & 1 deletion src/borrow_tracker/tree_borrows/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_abi::{BackendRepr, Size};
use rustc_middle::mir::{Mutability, RetagKind};
use rustc_middle::ty::layout::HasParamEnv;
use rustc_middle::ty::layout::HasTypingEnv;
use rustc_middle::ty::{self, Ty};
use rustc_span::def_id::DefId;

Expand Down
14 changes: 9 additions & 5 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,14 @@ pub fn create_ecx<'tcx>(
entry_type: EntryFnType,
config: &MiriConfig,
) -> InterpResult<'tcx, InterpCx<'tcx, MiriMachine<'tcx>>> {
let param_env = ty::ParamEnv::reveal_all();
let layout_cx = LayoutCx::new(tcx, param_env);
let mut ecx =
InterpCx::new(tcx, rustc_span::DUMMY_SP, param_env, MiriMachine::new(config, layout_cx));
let typing_env = ty::TypingEnv::fully_monomorphized();
let layout_cx = LayoutCx::new(tcx, typing_env);
let mut ecx = InterpCx::new(
tcx,
rustc_span::DUMMY_SP,
typing_env.param_env,
MiriMachine::new(config, layout_cx)
);

// Some parts of initialization require a full `InterpCx`.
MiriMachine::late_init(&mut ecx, config, {
Expand Down Expand Up @@ -376,7 +380,7 @@ pub fn create_ecx<'tcx>(
let main_ret_ty = main_ret_ty.no_bound_vars().unwrap();
let start_instance = ty::Instance::try_resolve(
tcx,
ty::ParamEnv::reveal_all(),
typing_env,
start_id,
tcx.mk_args(&[ty::GenericArg::from(main_ret_ty)]),
)
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ pub fn resolve_path<'tcx>(
/// Gets the layout of a type at a path.
#[track_caller]
pub fn path_ty_layout<'tcx>(cx: &impl LayoutOf<'tcx>, path: &[&str]) -> TyAndLayout<'tcx> {
let ty =
resolve_path(cx.tcx(), path, Namespace::TypeNS).ty(cx.tcx(), ty::ParamEnv::reveal_all());
let ty = resolve_path(cx.tcx(), path, Namespace::TypeNS)
.ty(cx.tcx(), cx.typing_env());
cx.layout_of(ty).to_result().ok().unwrap()
}

Expand Down
4 changes: 3 additions & 1 deletion src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,9 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
};
let info = ecx.get_alloc_info(alloc_id);
let def_ty = ecx.tcx.type_of(def_id).instantiate_identity();
let extern_decl_layout = ecx.tcx.layout_of(ty::ParamEnv::empty().and(def_ty)).unwrap();
let extern_decl_layout = ecx.tcx.layout_of(
ecx.typing_env().as_query_input(def_ty)
).unwrap();
if extern_decl_layout.size != info.size || extern_decl_layout.align.abi != info.align {
throw_unsup_format!(
"extern static `{link_name}` has been declared as `{krate}::{name}` \
Expand Down

0 comments on commit bc01bf9

Please sign in to comment.