This is an archive of the discontinued LLVM Phabricator instance.

[AST] Add API to iterate already loaded specializations
Needs ReviewPublic

Authored by Hahnfeld on Jul 3 2023, 1:47 AM.

Details

Summary

These new functions allow to look at specializations without triggering deserialization, which might be problematic in some contexts.

Diff Detail

Event Timeline

Hahnfeld created this revision.Jul 3 2023, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 1:47 AM
Hahnfeld requested review of this revision.Jul 3 2023, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2023, 1:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

gentle ping :)

which might be problematic in some contexts.

I'd appreciate some more details on what those contexts are. It's a bit unpleasant to expose these APIs as part of the public interface because we typically *do* want deserialization. I'm not opposed to the changes, but we don't usually add APIs without any calls to the API. I assume you're planning to use these once they're in; are those uses from within Clang itself?

Right, it's not ideal to land APIs without usage in Clang itself... The context is, once again, ROOT and the Cling interpreter (where we are already using this API via downstream patches): When unloading a "transaction" (now PartialTranslationUnit in clang-repl) we need to "unload" all contained declarations, ie make the code generator forget that it had already emitted them. For templates, this is a bit tricky so we need to iterate specializations without triggering more deserialization. This will get important with D41416 where we only load needed specializations.

When playing a bit earlier this week, I learned that the problem related to "unloading" of template specializations can be observed upstream in clang-repl:

clang-repl> template <typename T> void f() {}
clang-repl> f<int>();
clang-repl> %undo
clang-repl> template <> void f<int>() {}
In file included from <<< inputs >>>:1:
input_line_3:1:18: error: explicit specialization of 'f<int>' after instantiation
    1 | template <> void f<int>() {}
      |                  ^
input_line_2:1:1: note: implicit instantiation first required here
    1 | f<int>();
      | ^
error: Parsing failed.

Let me see if I can come up a fix for that in clang-repl that would then need this API. But for now, it's also fine for us if the patch stays pending in review, still better than completely disconnected local commits...

Let me see if I can come up a fix for that in clang-repl that would then need this API. But for now, it's also fine for us if the patch stays pending in review, still better than completely disconnected local commits...

Thank you for the explanation! I think it makes sense to hold off on landing this until clang-reply needs to use the API. The code changes themselves look correct to me, so the review should hopefully sail through once there's test coverage exercising the functionality.