diff --git a/crates/wasm-encoder/src/component/builder.rs b/crates/wasm-encoder/src/component/builder.rs index 8c78b40d43..379fbb54de 100644 --- a/crates/wasm-encoder/src/component/builder.rs +++ b/crates/wasm-encoder/src/component/builder.rs @@ -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) } diff --git a/crates/wasm-encoder/src/component/canonicals.rs b/crates/wasm-encoder/src/component/canonicals.rs index 04682c1ba6..73c97617af 100644 --- a/crates/wasm-encoder/src/component/canonicals.rs +++ b/crates/wasm-encoder/src/component/canonicals.rs @@ -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; diff --git a/crates/wasm-encoder/src/reencode/component.rs b/crates/wasm-encoder/src/reencode/component.rs index 52f6712cfe..70009a3c18 100644 --- a/crates/wasm-encoder/src/reencode/component.rs +++ b/crates/wasm-encoder/src/reencode/component.rs @@ -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); diff --git a/crates/wasmparser/src/readers/component/canonicals.rs b/crates/wasmparser/src/readers/component/canonicals.rs index d93f2f83d5..da22bb139c 100644 --- a/crates/wasmparser/src/readers/component/canonicals.rs +++ b/crates/wasmparser/src/readers/component/canonicals.rs @@ -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, }, @@ -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 { diff --git a/crates/wasmparser/src/validator.rs b/crates/wasmparser/src/validator.rs index 72eafb2380..8fbda6b8e6 100644 --- a/crates/wasmparser/src/validator.rs +++ b/crates/wasmparser/src/validator.rs @@ -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) diff --git a/crates/wasmparser/src/validator/component.rs b/crates/wasmparser/src/validator/component.rs index 3fc6748fa1..2952dfd94b 100644 --- a/crates/wasmparser/src/validator/component.rs +++ b/crates/wasmparser/src/validator/component.rs @@ -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, @@ -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"), diff --git a/crates/wasmprinter/src/component.rs b/crates/wasmprinter/src/component.rs index 0a4972bf85..ffde0b933d 100644 --- a/crates/wasmprinter/src/component.rs +++ b/crates/wasmprinter/src/component.rs @@ -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) })?; } diff --git a/crates/wast/src/component/binary.rs b/crates/wast/src/component/binary.rs index 0b9b4ef6f1..e788b1ae6a 100644 --- a/crates/wast/src/component/binary.rs +++ b/crates/wast/src/component/binary.rs @@ -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); diff --git a/crates/wast/src/component/expand.rs b/crates/wast/src/component/expand.rs index 8a45d35171..694f2c766d 100644 --- a/crates/wast/src/component/expand.rs +++ b/crates/wast/src/component/expand.rs @@ -268,7 +268,7 @@ impl<'a> Expander<'a> { | CanonicalFuncKind::ResourceNew(_) | CanonicalFuncKind::ResourceRep(_) | CanonicalFuncKind::ResourceDrop(_) - | CanonicalFuncKind::ThreadSpawn(_) + | CanonicalFuncKind::ThreadSpawnRef(_) | CanonicalFuncKind::ThreadSpawnIndirect(_) | CanonicalFuncKind::ThreadHwConcurrency(_) | CanonicalFuncKind::TaskBackpressure @@ -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, diff --git a/crates/wast/src/component/func.rs b/crates/wast/src/component/func.rs index 91ac9ab43b..c068161957 100644 --- a/crates/wast/src/component/func.rs +++ b/crates/wast/src/component/func.rs @@ -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, @@ -99,8 +99,8 @@ impl<'a> Parse<'a> for CoreFuncKind<'a> { Ok(CoreFuncKind::ResourceDrop(parser.parse()?)) } else if l.peek::()? { Ok(CoreFuncKind::ResourceRep(parser.parse()?)) - } else if l.peek::()? { - Ok(CoreFuncKind::ThreadSpawn(parser.parse()?)) + } else if l.peek::()? { + Ok(CoreFuncKind::ThreadSpawnRef(parser.parse()?)) } else if l.peek::()? { Ok(CoreFuncKind::ThreadSpawnIndirect(parser.parse()?)) } else if l.peek::()? { @@ -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), @@ -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 { - parser.parse::()?; + parser.parse::()?; Ok(Self { ty: parser.parse()?, diff --git a/crates/wast/src/component/resolve.rs b/crates/wast/src/component/resolve.rs index 6734bfd170..2ee984355d 100644 --- a/crates/wast/src/component/resolve.rs +++ b/crates/wast/src/component/resolve.rs @@ -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) => { @@ -970,7 +970,7 @@ impl<'a> ComponentState<'a> { | CanonicalFuncKind::ResourceNew(_) | CanonicalFuncKind::ResourceRep(_) | CanonicalFuncKind::ResourceDrop(_) - | CanonicalFuncKind::ThreadSpawn(_) + | CanonicalFuncKind::ThreadSpawnRef(_) | CanonicalFuncKind::ThreadSpawnIndirect(_) | CanonicalFuncKind::ThreadHwConcurrency(_) | CanonicalFuncKind::TaskBackpressure diff --git a/crates/wast/src/lib.rs b/crates/wast/src/lib.rs index b0485e698a..2d4aaba13f 100644 --- a/crates/wast/src/lib.rs +++ b/crates/wast/src/lib.rs @@ -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"); diff --git a/src/bin/wasm-tools/dump.rs b/src/bin/wasm-tools/dump.rs index 6e68aba306..eed13f82b3 100644 --- a/src/bin/wasm-tools/dump.rs +++ b/src/bin/wasm-tools/dump.rs @@ -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) diff --git a/tests/local/missing-features/component-model/shared-everything-threads-builtins.wast b/tests/local/missing-features/component-model/shared-everything-threads-builtins.wast index b24e038369..2f10ac1f76 100644 --- a/tests/local/missing-features/component-model/shared-everything-threads-builtins.wast +++ b/tests/local/missing-features/component-model/shared-everything-threads-builtins.wast @@ -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 diff --git a/tests/local/shared-everything-threads/builtins.wast b/tests/local/shared-everything-threads/builtins.wast index bb3522daaa..3cb9ff8e36 100644 --- a/tests/local/shared-everything-threads/builtins.wast +++ b/tests/local/shared-everything-threads/builtins.wast @@ -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)) @@ -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)) @@ -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)) )) @@ -40,7 +40,7 @@ (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" ) @@ -48,7 +48,7 @@ (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)" ) diff --git a/tests/snapshots/local/missing-features/component-model/shared-everything-threads-builtins.wast.json b/tests/snapshots/local/missing-features/component-model/shared-everything-threads-builtins.wast.json index a8a0b30fbf..1e27dab5d0 100644 --- a/tests/snapshots/local/missing-features/component-model/shared-everything-threads-builtins.wast.json +++ b/tests/snapshots/local/missing-features/component-model/shared-everything-threads-builtins.wast.json @@ -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", diff --git a/tests/snapshots/local/shared-everything-threads/builtins.wast/0.print b/tests/snapshots/local/shared-everything-threads/builtins.wast/0.print index 30f2c2e070..2321301bee 100644 --- a/tests/snapshots/local/shared-everything-threads/builtins.wast/0.print +++ b/tests/snapshots/local/shared-everything-threads/builtins.wast/0.print @@ -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)) diff --git a/tests/snapshots/local/shared-everything-threads/builtins.wast/1.print b/tests/snapshots/local/shared-everything-threads/builtins.wast/1.print index 6cbff4c6da..14cb2eb574 100644 --- a/tests/snapshots/local/shared-everything-threads/builtins.wast/1.print +++ b/tests/snapshots/local/shared-everything-threads/builtins.wast/1.print @@ -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)) @@ -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)) )