Merge pull request 'add an ast smith' (#31635) from gooncreeper/zig:ast-smith into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31635
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
This commit is contained in:
Andrew Kelley
2026-04-02 15:41:05 +02:00
12 changed files with 3245 additions and 712 deletions
+8 -4
View File
@@ -235,7 +235,8 @@ pub const fuzz = struct {
max: u64,
weight: u64,
fn intFromValue(x: anytype) u64 {
/// `inline` to propogate comptimeness
inline fn intFromValue(x: anytype) u64 {
const T = @TypeOf(x);
return switch (@typeInfo(T)) {
.comptime_int => x,
@@ -269,11 +270,13 @@ pub const fuzz = struct {
};
}
pub fn value(T: type, x: T, weight: u64) Weight {
/// `inline` to propogate comptimeness
pub inline fn value(T: type, x: T, weight: u64) Weight {
return .{ .min = intFromValue(x), .max = intFromValue(x), .weight = weight };
}
pub fn rangeAtMost(T: type, at_least: T, at_most: T, weight: u64) Weight {
/// `inline` to propogate comptimeness
pub inline fn rangeAtMost(T: type, at_least: T, at_most: T, weight: u64) Weight {
std.debug.assert(intFromValue(at_least) <= intFromValue(at_most));
return .{
.min = intFromValue(at_least),
@@ -282,7 +285,8 @@ pub const fuzz = struct {
};
}
pub fn rangeLessThan(T: type, at_least: T, less_than: T, weight: u64) Weight {
/// `inline` to propogate comptimeness
pub inline fn rangeLessThan(T: type, at_least: T, less_than: T, weight: u64) Weight {
std.debug.assert(intFromValue(at_least) < intFromValue(less_than));
return .{
.min = intFromValue(at_least),