about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSmitty <me@smitop.com>2021-06-19 10:49:06 -0400
committerSmitty <me@smitop.com>2021-06-29 19:08:30 -0400
commitab66c3fbd4ca7d3ec3e677c94a8fc65e633aa7f4 (patch)
tree505b5e7b95ae1017614a046419db3361ebcff0c1
parenta59fafeb13aa39991c3b8c704c66289fd8fd9253 (diff)
downloadrust-ab66c3fbd4ca7d3ec3e677c94a8fc65e633aa7f4.tar.gz
rust-ab66c3fbd4ca7d3ec3e677c94a8fc65e633aa7f4.zip
Add comment with reasoning for non-determinism
-rw-r--r--compiler/rustc_middle/src/mir/interpret/allocation.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs
index 36c87f335bd..550eb84fc87 100644
--- a/compiler/rustc_middle/src/mir/interpret/allocation.rs
+++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs
@@ -127,6 +127,15 @@ impl<Tag> Allocation<Tag> {
     pub fn uninit(size: Size, align: Align) -> InterpResult<'static, Self> {
         let mut bytes = Vec::new();
         bytes.try_reserve(size.bytes_usize()).map_err(|_| {
+            // This results in an error that can happen non-deterministically, since the memory
+            // 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
             InterpError::ResourceExhaustion(ResourceExhaustionInfo::MemoryExhausted)
         })?;
         bytes.resize(size.bytes_usize(), 0);