Skip to content

Commit f15cf87

Browse files
committed
fix test builds by pulling more changes from bytecodealliance#9582
Signed-off-by: Joel Dice <[email protected]>
1 parent 24a80c4 commit f15cf87

File tree

3 files changed

+121
-13
lines changed

3 files changed

+121
-13
lines changed

crates/wasmtime/src/runtime/component/matching.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::component::func::HostFunc;
22
use crate::component::linker::{Definition, Strings};
3+
use crate::component::types::{FutureType, StreamType};
34
use crate::component::ResourceType;
45
use crate::prelude::*;
56
use crate::runtime::vm::component::ComponentInstance;
@@ -9,7 +10,7 @@ use alloc::sync::Arc;
910
use core::any::Any;
1011
use wasmtime_environ::component::{
1112
ComponentTypes, NameMap, ResourceIndex, TypeComponentInstance, TypeDef, TypeFuncIndex,
12-
TypeModule, TypeResourceTableIndex,
13+
TypeFutureTableIndex, TypeModule, TypeResourceTableIndex, TypeStreamTableIndex,
1314
};
1415
use wasmtime_environ::PrimaryMap;
1516

@@ -199,6 +200,14 @@ impl<'a> InstanceType<'a> {
199200
.copied()
200201
.unwrap_or_else(|| ResourceType::uninstantiated(&self.types, index))
201202
}
203+
204+
pub fn future_type(&self, index: TypeFutureTableIndex) -> FutureType {
205+
FutureType::from(self.types[index].ty, self)
206+
}
207+
208+
pub fn stream_type(&self, index: TypeStreamTableIndex) -> StreamType {
209+
StreamType::from(self.types[index].ty, self)
210+
}
202211
}
203212

204213
/// Small helper method to downcast an `Arc` borrow into a borrow of a concrete

crates/wasmtime/src/runtime/component/types.rs

+103-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use core::fmt;
77
use core::ops::Deref;
88
use wasmtime_environ::component::{
99
ComponentTypes, InterfaceType, ResourceIndex, TypeComponentIndex, TypeComponentInstanceIndex,
10-
TypeDef, TypeEnumIndex, TypeFlagsIndex, TypeFuncIndex, TypeListIndex, TypeModuleIndex,
11-
TypeOptionIndex, TypeRecordIndex, TypeResourceTableIndex, TypeResultIndex, TypeTupleIndex,
12-
TypeVariantIndex,
10+
TypeDef, TypeEnumIndex, TypeFlagsIndex, TypeFuncIndex, TypeFutureIndex, TypeFutureTableIndex,
11+
TypeListIndex, TypeModuleIndex, TypeOptionIndex, TypeRecordIndex, TypeResourceTableIndex,
12+
TypeResultIndex, TypeStreamIndex, TypeStreamTableIndex, TypeTupleIndex, TypeVariantIndex,
1313
};
1414
use wasmtime_environ::PrimaryMap;
1515

@@ -145,9 +145,16 @@ impl TypeChecker<'_> {
145145
(InterfaceType::String, _) => false,
146146
(InterfaceType::Char, InterfaceType::Char) => true,
147147
(InterfaceType::Char, _) => false,
148-
(InterfaceType::Future(_), _)
149-
| (InterfaceType::Stream(_), _)
150-
| (InterfaceType::ErrorContext(_), _) => todo!(),
148+
(InterfaceType::Future(t1), InterfaceType::Future(t2)) => {
149+
self.future_table_types_equal(t1, t2)
150+
}
151+
(InterfaceType::Future(_), _) => false,
152+
(InterfaceType::Stream(t1), InterfaceType::Stream(t2)) => {
153+
self.stream_table_types_equal(t1, t2)
154+
}
155+
(InterfaceType::Stream(_), _) => false,
156+
(InterfaceType::ErrorContext(_), InterfaceType::ErrorContext(_)) => true,
157+
(InterfaceType::ErrorContext(_), _) => false,
151158
}
152159
}
153160

@@ -247,6 +254,34 @@ impl TypeChecker<'_> {
247254
let b = &self.b_types[f2];
248255
a.names == b.names
249256
}
257+
258+
fn future_table_types_equal(&self, t1: TypeFutureTableIndex, t2: TypeFutureTableIndex) -> bool {
259+
self.futures_equal(self.a_types[t1].ty, self.b_types[t2].ty)
260+
}
261+
262+
fn futures_equal(&self, t1: TypeFutureIndex, t2: TypeFutureIndex) -> bool {
263+
let a = &self.a_types[t1];
264+
let b = &self.b_types[t2];
265+
match (a.payload, b.payload) {
266+
(Some(t1), Some(t2)) => self.interface_types_equal(t1, t2),
267+
(None, None) => true,
268+
_ => false,
269+
}
270+
}
271+
272+
fn stream_table_types_equal(&self, t1: TypeStreamTableIndex, t2: TypeStreamTableIndex) -> bool {
273+
self.streams_equal(self.a_types[t1].ty, self.b_types[t2].ty)
274+
}
275+
276+
fn streams_equal(&self, t1: TypeStreamIndex, t2: TypeStreamIndex) -> bool {
277+
let a = &self.a_types[t1];
278+
let b = &self.b_types[t2];
279+
match (a.payload, b.payload) {
280+
(Some(t1), Some(t2)) => self.interface_types_equal(t1, t2),
281+
(None, None) => true,
282+
_ => false,
283+
}
284+
}
250285
}
251286

