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

chore: add a clippy job in CI #267

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b30aa65
upgrade wasmparser & wasm-encoder to v0.211.0
lwshang Jun 25, 2024
2df4d06
fmt
lwshang Jun 25, 2024
96a546b
cleanup workflow yml
lwshang Jun 25, 2024
2a6023c
update testsuite and skip all proposals
lwshang Jun 27, 2024
58b33f6
proc-macro has dash now
lwshang Jun 27, 2024
443462d
fix for bulk.wast by refresh elements
lwshang Jun 28, 2024
8c38eb5
bump to 0.212.0 and follow the features in wasm-tools
lwshang Jun 28, 2024
5eee359
fix elem.wast which failed in gc pass
lwshang Jun 28, 2024
60444cb
handle RefNull
lwshang Jun 29, 2024
fc4c360
always use default features from wasmparser
lwshang Jun 29, 2024
704239d
overhaul spec-tests.rs
lwshang Jun 29, 2024
26afde9
enable multi-memory spec-tests
lwshang Jun 29, 2024
98ea980
fix wabt bin path
lwshang Jun 29, 2024
9fc633f
fix binaryen bin path
lwshang Jun 29, 2024
6c0a24f
no memory64
lwshang Jun 29, 2024
f1bedde
typo
lwshang Jun 29, 2024
a098696
separate RefType
lwshang Jun 29, 2024
0f93d3c
rename InitExpr -> ConstExpr
lwshang Jun 29, 2024
4f029f0
align Memory with wasm-tools
lwshang Jun 29, 2024
2d54251
TODO for operators
lwshang Jun 29, 2024
8272e87
apply clippy fix
lwshang Jun 29, 2024
f455d79
Revert "apply clippy fix"
lwshang Jun 29, 2024
c1302d3
Reapply "apply clippy fix"
lwshang Jun 29, 2024
dac96ca
list all unimplemented operators
lwshang Jul 2, 2024
e40af5f
comment
lwshang Jul 2, 2024
a4f5965
Update src/module/mod.rs
lwshang Jul 2, 2024
bac785f
Merge branch 'upgrade_dependencies' into clippy
lwshang Jul 2, 2024
f4709ac
clippy cont.
lwshang Jul 2, 2024
17ad0da
upgrade criterion and fix deprecated
lwshang Jul 2, 2024
08d335e
upgrade env_logger
lwshang Jul 2, 2024
f51b828
add clippy CI job
lwshang Jul 2, 2024
96c5762
format main.yml
lwshang Jul 2, 2024
3763487
Merge branch 'main' into clippy
lwshang Jul 2, 2024
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
Prev Previous commit
Next Next commit
separate RefType
  • Loading branch information
lwshang committed Jun 29, 2024
commit a098696fb11ea32f8bbb31c37cd6b6955375a15c
21 changes: 12 additions & 9 deletions src/init_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::emit::EmitContext;
use crate::ir::Value;
use crate::parse::IndicesToIds;
use crate::ValType;
use crate::RefType;
use crate::{FunctionId, GlobalId, Result};
use anyhow::bail;

