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

threads: rename thread.hw_concurrency to thread.available_parallelism #2043

Merged
merged 1 commit into from
Feb 7, 2025
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: 3 additions & 3 deletions crates/wasm-encoder/src/component/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ impl ComponentBuilder {
inc(&mut self.core_funcs)
}

/// Declares a new `thread.hw_concurrency` intrinsic.
pub fn thread_hw_concurrency(&mut self) -> u32 {
self.canonical_functions().thread_hw_concurrency();
/// Declares a new `thread.available_parallelism` intrinsic.
pub fn thread_available_parallelism(&mut self) -> u32 {
self.canonical_functions().thread_available_parallelism();
inc(&mut self.core_funcs)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wasm-encoder/src/component/canonicals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl CanonicalFunctionSection {

/// Defines a function which will return the number of threads that can be
/// expected to execute concurrently.
pub fn thread_hw_concurrency(&mut self) -> &mut Self {
pub fn thread_available_parallelism(&mut self) -> &mut Self {
self.bytes.push(0x06);
self.num_added += 1;
self
Expand Down
4 changes: 2 additions & 2 deletions crates/wasm-encoder/src/reencode/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ pub mod component_utils {
let func_ty = reencoder.type_index(func_ty_index);
section.thread_spawn(func_ty);
}
wasmparser::CanonicalFunction::ThreadHwConcurrency => {
section.thread_hw_concurrency();
wasmparser::CanonicalFunction::ThreadAvailableParallelism => {
section.thread_available_parallelism();
}
wasmparser::CanonicalFunction::TaskBackpressure => {
section.task_backpressure();
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/readers/component/canonicals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum CanonicalFunction {
},
/// A function which returns the number of threads that can be expected to
/// execute concurrently
ThreadHwConcurrency,
ThreadAvailableParallelism,
/// A function which tells the host to enable or disable backpressure for
/// the caller's instance.
TaskBackpressure,
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<'a> FromReader<'a> for CanonicalFunction {
0x05 => CanonicalFunction::ThreadSpawn {
func_ty_index: reader.read()?,
},
0x06 => CanonicalFunction::ThreadHwConcurrency,
0x06 => CanonicalFunction::ThreadAvailableParallelism,
0x08 => CanonicalFunction::TaskBackpressure,
0x09 => CanonicalFunction::TaskReturn {
result: match reader.read_u8()? {
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,8 @@ impl Validator {
crate::CanonicalFunction::ThreadSpawn { func_ty_index } => {
current.thread_spawn(func_ty_index, types, offset, features)
}
crate::CanonicalFunction::ThreadHwConcurrency => {
current.thread_hw_concurrency(types, offset, features)
crate::CanonicalFunction::ThreadAvailableParallelism => {
current.thread_available_parallelism(types, offset, features)
}
crate::CanonicalFunction::TaskBackpressure => {
current.task_backpressure(types, offset, features)
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ impl ComponentState {
Ok(())
}

pub fn thread_hw_concurrency(
pub fn thread_available_parallelism(
&mut self,
types: &mut TypeAlloc,
offset: usize,
Expand All @@ -1742,7 +1742,7 @@ impl ComponentState {
if !features.shared_everything_threads() {
bail!(
offset,
"`thread.hw_concurrency` requires the shared-everything-threads proposal"
"`thread.available_parallelism` requires the shared-everything-threads proposal"
)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/wasmprinter/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,11 @@ impl Printer<'_, '_> {
self.end_group()?;
state.core.funcs += 1;
}
CanonicalFunction::ThreadHwConcurrency => {
CanonicalFunction::ThreadAvailableParallelism => {
self.start_group("core func ")?;
self.print_name(&state.core.func_names, state.core.funcs)?;
self.result.write_str(" ")?;
self.start_group("canon thread.hw_concurrency")?;
self.start_group("canon thread.available_parallelism")?;
self.end_group()?;
self.end_group()?;
state.core.funcs += 1;
Expand Down
4 changes: 2 additions & 2 deletions crates/wast/src/component/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ impl<'a> Encoder<'a> {
self.core_func_names.push(name);
self.funcs.thread_spawn(info.ty.into());
}
CanonicalFuncKind::ThreadHwConcurrency(_info) => {
CanonicalFuncKind::ThreadAvailableParallelism(_info) => {
self.core_func_names.push(name);
self.funcs.thread_hw_concurrency();
self.funcs.thread_available_parallelism();
}
CanonicalFuncKind::TaskBackpressure => {
self.core_func_names.push(name);
Expand Down
6 changes: 3 additions & 3 deletions crates/wast/src/component/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<'a> Expander<'a> {
| CanonicalFuncKind::ResourceRep(_)
| CanonicalFuncKind::ResourceDrop(_)
| CanonicalFuncKind::ThreadSpawn(_)
| CanonicalFuncKind::ThreadHwConcurrency(_)
| CanonicalFuncKind::ThreadAvailableParallelism(_)
| CanonicalFuncKind::TaskBackpressure
| CanonicalFuncKind::TaskReturn(_)
| CanonicalFuncKind::TaskWait(_)
Expand Down Expand Up @@ -338,12 +338,12 @@ impl<'a> Expander<'a> {
name: func.name,
kind: CanonicalFuncKind::ThreadSpawn(info),
}),
CoreFuncKind::ThreadHwConcurrency(info) => {
CoreFuncKind::ThreadAvailableParallelism(info) => {
ComponentField::CanonicalFunc(CanonicalFunc {
span: func.span,
id: func.id,
name: func.name,
kind: CanonicalFuncKind::ThreadHwConcurrency(info),
kind: CanonicalFuncKind::ThreadAvailableParallelism(info),
})
}
CoreFuncKind::TaskBackpressure => ComponentField::CanonicalFunc(CanonicalFunc {
Expand Down
14 changes: 7 additions & 7 deletions crates/wast/src/component/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum CoreFuncKind<'a> {
ResourceDrop(CanonResourceDrop<'a>),
ResourceRep(CanonResourceRep<'a>),
ThreadSpawn(CanonThreadSpawn<'a>),
ThreadHwConcurrency(CanonThreadHwConcurrency),
ThreadAvailableParallelism(CanonThreadAvailableParallelism),
TaskBackpressure,
TaskReturn(CanonTaskReturn<'a>),
TaskWait(CanonTaskWait<'a>),
Expand Down Expand Up @@ -100,8 +100,8 @@ impl<'a> Parse<'a> for CoreFuncKind<'a> {
Ok(CoreFuncKind::ResourceRep(parser.parse()?))
} else if l.peek::<kw::thread_spawn>()? {
Ok(CoreFuncKind::ThreadSpawn(parser.parse()?))
} else if l.peek::<kw::thread_hw_concurrency>()? {
Ok(CoreFuncKind::ThreadHwConcurrency(parser.parse()?))
} else if l.peek::<kw::thread_available_parallelism>()? {
Ok(CoreFuncKind::ThreadAvailableParallelism(parser.parse()?))
} else if l.peek::<kw::task_backpressure>()? {
parser.parse::<kw::task_backpressure>()?;
Ok(CoreFuncKind::TaskBackpressure)
Expand Down Expand Up @@ -341,7 +341,7 @@ pub enum CanonicalFuncKind<'a> {
ResourceRep(CanonResourceRep<'a>),

ThreadSpawn(CanonThreadSpawn<'a>),
ThreadHwConcurrency(CanonThreadHwConcurrency),
ThreadAvailableParallelism(CanonThreadAvailableParallelism),

TaskBackpressure,
TaskReturn(CanonTaskReturn<'a>),
Expand Down Expand Up @@ -509,11 +509,11 @@ impl<'a> Parse<'a> for CanonThreadSpawn<'a> {

/// Information relating to the `thread.spawn` intrinsic.
#[derive(Debug)]
pub struct CanonThreadHwConcurrency;
pub struct CanonThreadAvailableParallelism;

impl<'a> Parse<'a> for CanonThreadHwConcurrency {
impl<'a> Parse<'a> for CanonThreadAvailableParallelism {
fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_hw_concurrency>()?;
parser.parse::<kw::thread_available_parallelism>()?;
Ok(Self)
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/wast/src/component/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<'a> Resolver<'a> {
CanonicalFuncKind::ThreadSpawn(info) => {
self.resolve_ns(&mut info.ty, Ns::CoreType)?;
}
CanonicalFuncKind::ThreadHwConcurrency(_)
CanonicalFuncKind::ThreadAvailableParallelism(_)
| CanonicalFuncKind::TaskBackpressure
| CanonicalFuncKind::TaskYield(_)
| CanonicalFuncKind::SubtaskDrop
Expand Down Expand Up @@ -964,7 +964,7 @@ impl<'a> ComponentState<'a> {
| CanonicalFuncKind::ResourceRep(_)
| CanonicalFuncKind::ResourceDrop(_)
| CanonicalFuncKind::ThreadSpawn(_)
| CanonicalFuncKind::ThreadHwConcurrency(_)
| CanonicalFuncKind::ThreadAvailableParallelism(_)
| CanonicalFuncKind::TaskBackpressure
| CanonicalFuncKind::TaskReturn(_)
| CanonicalFuncKind::TaskWait(_)
Expand Down
2 changes: 1 addition & 1 deletion crates/wast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ pub mod kw {
custom_keyword!(import_info = "import-info");
custom_keyword!(thread);
custom_keyword!(thread_spawn = "thread.spawn");
custom_keyword!(thread_hw_concurrency = "thread.hw_concurrency");
custom_keyword!(thread_available_parallelism = "thread.available_parallelism");
custom_keyword!(task_backpressure = "task.backpressure");
custom_keyword!(task_return = "task.return");
custom_keyword!(task_wait = "task.wait");
Expand Down
2 changes: 1 addition & 1 deletion src/bin/wasm-tools/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl<'a> Dump<'a> {
| CanonicalFunction::ResourceDrop { .. }
| CanonicalFunction::ResourceRep { .. }
| CanonicalFunction::ThreadSpawn { .. }
| CanonicalFunction::ThreadHwConcurrency => {
| CanonicalFunction::ThreadAvailableParallelism => {
("core func", &mut i.core_funcs)
}
CanonicalFunction::TaskBackpressure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

(assert_invalid
(component
(core func $concurrency (canon thread.hw_concurrency))
(core func $parallelism (canon thread.available_parallelism))
)
"`thread.hw_concurrency` requires the shared-everything-threads proposal")
"`thread.available_parallelism` requires the shared-everything-threads proposal")
8 changes: 4 additions & 4 deletions tests/local/shared-everything-threads/builtins.wast
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
(component
(core type $start (shared (func (param $context i32))))
(core func $spawn (canon thread.spawn $start))
(core func $concurrency (canon thread.hw_concurrency))
(core func $parallelism (canon thread.available_parallelism))
)

(component
(core type $start (shared (func (param $context i32))))
(core func $spawn (canon thread.spawn $start))
(core func $concurrency (canon thread.hw_concurrency))
(core func $parallelism (canon thread.available_parallelism))

(core module $m
(type $st (shared (func (param $context i32))))
(import "" "spawn" (func (param (ref null $st)) (param i32) (result i32)))
(import "" "concurrency" (func (result i32)))
(import "" "parallelism" (func (result i32)))
)

(core instance (instantiate $m
(with "" (instance
(export "spawn" (func $spawn))
(export "concurrency" (func $concurrency))
(export "parallelism" (func $parallelism))
))
))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"line": 10,
"filename": "shared-everything-threads-builtins.1.wasm",
"module_type": "binary",
"text": "`thread.hw_concurrency` requires the shared-everything-threads proposal"
"text": "`thread.available_parallelism` requires the shared-everything-threads proposal"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(component
(core type $start (;0;) (shared (func (param i32))))
(core func $spawn (;0;) (canon thread.spawn $start))
(core func $concurrency (;1;) (canon thread.hw_concurrency))
(core func $parallelism (;1;) (canon thread.available_parallelism))
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(component
(core type $start (;0;) (shared (func (param i32))))
(core func $spawn (;0;) (canon thread.spawn $start))
(core func $concurrency (;1;) (canon thread.hw_concurrency))
(core func $parallelism (;1;) (canon thread.available_parallelism))
(core module $m (;0;)
(type $st (;0;) (shared (func (param i32))))
(type (;1;) (func (param (ref null $st) i32) (result i32)))
(type (;2;) (func (result i32)))
(import "" "spawn" (func (;0;) (type 1)))
(import "" "concurrency" (func (;1;) (type 2)))
(import "" "parallelism" (func (;1;) (type 2)))
)
(core instance (;0;)
(export "spawn" (func $spawn))
(export "concurrency" (func $concurrency))
(export "parallelism" (func $parallelism))
)
(core instance (;1;) (instantiate $m
(with "" (instance 0))
Expand Down