@@ -621,18 +621,36 @@ impl Wasmtime {
621
621
let body = mem:: take ( & mut generator. src ) . into ( ) ;
622
622
load = generator. extract_typed_function ( func) . 1 ;
623
623
assert ! ( generator. src. is_empty( ) ) ;
624
- self . exports . funcs . push ( body) ;
624
+ generator . generator . exports . funcs . push ( body) ;
625
625
ty_index = format ! ( "{wt}::component::ComponentExportIndex" ) ;
626
626
field = func_field_name ( resolve, func) ;
627
627
ty = format ! ( "{wt}::component::Func" ) ;
628
+ let sig = generator. typedfunc_sig ( func, TypeMode :: AllBorrowed ( "'_" ) ) ;
629
+ let typecheck = format ! (
630
+ "match item {{
631
+ {wt}::component::types::ComponentItem::ComponentFunc(func) => {{
632
+ anyhow::Context::context(
633
+ func.typecheck::<{sig}>(&_instance_type),
634
+ \" type-checking export func `{0}`\"
635
+ )?;
636
+ index
637
+ }}
638
+ _ => Err(anyhow::anyhow!(\" export `{0}` is not a function\" ))?,
639
+ }}" ,
640
+ func. name
641
+ ) ;
628
642
get_index_from_component = format ! (
629
- "_component.get_export_index(None, \" {}\" )
630
- .ok_or_else(|| anyhow::anyhow!(\" no function export `{0}` found\" ))?" ,
643
+ "{{ let (item, index) = _component.get_export(None, \" {}\" )
644
+ .ok_or_else(|| anyhow::anyhow!(\" no export `{0}` found\" ))?;
645
+ {typecheck}
646
+ }}" ,
631
647
func. name
632
648
) ;
633
649
get_index_from_instance = format ! (
634
- "_instance.get_export_index(&mut store, None, \" {}\" )
635
- .ok_or_else(|| anyhow::anyhow!(\" no function export `{0}` found\" ))?" ,
650
+ "{{ let (item, index) = _instance.get_export(&mut store, None, \" {}\" )
651
+ .ok_or_else(|| anyhow::anyhow!(\" no function export `{0}` found\" ))?;
652
+ {typecheck}
653
+ }}" ,
636
654
func. name
637
655
) ;
638
656
}
@@ -685,10 +703,11 @@ impl Wasmtime {
685
703
/// within a component.
686
704
pub fn new(
687
705
component: &{wt}::component::Component,
706
+ instance_type: &{wt}::component::__internal::InstanceType,
688
707
) -> {wt}::Result<{struct_name}Indices> {{
689
708
let instance = component.get_export_index(None, \" {instance_name}\" )
690
709
.ok_or_else(|| anyhow::anyhow!(\" no exported instance named `{instance_name}`\" ))?;
691
- Self::_new(|name| component.get_export_index(Some(&instance), name))
710
+ Self::_new(instance_type, |name| component.get_export_index(Some(&instance), name))
692
711
}}
693
712
694
713
/// This constructor is similar to [`{struct_name}Indices::new`] except that it
@@ -699,10 +718,12 @@ pub fn new_instance(
699
718
) -> {wt}::Result<{struct_name}Indices> {{
700
719
let instance_export = instance.get_export_index(&mut store, None, \" {instance_name}\" )
701
720
.ok_or_else(|| anyhow::anyhow!(\" no exported instance named `{instance_name}`\" ))?;
702
- Self::_new(|name| instance.get_export_index(&mut store, Some(&instance_export), name))
721
+ let instance_type = instance.instance_type(&mut store);
722
+ Self::_new(&instance_type, |name| instance.get_export_index(&mut store, Some(&instance_export), name))
703
723
}}
704
724
705
725
fn _new(
726
+ _instance_type: &{wt}::component::__internal::InstanceType,
706
727
mut lookup: impl FnMut (&str) -> Option<{wt}::component::ComponentExportIndex>,
707
728
) -> {wt}::Result<{struct_name}Indices> {{
708
729
let mut lookup = move |name| {{
@@ -740,6 +761,7 @@ fn _new(
740
761
let mut store = store.as_context_mut();
741
762
let _ = &mut store;
742
763
let _instance = instance;
764
+ let _instance_type = _instance.instance_type(&mut store);
743
765
"
744
766
) ;
745
767
let mut fields = Vec :: new ( ) ;
@@ -844,7 +866,7 @@ fn _new(
844
866
) ) ;
845
867
ty_index = format ! ( "{path}Indices" ) ;
846
868
ty = path;
847
- get_index_from_component = format ! ( "{ty_index}::new(_component)?" ) ;
869
+ get_index_from_component = format ! ( "{ty_index}::new(_component, _instance_type )?" ) ;
848
870
get_index_from_instance =
849
871
format ! ( "{ty_index}::new_instance(&mut store, _instance)?" ) ;
850
872
}
@@ -903,7 +925,7 @@ impl<_T> {camel}Pre<_T> {{
903
925
/// This method may fail if the component behind `instance_pre`
904
926
/// does not have the required exports.
905
927
pub fn new(instance_pre: {wt}::component::InstancePre<_T>) -> {wt}::Result<Self> {{
906
- let indices = {camel}Indices::new(instance_pre.component())?;
928
+ let indices = {camel}Indices::new(instance_pre.component(), instance_pre.instance_type() )?;
907
929
Ok(Self {{ instance_pre, indices }})
908
930
}}
909
931
@@ -1013,8 +1035,11 @@ impl<_T> {camel}Pre<_T> {{
1013
1035
///
1014
1036
/// This method may fail if the component does not have the
1015
1037
/// required exports.
1016
- pub fn new(component: &{wt}::component::Component) -> {wt}::Result<Self> {{
1038
+ pub fn new(component: &{wt}::component::Component,
1039
+ instance_type: &{wt}::component::__internal::InstanceType,
1040
+ ) -> {wt}::Result<Self> {{
1017
1041
let _component = component;
1042
+ let _instance_type = instance_type;
1018
1043
" ,
1019
1044
) ;
1020
1045
for ( name, field) in self . exports . fields . iter ( ) {
@@ -1042,6 +1067,7 @@ impl<_T> {camel}Pre<_T> {{
1042
1067
instance: &{wt}::component::Instance,
1043
1068
) -> {wt}::Result<Self> {{
1044
1069
let _instance = instance;
1070
+ let _instance_type = _instance.instance_type(&mut store);
1045
1071
" ,
1046
1072
) ;
1047
1073
for ( name, field) in self . exports . fields . iter ( ) {
@@ -1104,7 +1130,7 @@ impl<_T> {camel}Pre<_T> {{
1104
1130
instance: &{wt}::component::Instance,
1105
1131
) -> {wt}::Result<{camel}> {{
1106
1132
let indices = {camel}Indices::new_instance(&mut store, instance)?;
1107
- indices.load(store, instance)
1133
+ indices.load(&mut store, instance)
1108
1134
}}
1109
1135
" ,
1110
1136
) ;
0 commit comments