@@ -114,10 +114,13 @@ pub(super) fn run(
114114 if let TypeDef :: Interface ( _) = ty {
115115 continue ;
116116 }
117- let index = inliner
118- . result
119- . import_types
120- . push ( ( name. name . to_string ( ) , ty) ) ;
117+ let index = inliner. result . import_types . push ( (
118+ name. name . to_string ( ) ,
119+ ComponentExtern {
120+ ty,
121+ data : ComponentExternData :: new ( name) ,
122+ } ,
123+ ) ) ;
121124 let path = ImportPath :: root ( index) ;
122125 args. insert ( name. name , ComponentItemDef :: from_import ( path, ty) ?) ;
123126 }
@@ -134,8 +137,9 @@ pub(super) fn run(
134137 assert ! ( frames. is_empty( ) ) ;
135138
136139 let mut export_map = Default :: default ( ) ;
137- for ( name, def) in exports {
138- inliner. record_export ( name, def, types, & mut export_map) ?;
140+ for ( name, ( def, data) ) in exports {
141+ let data = ComponentExternData :: new ( data) ;
142+ inliner. record_export ( name, def, data, types, & mut export_map) ?;
139143 }
140144 inliner. result . exports = export_map;
141145 inliner. result . num_future_tables = types. num_future_tables ( ) ;
@@ -346,7 +350,7 @@ enum ComponentInstanceDef<'a> {
346350 // FIXME: same as the issue on `ComponentClosure` where this is cloned a lot
347351 // and may need `Rc`.
348352 Items (
349- IndexMap < & ' a str , ComponentItemDef < ' a > > ,
353+ IndexMap < & ' a str , ( ComponentItemDef < ' a > , wasmparser :: ComponentExternName < ' a > ) > ,
350354 TypeComponentInstanceIndex ,
351355 ) ,
352356}
@@ -376,7 +380,8 @@ impl<'a> Inliner<'a> {
376380 & mut self ,
377381 types : & mut ComponentTypesBuilder ,
378382 frames : & mut Vec < ( InlinerFrame < ' a > , ResourcesBuilder ) > ,
379- ) -> Result < IndexMap < & ' a str , ComponentItemDef < ' a > > > {
383+ ) -> Result < IndexMap < & ' a str , ( ComponentItemDef < ' a > , wasmparser:: ComponentExternName < ' a > ) > >
384+ {
380385 // This loop represents the execution of the instantiation of a
381386 // component. This is an iterative process which is finished once all
382387 // initializers are processed. Currently this is modeled as an infinite
@@ -407,7 +412,7 @@ impl<'a> Inliner<'a> {
407412 . translation
408413 . exports
409414 . iter ( )
410- . map ( |( name, item) | Ok ( ( * name, frame. item ( * item, types) ?) ) )
415+ . map ( |( name, ( item, data ) ) | Ok ( ( * name, ( frame. item ( * item, types) ?, * data ) ) ) )
411416 . collect :: < Result < _ > > ( ) ?;
412417 let instance_ty = frame. instance_ty ;
413418 let ( _, snapshot) = frames. pop ( ) . unwrap ( ) ;
@@ -1295,7 +1300,7 @@ impl<'a> Inliner<'a> {
12951300 ComponentSynthetic ( map, ty) => {
12961301 let items = map
12971302 . iter ( )
1298- . map ( |( name, index) | Ok ( ( * name, frame. item ( * index, types) ?) ) )
1303+ . map ( |( name, ( index, data ) ) | Ok ( ( * name, ( frame. item ( * index, types) ?, * data ) ) ) )
12991304 . collect :: < Result < _ > > ( ) ?;
13001305 let types_ref = frame. translation . types_ref ( ) ;
13011306 let ty = types. convert_instance ( types_ref, * ty) ?;
@@ -1401,15 +1406,16 @@ impl<'a> Inliner<'a> {
14011406 // item is then pushed in the relevant index space.
14021407 ComponentInstanceDef :: Import ( path, ty) => {
14031408 let path = path. push ( * name) ;
1404- let def = ComponentItemDef :: from_import ( path, types[ * ty] . exports [ * name] ) ?;
1409+ let def =
1410+ ComponentItemDef :: from_import ( path, types[ * ty] . exports [ * name] . ty ) ?;
14051411 frame. push_item ( def) ;
14061412 }
14071413
14081414 // Given a component instance which was either created
14091415 // through instantiation of a component or through a
14101416 // synthetic renaming of items we just schlep around the
14111417 // definitions of various items here.
1412- ComponentInstanceDef :: Items ( map, _) => frame. push_item ( map[ * name] . clone ( ) ) ,
1418+ ComponentInstanceDef :: Items ( map, _) => frame. push_item ( map[ * name] . 0 . clone ( ) ) ,
14131419 }
14141420 }
14151421
@@ -1615,8 +1621,9 @@ impl<'a> Inliner<'a> {
16151621 & mut self ,
16161622 name : & str ,
16171623 def : ComponentItemDef < ' a > ,
1624+ data : ComponentExternData ,
16181625 types : & ' a ComponentTypesBuilder ,
1619- map : & mut IndexMap < String , dfg:: Export > ,
1626+ map : & mut IndexMap < String , ( dfg:: Export , ComponentExternData ) > ,
16201627 ) -> Result < ( ) > {
16211628 let export = match def {
16221629 // Exported modules are currently saved in a `PrimaryMap`, at
@@ -1676,8 +1683,8 @@ impl<'a> Inliner<'a> {
16761683 ComponentInstanceDef :: Import ( path, ty) => {
16771684 for ( name, ty) in types[ ty] . exports . iter ( ) {
16781685 let path = path. push ( name) ;
1679- let def = ComponentItemDef :: from_import ( path, * ty) ?;
1680- self . record_export ( name, def, types, & mut exports) ?;
1686+ let def = ComponentItemDef :: from_import ( path, ty . ty ) ?;
1687+ self . record_export ( name, def, ty . data . clone ( ) , types, & mut exports) ?;
16811688 }
16821689 dfg:: Export :: Instance { ty, exports }
16831690 }
@@ -1686,8 +1693,9 @@ impl<'a> Inliner<'a> {
16861693 // translated recursively here to our `exports` map which is
16871694 // the bag of items we're exporting.
16881695 ComponentInstanceDef :: Items ( map, ty) => {
1689- for ( name, def) in map {
1690- self . record_export ( name, def, types, & mut exports) ?;
1696+ for ( name, ( def, data) ) in map {
1697+ let data = ComponentExternData :: new ( data) ;
1698+ self . record_export ( name, def, data. clone ( ) , types, & mut exports) ?;
16911699 }
16921700 dfg:: Export :: Instance { ty, exports }
16931701 }
@@ -1703,7 +1711,7 @@ impl<'a> Inliner<'a> {
17031711 ComponentItemDef :: Type ( def) => dfg:: Export :: Type ( def) ,
17041712 } ;
17051713
1706- map. insert ( name. to_string ( ) , export) ;
1714+ map. insert ( name. to_string ( ) , ( export, data ) ) ;
17071715 Ok ( ( ) )
17081716 }
17091717}
@@ -1838,7 +1846,7 @@ impl<'a> InlinerFrame<'a> {
18381846 /// and which component instantiated it.
18391847 fn finish_instantiate (
18401848 & mut self ,
1841- exports : IndexMap < & ' a str , ComponentItemDef < ' a > > ,
1849+ exports : IndexMap < & ' a str , ( ComponentItemDef < ' a > , wasmparser :: ComponentExternName < ' a > ) > ,
18421850 ty : ComponentInstanceTypeId ,
18431851 types : & mut ComponentTypesBuilder ,
18441852 ) -> Result < ( ) > {
@@ -1852,7 +1860,7 @@ impl<'a> InlinerFrame<'a> {
18521860 & mut path,
18531861 & mut |path| match path {
18541862 [ ] => unreachable ! ( ) ,
1855- [ name, rest @ ..] => exports[ name] . lookup_resource ( rest, types) ,
1863+ [ name, rest @ ..] => exports[ name] . 0 . lookup_resource ( rest, types) ,
18561864 } ,
18571865 ) ;
18581866 }
@@ -1916,7 +1924,7 @@ impl<'a> ComponentItemDef<'a> {
19161924 cur = match instance {
19171925 // If this instance is a "bag of things" then this is as easy as
19181926 // looking up the name in the bag of names.
1919- ComponentInstanceDef :: Items ( names, _) => names[ element] . clone ( ) ,
1927+ ComponentInstanceDef :: Items ( names, _) => names[ element] . 0 . clone ( ) ,
19201928
19211929 // If, however, this instance is an imported instance then this
19221930 // is a further projection within the import with one more path
@@ -1925,7 +1933,7 @@ impl<'a> ComponentItemDef<'a> {
19251933 // in conjunction with a one-longer `path` to produce a new item
19261934 // definition.
19271935 ComponentInstanceDef :: Import ( path, ty) => {
1928- ComponentItemDef :: from_import ( path. push ( element) , types[ ty] . exports [ element] )
1936+ ComponentItemDef :: from_import ( path. push ( element) , types[ ty] . exports [ element] . ty )
19291937 . unwrap ( )
19301938 }
19311939 ComponentInstanceDef :: Intrinsics => {
@@ -1948,3 +1956,11 @@ enum InstanceModule {
19481956 Static ( StaticModuleIndex ) ,
19491957 Import ( TypeModuleIndex ) ,
19501958}
1959+
1960+ impl ComponentExternData {
1961+ fn new ( data : wasmparser:: ComponentExternName < ' _ > ) -> Self {
1962+ ComponentExternData {
1963+ implements : data. implements . map ( |s| s. to_string ( ) ) ,
1964+ }
1965+ }
1966+ }
0 commit comments