Skip to content

Commit 1f19d96

Browse files
authored
threads: rename thread.hw_concurrency to thread.available_parallelism (#2043)
This propagates @sunfishcode's renaming of the built-in upstream (see [#419]) to these crates. [#419]: WebAssembly/component-model#419
1 parent 59b0020 commit 1f19d96

File tree

18 files changed

+41
-41
lines changed

18 files changed

+41
-41
lines changed

crates/wasm-encoder/src/component/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ impl ComponentBuilder {
379379
inc(&mut self.core_funcs)
380380
}
381381

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

crates/wasm-encoder/src/component/canonicals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl CanonicalFunctionSection {
169169

170170
/// Defines a function which will return the number of threads that can be
171171
/// expected to execute concurrently.
172-
pub fn thread_hw_concurrency(&mut self) -> &mut Self {
172+
pub fn thread_available_parallelism(&mut self) -> &mut Self {
173173
self.bytes.push(0x06);
174174
self.num_added += 1;
175175
self

crates/wasm-encoder/src/reencode/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,8 @@ pub mod component_utils {
964964
let func_ty = reencoder.type_index(func_ty_index);
965965
section.thread_spawn(func_ty);
966966
}
967-
wasmparser::CanonicalFunction::ThreadHwConcurrency => {
968-
section.thread_hw_concurrency();
967+
wasmparser::CanonicalFunction::ThreadAvailableParallelism => {
968+
section.thread_available_parallelism();
969969
}
970970
wasmparser::CanonicalFunction::TaskBackpressure => {
971971
section.task_backpressure();

crates/wasmparser/src/readers/component/canonicals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub enum CanonicalFunction {
7474
},
7575
/// A function which returns the number of threads that can be expected to
7676
/// execute concurrently
77-
ThreadHwConcurrency,
77+
ThreadAvailableParallelism,
7878
/// A function which tells the host to enable or disable backpressure for
7979
/// the caller's instance.
8080
TaskBackpressure,
@@ -272,7 +272,7 @@ impl<'a> FromReader<'a> for CanonicalFunction {
272272
0x05 => CanonicalFunction::ThreadSpawn {
273273
func_ty_index: reader.read()?,
274274
},
275-
0x06 => CanonicalFunction::ThreadHwConcurrency,
275+
0x06 => CanonicalFunction::ThreadAvailableParallelism,
276276
0x08 => CanonicalFunction::TaskBackpressure,
277277
0x09 => CanonicalFunction::TaskReturn {
278278
result: match reader.read_u8()? {

crates/wasmparser/src/validator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,8 +1307,8 @@ impl Validator {
13071307
crate::CanonicalFunction::ThreadSpawn { func_ty_index } => {
13081308
current.thread_spawn(func_ty_index, types, offset, features)
13091309
}
1310-
crate::CanonicalFunction::ThreadHwConcurrency => {
1311-
current.thread_hw_concurrency(types, offset, features)
1310+
crate::CanonicalFunction::ThreadAvailableParallelism => {
1311+
current.thread_available_parallelism(types, offset, features)
13121312
}
13131313
crate::CanonicalFunction::TaskBackpressure => {
13141314
current.task_backpressure(types, offset, features)

crates/wasmparser/src/validator/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ impl ComponentState {
17331733
Ok(())
17341734
}
17351735

1736-
pub fn thread_hw_concurrency(
1736+
pub fn thread_available_parallelism(
17371737
&mut self,
17381738
types: &mut TypeAlloc,
17391739
offset: usize,
@@ -1742,7 +1742,7 @@ impl ComponentState {
17421742
if !features.shared_everything_threads() {
17431743
bail!(
17441744
offset,
1745-
"`thread.hw_concurrency` requires the shared-everything-threads proposal"
1745+
"`thread.available_parallelism` requires the shared-everything-threads proposal"
17461746
)
17471747
}
17481748

crates/wasmprinter/src/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,11 +902,11 @@ impl Printer<'_, '_> {
902902
self.end_group()?;
903903
state.core.funcs += 1;
904904
}
905-
CanonicalFunction::ThreadHwConcurrency => {
905+
CanonicalFunction::ThreadAvailableParallelism => {
906906
self.start_group("core func ")?;
907907
self.print_name(&state.core.func_names, state.core.funcs)?;
908908
self.result.write_str(" ")?;
909-
self.start_group("canon thread.hw_concurrency")?;
909+
self.start_group("canon thread.available_parallelism")?;
910910
self.end_group()?;
911911
self.end_group()?;
912912
state.core.funcs += 1;

crates/wast/src/component/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ impl<'a> Encoder<'a> {
353353
self.core_func_names.push(name);
354354
self.funcs.thread_spawn(info.ty.into());
355355
}
356-
CanonicalFuncKind::ThreadHwConcurrency(_info) => {
356+
CanonicalFuncKind::ThreadAvailableParallelism(_info) => {
357357
self.core_func_names.push(name);
358-
self.funcs.thread_hw_concurrency();
358+
self.funcs.thread_available_parallelism();
359359
}
360360
CanonicalFuncKind::TaskBackpressure => {
361361
self.core_func_names.push(name);

crates/wast/src/component/expand.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl<'a> Expander<'a> {
269269
| CanonicalFuncKind::ResourceRep(_)
270270
| CanonicalFuncKind::ResourceDrop(_)
271271
| CanonicalFuncKind::ThreadSpawn(_)
272-
| CanonicalFuncKind::ThreadHwConcurrency(_)
272+
| CanonicalFuncKind::ThreadAvailableParallelism(_)
273273
| CanonicalFuncKind::TaskBackpressure
274274
| CanonicalFuncKind::TaskReturn(_)
275275
| CanonicalFuncKind::TaskWait(_)
@@ -338,12 +338,12 @@ impl<'a> Expander<'a> {
338338
name: func.name,
339339
kind: CanonicalFuncKind::ThreadSpawn(info),
340340
}),
341-
CoreFuncKind::ThreadHwConcurrency(info) => {
341+
CoreFuncKind::ThreadAvailableParallelism(info) => {
342342
ComponentField::CanonicalFunc(CanonicalFunc {
343343
span: func.span,
344344
id: func.id,
345345
name: func.name,
346-
kind: CanonicalFuncKind::ThreadHwConcurrency(info),
346+
kind: CanonicalFuncKind::ThreadAvailableParallelism(info),
347347
})
348348
}
349349
CoreFuncKind::TaskBackpressure => ComponentField::CanonicalFunc(CanonicalFunc {

crates/wast/src/component/func.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub enum CoreFuncKind<'a> {
5252
ResourceDrop(CanonResourceDrop<'a>),
5353
ResourceRep(CanonResourceRep<'a>),
5454
ThreadSpawn(CanonThreadSpawn<'a>),
55-
ThreadHwConcurrency(CanonThreadHwConcurrency),
55+
ThreadAvailableParallelism(CanonThreadAvailableParallelism),
5656
TaskBackpressure,
5757
TaskReturn(CanonTaskReturn<'a>),
5858
TaskWait(CanonTaskWait<'a>),
@@ -100,8 +100,8 @@ impl<'a> Parse<'a> for CoreFuncKind<'a> {
100100
Ok(CoreFuncKind::ResourceRep(parser.parse()?))
101101
} else if l.peek::<kw::thread_spawn>()? {
102102
Ok(CoreFuncKind::ThreadSpawn(parser.parse()?))
103-
} else if l.peek::<kw::thread_hw_concurrency>()? {
104-
Ok(CoreFuncKind::ThreadHwConcurrency(parser.parse()?))
103+
} else if l.peek::<kw::thread_available_parallelism>()? {
104+
Ok(CoreFuncKind::ThreadAvailableParallelism(parser.parse()?))
105105
} else if l.peek::<kw::task_backpressure>()? {
106106
parser.parse::<kw::task_backpressure>()?;
107107
Ok(CoreFuncKind::TaskBackpressure)
@@ -341,7 +341,7 @@ pub enum CanonicalFuncKind<'a> {
341341
ResourceRep(CanonResourceRep<'a>),
342342

343343
ThreadSpawn(CanonThreadSpawn<'a>),
344-
ThreadHwConcurrency(CanonThreadHwConcurrency),
344+
ThreadAvailableParallelism(CanonThreadAvailableParallelism),
345345

346346
TaskBackpressure,
347347
TaskReturn(CanonTaskReturn<'a>),
@@ -509,11 +509,11 @@ impl<'a> Parse<'a> for CanonThreadSpawn<'a> {
509509

510510
/// Information relating to the `thread.spawn` intrinsic.
511511
#[derive(Debug)]
512-
pub struct CanonThreadHwConcurrency;
512+
pub struct CanonThreadAvailableParallelism;
513513

514-
impl<'a> Parse<'a> for CanonThreadHwConcurrency {
514+
impl<'a> Parse<'a> for CanonThreadAvailableParallelism {
515515
fn parse(parser: Parser<'a>) -> Result<Self> {
516-
parser.parse::<kw::thread_hw_concurrency>()?;
516+
parser.parse::<kw::thread_available_parallelism>()?;
517517
Ok(Self)
518518
}
519519
}

0 commit comments

Comments
 (0)