James Widman
unread,Mar 3, 2014, 2:18:32 PM3/3/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mod...@isocpp.org, Bjarne.S...@morganstanley.com, Gabriel Dos Reis
[Keeping the CC line from before since I don’t know whether the subscriptions went through yet.]
Re phase 8, and assuming we wind up with import rules that say that an import-directive cause the importation of names/entities of the indicated TU as if it had just completed phases 7…
Has anyone considered a design where a use of a specialization (of a class template or function template) implicitly causes the importation of an Instantiation Unit (IU) where the only names visible are those that would be brought in by an import-directive that names each of the modules that defines either the template or one of the types/values/templates used as a template argument?
E.g., if module A defines class template A, and if B imports A and then uses A<int>, then that use would implicitly import the IU for module A. Names from B would not be visible during that separate translation.
The point is that each specialization would by implicitly declared in exactly one place, and if its definition is required, then it would be instantiated in an environment where the set of declared names is given by the specialization name itself (and therefore predictable).
To some extent, there would be no need for ODR checking, because (in a fully-modularized program) A<int> would be instantiated exactly once during translation for the entire program—instead of once per TU where its definition is required.
So, if Clang was doing this, it would reach A<int>, find that it had no type entry for A<int>, then behave as if a separate compiler instance had processed the forward-declaration of that type, and then allow translation to continue from the point of use (this time with type information for A<int> generated from the sub-translation).
And unless the definition of A changes, the post-phase-8 translation of the instantiated class A<int> could be used in subsequent builds by reading from a serialized AST (without instantiating) for any TU that needs A<int> to be defined.
This differs from the initially-assumed model where the TU that uses A<int> would generate a type node for that class, and then if necessary, perform an instantiation (which might need to be merged with duplicates from other TUs later on).
—James