Skip to content

Commit 769cf21

Browse files
committed
fix: apply collision disambiguation to guest codegen
Apply the same import_member_names() collision detection to guest.rs that was already applied to host.rs and rtypes.rs. Without this, guest_bindgen! would generate duplicate type aliases and getter functions when two packages export interfaces with the same name. Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 33f8d08 commit 769cf21

File tree

1 file changed

+5
-5
lines changed
  • src/hyperlight_component_util/src

1 file changed

+5
-5
lines changed

src/hyperlight_component_util/src/guest.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use proc_macro2::TokenStream;
1818
use quote::{format_ident, quote};
1919

2020
use crate::emit::{
21-
FnName, ResolvedBoundVar, ResourceItemName, State, WitName, kebab_to_exports_name, kebab_to_fn,
22-
kebab_to_getter, kebab_to_imports_name, kebab_to_namespace, kebab_to_type, kebab_to_var,
23-
split_wit_name,
21+
FnName, ResolvedBoundVar, ResourceItemName, State, WitName, find_colliding_import_names,
22+
import_member_names, kebab_to_exports_name, kebab_to_fn, kebab_to_getter,
23+
kebab_to_imports_name, kebab_to_namespace, kebab_to_type, kebab_to_var, split_wit_name,
2424
};
2525
use crate::etypes::{Component, Defined, ExternDecl, ExternDesc, Handleable, Instance, Tyvar};
2626
use crate::hl::{
@@ -117,8 +117,7 @@ fn emit_import_extern_decl<'a, 'b, 'c>(
117117
let wn = split_wit_name(ed.kebab_name);
118118
emit_import_instance(s, wn.clone(), it);
119119

120-
let getter = kebab_to_getter(wn.name);
121-
let tn = kebab_to_type(wn.name);
120+
let (tn, getter) = import_member_names(&wn, &s.colliding_import_names);
122121
quote! {
123122
type #tn = Self;
124123
#[allow(refining_impl_trait)]
@@ -287,6 +286,7 @@ fn emit_component<'a, 'b, 'c>(
287286
let export_trait = kebab_to_exports_name(wn.name);
288287
s.import_param_var = Some(format_ident!("I"));
289288
s.self_param_var = Some(format_ident!("S"));
289+
s.colliding_import_names = find_colliding_import_names(&ct.imports);
290290

291291
let rtsid = format_ident!("{}Resources", r#trait);
292292
resource::emit_tables(

0 commit comments

Comments
 (0)