This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Add index option to store preambles in memory
ClosedPublic

Authored by vedgy on Mar 13 2023, 11:47 AM.

Details

Summary

This commit allows libclang API users to opt into storing PCH in memory
instead of temporary files. The option can be set only during CXIndex
construction to avoid multithreading issues and confusion or bugs if
some preambles are stored in temporary files and others - in memory.

The added API works as expected in KDevelop:
https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/283

Diff Detail

Event Timeline

vedgy created this revision.Mar 13 2023, 11:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 11:47 AM
Herald added a subscriber: arphaman. · View Herald Transcript
vedgy requested review of this revision.Mar 13 2023, 11:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2023, 11:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I have implemented the setter for the new option locally and tested it in KDevelop.

void clang_CXIndex_setStorePreamblesInMemory(CXIndex CIdx,
                                             int storePreamblesInMemory) {
  if (CIdx)
    static_cast<CIndexer *>(CIdx)->setStorePreamblesInMemory(
        storePreamblesInMemory);
}

Works as expected: new preambles are created in memory or the temporary directory depending on the option selected in the UI. Even if the temporary storage option ends up in memory, all remaining preambles are removed from the temporary directory on exit.

This simple setter approach was rejected in recent comments under D143418 for valid reasons. But this quick test proves that changing the option on the fly is viable. Currently I don't think that the option change taking effect without restarting KDevelop justifies the effort of implementing the setter as clang_parseTranslationUnitWithOptions(). I expect this option's value to be changed very rarely. So I don't plan to change preamble storage API after this review.

This revision is now accepted and ready to land.Mar 14 2023, 8:03 AM
vedgy added a comment.Mar 15 2023, 1:02 AM

@aaron.ballman, can you land this revision for me please?

This revision was automatically updated to reflect the committed changes.

@aaron.ballman, can you land this revision for me please?

Oops, thank you for the reminder! I've landed it on your behalf in 55f7e00afc56c68421220d60d29c079b58fe9c79