Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare for 2024 edition migration #1932

Merged
merged 2 commits into from
Dec 3, 2024
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
2 changes: 1 addition & 1 deletion crates/wasm-mutate-stats/src/bin/wasm-mutate-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl State {
let wasmcp = wasm.clone();

while !self.timeout_reached.load(Relaxed) {
let seed = rng.gen();
let seed = rng.r#gen();
wasmmutate.seed(seed);
wasmmutate.fuel(1000);
wasmmutate.preserve_semantics(true);
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-mutate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl<'wasm> WasmMutate<'wasm> {
// Next a length of the replacement is chosen. Note that the replacement
// is always smaller than the input if reduction is requested, otherwise
// we choose some arbitrary length of bytes to insert.
let max_size = if self.reduce || self.rng().gen() {
let max_size = if self.reduce || self.rng().r#gen() {
0
} else {
max_size
Expand Down
12 changes: 6 additions & 6 deletions crates/wasm-mutate/src/mutators/modify_const_exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'cfg, 'wasm> Reencode for InitTranslator<'cfg, 'wasm> {
// removing the offset) as other values may not necessarily be valid
// (e.g. maximum table size is limited)
let is_element_offset = matches!(self.kind, ConstExpressionMutator::ElementOffset);
let should_zero = is_element_offset || self.config.rng().gen::<u8>() & 0b11 == 0;
let should_zero = is_element_offset || self.config.rng().r#gen::<u8>() & 0b11 == 0;
let new_op = match ty {
T::I32 if should_zero => CE::i32_const(0),
T::I64 if should_zero => CE::i64_const(0),
Expand All @@ -123,28 +123,28 @@ impl<'cfg, 'wasm> Reencode for InitTranslator<'cfg, 'wasm> {
let range = if value < 0 { value..0 } else { 0..value };
self.config.rng().gen_range(range)
} else {
self.config.rng().gen()
self.config.rng().r#gen()
}),
T::I64 => CE::i64_const(if let O::I64Const { value } = op {
let range = if value < 0 { value..0 } else { 0..value };
self.config.rng().gen_range(range)
} else {
self.config.rng().gen()
self.config.rng().r#gen()
}),
T::V128 => CE::v128_const(if let O::V128Const { value } = op {
self.config.rng().gen_range(0..value.i128() as u128) as i128
} else {
self.config.rng().gen()
self.config.rng().r#gen()
}),
T::F32 => CE::f32_const(if let O::F32Const { value } = op {
f32::from_bits(value.bits()) / 2.0
} else {
f32::from_bits(self.config.rng().gen())
f32::from_bits(self.config.rng().r#gen())
}),
T::F64 => CE::f64_const(if let O::F64Const { value } = op {
f64::from_bits(value.bits()) / 2.0
} else {
f64::from_bits(self.config.rng().gen())
f64::from_bits(self.config.rng().r#gen())
}),
T::FuncRef => CE::ref_null(wasm_encoder::HeapType::FUNC),
T::ExternRef => CE::ref_null(wasm_encoder::HeapType::EXTERN),
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-mutate/src/mutators/peephole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl PeepholeMutator {
root,
egraph.clone(),
self.max_tree_depth,
config.rng().gen(),
config.rng().r#gen(),
));

// Filter expression equal to the original one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ pub fn expr2wasm(
Lang::I64Load16S(memarg, _) => insn(Instruction::I64Load16S(memarg.into())),
Lang::I64Load32U(memarg, _) => insn(Instruction::I64Load32U(memarg.into())),
Lang::I64Load32S(memarg, _) => insn(Instruction::I64Load32S(memarg.into())),
Lang::RandI32 => insn(Instruction::I32Const(config.rng().gen())),
Lang::RandI64 => insn(Instruction::I64Const(config.rng().gen())),
Lang::RandI32 => insn(Instruction::I32Const(config.rng().r#gen())),
Lang::RandI64 => insn(Instruction::I64Const(config.rng().r#gen())),
Lang::RandF32 => {
newfunc.instruction(&Instruction::F32Const(f32::from_bits(
config.rng().gen(),
config.rng().r#gen(),
)));
}
Lang::RandF64 => {
newfunc.instruction(&Instruction::F64Const(f64::from_bits(
config.rng().gen(),
config.rng().r#gen(),
)));
}
Lang::Undef => { /* Do nothig */ }
Expand All @@ -135,7 +135,7 @@ pub fn expr2wasm(
Lang::I32(value) => {
// Getting type from eclass.

let r: i32 = config.rng().gen();
let r: i32 = config.rng().r#gen();
insn(Instruction::I32Const(r));
insn(Instruction::I32Const(
(Wrapping(*value as i32) - Wrapping(r)).0,
Expand All @@ -156,7 +156,7 @@ pub fn expr2wasm(
Lang::I64(value) => {
// Getting type from eclass.

let r: i64 = config.rng().gen();
let r: i64 = config.rng().r#gen();
insn(Instruction::I64Const(r));
insn(Instruction::I64Const((Wrapping(*value) - Wrapping(r)).0));
insn(Instruction::I64Add);
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-shrink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl ShrinkRun {
self.attempt += 1;

let mut mutate = WasmMutate::default();
let seed = self.rng.gen();
let seed = self.rng.r#gen();
mutate.reduce(true).seed(seed);
log::trace!("Attempt #{}: seed: {}", self.attempt, seed);

Expand Down
12 changes: 6 additions & 6 deletions crates/wast/src/component/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl<'a> Expander<'a> {
t.index = Some(*idx);
return;
}
let id = gensym::gen(item.span);
let id = gensym::generate(item.span);
to_prepend.push(ModuleTypeDecl::Type(core::Type {
span: item.span,
id: Some(id),
Expand Down Expand Up @@ -612,7 +612,7 @@ impl<'a> Expander<'a> {
// And if this type isn't already defined we append it to the index
// space with a fresh and unique name.
let span = Span::from_offset(0); // FIXME(#613): don't manufacture
let id = gensym::gen(span);
let id = gensym::generate(span);

self.types_to_prepend.push(inline.into_any_type(span, id));

Expand Down Expand Up @@ -658,7 +658,7 @@ impl<'a> Expander<'a> {

// And if this type isn't already defined we append it to the index
// space with a fresh and unique name.
let id = gensym::gen(span);
let id = gensym::generate(span);

self.types_to_prepend.push(inline.into_any_type(span, id));

Expand Down Expand Up @@ -711,7 +711,7 @@ impl<'a> Expander<'a> {

// And if this type isn't already defined we append it to the index
// space with a fresh and unique name.
let id = gensym::gen(span);
let id = gensym::generate(span);

self.types_to_prepend.push(inline.into_any_type(span, id));

Expand All @@ -731,7 +731,7 @@ impl<'a> Expander<'a> {
CoreInstantiationArgKind::Instance(_) => return,
CoreInstantiationArgKind::BundleOfExports(span, exports) => (*span, mem::take(exports)),
};
let id = gensym::gen(span);
let id = gensym::generate(span);
self.component_fields_to_prepend
.push(ComponentField::CoreInstance(CoreInstance {
span,
Expand All @@ -751,7 +751,7 @@ impl<'a> Expander<'a> {
InstantiationArgKind::Item(_) => return,
InstantiationArgKind::BundleOfExports(span, exports) => (*span, mem::take(exports)),
};
let id = gensym::gen(span);
let id = gensym::generate(span);
self.component_fields_to_prepend
.push(ComponentField::Instance(Instance {
span,
Expand Down
7 changes: 2 additions & 5 deletions crates/wast/src/core/resolve/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,14 +681,11 @@ impl<'a, 'b> ExprResolver<'a, 'b> {
fn resolve_resume_table(&self, table: &mut ResumeTable<'a>) -> Result<(), Error> {
for handle in &mut table.handlers {
match handle {
Handle::OnLabel {
ref mut tag,
ref mut label,
} => {
Handle::OnLabel { tag, label } => {
self.resolver.resolve(tag, Ns::Tag)?;
self.resolve_label(label)?;
}
Handle::OnSwitch { ref mut tag } => {
Handle::OnSwitch { tag } => {
self.resolver.resolve(tag, Ns::Tag)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wast/src/core/resolve/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a> Expander<'a> {
}

// ... and failing that we insert a new type definition.
let id = gensym::gen(span);
let id = gensym::generate(span);
self.to_prepend.push(ModuleField::Type(Type {
span,
id: Some(id),
Expand Down
10 changes: 5 additions & 5 deletions crates/wast/src/gensym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pub fn reset() {
NEXT.with(|c| c.set(0));
}

pub fn gen(span: Span) -> Id<'static> {
pub fn generate(span: Span) -> Id<'static> {
NEXT.with(|next| {
let gen = next.get() + 1;
next.set(gen);
Id::gensym(span, gen)
let generation = next.get() + 1;
next.set(generation);
Id::gensym(span, generation)
})
}

pub fn fill<'a>(span: Span, slot: &mut Option<Id<'a>>) -> Id<'a> {
*slot.get_or_insert_with(|| gen(span))
*slot.get_or_insert_with(|| generate(span))
}
26 changes: 16 additions & 10 deletions crates/wast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Span {
#[derive(Copy, Clone)]
pub struct Id<'a> {
name: &'a str,
gen: u32,
generation: u32,
span: Span,
}

Expand All @@ -63,14 +63,18 @@ impl<'a> Id<'a> {
/// Note that `name` can be any arbitrary string according to the
/// WebAssembly/annotations proposal.
pub fn new(name: &'a str, span: Span) -> Id<'a> {
Id { name, gen: 0, span }
Id {
name,
generation: 0,
span,
}
}

#[cfg(feature = "wasm-module")]
pub(crate) fn gensym(span: Span, gen: u32) -> Id<'a> {
pub(crate) fn gensym(span: Span, generation: u32) -> Id<'a> {
Id {
name: "gensym",
gen,
generation,
span,
}
}
Expand All @@ -89,20 +93,20 @@ impl<'a> Id<'a> {

#[cfg(feature = "wasm-module")]
pub(crate) fn is_gensym(&self) -> bool {
self.gen != 0
self.generation != 0
}
}

impl<'a> Hash for Id<'a> {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.name.hash(hasher);
self.gen.hash(hasher);
self.generation.hash(hasher);
}
}

impl<'a> PartialEq for Id<'a> {
fn eq(&self, other: &Id<'a>) -> bool {
self.name == other.name && self.gen == other.gen
self.name == other.name && self.generation == other.generation
}
}

Expand All @@ -115,7 +119,7 @@ impl<'a> Parse<'a> for Id<'a> {
return Ok((
Id {
name,
gen: 0,
generation: 0,
span: c.cur_span(),
},
rest,
Expand All @@ -128,8 +132,10 @@ impl<'a> Parse<'a> for Id<'a> {

impl fmt::Debug for Id<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.gen != 0 {
f.debug_struct("Id").field("gen", &self.gen).finish()
if self.generation != 0 {
f.debug_struct("Id")
.field("generation", &self.generation)
.finish()
} else {
self.name.fmt(f)
}
Expand Down
28 changes: 14 additions & 14 deletions crates/wit-smith/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type InterfaceList = IndexMap<String, FileInterface>;
type PackageList = Vec<(PackageName, InterfaceList)>;

struct InterfaceGenerator<'a> {
gen: &'a Generator,
generator: &'a Generator,
file: &'a mut File,
config: &'a Config,
unique_names: HashSet<String>,
Expand Down Expand Up @@ -55,7 +55,7 @@ impl Generator {
}
}

pub fn gen(&mut self, u: &mut Unstructured<'_>) -> Result<Vec<Package>> {
pub fn generate(&mut self, u: &mut Unstructured<'_>) -> Result<Vec<Package>> {
let mut packages = Vec::new();
let mut names = HashSet::new();
while packages.len() < self.config.max_packages && packages.is_empty() {
Expand Down Expand Up @@ -129,13 +129,13 @@ impl Generator {

// Only generate Use/Done if we've already generated a world or interface. This ensures
// that we never generate empty packages, which aren't representable.
let gen = if empty {
let generate = if empty {
u.choose(&[Generate::World, Generate::Interface])?.clone()
} else {
u.arbitrary()?
};

match gen {
match generate {
Generate::World => {
let name = file.gen_unique_package_name(u, &mut package_names)?;
log::debug!("new world `{name}` in {i}");
Expand Down Expand Up @@ -258,9 +258,9 @@ impl Generator {
name: Option<&str>,
file: &mut File,
) -> Result<(String, TypeList)> {
let mut gen = InterfaceGenerator::new(self, file);
let ret = gen.gen_interface(u, name)?;
Ok((ret, gen.types_in_interface))
let mut generator = InterfaceGenerator::new(self, file);
let ret = generator.gen_interface(u, name)?;
Ok((ret, generator.types_in_interface))
}

fn gen_path<'a>(
Expand Down Expand Up @@ -317,11 +317,11 @@ impl Generator {
}

impl<'a> InterfaceGenerator<'a> {
fn new(gen: &'a Generator, file: &'a mut File) -> InterfaceGenerator<'a> {
fn new(generator: &'a Generator, file: &'a mut File) -> InterfaceGenerator<'a> {
InterfaceGenerator {
gen,
generator,
file,
config: &gen.config,
config: &generator.config,
types_in_interface: Vec::new(),
// Claim the name `memory` to avoid conflicting with the canonical
// ABI always using a linear memory named `memory`.
Expand Down Expand Up @@ -454,7 +454,7 @@ impl<'a> InterfaceGenerator<'a> {
self.gen_func_sig(u, &mut part, false)?;
}
ItemKind::Interface(dir) => {
let id = match self.gen.gen_path(u, self.file, &mut part)? {
let id = match self.generator.gen_path(u, self.file, &mut part)? {
Some((_name, id, _types)) => id,
// If an interface couldn't be chosen or wasn't
// chosen then skip this import. A unique name was
Expand All @@ -477,8 +477,8 @@ impl<'a> InterfaceGenerator<'a> {
part.push_str(";");
}
ItemKind::AnonInterface(_) => {
let iface =
InterfaceGenerator::new(self.gen, self.file).gen_interface(u, None)?;
let iface = InterfaceGenerator::new(self.generator, self.file)
.gen_interface(u, None)?;
part.push_str(&iface);
}

Expand Down Expand Up @@ -572,7 +572,7 @@ impl<'a> InterfaceGenerator<'a> {

fn gen_use(&mut self, u: &mut Unstructured<'_>, part: &mut String) -> Result<bool> {
let mut path = String::new();
let (_name, _id, types) = match self.gen.gen_path(u, self.file, &mut path)? {
let (_name, _id, types) = match self.generator.gen_path(u, self.file, &mut path)? {
Some(types) => types,
None => return Ok(false),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-smith/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod generate;
/// The `config` guides the generation of the document and the `u` bytes are
/// used as input to construct the document.
pub fn smith(config: &Config, u: &mut Unstructured<'_>) -> Result<Vec<u8>> {
let pkgs = generate::Generator::new(config.clone()).gen(u)?;
let pkgs = generate::Generator::new(config.clone()).generate(u)?;
let mut resolve = Resolve::default();
let mut last = None;
for pkg in pkgs {
Expand Down
Loading