components: Fix support for 0-sized flags (#4560)

This commit goes through and updates support in the various argument
passing routines to support 0-sized flags. A bit of a degenerate case
but clarified in WebAssembly/component-model#76 as intentional.
This commit is contained in:
Alex Crichton
2022-08-01 11:05:09 -05:00
committed by GitHub
parent 05e6abf2f6
commit 893fadb485
9 changed files with 59 additions and 9 deletions

View File

@@ -48,6 +48,8 @@ impl From<DiscriminantSize> for usize {
/// Represents the number of bytes required to store a flags value in the component model
pub enum FlagsSize {
/// There are no flags
Size0,
/// Flags can fit in a u8
Size1,
/// Flags can fit in a u16
@@ -59,7 +61,9 @@ pub enum FlagsSize {
impl FlagsSize {
/// Calculate the size needed to represent a value with the specified number of flags.
pub fn from_count(count: usize) -> FlagsSize {
if count <= 8 {
if count == 0 {
FlagsSize::Size0
} else if count <= 8 {
FlagsSize::Size1
} else if count <= 16 {
FlagsSize::Size2