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

Merge with upstream #131

Merged
merged 9 commits into from
Aug 28, 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
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ jobs:
# skip testing crates that require wasmtime since wasmtime has a
# more aggressive msrv than wasm-tools
flags: --exclude fuzz-stats --exclude wit-component --exclude wasm-mutate-stats
# this is the rust nightly that oss-fuzz currently uses so we don't
# want this to break.
- os: ubuntu-latest
rust: nightly-2024-02-12
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -229,6 +233,8 @@ jobs:
- run: cargo check --no-default-features -p wasmparser --target x86_64-unknown-none --features validate,serde,no-hash-maps
- run: cargo check --no-default-features -p wasmparser --features std
- run: cargo check --no-default-features -p wasmparser --features validate
- run: cargo check --no-default-features -p wasmparser --features features
- run: cargo check --no-default-features -p wasmparser --features features,validate
- run: cargo check --no-default-features -p wasmparser --features no-hash-maps
- run: cargo check --no-default-features -p wasmparser --features serde
- run: cargo check --no-default-features -p wasmparser --features serde,no-hash-maps
Expand Down
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ wat = { workspace = true, features = ['dwarf'] }
termcolor = { workspace = true }

# Dependencies of `validate`
wasmparser = { workspace = true, optional = true, features = ['validate'] }
wasmparser = { workspace = true, optional = true }
rayon = { workspace = true, optional = true }
bitflags = { workspace = true, optional = true }

Expand Down Expand Up @@ -211,7 +211,15 @@ default = [
]

# Each subcommand is gated behind a feature and lists the dependencies it needs
validate = ['dep:wasmparser', 'rayon', 'dep:addr2line', 'dep:gimli', 'dep:bitflags']
validate = [
'dep:wasmparser',
'rayon',
'dep:addr2line',
'dep:gimli',
'dep:bitflags',
'wasmparser/validate',
'wasmparser/features',
]
print = []
parse = []
smith = ['wasm-smith', 'arbitrary', 'dep:serde', 'dep:serde_derive', 'dep:serde_json']
Expand Down
7 changes: 3 additions & 4 deletions crates/wasm-compose/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use wasmparser::{
ResourceId, SubtypeCx, Types, TypesRef,
},
Chunk, ComponentExternalKind, ComponentTypeRef, Encoding, Parser, Payload, ValidPayload,
Validator, WasmFeatures,
Validator,
};

