This is an archive of the discontinued LLVM Phabricator instance.

[llvm-c] Make LLVMAddAlias opaque pointer compatible
ClosedPublic

Authored by nikic on Dec 1 2021, 3:19 AM.

Details

Summary

Deprecate LLVMAddAlias in favor of LLVMAddAlias2, which accepts a value type and an address space. Previously these were extracted from the pointer type.

Diff Detail

Event Timeline

nikic created this revision.Dec 1 2021, 3:19 AM
nikic requested review of this revision.Dec 1 2021, 3:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2021, 3:19 AM
nikic added a comment.Dec 1 2021, 3:26 AM

I'd also like some advice on deprecations in the C API: As this is an FFI API, marking the functions as deprecated in the header is of limited usefulness, and we currently don't do that. But this means that people using the FFI API are likely not aware they need to take action wrt opaque pointers. I would propose that we go ahead and delete old deprecated functions like LLVMBuildInvoke, so that people are forced to take action now, while easy workarounds (like LLVMGetElementType) are still available.

The only alternative that comes to mind is a link-time deprecation, but I'm not familiar with how these are done and how well they work across platforms.

aeubanks accepted this revision.Dec 1 2021, 11:03 AM
aeubanks added a subscriber: aeubanks.

I think deleting functions with proper alternatives is fine, probably one at a time though so people can work through updating calls to those functions.

This revision is now accepted and ready to land.Dec 1 2021, 11:03 AM

I think deleting functions with proper alternatives is fine, probably one at a time though so people can work through updating calls to those functions.

Even if there's no way to communicate to all users that the original is deprecated (because they might be calling it through FFI in another language that doesn't consume the C header) there's probably still some amount of C header usage - so I think marking it as deprecated for a release & documenting it in the release notes, then removing it, seems suitable. Gives people at least /some/ chance to migrate on their own timeline rather than making it a hard break from the moment the new API is introduced with no chance of decoupling the transition. (also means even if you don't find out about the issue until you upgrade to a version missing the API - you can do a patch to your mainline that adopts the new API prior to picking up the breaking version - even if it's just minutes/hours/etc it decouples the release process a bit/doesn't make it such a monolithic change, which is good)

nikic added a comment.Dec 1 2021, 12:01 PM

@dblaikie To be clear, I'm not talking about the API replaced here, but about APIs that had an opaque pointer compatible version for many years now. I agree that there should be time between adding the replacement API and removing the old one.

CodaFi added a subscriber: CodaFi.Dec 1 2021, 2:19 PM

I think deleting functions with proper alternatives is fine, probably one at a time though so people can work through updating calls to those functions.

This is not, and has never been, the policy for deprecation for C API functions. We have a strict policy of ABI compatibility (for better or for worse) in these C bindings, these functions must stay.

Now, am I saying this is a good thing: absolutely not. I think this policy makes very little sense and we ought to get it changed. There's just not much will to do so at the moment.

I think deleting functions with proper alternatives is fine, probably one at a time though so people can work through updating calls to those functions.

This is not, and has never been, the policy for deprecation for C API functions. We have a strict policy of ABI compatibility (for better or for worse) in these C bindings, these functions must stay.

Now, am I saying this is a good thing: absolutely not. I think this policy makes very little sense and we ought to get it changed. There's just not much will to do so at the moment.

Like, at some point, these functions are going to be removed because it won't be possible to express them anymore - pointer types won't carry the necessary information. So it's not a question of if, but when.

@dblaikie To be clear, I'm not talking about the API replaced here, but about APIs that had an opaque pointer compatible version for many years now. I agree that there should be time between adding the replacement API and removing the old one.

Ah, sure - if something's been attributed as deprecated with a new alternative and had at least a release and it's going to be removed eventually, I'm OK with it being removed then. (I wouldn't argue that it /has/ to be attributed as deprecated for at least a release - if it's just in the release notes but doesn't have the attribute, someone could twist my arm into convincing me that it's still had enough opportunity for migration - but I'd prefer the attribute to go in whenever the new alternative API goes in anyway)

I think deleting functions with proper alternatives is fine, probably one at a time though so people can work through updating calls to those functions.

This is not, and has never been, the policy for deprecation for C API functions. We have a strict policy of ABI compatibility (for better or for worse) in these C bindings, these functions must stay.

That strict policy changed a few years ago based on an llvm-dev discussion, whose result was documented in d9f8ce997773e18315e04ab17d052f1db926d77b / r255300. The policy since then has been "best effort". The current text is:
https://llvm.org/docs/DeveloperPolicy.html#c-api-changes

This revision was landed with ongoing or failed builds.Dec 2 2021, 12:24 AM
This revision was automatically updated to reflect the committed changes.
nikic added a comment.Dec 2 2021, 1:17 AM

I submitted D114936 for header deprecation support in the C API. I think it won't help most consumers of the C API, but it definitely shouldn't hurt at least :)