-
Notifications
You must be signed in to change notification settings - Fork 27
cfg arch-specific ABIs for unsupported_{,fn_ptr}_calling_conventions
#67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
cfg arch-specific ABIs for unsupported_{,fn_ptr}_calling_conventions
#67
Conversation
b7fc23d
to
ee0b523
Compare
Currently includes #68 so this passes CI. |
Addresses FCW lints to assure code will compile on Rust 1.89 and beyond, as these ABIs get translated to others if the cfg condition is not met.
ee0b523
to
19fa964
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot of possible decisions regarding how to mitigate the breakage from this, so I am happy to edit this appropriately. I just wrote out the boringly obvious one of "just take it on the chin" because most of the others seem like they'd want your input first.
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "cdecl" fn($($ty),*) -> Ret)); | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "stdcall" fn($($ty),*) -> Ret)); | ||
#[cfg(target_arch = "x86")] | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "fastcall" fn($($ty),*) -> Ret)); | ||
#[cfg(target_arch = "x86")] | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "stdcall" fn($($ty),*) -> Ret)); | ||
#[cfg(target_arch = "x86_64")] | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "win64" fn($($ty),*) -> Ret)); | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "C" fn($($ty),*) -> Ret)); | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "system" fn($($ty),*) -> Ret)); | ||
|
||
#[cfg(feature = "thiscall-abi")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "thiscall-abi")))] | ||
#[cfg(any(docsrs, all(target_arch = "x86", feature = "thiscall-abi")))] | ||
impl_hookable!(@impl_pair ($($nm : $ty),*) (extern "thiscall" fn($($ty),*) -> Ret)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, all of these ABIs are silently translated to extern "C"
if the cfg
is not met. The type remains the same but the pointee is a different ABI in actual fact.
#[cfg(feature = "thiscall-abi")] | ||
#[cfg_attr(docsrs, doc(cfg(feature = "thiscall-abi")))] | ||
#[cfg(any(docsrs, all(target_arch = "x86", feature = "thiscall-abi")))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to build docs locally at the moment but I believe this loses the feature attribute on the docs (since doc(cfg(...))
is the attribute that adds it in the generated docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, is it? I'll revert that part of the change.
Is rust 1.89 changing how extern fns are treated when compiling for targets that don't support that specific extern? Or is it just changing warnings? |
@Hpmason Previously, using ABIs like I intend to propose that we switch this from a lint to a hard error for this case, because it makes the resulting behavior... does the code compile or not?... consistent for all usage of Separately, in 1.89, we have already started linting on usage of ABIs that were allowed on Windows if they were a mismatching architecture. Those will remain functional even if my recommendation regarding switching to an error is followed. This lint will remain for a while longer as we will only start linting in 1.89, and it will be on a new axis we may get different feedback for. So, I can fix up this PR to have either
|
Corrections to above statement in light of new information:
And to re-address this, specifically, and to perhaps better explain why we are making this change:
Previously to 1.90, we compute Handling all of those edge-cases is not done in a principled way because people who initially proposed adding this ABI support to the compiler did not think about it enough to document what their intentions were. They were focused on addressing a use-case, instead of interacting with the "negative space" off the happy path. |
I do think my changes handle it in a principled way... if somewhat depressing if you were hoping to not interact with this complexity. Namely, we cut off its head. An invalid ABI will remain syntactically valid... it parses. But it will no longer proceed past AST expansion, so we conclude we must error on it before we even reach the typechecking phase. This is important because that particular step is the only point in the compiler which is guaranteed to see every instance of |
Addresses FCW lints to assure code will compile on Rust 1.89 and beyond, as these ABIs get translated to others if the cfg condition is not met.