pub(crate) fn type_desc(item: ComponentEntityType) -> &'static str {
Expand Down Expand Up @@ -98,8 +98,7 @@ impl<'a> Component<'a> {
fn parse(name: String, path: Option<PathBuf>, bytes: Cow<'a, [u8]>) -> Result<Self> {
let mut parser = Parser::new(0);
let mut parsers = Vec::new();
let mut validator =
Validator::new_with_features(WasmFeatures::default() | WasmFeatures::COMPONENT_MODEL);
let mut validator = Validator::new();
let mut imports = IndexMap::new();
let mut exports = IndexMap::new();

Expand Down Expand Up @@ -990,7 +989,7 @@ impl<'a> CompositionGraph<'a> {
let bytes = CompositionGraphEncoder::new(options, self).encode()?;

if options.validate {
Validator::new_with_features(WasmFeatures::default() | WasmFeatures::COMPONENT_MODEL)
Validator::new()
.validate_all(&bytes)
.context("failed to validate encoded graph bytes")?;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-encoder/src/core/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ impl CodeSection {
/// into a new code section encoder:
///
/// ```
/// # use wasmparser::{BinaryReader, WasmFeatures, CodeSectionReader};
/// # use wasmparser::{BinaryReader, CodeSectionReader};
/// // id, size, # entries, entry
/// let code_section = [10, 6, 1, 4, 0, 65, 0, 11];
///
/// // Parse the code section.
/// let reader = BinaryReader::new(&code_section, 0, WasmFeatures::all());
/// let reader = BinaryReader::new(&code_section, 0);
/// let reader = CodeSectionReader::new(reader).unwrap();
/// let body = reader.into_iter().next().unwrap().unwrap();
/// let body_range = body.range();
Expand Down
8 changes: 4 additions & 4 deletions crates/wasm-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ops::Range;
use wasm_encoder::{ComponentSection as _, ComponentSectionId, Encode, Section};
use wasmparser::{
BinaryReader, ComponentNameSectionReader, KnownCustom, NameSectionReader, Parser, Payload::*,
ProducersSectionReader, WasmFeatures,
ProducersSectionReader,
};

/// A representation of a WebAssembly producers section.
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Producers {
}
/// Read the producers section from a Wasm binary.
pub fn from_bytes(bytes: &[u8], offset: usize) -> Result<Self> {
let reader = BinaryReader::new(bytes, offset, WasmFeatures::all());
let reader = BinaryReader::new(bytes, offset);
let section = ProducersSectionReader::new(reader)?;
let mut fields = IndexMap::new();
for field in section.into_iter() {
Expand Down Expand Up @@ -604,7 +604,7 @@ impl<'a> ModuleNames<'a> {
/// Read a name section from a WebAssembly binary. Records the module name, and all other
/// contents of name section, for later serialization.
pub fn from_bytes(bytes: &'a [u8], offset: usize) -> Result<ModuleNames<'a>> {
let reader = BinaryReader::new(bytes, offset, WasmFeatures::all());
let reader = BinaryReader::new(bytes, offset);
let section = NameSectionReader::new(reader);
let mut s = Self::empty();
for name in section.into_iter() {
Expand Down Expand Up @@ -690,7 +690,7 @@ impl<'a> ComponentNames<'a> {
/// Read a component-name section from a WebAssembly binary. Records the component name, as
/// well as all other component name fields for later serialization.
pub fn from_bytes(bytes: &'a [u8], offset: usize) -> Result<ComponentNames<'a>> {
let reader = BinaryReader::new(bytes, offset, WasmFeatures::all());
let reader = BinaryReader::new(bytes, offset);
let section = ComponentNameSectionReader::new(reader);
let mut s = Self::empty();
for name in section.into_iter() {
Expand Down
6 changes: 3 additions & 3 deletions crates/wasm-mutate/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use std::collections::HashSet;
use std::ops::Range;
use wasm_encoder::{RawSection, SectionId};
use wasmparser::{BinaryReader, Chunk, Parser, Payload, WasmFeatures};
use wasmparser::{BinaryReader, Chunk, Parser, Payload};

/// Provides module information for future usage during mutation
/// an instance of ModuleInfo could be user to determine which mutation could be applied
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'a> ModuleInfo<'a> {
pub fn has_nonempty_code(&self) -> bool {
if let Some(section) = self.code {
let section_data = self.raw_sections[section].data;
let reader = BinaryReader::new(section_data, 0, WasmFeatures::all());
let reader = BinaryReader::new(section_data, 0);
wasmparser::CodeSectionReader::new(reader)
.map(|r| r.count() != 0)
.unwrap_or(false)
Expand Down Expand Up @@ -253,7 +253,7 @@ impl<'a> ModuleInfo<'a> {
}

pub fn get_binary_reader(&self, i: usize) -> wasmparser::BinaryReader<'a> {
BinaryReader::new(self.raw_sections[i].data, 0, WasmFeatures::all())
BinaryReader::new(self.raw_sections[i].data, 0)
}

pub fn has_exports(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-mutate/src/mutators/remove_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum RemoveSection {

fn is_empty_section(section: &wasm_encoder::RawSection) -> bool {
use wasmparser::*;
let reader = BinaryReader::new(section.data, 0, WasmFeatures::all());
let reader = BinaryReader::new(section.data, 0);
crate::module::match_section_id! {
match section.id;
Custom => Ok(section.data.is_empty()),
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-shrink/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ log = { workspace = true }
rand = { workspace = true }
clap = { workspace = true, optional = true }
wasm-mutate = { workspace = true }
wasmparser = { workspace = true, features = ['validate'] }
wasmparser = { workspace = true, features = ['validate', 'features'] }

[dev-dependencies]
env_logger = { workspace = true }
Expand Down
23 changes: 2 additions & 21 deletions crates/wasm-shrink/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
//!
//! See the [`WasmShrink`] type for details.

use std::collections::HashSet;

use anyhow::{Context, Result};
use rand::{rngs::SmallRng, Rng, SeedableRng};
use std::collections::HashSet;
use wasm_mutate::WasmMutate;
use wasmparser::WasmFeatures;

Expand Down Expand Up @@ -217,25 +216,7 @@ impl ShrinkRun {
}

fn validate_wasm(&self, wasm: &[u8]) -> Result<()> {
let mut validator = wasmparser::Validator::new_with_features(
WasmFeatures::REFERENCE_TYPES
| WasmFeatures::MULTI_VALUE
| WasmFeatures::BULK_MEMORY
| WasmFeatures::SIMD
| WasmFeatures::THREADS
| WasmFeatures::TAIL_CALL
| WasmFeatures::MULTI_MEMORY
| WasmFeatures::EXCEPTIONS
| WasmFeatures::MEMORY64
| WasmFeatures::RELAXED_SIMD
| WasmFeatures::EXTENDED_CONST
| WasmFeatures::MUTABLE_GLOBAL
| WasmFeatures::SATURATING_FLOAT_TO_INT
| WasmFeatures::SIGN_EXTENSION
| WasmFeatures::FLOATS
| WasmFeatures::MEMORY_CONTROL,
);

let mut validator = wasmparser::Validator::new_with_features(WasmFeatures::all());
validator.validate_all(wasm)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-smith/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ wat = { workspace = true, optional = true }
[dev-dependencies]
criterion = { workspace = true }
rand = { workspace = true }
wasmparser = { workspace = true, features = ["validate"] }
wasmparser = { workspace = true, features = ["validate", "features"] }
wasmprinter = { path = "../wasmprinter" }
wat = { path = "../wat" }

Expand Down
11 changes: 10 additions & 1 deletion crates/wasmparser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ name = "benchmark"
harness = false

[features]
default = ['std', 'validate', 'serde']
default = ['std', 'validate', 'serde', 'features']

# A feature which enables implementations of `std::error::Error` as appropriate
# along with other convenience APIs. This additionally uses the standard
Expand All @@ -56,6 +56,7 @@ std = ['indexmap/std']
# to properly initialize hashmap based data structures for resilience against
# malious actors that control their inputs.
no-hash-maps = []

# A feature that enables validating WebAssembly files. This is enabled by
# default but not required if you're only parsing a file, for example, as
# opposed to validating all of its contents.
Expand All @@ -69,3 +70,11 @@ validate = [
# Enable Serialize/Deserialize implementations for types in
# `wasmparser::collections`
serde = ['dep:serde', 'indexmap/serde', 'hashbrown/serde']

# A feature that enables the guts of the `WasmFeatures` type in this crate.
#
# This feature is enabled by default. When disabled this crate does not support
# runtime configuration of WebAssembly features. Instead the set of WebAssembly
# features/proposals support are fixed at compile time to `wasmparser`'s default
# set of supported features.
features = []
Loading