Skip to content

Commit 3fd5624

Browse files
committed
we don't need intern_mode any more
1 parent 6d0220d commit 3fd5624

File tree

1 file changed

+5
-84
lines changed
  • compiler/rustc_const_eval/src/interpret

1 file changed

+5
-84
lines changed

compiler/rustc_const_eval/src/interpret/intern.rs

+5-84
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,14 @@ struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_ev
4444
/// The ectx from which we intern.
4545
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
4646
/// Previously encountered safe references.
47-
ref_tracking: &'rt mut RefTracking<(MPlaceTy<'tcx>, InternMode)>,
47+
ref_tracking: &'rt mut RefTracking<MPlaceTy<'tcx>>,
4848
/// A list of all encountered allocations. After type-based interning, we traverse this list to
4949
/// also intern allocations that are only referenced by a raw pointer or inside a union.
5050
leftover_allocations: &'rt mut FxIndexSet<AllocId>,
51-
/// The root kind of the value that we're looking at. This field is never mutated for a
52-
/// particular allocation. It is primarily used to make as many allocations as possible
53-
/// read-only so LLVM can place them in const memory.
54-
mode: InternMode,
55-
/// This field stores whether we are *currently* inside an `UnsafeCell`. This can affect
56-
/// the intern mode of references we encounter.
57-
inside_unsafe_cell: bool,
5851
/// The mutability with which to intern the pointers we find.
5952
intern_mutability: Mutability,
6053
}
6154

