Skip to content

Commit 3f059f6

Browse files
committed
Auto merge of rust-lang#107768 - matthiaskrgr:rollup-9u4cal4, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#107719 (Remove `arena_cache` modifier from `upstream_monomorphizations_for`) - rust-lang#107740 (Avoid locking the global context across the `after_expansion` callback) - rust-lang#107746 (Split fn_ctxt/adjust_fulfillment_errors from fn_ctxt/checks) - rust-lang#107749 (allow quick-edit convenience) - rust-lang#107750 (make more readable) - rust-lang#107755 (remove binder from query constraints) - rust-lang#107756 (miri: fix ICE when running out of address space) - rust-lang#107764 (llvm-16: Use Triple.h from new header location.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bd39bbb + 232213d commit 3f059f6

File tree

19 files changed

+461
-450
lines changed

19 files changed

+461
-450
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
8383
}
8484
self.constraints.member_constraints = tmp;
8585

86-
for (predicate, constraint_category) in outlives {
87-
// At the moment, we never generate any "higher-ranked"
88-
// region constraints like `for<'a> 'a: 'b`. At some point
89-
// when we move to universes, we will, and this assertion
90-
// will start to fail.
91-
let predicate = predicate.no_bound_vars().unwrap_or_else(|| {
92-
bug!("query_constraint {:?} contained bound vars", predicate,);
93-
});
94-
95-
self.convert(predicate, *constraint_category);
86+
for &(predicate, constraint_category) in outlives {
87+
self.convert(predicate, constraint_category);
9688
}
9789
}
9890

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7878
col: u32,
7979
) -> MPlaceTy<'tcx, M::Provenance> {
8080
let loc_details = &self.tcx.sess.opts.unstable_opts.location_detail;
81+
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
82+
// pointless, since that would require allocating more memory than these short strings.
8183
let file = if loc_details.file {
8284
self.allocate_str(filename.as_str(), MemoryKind::CallerLocation, Mutability::Not)
85+
.unwrap()
8386
} else {
8487
// FIXME: This creates a new allocation each time. It might be preferable to
8588
// perform this allocation only once, and re-use the `MPlaceTy`.
8689
// See https://github.com/rust-lang/rust/pull/89920#discussion_r730012398
87-
self.allocate_str("<redacted>", MemoryKind::CallerLocation, Mutability::Not)
90+
self.allocate_str("<redacted>", MemoryKind::CallerLocation, Mutability::Not).unwrap()
8891
};
8992
let line = if loc_details.line { Scalar::from_u32(line) } else { Scalar::from_u32(0) };
9093
let col = if loc_details.column { Scalar::from_u32(col) } else { Scalar::from_u32(0) };
@@ -95,8 +98,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9598
.bound_type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
9699
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
97100
let loc_layout = self.layout_of(loc_ty).unwrap();
98-
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
99-
// pointless, since that would require allocating more memory than a Location.
100101
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
101102

102103
// Initialize fields.

compiler/rustc_const_eval/src/interpret/machine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
291291
fn adjust_alloc_base_pointer(
292292
ecx: &InterpCx<'mir, 'tcx, Self>,
293293
ptr: Pointer,
294-
) -> Pointer<Self::Provenance>;
294+
) -> InterpResult<'tcx, Pointer<Self::Provenance>>;
295295

296296
/// "Int-to-pointer cast"
297297
fn ptr_from_addr_cast(
@@ -505,8 +505,8 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
505505
fn adjust_alloc_base_pointer(
506506
_ecx: &InterpCx<$mir, $tcx, Self>,
507507
ptr: Pointer<AllocId>,
508-
) -> Pointer<AllocId> {
509-
ptr
508+
) -> InterpResult<$tcx, Pointer<AllocId>> {
509+
Ok(ptr)
510510
}
511511

512512
#[inline(always)]

compiler/rustc_const_eval/src/interpret/memory.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
171171
_ => {}
172172
}
173173
// And we need to get the provenance.
174-
Ok(M::adjust_alloc_base_pointer(self, ptr))
174+
M::adjust_alloc_base_pointer(self, ptr)
175175
}
176176

