-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Docs] Explicitly document libclang ABI and API stability #141657
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: main
Are you sure you want to change the base?
[Docs] Explicitly document libclang ABI and API stability #141657
Conversation
Our current docs leave a lot of latitude ("relatively stable") without explaining what the goals are for this stability. This patch adds some basic documentation explaining that there are some changes which can impact ABI and API stability that we reserve the right to make, lists some scenarios we explicitly do not support, but otherwise tries to assure the reader that the APIs and ABI are stable.
@llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) ChangesOur current docs leave a lot of latitude ("relatively stable") without explaining what the goals are for this stability. This patch adds some basic documentation explaining that there are some changes which can impact ABI and API stability that we reserve the right to make, lists some scenarios we explicitly do not support, but otherwise tries to assure the reader that the APIs and ABI are stable. Full diff: https://github.com/llvm/llvm-project/pull/141657.diff 1 Files Affected:
diff --git a/clang/docs/LibClang.rst b/clang/docs/LibClang.rst
index 08cf452a0df6c..bfcb95ee4a8ad 100644
--- a/clang/docs/LibClang.rst
+++ b/clang/docs/LibClang.rst
@@ -4,7 +4,7 @@
Libclang tutorial
=================
The C Interface to Clang provides a relatively small API that exposes facilities for parsing source code into an abstract syntax tree (AST), loading already-parsed ASTs, traversing the AST, associating physical source locations with elements within the AST, and other facilities that support Clang-based development tools.
-This C interface to Clang will never provide all of the information representation stored in Clang's C++ AST, nor should it: the intent is to maintain an API that is relatively stable from one release to the next, providing only the basic functionality needed to support development tools.
+This C interface to Clang will never provide all of the information representation stored in Clang's C++ AST, nor should it: the intent is to maintain an API that is :ref:`relatively stable <Stability>` from one release to the next, providing only the basic functionality needed to support development tools.
The entire C interface of libclang is available in the file `Index.h`_
Essential types overview
@@ -358,3 +358,46 @@ Complete example code
.. _Index.h: https://github.com/llvm/llvm-project/blob/main/clang/include/clang-c/Index.h
+
+.. _Stability:
+
+ABI and API Stability
+---------------------
+
+The C interfaces in libclang are intended to be relatively stable. This allows
+a programmer to use libclang without having to worry as much about Clang
+upgrades breaking existing code. However, the library is not unchanging. For
+example, the library will gain new interfaces over time as needs arise,
+existing APIs may be deprecated for eventual removal, etc. Also, the underlying
+implementation of the facilities by Clang may change behavior as bugs are
+fixed, features get implemented, etc.
+
+The library should be ABI and API stable over time, but ABI- and API-breaking
+changes can happen in the following situations:
+
+* Adding new enumerator to an enumeration (can be ABI-breaking in C++).
+* Removing an explicitly deprecated API after a suitably long deprecation
+ period.
+* Uses of implementation details, such names or comments that say something is
+ "private", "reserved", "internal", etc.
+
+The library has version macros (``CINDEX_VERSION_MAJOR``,
+``CINDEX_VERSION_MINOR``, and ``CINDEX_VERSION``) which can be used to test for
+specific library versions at compile time. The ``CINDEX_VERSION_MAJOR`` macro
+is only incremented if there are major source- or ABI-breaking changes. Except
+for removing an explicitly deprecate API, the changes listed above are not
+considered major source- or ABI-breaking changes. Historically, the value this
+macro expands to has not changed, but may be incremented in the future should
+the need arise. The ``CINDEX_VERSION_MINOR`` macro is incremented as new APIs
+are added. The ``CINDEX_VERSION`` macro expands to a value based on the major
+and minor version macros.
+
+In an effort to allow the library to be modified as new needs arise, the
+following situations are explicitly unsupported:
+
+* Loading different library versions into the same executable and passing
+ objects between the libraries; despite general ABI stability, different
+ versions of the library may use different implementation details that are not
+ compatible across library versions.
+* For the same reason as above, serializing objects from one version of the
+ library and deserializing with a different version is also not supported.
|
I've added a handful of folks who might be reasonable reviewers for this, but if you know of anyone else who may have an opinion, feel free to rope them in. These changes came about because of #134551 where someone was trying to add a better string API that handles embedded nulls but we ran into "ABI stability" when working through the implementation. The intent here is not to shift away from ABI stability for the library but to remind folks that we still need enough wiggle room to maintain and evolve it, and that underlying details of Clang can sometimes still mean breaking changes between libclang versions. |
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.
This looks reasonable to me, but I'm coming from the Python bindings anyway and can't comment on the details for the C/C++ side.
"private", "reserved", "internal", etc. | ||
* Using implementation details, such as names or comments that say something | ||
is "private", "reserved", "internal", etc. | ||
* Bug fixes or changes to Clang's internal implementation, or (rarely), bug |
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.
Thank you for reminding me of the discussion we had sometime last year. We can write this down, but I'm not sure how good we are at enforcing this, because stable libclang API is implemented on top of unstable C++ API.
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 think bug fixes to Clang internals are always fair game for us and something libclang folks will have to react to, which is why it's important to disallow multiple versions of the library from interacting. But fixes to libclang itself is something I think we can be more judicious about. e.g., adding a forgotten enumerator really shouldn't be a problem. Renaming one we don't like the name for is more disruptive and something we'd likely avoid doing.
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.
Should we say that while API and ABI are stable, domain-specific behavior of exposed functions is explicitly unstable? In other words, Clang 21 is not going to pretend that it's Clang 3.x, and users will see it via their cursors and whatnot.
Our current docs leave a lot of latitude ("relatively stable") without explaining what the goals are for this stability. This patch adds some basic documentation explaining that there are some changes which can impact ABI and API stability that we reserve the right to make, lists some scenarios we explicitly do not support, but otherwise tries to assure the reader that the APIs and ABI are stable.