Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions tooling/ast_fuzzer/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
ctx.set_function_decl(FuncId(1), decl_inner.clone());
ctx.gen_function(u, FuncId(1))?;

// Parameterless main declaration wrapping the inner "main"

Check warning on line 54 in tooling/ast_fuzzer/src/program/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Parameterless)
// function call
let decl_main = FunctionDeclaration {
name: "main".into(),
Expand All @@ -63,7 +63,7 @@
};

ctx.set_function_decl(FuncId(0), decl_main);
ctx.gen_function_with_body(u, FuncId(0), |u, fctx| fctx.gen_body_with_lit_call(u, FuncId(1)))?;

Check warning on line 66 in tooling/ast_fuzzer/src/program/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)

Check warning on line 66 in tooling/ast_fuzzer/src/program/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
ctx.rewrite_functions(u)?;

let program = ctx.finalize();
Expand Down Expand Up @@ -251,7 +251,7 @@

/// Generate random function body.
fn gen_function(&mut self, u: &mut Unstructured, id: FuncId) -> arbitrary::Result<()> {
self.gen_function_with_body(u, id, |u, fctx| fctx.gen_body(u))

Check warning on line 254 in tooling/ast_fuzzer/src/program/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)

Check warning on line 254 in tooling/ast_fuzzer/src/program/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
}

/// Generate function with a specified body generator.
Expand All @@ -261,7 +261,7 @@
id: FuncId,
f: impl Fn(&mut Unstructured, FunctionContext) -> arbitrary::Result<Expression>,
) -> arbitrary::Result<()> {
let fctx = FunctionContext::new(self, id);

Check warning on line 264 in tooling/ast_fuzzer/src/program/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
let body = f(u, fctx)?;
let decl = self.function_decl(id);
let func = Function {
Expand Down Expand Up @@ -425,6 +425,9 @@
break;
}
}
if is_main {
println!("TYPE FOR MAIN: {typ}");
}
self.types.insert(typ.clone());

Ok(typ)
Expand Down
7 changes: 5 additions & 2 deletions tooling/ast_fuzzer/src/program/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ pub(crate) fn can_be_global(typ: &Type) -> bool {
/// as well as part of the databus. They are not expected in real programs as they don't do anything useful.
pub(crate) fn can_be_main(typ: &Type) -> bool {
match typ {
Type::Array(size, _) | Type::String(size) => *size > 0,
_ => true,
Type::String(size) => *size > 0,
Type::Array(size, typ) => *size > 0 && can_be_main(typ),
Type::Tuple(types) => types.iter().all(can_be_main),
Type::Bool | Type::Field | Type::Integer(_, _) => true,
_ => false,
}
}

Expand Down
Loading