252287
/// A `list` interface type
@@ -419,7 +454,7 @@ impl PartialEq for OptionType {
419454

420455
impl Eq for OptionType {}
421456

422-
/// An `expected` interface type
457+
/// A `result` interface type
423458
#[derive(Clone, Debug)]
424459
pub struct ResultType(Handle<TypeResultIndex>);
425460

@@ -479,6 +514,58 @@ impl PartialEq for Flags {
479514

480515
impl Eq for Flags {}
481516

517+
/// An `future` interface type
518+
#[derive(Clone, Debug)]
519+
pub struct FutureType(Handle<TypeFutureIndex>);
520+
521+
impl FutureType {
522+
pub(crate) fn from(index: TypeFutureIndex, ty: &InstanceType<'_>) -> Self {
523+
FutureType(Handle::new(index, ty))
524+
}
525+
526+
/// Retrieve the type parameter for this `future`.
527+
pub fn ty(&self) -> Option<Type> {
528+
Some(Type::from(
529+
self.0.types[self.0.index].payload.as_ref()?,
530+
&self.0.instance(),
531+
))
532+
}
533+
}
534+
535+
impl PartialEq for FutureType {
536+
fn eq(&self, other: &Self) -> bool {
537+
self.0.equivalent(&other.0, TypeChecker::futures_equal)
538+
}
539+
}
540+
541+
impl Eq for FutureType {}
542+
543+
/// An `stream` interface type
544+
#[derive(Clone, Debug)]
545+
pub struct StreamType(Handle<TypeStreamIndex>);
546+
547+
impl StreamType {
548+
pub(crate) fn from(index: TypeStreamIndex, ty: &InstanceType<'_>) -> Self {
549+
StreamType(Handle::new(index, ty))
550+
}
551+
552+
/// Retrieve the type parameter for this `stream`.
553+
pub fn ty(&self) -> Option<Type> {
554+
Some(Type::from(
555+
self.0.types[self.0.index].payload.as_ref()?,
556+
&self.0.instance(),
557+
))
558+
}
559+
}
560+
561+
impl PartialEq for StreamType {
562+
fn eq(&self, other: &Self) -> bool {
563+
self.0.equivalent(&other.0, TypeChecker::streams_equal)
564+
}
565+
}
566+
567+
impl Eq for StreamType {}
568+
482569
/// Represents a component model interface type
483570
#[derive(Clone, PartialEq, Eq, Debug)]
484571
#[allow(missing_docs)]
@@ -506,6 +593,9 @@ pub enum Type {
506593
Flags(Flags),
507594
Own(ResourceType),
508595
Borrow(ResourceType),
596+
Future(FutureType),
597+
Stream(StreamType),
598+
ErrorContext,
509599
}
510600

511601
impl Type {
@@ -663,9 +753,9 @@ impl Type {
663753
InterfaceType::Flags(index) => Type::Flags(Flags::from(*index, instance)),
664754
InterfaceType::Own(index) => Type::Own(instance.resource_type(*index)),
665755
InterfaceType::Borrow(index) => Type::Borrow(instance.resource_type(*index)),
666-
InterfaceType::Future(_)
667-
| InterfaceType::Stream(_)
668-
| InterfaceType::ErrorContext(_) => todo!(),
756+
InterfaceType::Future(index) => Type::Future(instance.future_type(*index)),
757+
InterfaceType::Stream(index) => Type::Stream(instance.stream_type(*index)),
758+
InterfaceType::ErrorContext(_) => Type::ErrorContext,
669759
}
670760
}
671761

@@ -694,6 +784,9 @@ impl Type {
694784
Type::Flags(_) => "flags",
695785
Type::Own(_) => "own",
696786
Type::Borrow(_) => "borrow",
787+
Type::Future(_) => "future",
788+
Type::Stream(_) => "stream",
789+
Type::ErrorContext => "error-context",
697790
}
698791
}
699792
}

crates/wasmtime/src/runtime/wave/component.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ impl WasmType for component::Type {
4141
Self::Result(_) => WasmTypeKind::Result,
4242
Self::Flags(_) => WasmTypeKind::Flags,
4343

44-
Self::Own(_) | Self::Borrow(_) => WasmTypeKind::Unsupported,
44+
Self::Own(_)
45+
| Self::Borrow(_)
46+
| Self::Stream(_)
47+
| Self::Future(_)
48+
| Self::ErrorContext => WasmTypeKind::Unsupported,
4549
}
4650
}
4751

@@ -134,7 +138,9 @@ impl WasmValue for component::Val {
134138
Self::Option(_) => WasmTypeKind::Option,
135139
Self::Result(_) => WasmTypeKind::Result,
136140
Self::Flags(_) => WasmTypeKind::Flags,
137-
Self::Resource(_) => WasmTypeKind::Unsupported,
141+
Self::Resource(_) | Self::Stream(_) | Self::Future(_) | Self::ErrorContext(_) => {
142+
WasmTypeKind::Unsupported
143+
}
138144
}
139145
}
140146

0 commit comments

Comments
 (0)