Emit warning on non-FFI safe spine types#75
Conversation
aec2218 to
309edb2
Compare
| let check_fn = format_ident!("_ffi_check_{}", field_ident); | ||
| let inner_ty_span = inner_ty.span(); | ||
| ffi_check_items | ||
| .push(quote_spanned! { inner_ty_span => fn #check_fn(var: *const #inner_ty); }); |
There was a problem hiding this comment.
🟡 Generated FFI check function names lack struct-name scoping, causing duplicate symbol errors when multiple #[from_spine] structs exist in the same module
The generated extern "C" function names use only the field name (_ffi_check_{field_ident}), not the struct name. If two #[from_spine] structs in the same module share any field name (e.g., every spine struct has tile_info: ShmemData<TileInfo>), the macro expansions produce duplicate extern function declarations (fn _ffi_check_tile_info(...)) in the module namespace, triggering a Rust E0428 duplicate definition error.
Example collision
Two structs in the same module:
#[from_spine("app1")]
struct Spine1 { pub tile_info: ShmemData<TileInfo>, pub qa: SpineQueue<MsgA> }
#[from_spine("app2")]
struct Spine2 { pub tile_info: ShmemData<TileInfo>, pub qb: SpineQueue<MsgB> }Both expand to:
unsafe extern "C" { fn _ffi_check_tile_info(var: *const TileInfo); ... }
unsafe extern "C" { fn _ffi_check_tile_info(var: *const TileInfo); ... }This is a duplicate definition error.
Prompt for agents
The generated FFI check function names at two locations (lines 172 and 322 in crates/spine-derive/src/lib.rs) use format_ident!("_ffi_check_{}", field_ident) which only incorporates the field name. To avoid duplicate symbol errors when multiple from_spine structs coexist in the same module, the struct name should be included in the generated function name. Change both occurrences to format_ident!("_ffi_check_{}_{}", struct_ident, field_ident). The struct_ident variable is already in scope at both locations.
Was this helpful? React with 👍 or 👎 to provide feedback.
The warning will look like this underlined on the type in the spine:
In this case, it's pointing out that one of the fields in a type of the spine is an Option which is not FFI-safe.