Expand All @@ -16,7 +16,7 @@ pub enum InitExpr {
/// A constant value referenced by the global specified
Global(GlobalId),
/// A null reference
RefNull(ValType),
RefNull(RefType),
/// A function initializer
RefFunc(FunctionId),
}
Expand All @@ -35,11 +35,15 @@ impl InitExpr {
RefNull { hty } => {
let val_type = match hty {
wasmparser::HeapType::Abstract { shared: _, ty } => match ty {
wasmparser::AbstractHeapType::Func => ValType::Funcref,
wasmparser::AbstractHeapType::Extern => ValType::Externref,
_ => bail!("invalid constant expression"),
wasmparser::AbstractHeapType::Func => RefType::Funcref,
wasmparser::AbstractHeapType::Extern => RefType::Externref,
other => bail!(
"unsupported abstract heap type in constant expression: {other:?}"
),
},
wasmparser::HeapType::Concrete(_) => bail!("invalid constant expression"),
wasmparser::HeapType::Concrete(_) => {
bail!("unsupported concrete heap type in constant expression")
}
};
InitExpr::RefNull(val_type)
}
Expand Down Expand Up @@ -67,15 +71,14 @@ impl InitExpr {
wasm_encoder::ConstExpr::global_get(cx.indices.get_global_index(*g))
}
InitExpr::RefNull(ty) => wasm_encoder::ConstExpr::ref_null(match ty {
ValType::Externref => wasm_encoder::HeapType::Abstract {
RefType::Externref => wasm_encoder::HeapType::Abstract {
shared: false,
ty: wasm_encoder::AbstractHeapType::Extern,
},
ValType::Funcref => wasm_encoder::HeapType::Abstract {
RefType::Funcref => wasm_encoder::HeapType::Abstract {
shared: false,
ty: wasm_encoder::AbstractHeapType::Func,
},
_ => unreachable!(),
}),
InitExpr::RefFunc(f) => {
wasm_encoder::ConstExpr::ref_func(cx.indices.get_func_index(*f))
Expand Down
6 changes: 3 additions & 3 deletions src/ir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod traversals;
pub use self::traversals::*;

use crate::{
DataId, ElementId, FunctionId, GlobalId, LocalFunction, MemoryId, ModuleTypes, TableId, TypeId,
ValType,
DataId, ElementId, FunctionId, GlobalId, LocalFunction, MemoryId, ModuleTypes, RefType,
TableId, TypeId, ValType,
};
use id_arena::Id;
use std::fmt;
Expand Down Expand Up @@ -532,7 +532,7 @@ pub enum Instr {
RefNull {
/// The type of null that we're producing
#[walrus(skip_visit)]
ty: ValType,
ty: RefType,
},

/// `ref.is_null`
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ pub use crate::init_expr::InitExpr;
pub use crate::ir::{Local, LocalId};
pub use crate::module::*;
pub use crate::parse::IndicesToIds;
pub use crate::ty::{Type, TypeId, ValType};
pub use crate::ty::{RefType, Type, TypeId, ValType};
13 changes: 6 additions & 7 deletions src/module/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::emit::{Emit, EmitContext};
use crate::parse::IndicesToIds;
use crate::tombstone_arena::{Id, Tombstone, TombstoneArena};
use crate::{ir::Value, FunctionId, InitExpr, Module, Result, TableId, ValType};
use crate::{ir::Value, FunctionId, InitExpr, Module, RefType, Result, TableId, ValType};
use anyhow::{bail, Context};

/// A passive element segment identifier
Expand Down Expand Up @@ -44,7 +44,7 @@ pub enum ElementItems {
/// This element contains function indices.
Functions(Vec<FunctionId>),
/// This element contains constant expressions used to initialize the table.
Expressions(ValType, Vec<InitExpr>),
Expressions(RefType, Vec<InitExpr>),
}

impl Element {
Expand Down Expand Up @@ -134,8 +134,8 @@ impl Module {
}
wasmparser::ElementItems::Expressions(ref_type, items) => {
let ty = match ref_type {
wasmparser::RefType::FUNCREF => ValType::Funcref,
wasmparser::RefType::EXTERNREF => ValType::Externref,
wasmparser::RefType::FUNCREF => RefType::Funcref,
wasmparser::RefType::EXTERNREF => RefType::Externref,
_ => bail!("unsupported ref type in element segment {}", i),
};
let mut init_exprs = Vec::with_capacity(items.count() as usize);
Expand Down Expand Up @@ -211,9 +211,8 @@ impl Emit for ModuleElements {
}
ElementItems::Expressions(ty, init_exprs) => {
let ref_type = match ty {
ValType::Funcref => wasm_encoder::RefType::FUNCREF,
ValType::Externref => wasm_encoder::RefType::EXTERNREF,
_ => unreachable!(),
RefType::Funcref => wasm_encoder::RefType::FUNCREF,
RefType::Externref => wasm_encoder::RefType::EXTERNREF,
};
let const_exprs = init_exprs
.iter()
Expand Down
7 changes: 3 additions & 4 deletions src/module/functions/local_function/emit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::emit::IdsToIndices;
use crate::ir::*;
use crate::map::IdHashMap;
use crate::module::functions::LocalFunction;
use crate::module::memories::MemoryId;
use crate::{ir::*, RefType};
use wasm_encoder::Instruction;

pub(crate) fn run(
Expand Down Expand Up @@ -775,15 +775,14 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
TableSize(e) => Instruction::TableSize(self.indices.get_table_index(e.table)),
TableFill(e) => Instruction::TableFill(self.indices.get_table_index(e.table)),
RefNull(e) => Instruction::RefNull(match &e.ty {
crate::ValType::Externref => wasm_encoder::HeapType::Abstract {
RefType::Externref => wasm_encoder::HeapType::Abstract {
shared: false,
ty: wasm_encoder::AbstractHeapType::Extern,
},
crate::ValType::Funcref => wasm_encoder::HeapType::Abstract {
RefType::Funcref => wasm_encoder::HeapType::Abstract {
shared: false,
ty: wasm_encoder::AbstractHeapType::Func,
},
_ => unreachable!(),
}),
RefIsNull(_) => Instruction::RefIsNull,
RefFunc(e) => Instruction::RefFunc(self.indices.get_func_index(e.func)),
Expand Down
10 changes: 6 additions & 4 deletions src/module/functions/local_function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ mod emit;

use self::context::ValidationContext;
use crate::emit::IdsToIndices;
use crate::ir::*;
use crate::map::{IdHashMap, IdHashSet};
use crate::parse::IndicesToIds;
use crate::{ir::*, RefType};
use crate::{Data, DataId, FunctionBuilder, FunctionId, MemoryId, Module, Result, TypeId, ValType};
use std::collections::BTreeMap;
use std::ops::Range;
Expand Down Expand Up @@ -1001,9 +1001,11 @@ fn append_instruction<'context>(
Operator::RefNull { hty } => {
let ty = match hty {
wasmparser::HeapType::Abstract { shared: _, ty } => match ty {
wasmparser::AbstractHeapType::Func => ValType::Funcref,
wasmparser::AbstractHeapType::Extern => ValType::Externref,
_ => panic!("unsupported abstract heap type for ref.null"),
wasmparser::AbstractHeapType::Func => RefType::Funcref,
wasmparser::AbstractHeapType::Extern => RefType::Externref,
other => {
panic!("unsupported abstract heap type for ref.null: {:?}", other)
}
},
wasmparser::HeapType::Concrete(_) => {
panic!("unsupported concrete heap type for ref.null")
Expand Down
14 changes: 7 additions & 7 deletions src/module/imports.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! A wasm module's imports.

use std::convert::TryInto;

use anyhow::{bail, Context};

use crate::emit::{Emit, EmitContext};
use crate::parse::IndicesToIds;
use crate::tombstone_arena::{Id, Tombstone, TombstoneArena};
use crate::{FunctionId, GlobalId, MemoryId, Result, TableId};
use crate::{Module, TypeId, ValType};
use crate::{Module, RefType, TypeId, ValType};

/// The id of an import.
pub type ImportId = Id<Import>;
Expand Down Expand Up @@ -159,14 +161,13 @@ impl Module {
ids.push_func(id.0);
}
wasmparser::TypeRef::Table(t) => {
let ty = ValType::parse(&wasmparser::ValType::Ref(t.element_type))?;
let id = self.add_import_table(
entry.module,
entry.name,
t.table64,
t.initial,
t.maximum,
ty,
t.element_type.try_into()?,
);
ids.push_table(id.0);
}
Expand Down Expand Up @@ -242,7 +243,7 @@ impl Module {
table64: bool,
initial: u64,
maximum: Option<u64>,
ty: ValType,
ty: RefType,
) -> (TableId, ImportId) {
let import = self.imports.arena.next_id();
let table = self
Expand Down Expand Up @@ -295,9 +296,8 @@ impl Emit for ModuleImports {
let table = cx.module.tables.get(id);
wasm_encoder::EntityType::Table(wasm_encoder::TableType {
element_type: match table.element_ty {
ValType::Externref => wasm_encoder::RefType::EXTERNREF,
ValType::Funcref => wasm_encoder::RefType::FUNCREF,
_ => panic!("Unexpected table type"),
RefType::Externref => wasm_encoder::RefType::EXTERNREF,
RefType::Funcref => wasm_encoder::RefType::FUNCREF,
},
table64: table.table64,
minimum: table.initial,
Expand Down
19 changes: 10 additions & 9 deletions src/module/tables.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Tables within a wasm module.

use std::convert::TryInto;

use crate::emit::{Emit, EmitContext};
use crate::map::IdHashSet;
use crate::parse::IndicesToIds;
use crate::tombstone_arena::{Id, Tombstone, TombstoneArena};
use crate::{Element, ImportId, Module, Result, ValType};
use crate::{Element, ImportId, Module, RefType, Result};
use anyhow::bail;

/// The id of a table.
Expand All @@ -21,7 +23,7 @@ pub struct Table {
/// The maximum size of this table
pub maximum: Option<u64>,
/// The type of the elements in this table
pub element_ty: ValType,
pub element_ty: RefType,
/// Whether or not this table is imported, and if so what imports it.
pub import: Option<ImportId>,
/// Active data segments that will be used to initialize this memory.
Expand Down Expand Up @@ -54,7 +56,7 @@ impl ModuleTables {
table64: bool,
initial: u64,
maximum: Option<u64>,
element_ty: ValType,
element_ty: RefType,
import: ImportId,
) -> TableId {
let id = self.arena.next_id();
Expand All @@ -77,7 +79,7 @@ impl ModuleTables {
table64: bool,
initial: u64,
maximum: Option<u64>,
element_ty: ValType,
element_ty: RefType,
) -> TableId {
let id = self.arena.next_id();
let id2 = self.arena.alloc(Table {
Expand Down Expand Up @@ -128,7 +130,7 @@ impl ModuleTables {
///
/// Returns an error if there are two function tables in this module
pub fn main_function_table(&self) -> Result<Option<TableId>> {
let mut tables = self.iter().filter(|t| t.element_ty == ValType::Funcref);
let mut tables = self.iter().filter(|t| t.element_ty == RefType::Funcref);
let id = match tables.next() {
Some(t) => t.id(),
None => return Ok(None),
Expand Down Expand Up @@ -159,7 +161,7 @@ impl Module {
t.ty.table64,
t.ty.initial,
t.ty.maximum,
ValType::parse(&wasmparser::ValType::Ref(t.ty.element_type))?,
t.ty.element_type.try_into()?,
);
ids.push_table(id);
}
Expand Down Expand Up @@ -187,9 +189,8 @@ impl Emit for ModuleTables {
minimum: table.initial,
maximum: table.maximum,
element_type: match table.element_ty {
ValType::Externref => wasm_encoder::RefType::EXTERNREF,
ValType::Funcref => wasm_encoder::RefType::FUNCREF,
_ => unreachable!(),
RefType::Externref => wasm_encoder::RefType::EXTERNREF,
RefType::Funcref => wasm_encoder::RefType::FUNCREF,
},
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/passes/used.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ir::*;
use crate::map::IdHashSet;
use crate::{ActiveDataLocation, Data, DataId, DataKind, Element, ExportItem, Function, InitExpr};
use crate::{ElementId, ElementItems, ElementKind, Module, Type, TypeId};
use crate::{ElementId, ElementItems, ElementKind, Module, RefType, Type, TypeId};
use crate::{FunctionId, FunctionKind, Global, GlobalId};
use crate::{GlobalKind, Memory, MemoryId, Table, TableId};

Expand Down Expand Up @@ -209,7 +209,7 @@ impl Used {
stack.push_func(*f);
});
}
if let ElementItems::Expressions(crate::ValType::Funcref, items) = &e.items {
if let ElementItems::Expressions(RefType::Funcref, items) = &e.items {
for item in items {
match item {
InitExpr::Global(g) => {
Expand Down
43 changes: 34 additions & 9 deletions src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::tombstone_arena::Tombstone;
use anyhow::bail;
use id_arena::Id;
use std::cmp::Ordering;
use std::convert::TryFrom;
use std::fmt;
use std::hash;

Expand Down Expand Up @@ -135,10 +136,32 @@ pub enum ValType {
F64,
/// 128-bit vector.
V128,
/// The `externref` opaque value type
Externref,
/// The `funcref` value type, representing a callable function
/// Reference.
Ref(RefType),
}

/// A reference type.
///
/// The "function references" and "gc" proposals will add more reference types.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[non_exhaustive]
pub enum RefType {
/// A nullable reference to an untyped function
Funcref,
/// A nullable reference to an extern object
Externref,
}

impl TryFrom<wasmparser::RefType> for RefType {
type Error = anyhow::Error;

fn try_from(ref_type: wasmparser::RefType) -> Result<RefType> {
match ref_type {
wasmparser::RefType::FUNCREF => Ok(RefType::Funcref),
wasmparser::RefType::EXTERNREF => Ok(RefType::Externref),
_ => bail!("unsupported ref type {:?}", ref_type),
}
}
}

impl ValType {
Expand All @@ -154,8 +177,10 @@ impl ValType {
ValType::F32 => wasm_encoder::ValType::F32,
ValType::F64 => wasm_encoder::ValType::F64,
ValType::V128 => wasm_encoder::ValType::V128,
ValType::Externref => wasm_encoder::ValType::Ref(wasm_encoder::RefType::EXTERNREF),
ValType::Funcref => wasm_encoder::ValType::Ref(wasm_encoder::RefType::FUNCREF),
ValType::Ref(ref_type) => match ref_type {
RefType::Externref => wasm_encoder::ValType::Ref(wasm_encoder::RefType::EXTERNREF),
RefType::Funcref => wasm_encoder::ValType::Ref(wasm_encoder::RefType::FUNCREF),
},
}
}

Expand All @@ -167,8 +192,8 @@ impl ValType {
wasmparser::ValType::F64 => Ok(ValType::F64),
wasmparser::ValType::V128 => Ok(ValType::V128),
wasmparser::ValType::Ref(ref_type) => match *ref_type {
wasmparser::RefType::EXTERNREF => Ok(ValType::Externref),
wasmparser::RefType::FUNCREF => Ok(ValType::Funcref),
wasmparser::RefType::EXTERNREF => Ok(ValType::Ref(RefType::Externref)),
wasmparser::RefType::FUNCREF => Ok(ValType::Ref(RefType::Funcref)),
_ => bail!("unsupported ref type {:?}", ref_type),
},
}
Expand All @@ -186,8 +211,8 @@ impl fmt::Display for ValType {
ValType::F32 => "f32",
ValType::F64 => "f64",
ValType::V128 => "v128",
ValType::Externref => "externref",
ValType::Funcref => "funcref",
ValType::Ref(RefType::Externref) => "externref",
ValType::Ref(RefType::Funcref) => "funcref",
}
)
}
Expand Down