From 9f227945f141deb0ae1540b0439cd8330d4df454 Mon Sep 17 00:00:00 2001 From: Smitty Date: Wed, 30 Jun 2021 11:24:52 -0400 Subject: [PATCH] Simplify memory failure checking --- .../rustc_middle/src/mir/interpret/error.rs | 6 ---- .../rustc_mir/src/transform/const_prop.rs | 33 +++++++++---------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index e17017f7225..ab9239585c4 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -535,10 +535,4 @@ pub fn is_hard_err(&self) -> bool { _ => false, } } - - /// Did the error originate from volatile conditons such as the memory available to the - /// interpreter? - pub fn is_volatile(&self) -> bool { - matches!(self, InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)) - } } diff --git a/compiler/rustc_mir/src/transform/const_prop.rs b/compiler/rustc_mir/src/transform/const_prop.rs index 5ab6b334ed4..e7ab8c1e35c 100644 --- a/compiler/rustc_mir/src/transform/const_prop.rs +++ b/compiler/rustc_mir/src/transform/const_prop.rs @@ -31,9 +31,9 @@ use crate::const_eval::ConstEvalErr; use crate::interpret::{ self, compile_time_machine, AllocId, Allocation, ConstValue, CtfeValidationMode, Frame, ImmTy, - Immediate, InterpCx, InterpResult, LocalState, LocalValue, MemPlace, Memory, MemoryKind, OpTy, - Operand as InterpOperand, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, StackPopCleanup, - StackPopUnwind, + Immediate, InterpCx, InterpError, InterpResult, LocalState, LocalValue, MemPlace, Memory, + MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, Pointer, ResourceExhaustionInfo, Scalar, + ScalarMaybeUninit, StackPopCleanup, StackPopUnwind, }; use crate::transform::MirPass; @@ -478,19 +478,6 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti Ok(op) => Some(op), Err(error) => { let tcx = self.ecx.tcx.at(c.span); - if error.kind().is_volatile() { - // Volatile errors can't be ignored since otherwise the amount of available - // memory influences the result of optimization and the build. The error - // doesn't need to be fatal since no code will actually be generated anyways. - self.ecx - .tcx - .tcx - .sess - .struct_err("memory exhausted during optimization") - .help("try increasing the amount of memory available to the compiler") - .emit(); - return None; - } let err = ConstEvalErr::new(&self.ecx, error, Some(c.span)); if let Some(lint_root) = self.lint_root(source_info) { let lint_only = match c.literal { @@ -507,7 +494,19 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti }, ConstantKind::Val(_, ty) => ty.needs_subst(), }; - if lint_only { + // Memory errors can't be ignored since otherwise the amount of available + // memory influences the result of optimization and the build. The error + // doesn't need to be fatal since no code will actually be generated anyways. + // FIXME(#86255): use err.error.is_hard_err(), but beware of backwards + // compatibility and interactions with promoteds + if lint_only + && !matches!( + err.error, + InterpError::ResourceExhaustion( + ResourceExhaustionInfo::MemoryExhausted, + ), + ) + { // Out of backwards compatibility we cannot report hard errors in unused // generic functions using associated constants of the generic parameters. err.report_as_lint(tcx, "erroneous constant used", lint_root, Some(c.span)); -- 2.44.0