Some PostgreSQL extensions need to sort their pieces of data. Then it worth to re-use our tuplesort. But despite our tuplesort having extensibility, it's hidden inside tuplesort.c. There are at least a couple of examples of how extensions deal with that.
I think we need a proper way to let extension re-use our core tuplesort facility. The attached patchset is intended to do this the right way. Patches don't revise all the comments and lack code beautification. The intention behind publishing this revision is to verify the direction and get some feedback for further work.
I still have one doubt about the thing: the compatibility with previous PG versions requires me to support code paths that I already added into RUM extension. I won't be able to drop it from extension for quite long time in the future. It could be avoided if we backpatch this, which seems doubtful to me provided the volume of code changes.
If we just change this thing since say v16 this will only help to extensions that doesn't support earlier PG versions. I still consider the change beneficial but wonder do you have some view on how should it be managed in existing extensions to benefit them?