62-
#[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)]
63-
enum InternMode {
64-
/// A static and its current mutability. Below shared references inside a `static mut`,
65-
/// this is *immutable*, and below mutable references inside an `UnsafeCell`, this
66-
/// is *mutable*.
67-
Static(hir::Mutability),
68-
/// A `const`.
69-
Const,
70-
}
71-
7255
/// Signalling data structure to ensure we don't recurse
7356
/// into the memory of other constants or statics
7457
struct IsStaticOrFn;
@@ -151,7 +134,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
151134
// Raw pointers (and boxes) are handled by the `leftover_allocations` logic.
152135
let tcx = self.ecx.tcx;
153136
let ty = mplace.layout.ty;
154-
if let ty::Ref(_, referenced_ty, ref_mutability) = *ty.kind() {
137+
if let ty::Ref(_, referenced_ty, _ref_mutability) = *ty.kind() {
155138
let value = self.ecx.read_immediate(mplace)?;
156139
let mplace = self.ecx.ref_to_mplace(&value)?;
157140
assert_eq!(mplace.layout.ty, referenced_ty);
@@ -174,56 +157,14 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
174157
// Check if we have encountered this pointer+layout combination before.
175158
// Only recurse for allocation-backed pointers.
176159
if let Some(alloc_id) = mplace.ptr().provenance {
177-
// Compute the mode with which we intern this. Our goal here is to make as many
178-
// statics as we can immutable so they can be placed in read-only memory by LLVM.
179-
let ref_mode = match self.mode {
180-
InternMode::Static(mutbl) => {
181-
// In statics, merge outer mutability with reference mutability and
182-
// take into account whether we are in an `UnsafeCell`.
183-
184-
// The only way a mutable reference actually works as a mutable reference is
185-
// by being in a `static mut` directly or behind another mutable reference.
186-
// If there's an immutable reference or we are inside a `static`, then our
187-
// mutable reference is equivalent to an immutable one. As an example:
188-
// `&&mut Foo` is semantically equivalent to `&&Foo`
189-
match ref_mutability {
190-
_ if self.inside_unsafe_cell => {
191-
// Inside an `UnsafeCell` is like inside a `static mut`, the "outer"
192-
// mutability does not matter.
193-
InternMode::Static(ref_mutability)
194-
}
195-
Mutability::Not => {
196-
// A shared reference, things become immutable.
197-
// We do *not* consider `freeze` here: `intern_shallow` considers
198-
// `freeze` for the actual mutability of this allocation; the intern
199-
// mode for references contained in this allocation is tracked more
200-
// precisely when traversing the referenced data (by tracking
201-
// `UnsafeCell`). This makes sure that `&(&i32, &Cell<i32>)` still
202-
// has the left inner reference interned into a read-only
203-
// allocation.
204-
InternMode::Static(Mutability::Not)
205-
}
206-
Mutability::Mut => {
207-
// Mutable reference.
208-
InternMode::Static(mutbl)
209-
}
210-
}
211-
}
212-
InternMode::Const => {
213-
// Ignore `UnsafeCell`, everything is immutable. Validity does some sanity
214-
// checking for mutable references that we encounter -- they must all be
215-
// ZST.
216-
InternMode::Const
217-
}
218-
};
219160
match self.intern_shallow(alloc_id) {
220161
// No need to recurse, these are interned already and statics may have
221162
// cycles, so we don't want to recurse there
222163
Some(IsStaticOrFn) => {}
223164
// intern everything referenced by this value. The mutability is taken from the
224165
// reference. It is checked above that mutable references only happen in
225166
// `static mut`
226-
None => self.ref_tracking.track((mplace, ref_mode), || ()),
167+
None => self.ref_tracking.track(mplace, || ()),
227168
}
228169
}
229170
Ok(())
@@ -272,19 +213,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
272213
return Ok(());
273214
}
274215

275-
if let Some(def) = mplace.layout.ty.ty_adt_def() {
276-
if def.is_unsafe_cell() {
277-
// We are crossing over an `UnsafeCell`, we can mutate again. This means that
278-
// References we encounter inside here are interned as pointing to mutable
279-
// allocations.
280-
// Remember the `old` value to handle nested `UnsafeCell`.
281-
let old = std::mem::replace(&mut self.inside_unsafe_cell, true);
282-
let walked = self.walk_value(mplace);
283-
self.inside_unsafe_cell = old;
284-
return walked;
285-
}
286-
}
287-
288216
self.walk_value(mplace)
289217
}
290218
}
@@ -314,11 +242,6 @@ pub fn intern_const_alloc_recursive<
314242
intern_kind: InternKind,
315243
ret: &MPlaceTy<'tcx>,
316244
) -> Result<(), ErrorGuaranteed> {
317-
let base_intern_mode = match intern_kind {
318-
InternKind::Static(mutbl) => InternMode::Static(mutbl),
319-
// `Constant` includes array lengths.
320-
InternKind::Constant | InternKind::Promoted => InternMode::Const,
321-
};
322245
// We are interning recursively, and for mutability we are distinguishing the "root" allocation
323246
// that we are starting in, and all other allocations that we are encountering recursively.
324247
let (base_mutability, inner_mutability) = match intern_kind {
@@ -363,20 +286,18 @@ pub fn intern_const_alloc_recursive<
363286
base_mutability,
364287
);
365288

366-
ref_tracking.track((ret.clone(), base_intern_mode), || ());
289+
ref_tracking.track(ret.clone(), || ());
367290

368291
// We do a type-based traversal to find more allocations to intern. The interner is currently
369292
// mid-refactoring; eventually the type-based traversal will be replaced but a simple traversal
370293
// of all provenance we see in the allocations, but for now we avoid changing rustc error
371294
// messages or accepting extra programs by keeping the old type-based interner around.
372-
while let Some(((mplace, mode), _)) = ref_tracking.todo.pop() {
295+
while let Some((mplace, _)) = ref_tracking.todo.pop() {
373296
let res = InternVisitor {
374297
ref_tracking: &mut ref_tracking,
375298
ecx,
376-
mode,
377299
leftover_allocations,
378300
intern_mutability: inner_mutability,
379-
inside_unsafe_cell: false,
380301
}
381302
.visit_value(&mplace);
382303
// We deliberately *ignore* interpreter errors here. When there is a problem, the remaining

0 commit comments

Comments
 (0)