diff --git a/core/src/ast/attrs.rs b/core/src/ast/attrs.rs index 6d2180d98..c0f398445 100644 --- a/core/src/ast/attrs.rs +++ b/core/src/ast/attrs.rs @@ -20,10 +20,10 @@ pub struct Attrs { /// in HIR backends, pub skip_if_unsupported: bool, - /// Renames to apply to the underlying C function. Can be found on methods, impls, and bridge modules, and is inherited. + /// Renames to apply to the underlying C symbol. Can be found on methods, impls, and bridge modules, and is inherited. /// /// Has no effect on types. - pub c_rename: RenameAttr, + pub abi_rename: RenameAttr, } impl Attrs { @@ -32,15 +32,15 @@ impl Attrs { Attr::Cfg(attr) => self.cfg.push(attr), Attr::DiplomatBackend(attr) => self.attrs.push(attr), Attr::SkipIfUnsupported => self.skip_if_unsupported = true, - Attr::CRename(rename) => self.c_rename.extend(&rename, AttrExtendMode::Override), + Attr::CRename(rename) => self.abi_rename.extend(&rename, AttrExtendMode::Override), } } /// Merge attributes that should be inherited from the parent pub(crate) fn merge_parent_attrs(&mut self, other: &Attrs) { self.cfg.extend(other.cfg.iter().cloned()); - self.c_rename - .extend(&other.c_rename, AttrExtendMode::Inherit); + self.abi_rename + .extend(&other.abi_rename, AttrExtendMode::Inherit); } pub(crate) fn add_attrs(&mut self, attrs: &[Attribute]) { for attr in syn_attr_to_ast_attr(attrs) { @@ -71,7 +71,7 @@ enum Attr { fn syn_attr_to_ast_attr(attrs: &[Attribute]) -> impl Iterator + '_ { let cfg_path: syn::Path = syn::parse_str("cfg").unwrap(); let dattr_path: syn::Path = syn::parse_str("diplomat::attr").unwrap(); - let crename_attr: syn::Path = syn::parse_str("diplomat::c_rename").unwrap(); + let crename_attr: syn::Path = syn::parse_str("diplomat::abi_rename").unwrap(); let skipast: syn::Path = syn::parse_str("diplomat::skip_if_unsupported").unwrap(); attrs.iter().filter_map(move |a| { if a.path() == &cfg_path { @@ -112,8 +112,8 @@ impl Serialize for Attrs { if self.skip_if_unsupported { state.serialize_field("skip_if_unsupported", &self.skip_if_unsupported)?; } - if !self.c_rename.is_empty() { - state.serialize_field("c_rename", &self.c_rename)?; + if !self.abi_rename.is_empty() { + state.serialize_field("abi_rename", &self.abi_rename)?; } state.end() } @@ -220,13 +220,13 @@ pub(crate) enum AttrExtendMode { Override, } -/// A pattern for use in rename attributes, like `#[diplomat::c_rename]` +/// A pattern for use in rename attributes, like `#[diplomat::abi_rename]` /// /// This can be parsed from a string, typically something like `icu4x_{0}`. /// It can have up to one {0} for replacement. /// /// In the future this may support transformations like to_camel_case, etc, -/// probably specified as a list like `#[diplomat::c_rename("foo{0}", to_camel_case)]` +/// probably specified as a list like `#[diplomat::abi_rename("foo{0}", to_camel_case)]` #[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)] pub struct RenameAttr { pattern: Option, @@ -273,23 +273,23 @@ impl RenameAttr { } pub(crate) fn from_meta(meta: &Meta) -> Result> { - static C_RENAME_ERROR: &str = "#[diplomat::c_rename] must be given a string value"; + static ABI_RENAME_ERROR: &str = "#[diplomat::abi_rename] must be given a string value"; match meta { - Meta::Path(..) => Err(C_RENAME_ERROR.into()), + Meta::Path(..) => Err(ABI_RENAME_ERROR.into()), Meta::NameValue(ref nv) => { - // Support a shortcut `c_rename = "..."` + // Support a shortcut `abi_rename = "..."` let Expr::Lit(ref lit) = nv.value else { - return Err(C_RENAME_ERROR.into()); + return Err(ABI_RENAME_ERROR.into()); }; let Lit::Str(ref lit) = lit.lit else { - return Err(C_RENAME_ERROR.into()); + return Err(ABI_RENAME_ERROR.into()); }; Ok(RenameAttr::from_pattern(&lit.value())) } - // The full syntax to which we'll add more things in the future, `c_rename("")` + // The full syntax to which we'll add more things in the future, `abi_rename("")` Meta::List(list) => list.parse_args().map_err(|e| { - format!("Failed to parse malformed #[diplomat::c_rename(...)]: {e}").into() + format!("Failed to parse malformed #[diplomat::abi_rename(...)]: {e}").into() }), } } @@ -364,10 +364,10 @@ mod tests { #[test] fn test_rename() { - let attr: syn::Attribute = syn::parse_quote!(#[diplomat::c_rename = "foobar_{0}"]); + let attr: syn::Attribute = syn::parse_quote!(#[diplomat::abi_rename = "foobar_{0}"]); let attr = RenameAttr::from_meta(&attr.meta).unwrap(); insta::assert_yaml_snapshot!(attr); - let attr: syn::Attribute = syn::parse_quote!(#[diplomat::c_rename("foobar_{0}")]); + let attr: syn::Attribute = syn::parse_quote!(#[diplomat::abi_rename("foobar_{0}")]); let attr = RenameAttr::from_meta(&attr.meta).unwrap(); insta::assert_yaml_snapshot!(attr); } diff --git a/core/src/ast/methods.rs b/core/src/ast/methods.rs index 5cfc47840..b0b07e0cd 100644 --- a/core/src/ast/methods.rs +++ b/core/src/ast/methods.rs @@ -56,7 +56,7 @@ impl Method { let method_ident = &m.sig.ident; let concat_method_ident = format!("{self_ident}_{method_ident}"); let extern_ident = syn::Ident::new( - &attrs.c_rename.apply(concat_method_ident.into()), + &attrs.abi_rename.apply(concat_method_ident.into()), m.sig.ident.span(), ); diff --git a/core/src/hir/attrs.rs b/core/src/hir/attrs.rs index c70d27cd8..81484c77b 100644 --- a/core/src/hir/attrs.rs +++ b/core/src/hir/attrs.rs @@ -13,7 +13,7 @@ pub use crate::ast::attrs::RenameAttr; pub struct Attrs { pub disable: bool, pub rename: RenameAttr, - pub c_rename: RenameAttr, + pub abi_rename: RenameAttr, // more to be added: rename, namespace, etc } @@ -38,7 +38,7 @@ impl Attrs { ) -> Self { let mut this = Attrs { // Backends must support this since it applies to the macro/C code. - c_rename: ast.c_rename.clone(), + abi_rename: ast.abi_rename.clone(), ..Default::default() }; diff --git a/core/src/hir/snapshots/diplomat_core__hir__elision__tests__simple_mod.snap b/core/src/hir/snapshots/diplomat_core__hir__elision__tests__simple_mod.snap index 7c1a22f86..ec7a8a95f 100644 --- a/core/src/hir/snapshots/diplomat_core__hir__elision__tests__simple_mod.snap +++ b/core/src/hir/snapshots/diplomat_core__hir__elision__tests__simple_mod.snap @@ -95,7 +95,7 @@ TypeContext { rename: RenameAttr { pattern: None, }, - c_rename: RenameAttr { + abi_rename: RenameAttr { pattern: None, }, }, @@ -106,7 +106,7 @@ TypeContext { rename: RenameAttr { pattern: None, }, - c_rename: RenameAttr { + abi_rename: RenameAttr { pattern: None, }, }, @@ -213,7 +213,7 @@ TypeContext { rename: RenameAttr { pattern: None, }, - c_rename: RenameAttr { + abi_rename: RenameAttr { pattern: None, }, }, @@ -224,7 +224,7 @@ TypeContext { rename: RenameAttr { pattern: None, }, - c_rename: RenameAttr { + abi_rename: RenameAttr { pattern: None, }, }, @@ -253,7 +253,7 @@ TypeContext { rename: RenameAttr { pattern: None, }, - c_rename: RenameAttr { + abi_rename: RenameAttr { pattern: None, }, }, diff --git a/feature_tests/c/include/AttrOpaque1.h b/feature_tests/c/include/AttrOpaque1.h index fc8e1d82f..af5c14fb6 100644 --- a/feature_tests/c/include/AttrOpaque1.h +++ b/feature_tests/c/include/AttrOpaque1.h @@ -23,7 +23,7 @@ AttrOpaque1* namespace_AttrOpaque1_new(); uint8_t namespace_AttrOpaque1_method(const AttrOpaque1* self); -uint8_t renamed_in_c_only(const AttrOpaque1* self); +uint8_t renamed_on_abi_only(const AttrOpaque1* self); void namespace_AttrOpaque1_method_disabledcpp(const AttrOpaque1* self); void AttrOpaque1_destroy(AttrOpaque1* self); diff --git a/feature_tests/c2/include/AttrOpaque1.h b/feature_tests/c2/include/AttrOpaque1.h index 65a533ed2..7949a246f 100644 --- a/feature_tests/c2/include/AttrOpaque1.h +++ b/feature_tests/c2/include/AttrOpaque1.h @@ -19,7 +19,7 @@ AttrOpaque1* namespace_AttrOpaque1_new(); uint8_t namespace_AttrOpaque1_method(const AttrOpaque1* self); -uint8_t renamed_in_c_only(const AttrOpaque1* self); +uint8_t renamed_on_abi_only(const AttrOpaque1* self); void namespace_AttrOpaque1_method_disabledcpp(const AttrOpaque1* self); diff --git a/feature_tests/cpp/docs/source/attrs_ffi.rst b/feature_tests/cpp/docs/source/attrs_ffi.rst index 4c6194a39..df86cdc20 100644 --- a/feature_tests/cpp/docs/source/attrs_ffi.rst +++ b/feature_tests/cpp/docs/source/attrs_ffi.rst @@ -17,7 +17,7 @@ .. cpp:function:: uint8_t method() const - .. cpp:function:: uint8_t crenamed() const + .. cpp:function:: uint8_t abirenamed() const .. cpp:function:: void method_disabledcpp() const diff --git a/feature_tests/cpp/include/AttrOpaque1.h b/feature_tests/cpp/include/AttrOpaque1.h index fc8e1d82f..af5c14fb6 100644 --- a/feature_tests/cpp/include/AttrOpaque1.h +++ b/feature_tests/cpp/include/AttrOpaque1.h @@ -23,7 +23,7 @@ AttrOpaque1* namespace_AttrOpaque1_new(); uint8_t namespace_AttrOpaque1_method(const AttrOpaque1* self); -uint8_t renamed_in_c_only(const AttrOpaque1* self); +uint8_t renamed_on_abi_only(const AttrOpaque1* self); void namespace_AttrOpaque1_method_disabledcpp(const AttrOpaque1* self); void AttrOpaque1_destroy(AttrOpaque1* self); diff --git a/feature_tests/cpp/include/AttrOpaque1.hpp b/feature_tests/cpp/include/AttrOpaque1.hpp index df355af9c..2e0f32549 100644 --- a/feature_tests/cpp/include/AttrOpaque1.hpp +++ b/feature_tests/cpp/include/AttrOpaque1.hpp @@ -25,7 +25,7 @@ class AttrOpaque1 { public: static AttrOpaque1 new_(); uint8_t method() const; - uint8_t crenamed() const; + uint8_t abirenamed() const; void method_disabledcpp() const; inline const capi::AttrOpaque1* AsFFI() const { return this->inner.get(); } inline capi::AttrOpaque1* AsFFIMut() { return this->inner.get(); } @@ -44,8 +44,8 @@ inline AttrOpaque1 AttrOpaque1::new_() { inline uint8_t AttrOpaque1::method() const { return capi::namespace_AttrOpaque1_method(this->inner.get()); } -inline uint8_t AttrOpaque1::crenamed() const { - return capi::renamed_in_c_only(this->inner.get()); +inline uint8_t AttrOpaque1::abirenamed() const { + return capi::renamed_on_abi_only(this->inner.get()); } inline void AttrOpaque1::method_disabledcpp() const { capi::namespace_AttrOpaque1_method_disabledcpp(this->inner.get()); diff --git a/feature_tests/cpp/tests/attrs.cpp b/feature_tests/cpp/tests/attrs.cpp index 024b9e983..59ebe7489 100644 --- a/feature_tests/cpp/tests/attrs.cpp +++ b/feature_tests/cpp/tests/attrs.cpp @@ -6,10 +6,10 @@ int main(int argc, char *argv[]) { AttrOpaque1 o = AttrOpaque1::new_(); // the cpp2 renames don't apply. However, these must link correctly!! simple_assert_eq("method should call", o.method(), 77); - simple_assert_eq("method should call", o.crenamed(), 123); + simple_assert_eq("method should call", o.abirenamed(), 123); // These C names should also resolve - void* renamed = (void*)capi::renamed_in_c_only; + void* renamed = (void*)capi::renamed_on_abi_only; std::cout<<"Renamed function at "<AsFFI()); +inline uint8_t AttrOpaque1Renamed::abirenamed() const { + auto result = capi::renamed_on_abi_only(this->AsFFI()); return result; } diff --git a/feature_tests/cpp2/tests/attrs.cpp b/feature_tests/cpp2/tests/attrs.cpp index b545fd12a..39313c6f5 100644 --- a/feature_tests/cpp2/tests/attrs.cpp +++ b/feature_tests/cpp2/tests/attrs.cpp @@ -5,10 +5,10 @@ int main(int argc, char *argv[]) { std::unique_ptr r = AttrOpaque1Renamed::totally_not_new(); simple_assert_eq("method should call", r->method_renamed(), 77); - simple_assert_eq("method should call", r->crenamed(), 123); + simple_assert_eq("method should call", r->abirenamed(), 123); // These C names should also resolve - void* renamed = (void*)capi::renamed_in_c_only; + void* renamed = (void*)capi::renamed_on_abi_only; std::cout<<"Renamed function at "< _namespace_AttrOpaque1_new(); // ignore: non_constant_identifier_names external int _namespace_AttrOpaque1_method(ffi.Pointer self); -@ffi.Native)>(isLeaf: true, symbol: 'renamed_in_c_only') +@ffi.Native)>(isLeaf: true, symbol: 'renamed_on_abi_only') // ignore: non_constant_identifier_names -external int _renamed_in_c_only(ffi.Pointer self); +external int _renamed_on_abi_only(ffi.Pointer self); @ffi.Native)>(isLeaf: true, symbol: 'namespace_AttrOpaque1_method_disabledcpp') // ignore: non_constant_identifier_names diff --git a/feature_tests/dotnet/Lib/Generated/AttrOpaque1.cs b/feature_tests/dotnet/Lib/Generated/AttrOpaque1.cs index cd6c56c48..dbc50129f 100644 --- a/feature_tests/dotnet/Lib/Generated/AttrOpaque1.cs +++ b/feature_tests/dotnet/Lib/Generated/AttrOpaque1.cs @@ -54,7 +54,7 @@ public byte Method() } } - public byte Crenamed() + public byte Abirenamed() { unsafe { @@ -62,7 +62,7 @@ public byte Crenamed() { throw new ObjectDisposedException("AttrOpaque1"); } - byte retVal = Raw.AttrOpaque1.Crenamed(_inner); + byte retVal = Raw.AttrOpaque1.Abirenamed(_inner); return retVal; } } diff --git a/feature_tests/dotnet/Lib/Generated/RawAttrOpaque1.cs b/feature_tests/dotnet/Lib/Generated/RawAttrOpaque1.cs index fa47cb219..00baea362 100644 --- a/feature_tests/dotnet/Lib/Generated/RawAttrOpaque1.cs +++ b/feature_tests/dotnet/Lib/Generated/RawAttrOpaque1.cs @@ -22,8 +22,8 @@ public partial struct AttrOpaque1 [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "namespace_AttrOpaque1_method", ExactSpelling = true)] public static unsafe extern byte NamespaceMethod(AttrOpaque1* self); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "renamed_in_c_only", ExactSpelling = true)] - public static unsafe extern byte RenamedInCOnly(AttrOpaque1* self); + [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "renamed_on_abi_only", ExactSpelling = true)] + public static unsafe extern byte RenamedOnAbiOnly(AttrOpaque1* self); [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "namespace_AttrOpaque1_method_disabledcpp", ExactSpelling = true)] public static unsafe extern void NamespaceMethodDisabledcpp(AttrOpaque1* self); diff --git a/feature_tests/js/api/AttrOpaque1.d.ts b/feature_tests/js/api/AttrOpaque1.d.ts index caeff8f8b..9239449c5 100644 --- a/feature_tests/js/api/AttrOpaque1.d.ts +++ b/feature_tests/js/api/AttrOpaque1.d.ts @@ -14,7 +14,7 @@ export class AttrOpaque1 { /** */ - crenamed(): u8; + abirenamed(): u8; /** */ diff --git a/feature_tests/js/api/AttrOpaque1.mjs b/feature_tests/js/api/AttrOpaque1.mjs index 8bfeb2324..9439ecb3c 100644 --- a/feature_tests/js/api/AttrOpaque1.mjs +++ b/feature_tests/js/api/AttrOpaque1.mjs @@ -23,8 +23,8 @@ export class AttrOpaque1 { return wasm.namespace_AttrOpaque1_method(this.underlying); } - crenamed() { - return wasm.renamed_in_c_only(this.underlying); + abirenamed() { + return wasm.renamed_on_abi_only(this.underlying); } method_disabledcpp() { diff --git a/feature_tests/js/docs/source/attrs_ffi.rst b/feature_tests/js/docs/source/attrs_ffi.rst index 1d2066e61..3b050ba2b 100644 --- a/feature_tests/js/docs/source/attrs_ffi.rst +++ b/feature_tests/js/docs/source/attrs_ffi.rst @@ -9,7 +9,7 @@ .. js:method:: method() - .. js:method:: crenamed() + .. js:method:: abirenamed() .. js:method:: method_disabledcpp() diff --git a/feature_tests/src/attrs.rs b/feature_tests/src/attrs.rs index 6cf1d5cbc..c06278379 100644 --- a/feature_tests/src/attrs.rs +++ b/feature_tests/src/attrs.rs @@ -1,5 +1,5 @@ #[diplomat::bridge] -#[diplomat::c_rename = "namespace_{0}"] +#[diplomat::abi_rename = "namespace_{0}"] pub mod ffi { #[diplomat::opaque] #[diplomat::attr(cpp2, rename = "AttrOpaque1Renamed")] @@ -16,8 +16,8 @@ pub mod ffi { 77 } - #[diplomat::c_rename("renamed_in_c_only")] - pub fn crenamed(&self) -> u8 { + #[diplomat::abi_rename("renamed_on_abi_only")] + pub fn abirenamed(&self) -> u8 { 123 } @@ -34,7 +34,7 @@ pub mod ffi { pub enum AttrEnum { A, B, - #[diplomat::attr(cpp2, rename = "CRenamed")] + #[diplomat::attr(cpp2, rename = "CPPRenamed")] C, } } diff --git a/macro/src/lib.rs b/macro/src/lib.rs index 34c51646e..0ab8d1273 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -277,7 +277,7 @@ impl AttributeInfo { || seg == "out" || seg == "attr" || seg == "skip_if_unsupported" - || seg == "c_rename" + || seg == "abi_rename" { // diplomat-tool reads these, not diplomat::bridge. // throw them away so rustc doesn't complain about unknown attributes diff --git a/tool/src/c2/formatter.rs b/tool/src/c2/formatter.rs index dcbda7e2d..963fd1501 100644 --- a/tool/src/c2/formatter.rs +++ b/tool/src/c2/formatter.rs @@ -79,7 +79,7 @@ impl<'tcx> CFormatter<'tcx> { let ty_name = self.fmt_type_name(ty); let method_name = method.name.as_str(); let put_together = format!("{ty_name}_{method_name}"); - method.attrs.c_rename.apply(put_together.into()).into() + method.attrs.abi_rename.apply(put_together.into()).into() } pub fn fmt_ptr<'a>(&self, ident: &'a str, mutability: hir::Mutability) -> Cow<'a, str> {