Skip to content
Merged
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
1 change: 1 addition & 0 deletions tooling/ast_fuzzer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![forbid(unsafe_code)]
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

Expand Down
6 changes: 3 additions & 3 deletions tooling/ast_fuzzer/src/program/freq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ pub(crate) struct Freq {
}

impl Freq {
pub fn new(u: &mut Unstructured, freqs: &Freqs) -> arbitrary::Result<Self> {
pub(crate) fn new(u: &mut Unstructured, freqs: &Freqs) -> arbitrary::Result<Self> {
let x = u.choose_index(freqs.total())?;
Ok(Self { freqs: freqs.clone(), x, accumulated: 0, disabled: 0 })
}

/// Check if a key is enabled, based on the already checked cumulative values.
///
/// To work correctly, `enabled` calls should come after `enabled_when`s.
pub fn enabled(&mut self, key: &str) -> bool {
pub(crate) fn enabled(&mut self, key: &str) -> bool {
self.accumulated += self.freqs[key];
self.passed()
}
Expand All @@ -64,7 +64,7 @@ impl Freq {
/// As a workaround, we should
/// * check keys which are more likely to be disabled up front
/// * have a default case at the end which is always enabled
pub fn enabled_when(&mut self, key: &str, cond: bool) -> bool {
pub(crate) fn enabled_when(&mut self, key: &str, cond: bool) -> bool {
if cond {
self.enabled(key)
} else {
Expand Down
8 changes: 4 additions & 4 deletions tooling/ast_fuzzer/src/program/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

impl FunctionDeclaration {
/// Generate a HIR function signature.
pub fn signature(&self) -> hir_def::function::FunctionSignature {
pub(super) fn signature(&self) -> hir_def::function::FunctionSignature {
let param_types = self
.params
.iter()
Expand Down Expand Up @@ -140,7 +140,7 @@
}

impl<'a> FunctionContext<'a> {
pub fn new(ctx: &'a mut Context, id: FuncId) -> Self {
pub(super) fn new(ctx: &'a mut Context, id: FuncId) -> Self {
let decl = ctx.function_decl(id);
let next_local_id = decl.params.iter().map(|p| p.0.0 + 1).max().unwrap_or_default();
let budget = ctx.config.max_function_size;
Expand Down Expand Up @@ -206,7 +206,7 @@
}

/// Generate the function body.
pub fn gen_body(mut self, u: &mut Unstructured) -> arbitrary::Result<Expression> {
pub(super) fn gen_body(mut self, u: &mut Unstructured) -> arbitrary::Result<Expression> {
// If we don't limit the budget according to the available data,
// it gives us a lot of `false` and 0 and we end up with deep `!(!false)` if expressions.
self.budget = self.budget.min(u.len());
Expand All @@ -220,7 +220,7 @@

/// Generate the function body, wrapping a function call with literal arguments.
/// This is used to test comptime functions, which can only take those.
pub fn gen_body_with_lit_call(
pub(super) fn gen_body_with_lit_call(
mut self,
u: &mut Unstructured,
callee_id: FuncId,
Expand Down Expand Up @@ -1158,9 +1158,9 @@
ctx.config.max_loop_size = 10;
ctx.config.vary_loop_size = false;
ctx.gen_main_decl(&mut u);
let mut fctx = FunctionContext::new(&mut ctx, FuncId(0));

Check warning on line 1161 in tooling/ast_fuzzer/src/program/func.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
fctx.budget = 2;

Check warning on line 1162 in tooling/ast_fuzzer/src/program/func.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
let loop_code = format!("{}", fctx.gen_loop(&mut u).unwrap()).replace(" ", "");

Check warning on line 1163 in tooling/ast_fuzzer/src/program/func.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)

println!("{loop_code}");
assert!(
Expand All @@ -1184,8 +1184,8 @@
ctx.config.max_loop_size = 10;
ctx.config.vary_loop_size = false;
ctx.gen_main_decl(&mut u);
let mut fctx = FunctionContext::new(&mut ctx, FuncId(0));

Check warning on line 1187 in tooling/ast_fuzzer/src/program/func.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
fctx.budget = 2;

Check warning on line 1188 in tooling/ast_fuzzer/src/program/func.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (fctx)
let while_code = format!("{}", fctx.gen_while(&mut u).unwrap()).replace(" ", "");

println!("{while_code}");
Expand Down
26 changes: 13 additions & 13 deletions tooling/ast_fuzzer/src/program/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
K: Ord + Clone + Copy + Debug,
{
/// Create the initial scope from function parameters.
pub fn new(vars: impl Iterator<Item = (K, bool, Name, Type)>) -> Self {
pub(super) fn new(vars: impl Iterator<Item = (K, bool, Name, Type)>) -> Self {
let mut scope = Self { variables: im::OrdMap::new(), producers: im::OrdMap::new() };
for (id, mutable, name, typ) in vars {
scope.add(id, mutable, name, typ);
Expand Down Expand Up @@ -72,7 +72,7 @@ where
}

/// Choose a random producer of a type, if there is one.
pub fn choose_producer(
pub(super) fn choose_producer(
&self,
u: &mut Unstructured,
typ: &Type,
Expand All @@ -87,7 +87,7 @@ where
}

/// Get a variable in scope.
pub fn get_variable(&self, id: &K) -> &Variable {
pub(super) fn get_variable(&self, id: &K) -> &Variable {
self.variables.get(id).unwrap_or_else(|| panic!("variable doesn't exist: {:?}", id))
}
}
Expand All @@ -97,22 +97,22 @@ where
K: Ord,
{
/// Check if there are any variables in scope.
pub fn is_empty(&self) -> bool {
pub(super) fn is_empty(&self) -> bool {
self.variables.is_empty()
}

/// Iterate the variables in scope.
pub fn variables(&self) -> impl ExactSizeIterator<Item = (&K, &Variable)> {
pub(super) fn variables(&self) -> impl ExactSizeIterator<Item = (&K, &Variable)> {
self.variables.iter()
}

/// Iterate the IDs of the variables in scope.
pub fn variable_ids(&self) -> impl ExactSizeIterator<Item = &K> {
pub(super) fn variable_ids(&self) -> impl ExactSizeIterator<Item = &K> {
self.variables.keys()
}

/// Iterate the types we can produce from other variables.
pub fn types_produced(&self) -> impl ExactSizeIterator<Item = &Type> {
pub(super) fn types_produced(&self) -> impl ExactSizeIterator<Item = &Type> {
self.producers.keys()
}
}
Expand All @@ -125,34 +125,34 @@ where
K: Ord + Clone + Copy + Debug,
{
/// Create a stack from the base variables.
pub fn new(vars: impl Iterator<Item = (K, bool, Name, Type)>) -> Self {
pub(super) fn new(vars: impl Iterator<Item = (K, bool, Name, Type)>) -> Self {
Self(vec![Scope::new(vars)])
}

/// The top scope in the stack.
pub fn current(&self) -> &Scope<K> {
pub(super) fn current(&self) -> &Scope<K> {
self.0.last().expect("there is always the base layer")
}

/// Push a new scope on top of the current one.
pub fn enter(&mut self) {
pub(super) fn enter(&mut self) {
// Instead of shallow cloning an immutable map, we could loop through layers when looking up variables.
self.0.push(self.current().clone());
}

/// Remove the last layer of block variables.
pub fn exit(&mut self) {
pub(super) fn exit(&mut self) {
self.0.pop();
assert!(!self.0.is_empty(), "never pop the base layer");
}

/// Add a new variable to the current scope.
pub fn add(&mut self, id: K, mutable: bool, name: String, typ: Type) {
pub(super) fn add(&mut self, id: K, mutable: bool, name: String, typ: Type) {
self.0.last_mut().expect("there is always a layer").add(id, mutable, name, typ);
}

/// Remove a variable from all scopes.
pub fn remove(&mut self, id: &K) {
pub(super) fn remove(&mut self, id: &K) {
for scope in self.0.iter_mut() {
scope.remove(id);
}
Expand Down
Loading