Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions generate/src/generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,16 @@ impl GenerationCtx {
local
}

// Declare a bunch of variables when we first start a function
fn declare_seed_vars(&mut self) {
for tyid in self
.ty_weights
.choose_tys(self.rng.get_mut(), &self.tcx, self.tcx.len() / 3)
{
self.declare_new_var(Mutability::Mut, tyid);
}
}

#[allow(dead_code)]
fn generate_storage_live(&self) -> Result<Statement> {
let local = self
Expand Down Expand Up @@ -1084,6 +1094,9 @@ impl GenerationCtx {
args,
return_dest,
);

self.declare_seed_vars();

new_fn
}

Expand All @@ -1108,6 +1121,8 @@ impl GenerationCtx {

self.pt
.enter_fn0(&self.program.functions[self.cursor.function]);

self.declare_seed_vars();
}

// Returns from the currnt function. Returns false if we're returning from
Expand Down
5 changes: 5 additions & 0 deletions generate/src/place_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ impl PlaceSelector {
pt.reachable_nodes().filter(move |ppath| {
let index = ppath.target_index();

// Don't generate anything of unit type
if pt.ty(index) == TyCtxt::UNIT {
return false;
}

// Well-typedness
if let Some(tys) = &self.tys
&& !tys.contains(&pt.ty(index))
Expand Down
8 changes: 8 additions & 0 deletions generate/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ impl TySelect {
.nth(self.weights.sample(rng))
.expect("tyctxt isn't empty")
}

pub fn choose_tys(&self, rng: &mut impl Rng, tcx: &TyCtxt, count: usize) -> Vec<TyId> {
(&self.weights)
.sample_iter(rng)
.take(count)
.map(|tyid| tcx.indices().nth(tyid).expect("tyctxt isn't empty"))
.collect()
}
}

fn new_composite(tcx: &mut TyCtxt, rng: &mut impl Rng) {
Expand Down