[clang] [C++20] [Modules] Instantiate pending instantiations when GMF ends (PR #126842)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 05:02:30 PST 2025


================
@@ -1104,9 +1104,13 @@ void Sema::ActOnStartOfTranslationUnit() {
 }
 
 void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
-  // No explicit actions are required at the end of the global module fragment.
-  if (Kind == TUFragmentKind::Global)
+  if (Kind == TUFragmentKind::Global) {
+    // Perform Pending Instantiations at the end of global module fragment so
+    // that the module ownership of TU-level decls won't get messed.
+    llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
+    PerformPendingInstantiations();
----------------
mizvekov wrote:

I find problematic the existing model of template instantiation module ownership.

Surely a template may need a certain instantiation for multiple uses, possibly in different modules.
If a template has been instantiated, we don't need to instantiate it again. It looks accidental that these declarations
end up being owned by the module which first instantiated it.

The instantiations should either have no ownership, perhaps homed to the owner of the pattern, or maybe be multiply owned.

https://github.com/llvm/llvm-project/pull/126842


More information about the cfe-commits mailing list