Skip to content

Commit

Permalink
fix test builds by pulling more changes from bytecodealliance#9582
Browse files Browse the repository at this point in the history
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Jan 22, 2025
1 parent 24a80c4 commit 0b43dd5
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 15 deletions.
6 changes: 4 additions & 2 deletions crates/fuzzing/src/generators/component_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ pub fn arbitrary_val(ty: &component::Type, input: &mut Unstructured) -> arbitrar
.collect::<arbitrary::Result<_>>()?,
),

// Resources aren't fuzzed at this time.
Type::Own(_) | Type::Borrow(_) => unreachable!(),
// Resources, futures, streams, and error contexts aren't fuzzed at this time.
Type::Own(_) | Type::Borrow(_) | Type::Future(_) | Type::Stream(_) | Type::ErrorContext => {
unreachable!()
}
})
}

Expand Down
11 changes: 10 additions & 1 deletion crates/wasmtime/src/runtime/component/matching.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::component::func::HostFunc;
use crate::component::linker::{Definition, Strings};
use crate::component::types::{FutureType, StreamType};
use crate::component::ResourceType;
use crate::prelude::*;
use crate::runtime::vm::component::ComponentInstance;
Expand All @@ -9,7 +10,7 @@ use alloc::sync::Arc;
use core::any::Any;
use wasmtime_environ::component::{
ComponentTypes, NameMap, ResourceIndex, TypeComponentInstance, TypeDef, TypeFuncIndex,
TypeModule, TypeResourceTableIndex,
TypeFutureTableIndex, TypeModule, TypeResourceTableIndex, TypeStreamTableIndex,
};
use wasmtime_environ::PrimaryMap;

Expand Down Expand Up @@ -199,6 +200,14 @@ impl<'a> InstanceType<'a> {
.copied()
.unwrap_or_else(|| ResourceType::uninstantiated(&self.types, index))
}

pub fn future_type(&self, index: TypeFutureTableIndex) -> FutureType {
FutureType::from(self.types[index].ty, self)
}

pub fn stream_type(&self, index: TypeStreamTableIndex) -> StreamType {
StreamType::from(self.types[index].ty, self)
}
}

/// Small helper method to downcast an `Arc` borrow into a borrow of a concrete
Expand Down
113 changes: 103 additions & 10 deletions crates/wasmtime/src/runtime/component/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use core::fmt;
use core::ops::Deref;
use wasmtime_environ::component::{
ComponentTypes, InterfaceType, ResourceIndex, TypeComponentIndex, TypeComponentInstanceIndex,
TypeDef, TypeEnumIndex, TypeFlagsIndex, TypeFuncIndex, TypeListIndex, TypeModuleIndex,
TypeOptionIndex, TypeRecordIndex, TypeResourceTableIndex, TypeResultIndex, TypeTupleIndex,
TypeVariantIndex,
TypeDef, TypeEnumIndex, TypeFlagsIndex, TypeFuncIndex, TypeFutureIndex, TypeFutureTableIndex,
TypeListIndex, TypeModuleIndex, TypeOptionIndex, TypeRecordIndex, TypeResourceTableIndex,
TypeResultIndex, TypeStreamIndex, TypeStreamTableIndex, TypeTupleIndex, TypeVariantIndex,
};
use wasmtime_environ::PrimaryMap;

Expand Down Expand Up @@ -145,9 +145,16 @@ impl TypeChecker<'_> {
(InterfaceType::String, _) => false,
(InterfaceType::Char, InterfaceType::Char) => true,
(InterfaceType::Char, _) => false,
(InterfaceType::Future(_), _)
| (InterfaceType::Stream(_), _)
| (InterfaceType::ErrorContext(_), _) => todo!(),
(InterfaceType::Future(t1), InterfaceType::Future(t2)) => {
self.future_table_types_equal(t1, t2)
}
(InterfaceType::Future(_), _) => false,
(InterfaceType::Stream(t1), InterfaceType::Stream(t2)) => {
self.stream_table_types_equal(t1, t2)
}
(InterfaceType::Stream(_), _) => false,
(InterfaceType::ErrorContext(_), InterfaceType::ErrorContext(_)) => true,
(InterfaceType::ErrorContext(_), _) => false,
}
}

Expand Down Expand Up @@ -247,6 +254,34 @@ impl TypeChecker<'_> {
let b = &self.b_types[f2];
a.names == b.names
}

fn future_table_types_equal(&self, t1: TypeFutureTableIndex, t2: TypeFutureTableIndex) -> bool {
self.futures_equal(self.a_types[t1].ty, self.b_types[t2].ty)
}

fn futures_equal(&self, t1: TypeFutureIndex, t2: TypeFutureIndex) -> bool {
let a = &self.a_types[t1];
let b = &self.b_types[t2];
match (a.payload, b.payload) {
(Some(t1), Some(t2)) => self.interface_types_equal(t1, t2),
(None, None) => true,
_ => false,
}
}

