Skip to content

Commit 8d76d07

Browse files
committed
Auto merge of rust-lang#116012 - cjgillot:gvn-const, r=oli-obk
Implement constant propagation on top of MIR SSA analysis This implements the idea I proposed in rust-lang#110719 (comment) Based on rust-lang#109597 The value numbering "GVN" pass formulates each rvalue that appears in MIR with an abstract form (the `Value` enum), and assigns an integer `VnIndex` to each. This abstract form can be used to deduplicate values, reusing an earlier local that holds the same value instead of recomputing. This part is proposed in rust-lang#109597. From this abstract representation, we can perform more involved simplifications, for example in rust-lang#111344. With the abstract representation `Value`, we can also attempt to evaluate each to a constant using the interpreter. This builds a `VnIndex -> OpTy` map. From this map, we can opportunistically replace an operand or a rvalue with a constant if their value has an associated `OpTy`. The most relevant commit is [Evaluated computed values to constants.](rust-lang@2767c49)" r? `@oli-obk`
2 parents 03b5019 + 6d7f063 commit 8d76d07

File tree

209 files changed

+1088
-1581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+1088
-1581
lines changed

compiler/rustc_infer/src/infer/relate/generalize.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::mem;
22

33
use rustc_data_structures::sso::SsoHashMap;
4+
use rustc_data_structures::stack::ensure_sufficient_stack;
45
use rustc_hir::def_id::DefId;
56
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
67
use rustc_middle::ty::error::TypeError;
@@ -215,7 +216,9 @@ where
215216
let old_ambient_variance = self.ambient_variance;
216217
self.ambient_variance = self.ambient_variance.xform(variance);
217218
debug!(?self.ambient_variance, "new ambient variance");
218-
let r = self.relate(a, b)?;
219+
// Recursive calls to `relate` can overflow the stack. For example a deeper version of
220+
// `ui/associated-consts/issue-93775.rs`.
221+
let r = ensure_sufficient_stack(|| self.relate(a, b))?;
219222
self.ambient_variance = old_ambient_variance;
220223
Ok(r)
221224
}

0 commit comments

Comments
 (0)