pub struct CompiledModuleStrategyGen { /* private fields */ }
Expand description
Contains configuration to generate CompiledModule
instances.
If you don’t care about customizing these parameters, see CompiledModule::valid_strategy
.
A CompiledModule
can be looked at as a graph, with several kinds of nodes, and a nest of
pointers among those nodes. This graph has some properties:
- The graph has cycles. Generating DAGs is often simpler, but is not an option in this case.
- The actual structure of the graph is well-defined in terms of the kinds of nodes and pointers that exist.
TODO: the graph also has pointers out of it, via address references to other modules. This doesn’t need to be handled when viewing modules in isolation, but some verification passes will need to look at the entire set of modules. The work to make generating such modules possible remains to be done.
Intermediate types
The pointers are represented as indexes into vectors of other kinds of nodes. One of the
bigger problems is that the number of types, functions etc isn’t known upfront so it is
impossible to know what range to pick from for the index types (ModuleHandleIndex
,
StructHandleIndex
, etc). To deal with this, the code generates a bunch of intermediate
structures (sometimes tuples, other times more complicated structures with their own internal
constraints), with “holes” represented by Index
instances. Once all
the lengths are known, there’s a final “materialize” step at the end that “fills in” these
holes.
One alternative would have been to generate lengths up front, then create vectors of those lengths. This would have worked fine for generation but would have made shrinking take much longer, because the shrinker would be less aware of the overall structure of the problem and would have ended up redoing a lot of work. The approach taken here does end up being more verbose but should perform optimally.
See proptest
issue #130 for more discussion
about this.
Implementations§
source§impl CompiledModuleStrategyGen
impl CompiledModuleStrategyGen
sourcepub fn new(size: TableSize) -> Self
pub fn new(size: TableSize) -> Self
Create a new configuration for randomly generating CompiledModule
instances.
sourcepub fn zeros_all(&mut self) -> &mut Self
pub fn zeros_all(&mut self) -> &mut Self
Zero out all fields, type parameters, arguments and return types of struct and functions.
sourcepub fn generate(self) -> impl Strategy<Value = CompiledModule>
pub fn generate(self) -> impl Strategy<Value = CompiledModule>
Create a proptest
strategy for CompiledModule
instances using this configuration.
Trait Implementations§
source§impl Clone for CompiledModuleStrategyGen
impl Clone for CompiledModuleStrategyGen
source§fn clone(&self) -> CompiledModuleStrategyGen
fn clone(&self) -> CompiledModuleStrategyGen
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more