Skip to content

Commit 879e841

Browse files
committed
Updates for wasmparser apis
This was a bit more involved due to a big change in the way function return types are handled. The orginal change was done in WebAssembly/component-model#368 and put initially put behind a feature flag in bytecodealliance/wasm-tools#1670. In 0.226.0 version of wasmparser this feature flag was removed simplify the return results. This in turn simplifies the handling of the results here as well. Signed-off-by: James Sturtevant <[email protected]>
1 parent 98e31f2 commit 879e841

File tree

7 files changed

+32
-46
lines changed

7 files changed

+32
-46
lines changed

src/hyperlight_component_util/src/elaborate.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ limitations under the License.
2424
//! substitute.rs for more details of the approach here).
2525
2626
use wasmparser::{
27-
ComponentAlias, ComponentDefinedType, ComponentFuncResult, ComponentFuncType,
28-
ComponentOuterAliasKind, ComponentType, ComponentTypeDeclaration, ComponentTypeRef,
29-
ComponentValType, CompositeInnerType, CoreType, InstanceTypeDeclaration, ModuleTypeDeclaration,
30-
OuterAliasKind, PrimitiveValType, TypeBounds, TypeRef,
27+
ComponentAlias, ComponentDefinedType, ComponentFuncType, ComponentOuterAliasKind,
28+
ComponentType, ComponentTypeDeclaration, ComponentTypeRef, ComponentValType,
29+
CompositeInnerType, CoreType, InstanceTypeDeclaration, ModuleTypeDeclaration, OuterAliasKind,
30+
PrimitiveValType, TypeBounds, TypeRef,
3131
};
3232

3333
use crate::etypes::{
34-
self, BoundedTyvar, Component, CoreDefined, CoreExportDecl, CoreExternDesc, CoreModule,
34+
BoundedTyvar, Component, CoreDefined, CoreExportDecl, CoreExternDesc, CoreModule,
3535
CoreOrComponentExternDesc, Ctx, Defined, ExternDecl, ExternDesc, FloatWidth, Func, Handleable,
3636
Instance, IntWidth, Name, Param, QualifiedInstance, RecordField, Resource, ResourceId,
3737
TypeBound, Tyvar, Value, VariantCase,
@@ -366,6 +366,7 @@ impl<'p, 'a> Ctx<'p, 'a> {
366366
PrimitiveValType::F64 => Value::F(FloatWidth::F64),
367367
PrimitiveValType::Char => Value::Char,
368368
PrimitiveValType::String => Value::String,
369+
PrimitiveValType::ErrorContext => panic!("async not yet supported"),
369370
}),
370371
}
371372
}
@@ -428,9 +429,12 @@ impl<'p, 'a> Ctx<'p, 'a> {
428429
Defined::Handleable(h) => Ok(Value::Borrow(h.clone())),
429430
_ => Err(Error::HandleToNonResource),
430431
},
431-
ComponentDefinedType::Future(_)
432-
| ComponentDefinedType::Stream(_)
433-
| ComponentDefinedType::ErrorContext => panic!("async not yet supported"),
432+
ComponentDefinedType::Future(_) | ComponentDefinedType::Stream(_) => {
433+
panic!("async not yet supported")
434+
}
435+
ComponentDefinedType::FixedSizeList(vt, _) => {
436+
Ok(Value::List(Box::new(self.elab_value(vt)?)))
437+
}
434438
}
435439
}
436440

@@ -446,18 +450,9 @@ impl<'p, 'a> Ctx<'p, 'a> {
446450
})
447451
})
448452
.collect::<Result<Vec<_>, Error<'a>>>()?,
449-
result: match &ft.results {
450-
ComponentFuncResult::Unnamed(vt) => etypes::Result::Unnamed(self.elab_value(vt)?),
451-
ComponentFuncResult::Named(rs) => etypes::Result::Named(
452-
rs.iter()
453-
.map(|(n, vt)| {
454-
Ok(Param {
455-
name: Name { name: n },
456-
ty: self.elab_value(vt)?,
457-
})
458-
})
459-
.collect::<Result<Vec<_>, Error<'a>>>()?,
460-
),
453+
result: match &ft.result {
454+
Some(vt) => Some(self.elab_value(vt)?),
455+
None => None,
461456
},
462457
})
463458
}

src/hyperlight_component_util/src/etypes.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,7 @@ pub struct Param<'a> {
136136
pub ty: Value<'a>,
137137
}
138138

