Skip to content

Commit 42d10d8

Browse files
authored
Unrolled build for rust-lang#133241
Rollup merge of rust-lang#133241 - RalfJung:typing-env, r=lcnr interpret: make typing_env field private This was made public in rust-lang#133212 but IMO it should remain private. (Specifically, this prevents it from being mutated.) r? `@lcnr`
2 parents bfe809d + d04088f commit 42d10d8

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::bug;
77
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, InterpErrorInfo};
88
use rustc_middle::mir::{self, ConstAlloc, ConstValue};
99
use rustc_middle::query::TyCtxtAt;
10-
use rustc_middle::ty::layout::LayoutOf;
10+
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
1111
use rustc_middle::ty::print::with_no_trimmed_paths;
1212
use rustc_middle::ty::{self, Ty, TyCtxt};
1313
use rustc_span::def_id::LocalDefId;
@@ -30,7 +30,6 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
3030
cid: GlobalId<'tcx>,
3131
body: &'tcx mir::Body<'tcx>,
3232
) -> InterpResult<'tcx, R> {
33-
trace!(?ecx.typing_env);
3433
let tcx = *ecx.tcx;
3534
assert!(
3635
cid.promoted.is_some()
@@ -220,7 +219,7 @@ pub(super) fn op_to_const<'tcx>(
220219
let pointee_ty = imm.layout.ty.builtin_deref(false).unwrap(); // `false` = no raw ptrs
221220
debug_assert!(
222221
matches!(
223-
ecx.tcx.struct_tail_for_codegen(pointee_ty, ecx.typing_env).kind(),
222+
ecx.tcx.struct_tail_for_codegen(pointee_ty, ecx.typing_env()).kind(),
224223
ty::Str | ty::Slice(..),
225224
),
226225
"`ConstValue::Slice` is for slice-tailed types only, but got {}",

compiler/rustc_const_eval/src/const_eval/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem};
1010
use rustc_middle::mir::AssertMessage;
1111
use rustc_middle::query::TyCtxtAt;
12-
use rustc_middle::ty::layout::TyAndLayout;
12+
use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout};
1313
use rustc_middle::ty::{self, Ty, TyCtxt};
1414
use rustc_middle::{bug, mir};
1515
use rustc_span::Span;
@@ -667,7 +667,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
667667
.is_some_and(|p| !p.immutable())
668668
{
669669
// That next check is expensive, that's why we have all the guards above.
670-
let is_immutable = ty.is_freeze(*ecx.tcx, ecx.typing_env);
670+
let is_immutable = ty.is_freeze(*ecx.tcx, ecx.typing_env());
671671
let place = ecx.ref_to_mplace(val)?;
672672
let new_place = if is_immutable {
673673
place.map_provenance(CtfeProvenance::as_immutable)

compiler/rustc_const_eval/src/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub struct InterpCx<'tcx, M: Machine<'tcx>> {
3939
pub tcx: TyCtxtAt<'tcx>,
4040

4141
/// The current context in case we're evaluating in a
42-
/// polymorphic context. This always uses `ty::TypingMode::PostAnalysis`
43-
pub typing_env: ty::TypingEnv<'tcx>,
42+
/// polymorphic context. This always uses `ty::TypingMode::PostAnalysis`.
43+
pub(super) typing_env: ty::TypingEnv<'tcx>,
4444

4545
/// The virtual memory system.
4646
pub memory: Memory<'tcx, M>,

compiler/rustc_mir_transform/src/gvn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ use rustc_middle::bug;
100100
use rustc_middle::mir::interpret::GlobalAlloc;
101101
use rustc_middle::mir::visit::*;
102102
use rustc_middle::mir::*;
103-
use rustc_middle::ty::layout::LayoutOf;
103+
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
104104
use rustc_middle::ty::{self, Ty, TyCtxt};
105105
use rustc_span::DUMMY_SP;
106106
use rustc_span::def_id::DefId;
@@ -294,7 +294,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
294294
}
295295

296296
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
297-
self.ecx.typing_env
297+
self.ecx.typing_env()
298298
}
299299

300300
#[instrument(level = "trace", skip(self), ret)]

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +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::HasTypingEnv;
1516
use rustc_middle::ty::{self, Ty};
1617

1718
use self::diagnostics::{RetagCause, RetagInfo};
@@ -70,7 +71,7 @@ impl NewPermission {
7071
access: None,
7172
protector: None,
7273
}
73-
} else if pointee.is_unpin(*cx.tcx, cx.typing_env) {
74+
} else if pointee.is_unpin(*cx.tcx, cx.typing_env()) {
7475
// A regular full mutable reference. On `FnEntry` this is `noalias` and `dereferenceable`.
7576
NewPermission::Uniform {
7677
perm: Permission::Unique,
@@ -128,7 +129,7 @@ impl NewPermission {
128129
fn from_box_ty<'tcx>(ty: Ty<'tcx>, kind: RetagKind, cx: &crate::MiriInterpCx<'tcx>) -> Self {
129130
// `ty` is not the `Box` but the field of the Box with this pointer (due to allocator handling).
130131
let pointee = ty.builtin_deref(true).unwrap();
131-
if pointee.is_unpin(*cx.tcx, cx.typing_env) {
132+
if pointee.is_unpin(*cx.tcx, cx.typing_env()) {
132133
// A regular box. On `FnEntry` this is `noalias`, but not `dereferenceable` (hence only
133134
// a weak protector).
134135
NewPermission::Uniform {
@@ -607,7 +608,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
607608
match new_perm {
608609
NewPermission::Uniform { perm, .. } =>
609610
write!(kind_str, "{perm:?} permission").unwrap(),
610-
NewPermission::FreezeSensitive { freeze_perm, .. } if ty.is_freeze(*this.tcx, this.typing_env) =>
611+
NewPermission::FreezeSensitive { freeze_perm, .. } if ty.is_freeze(*this.tcx, this.typing_env()) =>
611612
write!(kind_str, "{freeze_perm:?} permission").unwrap(),
612613
NewPermission::FreezeSensitive { freeze_perm, nonfreeze_perm, .. } =>
613614
write!(kind_str, "{freeze_perm:?}/{nonfreeze_perm:?} permission for frozen/non-frozen parts").unwrap(),

src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_abi::{BackendRepr, Size};
22
use rustc_middle::mir::{Mutability, RetagKind};
3+
use rustc_middle::ty::layout::HasTypingEnv;
34
use rustc_middle::ty::{self, Ty};
45
use rustc_span::def_id::DefId;
56

@@ -131,8 +132,8 @@ impl<'tcx> NewPermission {
131132
kind: RetagKind,
132133
cx: &crate::MiriInterpCx<'tcx>,
133134
) -> Option<Self> {
134-
let ty_is_freeze = pointee.is_freeze(*cx.tcx, cx.typing_env);
135-
let ty_is_unpin = pointee.is_unpin(*cx.tcx, cx.typing_env);
135+
let ty_is_freeze = pointee.is_freeze(*cx.tcx, cx.typing_env());
136+
let ty_is_unpin = pointee.is_unpin(*cx.tcx, cx.typing_env());
136137
let is_protected = kind == RetagKind::FnEntry;
137138
// As demonstrated by `tests/fail/tree_borrows/reservedim_spurious_write.rs`,
138139
// interior mutability and protectors interact poorly.
@@ -163,10 +164,10 @@ impl<'tcx> NewPermission {
163164
zero_size: bool,
164165
) -> Option<Self> {
165166
let pointee = ty.builtin_deref(true).unwrap();
166-
pointee.is_unpin(*cx.tcx, cx.typing_env).then_some(()).map(|()| {
167+
pointee.is_unpin(*cx.tcx, cx.typing_env()).then_some(()).map(|()| {
167168
// Regular `Unpin` box, give it `noalias` but only a weak protector
168169
// because it is valid to deallocate it within the function.
169-
let ty_is_freeze = ty.is_freeze(*cx.tcx, cx.typing_env);
170+
let ty_is_freeze = ty.is_freeze(*cx.tcx, cx.typing_env());
170171
let protected = kind == RetagKind::FnEntry;
171172
let initial_state = Permission::new_reserved(ty_is_freeze, protected);
172173
Self {
@@ -520,7 +521,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
520521
// Note: if we were to inline `new_reserved` below we would find out that
521522
// `ty_is_freeze` is eventually unused because it appears in a `ty_is_freeze || true`.
522523
// We are nevertheless including it here for clarity.
523-
let ty_is_freeze = place.layout.ty.is_freeze(*this.tcx, this.typing_env);
524+
let ty_is_freeze = place.layout.ty.is_freeze(*this.tcx, this.typing_env());
524525
// Retag it. With protection! That is the entire point.
525526
let new_perm = NewPermission {
526527
initial_state: Permission::new_reserved(ty_is_freeze, /* protected */ true),

src/tools/miri/src/machine.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1717
use rustc_data_structures::static_assert_size;
1818
use rustc_middle::mir;
1919
use rustc_middle::query::TyCtxtAt;
20-
use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, LayoutError, LayoutOf, TyAndLayout};
20+
use rustc_middle::ty::layout::{
21+
HasTyCtxt, HasTypingEnv, LayoutCx, LayoutError, LayoutOf, TyAndLayout,
22+
};
2123
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
2224
use rustc_session::config::InliningThreshold;
2325
use rustc_span::def_id::{CrateNum, DefId};
@@ -1127,9 +1129,8 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11271129
};
11281130
let info = ecx.get_alloc_info(alloc_id);
11291131
let def_ty = ecx.tcx.type_of(def_id).instantiate_identity();
1130-
let extern_decl_layout = ecx.tcx.layout_of(
1131-
ecx.typing_env.as_query_input(def_ty)
1132-
).unwrap();
1132+
let extern_decl_layout =
1133+
ecx.tcx.layout_of(ecx.typing_env().as_query_input(def_ty)).unwrap();
11331134
if extern_decl_layout.size != info.size || extern_decl_layout.align.abi != info.align {
11341135
throw_unsup_format!(
11351136
"extern static `{link_name}` has been declared as `{krate}::{name}` \

0 commit comments

Comments
 (0)