This is a tracking issue for the work I'm doing together with @oli-obk, regarding the upgrade of the MIR const-prop pass into a dataflow-analysis-enhanced Constant Propagation pass. This is part of my undergrad thesis, so as long as I am able to work on it, I should have at least the equivalent of part-time availability for the development of the feature.
The feature gate for this issue is #![feature(non_lexical_constprop)]
(feature gate is not in-tree yet)
What this feature means
Currently, there is a MIR optimization pass that does what is commonly know as Constant Folding. In this post however, I'll refer to it as Constant Propagation, since that is the name that we've given it in the mir-opts directory and documentation 馃檪
What the Constant Propagation pass currently does is very limited in scope: it has no awareness of conditional execution (the true and false branches of an if block, for example) and therefore, it limits the propagation range of values known-to-be-constant to just the block in which these values reside.
In this work we will do our best to bring CP up to at least the standard constant propagation passes present in the literature: where the compiler is smart enough to understand control flow, and can conditionally propagate values into control-flow-dependent blocks. For this, the tool we expect to use is the MIR dataflow analysis framework, since CP is a problem known to be well-suited for dataflow analysis.
There are two end goals for this feature so far:
- To bring faster compilation times via the
rustc frontend giving IR of greater quality to LLVM.
- To make certain kinds of static analyses possible, that so far require ad-hoc machinery to even be possible, like this Clippy lint that tries to catch whether or not the user is transmuting a
null pointer at compile time. By having better compile-time information on the value of variables, we expect many analyses like this one to be more viable to realize.
Steps
(Subject to further breakup into smaller steps)
Unresolved Questions
None so far. Please ask away, I'm sure there's something I've missed 馃檪
Implementation history
There's no implementation yet, although I can look up the recent changes to the const-prop pass and outline them here.
Closing note
This should probably be called Non-Lexical ConstProp, since Lexical boundaries are precisely as far as ConstProp can reach right now, and dataflow-aware ConstProp will go beyond, just like the Lifetime analysis did ^^
This is a tracking issue for the work I'm doing together with @oli-obk, regarding the upgrade of the MIR
const-proppass into a dataflow-analysis-enhanced Constant Propagation pass. This is part of my undergrad thesis, so as long as I am able to work on it, I should have at least the equivalent of part-time availability for the development of the feature.The feature gate for this issue is
#
What this feature means
Currently, there is a MIR optimization pass that does what is commonly know as Constant Folding. In this post however, I'll refer to it as Constant Propagation, since that is the name that we've given it in the mir-opts directory and documentation 馃檪
What the Constant Propagation pass currently does is very limited in scope: it has no awareness of conditional execution (the true and false branches of an
ifblock, for example) and therefore, it limits the propagation range of values known-to-be-constant to just the block in which these values reside.In this work we will do our best to bring CP up to at least the standard constant propagation passes present in the literature: where the compiler is smart enough to understand control flow, and can conditionally propagate values into control-flow-dependent blocks. For this, the tool we expect to use is the MIR dataflow analysis framework, since CP is a problem known to be well-suited for dataflow analysis.
There are two end goals for this feature so far:
rustcfrontend givingIRof greater quality toLLVM.nullpointer at compile time. By having better compile-time information on the value of variables, we expect many analyses like this one to be more viable to realize.Steps
(Subject to further breakup into smaller steps)
rustcUnresolved Questions
None so far. Please ask away, I'm sure there's something I've missed 馃檪
Implementation history
There's no implementation yet, although I can look up the recent changes to the
const-proppass and outline them here.Closing note
This should probably be called Non-Lexical ConstProp, since Lexical boundaries are precisely as far as ConstProp can reach right now, and dataflow-aware ConstProp will go beyond, just like the Lifetime analysis did ^^