139-
#[derive(Debug, Clone)]
140-
pub enum Result<'a> {
141-
Unnamed(Value<'a>),
142-
Named(Vec<Param<'a>>),
143-
}
139+
pub type Result<'a> = Option<Value<'a>>;
144140

145141
/// functype_e in the specification
146142
#[derive(Debug, Clone)]

src/hyperlight_component_util/src/hl.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,13 @@ pub fn emit_hl_unmarshal_param(s: &mut State, id: Ident, pt: &Value) -> TokenStr
653653
///
654654
/// Precondition: the result type must only be a named result if there
655655
/// are no names in it (i.e. a unit type)
656-
pub fn emit_hl_unmarshal_result(s: &mut State, id: Ident, rt: &etypes::Result) -> TokenStream {
656+
pub fn emit_hl_unmarshal_result(s: &mut State, id: Ident, rt: &etypes::Result<'_>) -> TokenStream {
657657
match rt {
658-
etypes::Result::Named(rs) if rs.is_empty() => quote! { () },
659-
etypes::Result::Unnamed(vt) => {
658+
Some(vt) => {
660659
let toks = emit_hl_unmarshal_value(s, id, vt);
661660
quote! { { #toks }.0 }
662661
}
663-
_ => panic!("named results not supported"),
662+
None => quote! { () },
664663
}
665664
}
666665

@@ -680,11 +679,10 @@ pub fn emit_hl_marshal_param(s: &mut State, id: Ident, pt: &Value) -> TokenStrea
680679
/// are no names in it (a unit type)
681680
pub fn emit_hl_marshal_result(s: &mut State, id: Ident, rt: &etypes::Result) -> TokenStream {
682681
match rt {
683-
etypes::Result::Named(rs) if rs.is_empty() => quote! { ::alloc::vec::Vec::new() },
684-
etypes::Result::Unnamed(vt) => {
682+
None => quote! { ::alloc::vec::Vec::new() },
683+
Some(vt) => {
685684
let toks = emit_hl_marshal_value(s, id, vt);
686685
quote! { { #toks } }
687686
}
688-
_ => panic!("named results not supported"),
689687
}
690688
}

src/hyperlight_component_util/src/rtypes.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use crate::emit::{
2929
split_wit_name,
3030
};
3131
use crate::etypes::{
32-
Component, Defined, ExternDecl, ExternDesc, Func, Handleable, ImportExport, Instance, Param,
33-
Result, TypeBound, Tyvar, Value,
32+
self, Component, Defined, ExternDecl, ExternDesc, Func, Handleable, ImportExport, Instance,
33+
Param, TypeBound, Tyvar, Value,
3434
};
3535

3636
/// When referring to an instance or resource trait, emit a token
@@ -521,11 +521,10 @@ pub fn emit_func_param(s: &mut State, p: &Param) -> TokenStream {
521521
///
522522
/// Precondition: the result type must only be a named result if there
523523
/// are no names in it (i.e. a unit type)
524-
pub fn emit_func_result(s: &mut State, r: &Result) -> TokenStream {
524+
pub fn emit_func_result(s: &mut State, r: &etypes::Result<'_>) -> TokenStream {
525525
match r {
526-
Result::Unnamed(vt) => emit_value(s, vt),
527-
Result::Named(rs) if rs.is_empty() => quote! { () },
528-
_ => panic!("multiple named function results are not currently supported"),
526+
Some(vt) => emit_value(s, vt),
527+
None => quote! { () },
529528
}
530529
}
531530

src/hyperlight_component_util/src/substitute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ where
139139
rt: &crate::etypes::Result<'a>,
140140
) -> Result<crate::etypes::Result<'a>, Self::Error> {
141141
Ok(match rt {
142-
crate::etypes::Result::Unnamed(vt) => crate::etypes::Result::Unnamed(self.value(vt)?),
143-
crate::etypes::Result::Named(pts) => crate::etypes::Result::Named(self.params(pts)?),
142+
Some(vt) => Some(self.value(vt)?),
143+
None => None,
144144
})
145145
}
146146

src/hyperlight_component_util/src/wf.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,8 @@ impl<'p, 'a> Ctx<'p, 'a> {
268268
.iter()
269269
.try_for_each(|fp: &'r Param<'a>| self.wf_value(param_pos, &fp.ty))?;
270270
match &ft.result {
271-
crate::etypes::Result::Unnamed(vt) => self.wf_value(result_pos, vt),
272-
crate::etypes::Result::Named(ps) => ps
273-
.iter()
274-
.try_for_each(|fp: &'r Param<'a>| self.wf_value(result_pos, &fp.ty)),
271+
Some(vt) => self.wf_value(result_pos, vt),
272+
None => Ok(()),
275273
}
276274
}
277275
fn wf_type_bound<'r>(

src/tests/rust_guests/witguest/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)