Skip to content

Commit

Permalink
threads: rename thread.spawn to thread.spawn_ref
Browse files Browse the repository at this point in the history
[#447] tries to make the built-in naming a bit more consistent; this
change propagates that here.

[#447]: WebAssembly/component-model#447
  • Loading branch information
abrown committed Feb 7, 2025
1 parent abaec1e commit cfc0969
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 46 deletions.
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 @@ -373,9 +373,9 @@ impl ComponentBuilder {
inc(&mut self.core_funcs)
}

/// Declares a new `thread.spawn` intrinsic.
pub fn thread_spawn(&mut self, ty: u32) -> u32 {
self.canonical_functions().thread_spawn(ty);
/// Declares a new `thread.spawn_ref` intrinsic.
pub fn thread_spawn_ref(&mut self, ty: u32) -> u32 {
self.canonical_functions().thread_spawn_ref(ty);
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 @@ -160,7 +160,7 @@ impl CanonicalFunctionSection {

/// Defines a function which will spawn a new thread by invoking a shared
/// function of type `ty_index`.
pub fn thread_spawn(&mut self, ty_index: u32) -> &mut Self {
pub fn thread_spawn_ref(&mut self, ty_index: u32) -> &mut Self {
self.bytes.push(0x05);
ty_index.encode(&mut self.bytes);
self.num_added += 1;
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 @@ -960,9 +960,9 @@ pub mod component_utils {
let resource = reencoder.component_type_index(resource);
section.resource_rep(resource);
}
wasmparser::CanonicalFunction::ThreadSpawn { func_ty_index } => {
wasmparser::CanonicalFunction::ThreadSpawnRef { func_ty_index } => {
let func_ty = reencoder.type_index(func_ty_index);
section.thread_spawn(func_ty);
section.thread_spawn_ref(func_ty);
}
wasmparser::CanonicalFunction::ThreadSpawnIndirect { table_index } => {
let table_index = reencoder.table_index(table_index);
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 @@ -68,7 +68,7 @@ pub enum CanonicalFunction {
resource: u32,
},
/// A function which spawns a new thread by invoking the shared function.
ThreadSpawn {
ThreadSpawnRef {
/// The index of the function to spawn.
func_ty_index: u32,
},
Expand Down Expand Up @@ -282,7 +282,7 @@ impl<'a> FromReader<'a> for CanonicalFunction {
0x04 => CanonicalFunction::ResourceRep {
resource: reader.read()?,
},
0x05 => CanonicalFunction::ThreadSpawn {
0x05 => CanonicalFunction::ThreadSpawnRef {
func_ty_index: reader.read()?,
},
0x24 => CanonicalFunction::ThreadSpawnIndirect {
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 @@ -1304,8 +1304,8 @@ impl Validator {
crate::CanonicalFunction::ResourceRep { resource } => {
current.resource_rep(resource, types, offset)
}
crate::CanonicalFunction::ThreadSpawn { func_ty_index } => {
current.thread_spawn(func_ty_index, types, offset, features)
crate::CanonicalFunction::ThreadSpawnRef { func_ty_index } => {
current.thread_spawn_ref(func_ty_index, types, offset, features)
}
crate::CanonicalFunction::ThreadSpawnIndirect { table_index } => {
current.thread_spawn_indirect(table_index, types, offset, features)
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmparser/src/validator/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,7 @@ impl ComponentState {
bail!(offset, "type index {} is not a resource type", idx)
}

pub fn thread_spawn(
pub fn thread_spawn_ref(
&mut self,
func_ty_index: u32,
types: &mut TypeAlloc,
Expand All @@ -1692,11 +1692,11 @@ impl ComponentState {
if !features.shared_everything_threads() {
bail!(
offset,
"`thread.spawn` requires the shared-everything-threads proposal"
"`thread.spawn_ref` requires the shared-everything-threads proposal"
)
}

// Validate the type accepted by `thread.spawn`.
// Validate the type accepted by `thread.spawn_ref`.
let core_type_id = match self.core_type_at(func_ty_index, offset)? {
ComponentCoreTypeId::Sub(c) => c,
ComponentCoreTypeId::Module(_) => bail!(offset, "expected a core function type"),
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 @@ -890,10 +890,10 @@ impl Printer<'_, '_> {
me.print_idx(&state.component.type_names, resource)
})?;
}
CanonicalFunction::ThreadSpawn {
CanonicalFunction::ThreadSpawnRef {
func_ty_index: func_index,
} => {
self.print_intrinsic(state, "canon thread.spawn ", &|me, state| {
self.print_intrinsic(state, "canon thread.spawn_ref ", &|me, state| {
me.print_idx(&state.core.type_names, func_index)
})?;
}
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 @@ -349,9 +349,9 @@ impl<'a> Encoder<'a> {
self.core_func_names.push(name);
self.funcs.resource_rep(info.ty.into());
}
CanonicalFuncKind::ThreadSpawn(info) => {
CanonicalFuncKind::ThreadSpawnRef(info) => {
self.core_func_names.push(name);
self.funcs.thread_spawn(info.ty.into());
self.funcs.thread_spawn_ref(info.ty.into());
}
CanonicalFuncKind::ThreadSpawnIndirect(info) => {
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 @@ -268,7 +268,7 @@ impl<'a> Expander<'a> {
| CanonicalFuncKind::ResourceNew(_)
| CanonicalFuncKind::ResourceRep(_)
| CanonicalFuncKind::ResourceDrop(_)
| CanonicalFuncKind::ThreadSpawn(_)
| CanonicalFuncKind::ThreadSpawnRef(_)
| CanonicalFuncKind::ThreadSpawnIndirect(_)
| CanonicalFuncKind::ThreadHwConcurrency(_)
| CanonicalFuncKind::TaskBackpressure
Expand Down Expand Up @@ -333,11 +333,11 @@ impl<'a> Expander<'a> {
name: func.name,
kind: CanonicalFuncKind::ResourceRep(info),
}),
CoreFuncKind::ThreadSpawn(info) => ComponentField::CanonicalFunc(CanonicalFunc {
CoreFuncKind::ThreadSpawnRef(info) => ComponentField::CanonicalFunc(CanonicalFunc {
span: func.span,
id: func.id,
name: func.name,
kind: CanonicalFuncKind::ThreadSpawn(info),
kind: CanonicalFuncKind::ThreadSpawnRef(info),
}),
CoreFuncKind::ThreadSpawnIndirect(info) => ComponentField::CanonicalFunc(CanonicalFunc {
span: func.span,
Expand Down
16 changes: 8 additions & 8 deletions crates/wast/src/component/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum CoreFuncKind<'a> {
ResourceNew(CanonResourceNew<'a>),
ResourceDrop(CanonResourceDrop<'a>),
ResourceRep(CanonResourceRep<'a>),
ThreadSpawn(CanonThreadSpawn<'a>),
ThreadSpawnRef(CanonThreadSpawnRef<'a>),
ThreadSpawnIndirect(CanonThreadSpawnIndirect<'a>),
ThreadHwConcurrency(CanonThreadHwConcurrency),
TaskBackpressure,
Expand Down Expand Up @@ -99,8 +99,8 @@ impl<'a> Parse<'a> for CoreFuncKind<'a> {
Ok(CoreFuncKind::ResourceDrop(parser.parse()?))
} else if l.peek::<kw::resource_rep>()? {
Ok(CoreFuncKind::ResourceRep(parser.parse()?))
} else if l.peek::<kw::thread_spawn>()? {
Ok(CoreFuncKind::ThreadSpawn(parser.parse()?))
} else if l.peek::<kw::thread_spawn_ref>()? {
Ok(CoreFuncKind::ThreadSpawnRef(parser.parse()?))
} else if l.peek::<kw::thread_spawn_indirect>()? {
Ok(CoreFuncKind::ThreadSpawnIndirect(parser.parse()?))
} else if l.peek::<kw::thread_hw_concurrency>()? {
Expand Down Expand Up @@ -343,7 +343,7 @@ pub enum CanonicalFuncKind<'a> {
ResourceDrop(CanonResourceDrop<'a>),
ResourceRep(CanonResourceRep<'a>),

ThreadSpawn(CanonThreadSpawn<'a>),
ThreadSpawnRef(CanonThreadSpawnRef<'a>),
ThreadSpawnIndirect(CanonThreadSpawnIndirect<'a>),
ThreadHwConcurrency(CanonThreadHwConcurrency),

Expand Down Expand Up @@ -494,16 +494,16 @@ impl<'a> Parse<'a> for CanonResourceRep<'a> {
}
}

/// Information relating to the `thread.spawn` intrinsic.
/// Information relating to the `thread.spawn_ref` intrinsic.
#[derive(Debug)]
pub struct CanonThreadSpawn<'a> {
pub struct CanonThreadSpawnRef<'a> {
/// The function type that is being spawned.
pub ty: Index<'a>,
}

impl<'a> Parse<'a> for CanonThreadSpawn<'a> {
impl<'a> Parse<'a> for CanonThreadSpawnRef<'a> {
fn parse(parser: Parser<'a>) -> Result<Self> {
parser.parse::<kw::thread_spawn>()?;
parser.parse::<kw::thread_spawn_ref>()?;

Ok(Self {
ty: parser.parse()?,
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 @@ -383,7 +383,7 @@ impl<'a> Resolver<'a> {
CanonicalFuncKind::ResourceDrop(info) => {
self.resolve_ns(&mut info.ty, Ns::Type)?;
}
CanonicalFuncKind::ThreadSpawn(info) => {
CanonicalFuncKind::ThreadSpawnRef(info) => {
self.resolve_ns(&mut info.ty, Ns::CoreType)?;
}
CanonicalFuncKind::ThreadSpawnIndirect(info) => {
Expand Down Expand Up @@ -970,7 +970,7 @@ impl<'a> ComponentState<'a> {
| CanonicalFuncKind::ResourceNew(_)
| CanonicalFuncKind::ResourceRep(_)
| CanonicalFuncKind::ResourceDrop(_)
| CanonicalFuncKind::ThreadSpawn(_)
| CanonicalFuncKind::ThreadSpawnRef(_)
| CanonicalFuncKind::ThreadSpawnIndirect(_)
| CanonicalFuncKind::ThreadHwConcurrency(_)
| CanonicalFuncKind::TaskBackpressure
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 @@ -554,7 +554,7 @@ pub mod kw {
custom_keyword!(export_info = "export-info");
custom_keyword!(import_info = "import-info");
custom_keyword!(thread);
custom_keyword!(thread_spawn = "thread.spawn");
custom_keyword!(thread_spawn_ref = "thread.spawn_ref");
custom_keyword!(thread_spawn_indirect = "thread.spawn_indirect");
custom_keyword!(thread_hw_concurrency = "thread.hw_concurrency");
custom_keyword!(task_backpressure = "task.backpressure");
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 @@ -418,7 +418,7 @@ impl<'a> Dump<'a> {
| CanonicalFunction::ResourceNew { .. }
| CanonicalFunction::ResourceDrop { .. }
| CanonicalFunction::ResourceRep { .. }
| CanonicalFunction::ThreadSpawn { .. }
| CanonicalFunction::ThreadSpawnRef { .. }
| CanonicalFunction::ThreadSpawnIndirect { .. }
| CanonicalFunction::ThreadHwConcurrency => {
("core func", &mut i.core_funcs)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(assert_invalid
(component
;; Refer to a non-existent function type (i.e., 0); validation for
;; `thread.spawn` happens first.
(core func $spawn (canon thread.spawn 0))
;; `thread.spawn_ref` happens first.
(core func $spawn (canon thread.spawn_ref 0))
)
"`thread.spawn` requires the shared-everything-threads proposal")
"`thread.spawn_ref` requires the shared-everything-threads proposal")

(assert_invalid
(component
Expand Down
12 changes: 6 additions & 6 deletions tests/local/shared-everything-threads/builtins.wast
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(component
(core type $start (shared (func (param $context i32))))
(core func $spawn (canon thread.spawn $start))
(core func $spawn_ref (canon thread.spawn_ref $start))

(core module $libc (table (export "start-table") 1 (ref null (shared func))))
(core instance $libc (instantiate $libc))
Expand All @@ -13,7 +13,7 @@

(component
(core type $start (shared (func (param $context i32))))
(core func $spawn (canon thread.spawn $start))
(core func $spawn_ref (canon thread.spawn_ref $start))

(core module $libc (table (export "start-table") 1 (ref null (shared func))))
(core instance $libc (instantiate $libc))
Expand All @@ -23,14 +23,14 @@

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

(core instance (instantiate $m
(with "" (instance
(export "spawn" (func $spawn))
(export "spawn_ref" (func $spawn_ref))
(export "spawn_indirect" (func $spawn_indirect))
(export "concurrency" (func $concurrency))
))
Expand All @@ -40,15 +40,15 @@
(assert_invalid
(component
(core type $start (func))
(core func $spawn (canon thread.spawn $start))
(core func $spawn (canon thread.spawn_ref $start))
)
"spawn type must be shared"
)

(assert_invalid
(component
(core type $start (shared (func)))
(core func $spawn (canon thread.spawn $start))
(core func $spawn_ref (canon thread.spawn_ref $start))
)
"spawn function must take a single `i32` argument (currently)"
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"line": 2,
"filename": "shared-everything-threads-builtins.0.wasm",
"module_type": "binary",
"text": "`thread.spawn` requires the shared-everything-threads proposal"
"text": "`thread.spawn_ref` requires the shared-everything-threads proposal"
},
{
"type": "assert_invalid",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(component
(core type $start (;0;) (shared (func (param i32))))
(core func $spawn (;0;) (canon thread.spawn $start))
(core func $spawn_ref (;0;) (canon thread.spawn_ref $start))
(core module $libc (;0;)
(table (;0;) 1 (ref null (shared func)))
(export "start-table" (table 0))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(component
(core type $start (;0;) (shared (func (param i32))))
(core func $spawn (;0;) (canon thread.spawn $start))
(core func $spawn_ref (;0;) (canon thread.spawn_ref $start))
(core module $libc (;0;)
(table (;0;) 1 (ref null (shared func)))
(export "start-table" (table 0))
Expand All @@ -14,12 +14,12 @@
(type (;1;) (func (param (ref null $st) i32) (result i32)))
(type (;2;) (func (param i32 i32) (result i32)))
(type (;3;) (func (result i32)))
(import "" "spawn" (func (;0;) (type 1)))
(import "" "spawn_ref" (func (;0;) (type 1)))
(import "" "spawn_indirect" (func (;1;) (type 2)))
(import "" "concurrency" (func (;2;) (type 3)))
)
(core instance (;1;)
(export "spawn" (func $spawn))
(export "spawn_ref" (func $spawn_ref))
(export "spawn_indirect" (func $spawn_indirect))
(export "concurrency" (func $concurrency))
)
Expand Down

0 comments on commit cfc0969

Please sign in to comment.