diff options
| author | Smitty <me@smitop.com> | 2021-06-29 20:22:32 -0400 |
|---|---|---|
| committer | Smitty <me@smitop.com> | 2021-06-29 20:22:32 -0400 |
| commit | d04da1125d8583e7ae85491eb764c19564b2ab19 (patch) | |
| tree | 9afd51e5327c31b4e977682f745c9b1f547633c6 /compiler/rustc_middle/src | |
| parent | c94bafb69b5a09c7d91959f9be7f5c2d7be1b69d (diff) | |
| download | rust-d04da1125d8583e7ae85491eb764c19564b2ab19.tar.gz rust-d04da1125d8583e7ae85491eb764c19564b2ab19.zip | |
Properly handle const prop failures
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/allocation.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/error.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/vtable.rs | 2 |
3 files changed, 15 insertions, 6 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs index 550eb84fc87..9bc41da1b46 100644 --- a/compiler/rustc_middle/src/mir/interpret/allocation.rs +++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs @@ -131,11 +131,14 @@ impl<Tag> Allocation<Tag> { // available to the compiler can change between runs. Normally queries are always // deterministic. However, we can be non-determinstic here because all uses of const // evaluation do one of: - // - cause a fatal compiler error when they see this error as the result of const - // evaluation - // - panic on evaluation failure - // - always evaluate very small constants that are practically unlikely to result in - // memory exhaustion + // - error on failure + // - used for static initalizer evalution + // - used for const value evaluation + // - const prop errors on this since otherwise it would generate different code based + // on available memory + // - panic on failure to allocate very small sizes + // - actually panicking won't happen since there wouldn't be enough memory to panic + // - used for caller location evaluation InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted) })?; bytes.resize(size.bytes_usize(), 0); diff --git a/compiler/rustc_middle/src/mir/interpret/error.rs b/compiler/rustc_middle/src/mir/interpret/error.rs index ab9239585c4..2e461015b62 100644 --- a/compiler/rustc_middle/src/mir/interpret/error.rs +++ b/compiler/rustc_middle/src/mir/interpret/error.rs @@ -535,4 +535,10 @@ impl InterpError<'_> { _ => false, } } + + /// Did the error originate from volatile conditons such as the memory available to the + /// interpreter? + pub fn is_spurious(&self) -> bool { + matches!(self, InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)) + } } diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index 61c146d03a3..0230e05c12e 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -1,6 +1,6 @@ use std::convert::TryFrom; -use crate::mir::interpret::{alloc_range, AllocId, Allocation, Pointer, Scalar, InterpResult}; +use crate::mir::interpret::{alloc_range, AllocId, Allocation, InterpResult, Pointer, Scalar}; use crate::ty::fold::TypeFoldable; use crate::ty::{self, DefId, SubstsRef, Ty, TyCtxt}; use rustc_ast::Mutability; |
