Skip to content

Commit bf1ed5d

Browse files
authored
threads: no shared function expansion (#1745)
If I understand `wast`'s `Expander` correctly (which I may not!), there is no need for it to know how to create type definitions for shared functions because there is no way to write WAT that would mark a function shared in an inline way. Since the only way to create a shared function is with an explicit type ID (e.g., `(func (type $ft))`), we can set `shared = false` when a `TypeDef` must be created.
1 parent 60bf141 commit bf1ed5d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

crates/wast/src/component/expand.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a> Expander<'a> {
455455
) {
456456
match &mut item.kind {
457457
core::ItemKind::Func(t) | core::ItemKind::Tag(core::TagType::Exception(t)) => {
458-
// If the index is already filled in then this is skipped
458+
// If the index is already filled in then this is skipped.
459459
if t.index.is_some() {
460460
return;
461461
}
@@ -476,7 +476,11 @@ impl<'a> Expander<'a> {
476476
span: item.span,
477477
id: Some(id),
478478
name: None,
479-
def: key.to_def(item.span),
479+
// Currently, there is no way in the WebAssembly text
480+
// format to mark a function `shared` inline; a
481+
// `shared` function must use an explicit type index,
482+
// e.g., `(func (type $ft))`.
483+
def: key.to_def(item.span, /* shared = */ false),
480484
parent: None,
481485
final_type: None,
482486
}));

crates/wast/src/core/resolve/types.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ impl<'a> Expander<'a> {
213213
span,
214214
id: Some(id),
215215
name: None,
216-
def: key.to_def(span),
216+
// Currently, there is no way in the WebAssembly text format to mark
217+
// a function `shared` inline; a `shared` function must use an
218+
// explicit type index, e.g., `(func (type $ft))`.
219+
def: key.to_def(span, /* shared = */ false),
217220
parent: None,
218221
final_type: None,
219222
}));
@@ -231,7 +234,7 @@ pub(crate) trait TypeReference<'a>: Default {
231234

232235
pub(crate) trait TypeKey<'a> {
233236
fn lookup(&self, cx: &Expander<'a>) -> Option<Index<'a>>;
234-
fn to_def(&self, span: Span) -> TypeDef<'a>;
237+
fn to_def(&self, span: Span, shared: bool) -> TypeDef<'a>;
235238
fn insert(&self, cx: &mut Expander<'a>, id: Index<'a>);
236239
}
237240

@@ -254,13 +257,13 @@ impl<'a> TypeKey<'a> for FuncKey<'a> {
254257
cx.func_type_to_idx.get(self).cloned()
255258
}
256259

257-
fn to_def(&self, _span: Span) -> TypeDef<'a> {
260+
fn to_def(&self, _span: Span, shared: bool) -> TypeDef<'a> {
258261
TypeDef {
259262
kind: InnerTypeKind::Func(FunctionType {
260263
params: self.0.iter().map(|t| (None, None, *t)).collect(),
261264
results: self.1.clone(),
262265
}),
263-
shared: false, // TODO: handle shared
266+
shared,
264267
}
265268
}
266269

0 commit comments

Comments
 (0)