fn stream_table_types_equal(&self, t1: TypeStreamTableIndex, t2: TypeStreamTableIndex) -> bool {
self.streams_equal(self.a_types[t1].ty, self.b_types[t2].ty)
}

fn streams_equal(&self, t1: TypeStreamIndex, t2: TypeStreamIndex) -> bool {
let a = &self.a_types[t1];
let b = &self.b_types[t2];
match (a.payload, b.payload) {
(Some(t1), Some(t2)) => self.interface_types_equal(t1, t2),
(None, None) => true,
_ => false,
}
}
}

/// A `list` interface type
Expand Down Expand Up @@ -419,7 +454,7 @@ impl PartialEq for OptionType {

impl Eq for OptionType {}

/// An `expected` interface type
/// A `result` interface type
#[derive(Clone, Debug)]
pub struct ResultType(Handle<TypeResultIndex>);

Expand Down Expand Up @@ -479,6 +514,58 @@ impl PartialEq for Flags {

impl Eq for Flags {}

/// An `future` interface type
#[derive(Clone, Debug)]
pub struct FutureType(Handle<TypeFutureIndex>);

impl FutureType {
pub(crate) fn from(index: TypeFutureIndex, ty: &InstanceType<'_>) -> Self {
FutureType(Handle::new(index, ty))
}

/// Retrieve the type parameter for this `future`.
pub fn ty(&self) -> Option<Type> {
Some(Type::from(
self.0.types[self.0.index].payload.as_ref()?,
&self.0.instance(),
))
}
}

impl PartialEq for FutureType {
fn eq(&self, other: &Self) -> bool {
self.0.equivalent(&other.0, TypeChecker::futures_equal)
}
}

impl Eq for FutureType {}

/// An `stream` interface type
#[derive(Clone, Debug)]
pub struct StreamType(Handle<TypeStreamIndex>);

impl StreamType {
pub(crate) fn from(index: TypeStreamIndex, ty: &InstanceType<'_>) -> Self {
StreamType(Handle::new(index, ty))
}

/// Retrieve the type parameter for this `stream`.
pub fn ty(&self) -> Option<Type> {
Some(Type::from(
self.0.types[self.0.index].payload.as_ref()?,
&self.0.instance(),
))
}
}

impl PartialEq for StreamType {
fn eq(&self, other: &Self) -> bool {
self.0.equivalent(&other.0, TypeChecker::streams_equal)
}
}

impl Eq for StreamType {}

/// Represents a component model interface type
#[derive(Clone, PartialEq, Eq, Debug)]
#[allow(missing_docs)]
Expand Down Expand Up @@ -506,6 +593,9 @@ pub enum Type {
Flags(Flags),
Own(ResourceType),
Borrow(ResourceType),
Future(FutureType),
Stream(StreamType),
ErrorContext,
}

impl Type {
Expand Down Expand Up @@ -663,9 +753,9 @@ impl Type {
InterfaceType::Flags(index) => Type::Flags(Flags::from(*index, instance)),
InterfaceType::Own(index) => Type::Own(instance.resource_type(*index)),
InterfaceType::Borrow(index) => Type::Borrow(instance.resource_type(*index)),
InterfaceType::Future(_)
| InterfaceType::Stream(_)
| InterfaceType::ErrorContext(_) => todo!(),
InterfaceType::Future(index) => Type::Future(instance.future_type(*index)),
InterfaceType::Stream(index) => Type::Stream(instance.stream_type(*index)),
InterfaceType::ErrorContext(_) => Type::ErrorContext,
}
}

Expand Down Expand Up @@ -694,6 +784,9 @@ impl Type {
Type::Flags(_) => "flags",
Type::Own(_) => "own",
Type::Borrow(_) => "borrow",
Type::Future(_) => "future",
Type::Stream(_) => "stream",
Type::ErrorContext => "error-context",
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions crates/wasmtime/src/runtime/wave/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ impl WasmType for component::Type {
Self::Result(_) => WasmTypeKind::Result,
Self::Flags(_) => WasmTypeKind::Flags,

Self::Own(_) | Self::Borrow(_) => WasmTypeKind::Unsupported,
Self::Own(_)
| Self::Borrow(_)
| Self::Stream(_)
| Self::Future(_)
| Self::ErrorContext => WasmTypeKind::Unsupported,
}
}

Expand Down Expand Up @@ -134,7 +138,9 @@ impl WasmValue for component::Val {
Self::Option(_) => WasmTypeKind::Option,
Self::Result(_) => WasmTypeKind::Result,
Self::Flags(_) => WasmTypeKind::Flags,
Self::Resource(_) => WasmTypeKind::Unsupported,
Self::Resource(_) | Self::Stream(_) | Self::Future(_) | Self::ErrorContext(_) => {
WasmTypeKind::Unsupported
}
}
}

Expand Down

0 comments on commit 0b43dd5

Please sign in to comment.