Skip to content

Commit b3666ed

Browse files
authored
Disallow stream<char> in component-model-async (#2437)
Accounts for WebAssembly/component-model#607
1 parent 2b446bd commit b3666ed

3 files changed

Lines changed: 54 additions & 4 deletions

File tree

crates/wasmparser/src/validator/component.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3965,10 +3965,25 @@ impl ComponentState {
39653965
"`stream` requires the component model async feature"
39663966
)
39673967
}
3968-
Ok(ComponentDefinedType::Stream(
3969-
ty.map(|ty| self.create_component_val_type(ty, offset))
3970-
.transpose()?,
3971-
))
3968+
let ty = ty
3969+
.map(|ty| self.create_component_val_type(ty, offset))
3970+
.transpose()?;
3971+
let prim = match ty {
3972+
Some(ComponentValType::Primitive(p)) => Some(p),
3973+
Some(ComponentValType::Type(id)) => match types[id] {
3974+
ComponentDefinedType::Primitive(p) => Some(p),
3975+
_ => None,
3976+
},
3977+
None => None,
3978+
};
3979+
if prim == Some(crate::PrimitiveValType::Char) {
3980+
bail!(
3981+
offset,
3982+
"`stream<char>` is not valid at this time, use `stream<u8>` \
3983+
with a defined by encoding instead for now"
3984+
)
3985+
}
3986+
Ok(ComponentDefinedType::Stream(ty))
39723987
}
39733988
}
39743989
}

tests/cli/component-model/async/streams.wast

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,17 @@
211211
)
212212
"type mismatch for export `stream.drop-writable` of module instantiation argument ``"
213213
)
214+
215+
;; stream<char> isn't valid yet
216+
(assert_invalid
217+
(component (type (stream char)))
218+
"`stream<char>` is not valid at this time, use `stream<u8>` with a defined by encoding instead for now"
219+
)
220+
(assert_invalid
221+
(component (type $t char) (type (stream $t)))
222+
"`stream<char>` is not valid at this time, use `stream<u8>` with a defined by encoding instead for now"
223+
)
224+
(assert_invalid
225+
(component (type (func (param "x" (stream char)))))
226+
"`stream<char>` is not valid at this time, use `stream<u8>` with a defined by encoding instead for now"
227+
)

tests/snapshots/cli/component-model/async/streams.wast.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@
111111
"filename": "streams.16.wasm",
112112
"module_type": "binary",
113113
"text": "type mismatch for export `stream.drop-writable` of module instantiation argument ``"
114+
},
115+
{
116+
"type": "assert_invalid",
117+
"line": 217,
118+
"filename": "streams.17.wasm",
119+
"module_type": "binary",
120+
"text": "`stream<char>` is not valid at this time, use `stream<u8>` with a defined by encoding instead for now"
121+
},
122+
{
123+
"type": "assert_invalid",
124+
"line": 221,
125+
"filename": "streams.18.wasm",
126+
"module_type": "binary",
127+
"text": "`stream<char>` is not valid at this time, use `stream<u8>` with a defined by encoding instead for now"
128+
},
129+
{
130+
"type": "assert_invalid",
131+
"line": 225,
132+
"filename": "streams.19.wasm",
133+
"module_type": "binary",
134+
"text": "`stream<char>` is not valid at this time, use `stream<u8>` with a defined by encoding instead for now"
114135
}
115136
]
116137
}

0 commit comments

Comments
 (0)