177177
pub fn create_fn_alloc_ptr(
@@ -200,8 +200,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
200200
kind: MemoryKind<M::MemoryKind>,
201201
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
202202
let alloc = Allocation::uninit(size, align, M::PANIC_ON_ALLOC_FAIL)?;
203-
// We can `unwrap` since `alloc` contains no pointers.
204-
Ok(self.allocate_raw_ptr(alloc, kind).unwrap())
203+
self.allocate_raw_ptr(alloc, kind)
205204
}
206205

207206
pub fn allocate_bytes_ptr(
@@ -210,10 +209,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
210209
align: Align,
211210
kind: MemoryKind<M::MemoryKind>,
212211
mutability: Mutability,
213-
) -> Pointer<M::Provenance> {
212+
) -> InterpResult<'tcx, Pointer<M::Provenance>> {
214213
let alloc = Allocation::from_bytes(bytes, align, mutability);
215-
// We can `unwrap` since `alloc` contains no pointers.
216-
self.allocate_raw_ptr(alloc, kind).unwrap()
214+
self.allocate_raw_ptr(alloc, kind)
217215
}
218216

219217
/// This can fail only of `alloc` contains provenance.
@@ -230,7 +228,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
230228
);
231229
let alloc = M::adjust_allocation(self, id, Cow::Owned(alloc), Some(kind))?;
232230
self.memory.alloc_map.insert(id, (kind, alloc.into_owned()));
233-
Ok(M::adjust_alloc_base_pointer(self, Pointer::from(id)))
231+
M::adjust_alloc_base_pointer(self, Pointer::from(id))
234232
}
235233

236234
pub fn reallocate_ptr(

compiler/rustc_const_eval/src/interpret/place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ where
754754
str: &str,
755755
kind: MemoryKind<M::MemoryKind>,
756756
mutbl: Mutability,
757-
) -> MPlaceTy<'tcx, M::Provenance> {
758-
let ptr = self.allocate_bytes_ptr(str.as_bytes(), Align::ONE, kind, mutbl);
757+
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
758+
let ptr = self.allocate_bytes_ptr(str.as_bytes(), Align::ONE, kind, mutbl)?;
759759
let meta = Scalar::from_machine_usize(u64::try_from(str.len()).unwrap(), self);
760760
let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) };
761761

@@ -764,7 +764,7 @@ where
764764
ty::TypeAndMut { ty: self.tcx.types.str_, mutbl },
765765
);
766766
let layout = self.layout_of(ty).unwrap();
767-
MPlaceTy { mplace, layout, align: layout.align.abi }
767+
Ok(MPlaceTy { mplace, layout, align: layout.align.abi })
768768
}
769769

770770
/// Writes the aggregate to the destination.

compiler/rustc_driver_impl/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,16 @@ fn run_compiler(
326326
}
327327
}
328328

329-
let mut gctxt = queries.global_ctxt()?;
329+
// Make sure name resolution and macro expansion is run.
330+
queries.global_ctxt()?;
331+
330332
if callbacks.after_expansion(compiler, queries) == Compilation::Stop {
331333
return early_exit();
332334
}
333335

334336
// Make sure the `output_filenames` query is run for its side
335337
// effects of writing the dep-info and reporting errors.
336-
gctxt.enter(|tcx| tcx.output_filenames(()));
338+
queries.global_ctxt()?.enter(|tcx| tcx.output_filenames(()));
337339

338340
if sess.opts.output_types.contains_key(&OutputType::DepInfo)
339341
&& sess.opts.output_types.len() == 1
@@ -345,7 +347,7 @@ fn run_compiler(
345347
return early_exit();
346348
}
347349

348-
gctxt.enter(|tcx| {
350+
queries.global_ctxt()?.enter(|tcx| {
349351
let result = tcx.analysis(());
350352
if sess.opts.unstable_opts.save_analysis {
351353
let crate_name = tcx.crate_name(LOCAL_CRATE);
@@ -362,8 +364,6 @@ fn run_compiler(
362364
result
363365
})?;
364366

365-
drop(gctxt);
366-
367367
if callbacks.after_analysis(compiler, queries) == Compilation::Stop {
368368
return early_exit();
369369
}

0 commit comments

Comments
 (0)