Trying to merge identical block copy/destroy helpers and descriptors

I am working on an binary code size optimization similar to this patch for clang - some TODOs have been lying in Swift's source code for years.

Now I have encountered 2 problems:

  1. I have no idea how to properly encode capture for CanSILBlockStorageType::getCaptureType. I found that Swift-created block have identical capture currently (just a Swift closure), so I hardcoded a fixed string temporarily for the capture type.

  2. I found that the names of Objective-C classes and protocols are encoded in the signature of block descriptors, and clang behaves the same with -fencode-extended-block-signature which is enabled by default on Darwin. I am not sure about the necessity of doing so. It definitely precludes some opportunities of further merging block descriptors; also, the extended encoding itself contributes a lot in terms of binary size.

4 Likes

Since there have been no replies, I decided to create pull request first and leave the link to the source code where I don't know what to do (encoding for the capture type), hoping that someone knows where I am stuck at and gives some help (btw, I saw the like, Joe! I know you wrote this almost 10 years ago and I think you are a good candidate to help me).

As for the -fencode-extended-block-signature thing, I made a custom toolchain build to switch the extended encoding off and tested on an iOS app which heavily uses Swift. Surprisingly it makes little difference in terms of code size (~30K out of ~250M). Considering the little gain and unknown risk of breaking runtime behavior, I give up this idea.