<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 15 May 2017 at 10:28, Jordan Rose via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, Richard. Swift was using this information in order to put imported macros in a particular context. It wouldn't surprise me to hear that we were doing it wrong, and that there's a better way to go from a macro back to a module, but is there a recommended replacement?<br></blockquote><div><br></div><div>The recommended way to connect macros to modules is via the ModuleMacro objects, which represent a macro exported from a module. You can query the exported macro for a (module, identifier) pair with Preprocessor::getModuleMacro, or walk the ModuleMacro graph for an identifier by starting from Preprocessor::getLeafModuleMacros.</div><div><br></div><div>If you alternatively want to know the set of macros that would be visible with a given set of imports, after setting up that state you can walk the range produced by Preprocessor::macros(true) and query getActiveModuleMacros on each MacroState.</div><div><br></div><div>If you want to know "what is the set of macros exported directly by this module?", we don't have a prebuilt mechanism for that, since no in-tree client wants that information, but one way would be to walk macros(true) and query getModuleMacro(module, identifier) on each one.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks,<br>
Jordan<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> On May 12, 2017, at 16:40, Richard Smith via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: rsmith<br>
> Date: Fri May 12 18:40:52 2017<br>
> New Revision: 302966<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=302966&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=302966&view=rev</a><br>
> Log:<br>
> Remove unused tracking of owning module for MacroInfo objects.<br>
><br>
> Modified:<br>
>    cfe/trunk/include/clang/Lex/<wbr>MacroInfo.h<br>
>    cfe/trunk/include/clang/Lex/<wbr>Preprocessor.h<br>
>    cfe/trunk/lib/Lex/MacroInfo.<wbr>cpp<br>
>    cfe/trunk/lib/Lex/<wbr>PPDirectives.cpp<br>
>    cfe/trunk/lib/Lex/<wbr>Preprocessor.cpp<br>
>    cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp<br>
>    cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Lex/<wbr>MacroInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Lex/MacroInfo.h?rev=<wbr>302966&r1=302965&r2=302966&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Lex/<wbr>MacroInfo.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/<wbr>MacroInfo.h Fri May 12 18:40:52 2017<br>
> @@ -105,9 +105,6 @@ class MacroInfo {<br>
>   /// \brief Must warn if the macro is unused at the end of translation unit.<br>
>   bool IsWarnIfUnused : 1;<br>
><br>
> -  /// \brief Whether this macro info was loaded from an AST file.<br>
> -  bool FromASTFile : 1;<br>
> -<br>
>   /// \brief Whether this macro was used as header guard.<br>
>   bool UsedForHeaderGuard : 1;<br>
><br>
> @@ -264,34 +261,16 @@ public:<br>
>     IsDisabled = true;<br>
>   }<br>
><br>
> -  /// \brief Determine whether this macro info came from an AST file (such as<br>
> -  /// a precompiled header or module) rather than having been parsed.<br>
> -  bool isFromASTFile() const { return FromASTFile; }<br>
> -<br>
>   /// \brief Determine whether this macro was used for a header guard.<br>
>   bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }<br>
><br>
>   void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; }<br>
><br>
> -  /// \brief Retrieve the global ID of the module that owns this particular<br>
> -  /// macro info.<br>
> -  unsigned getOwningModuleID() const {<br>
> -    if (isFromASTFile())<br>
> -      return *(const unsigned *)(this + 1);<br>
> -<br>
> -    return 0;<br>
> -  }<br>
> -<br>
>   void dump() const;<br>
><br>
> private:<br>
>   unsigned getDefinitionLengthSlow(const SourceManager &SM) const;<br>
><br>
> -  void setOwningModuleID(unsigned ID) {<br>
> -    assert(isFromASTFile());<br>
> -    *(unsigned *)(this + 1) = ID;<br>
> -  }<br>
> -<br>
>   friend class Preprocessor;<br>
> };<br>
><br>
><br>
> Modified: cfe/trunk/include/clang/Lex/<wbr>Preprocessor.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/include/<wbr>clang/Lex/Preprocessor.h?rev=<wbr>302966&r1=302965&r2=302966&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Lex/<wbr>Preprocessor.h (original)<br>
> +++ cfe/trunk/include/clang/Lex/<wbr>Preprocessor.h Fri May 12 18:40:52 2017<br>
> @@ -644,14 +644,6 @@ class Preprocessor {<br>
>   /// of that list.<br>
>   MacroInfoChain *MIChainHead;<br>
><br>
> -  struct DeserializedMacroInfoChain {<br>
> -    MacroInfo MI;<br>
> -    unsigned OwningModuleID; // MUST be immediately after the MacroInfo object<br>
> -                     // so it can be accessed by MacroInfo::getOwningModuleID()<wbr>.<br>
> -    DeserializedMacroInfoChain *Next;<br>
> -  };<br>
> -  DeserializedMacroInfoChain *DeserialMIChainHead;<br>
> -<br>
>   void updateOutOfDateIdentifier(<wbr>IdentifierInfo &II) const;<br>
><br>
> public:<br>
> @@ -1669,10 +1661,6 @@ public:<br>
>   /// \brief Allocate a new MacroInfo object with the provided SourceLocation.<br>
>   MacroInfo *AllocateMacroInfo(<wbr>SourceLocation L);<br>
><br>
> -  /// \brief Allocate a new MacroInfo object loaded from an AST file.<br>
> -  MacroInfo *<wbr>AllocateDeserializedMacroInfo(<wbr>SourceLocation L,<br>
> -                                           unsigned SubModuleID);<br>
> -<br>
>   /// \brief Turn the specified lexer token into a fully checked and spelled<br>
>   /// filename, e.g. as an operand of \#include.<br>
>   ///<br>
> @@ -1764,9 +1752,6 @@ private:<br>
>   /// macro name.<br>
>   void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info);<br>
><br>
> -  /// \brief Allocate a new MacroInfo object.<br>
> -  MacroInfo *AllocateMacroInfo();<br>
> -<br>
>   DefMacroDirective *AllocateDefMacroDirective(<wbr>MacroInfo *MI,<br>
>                                                SourceLocation Loc);<br>
>   UndefMacroDirective *AllocateUndefMacroDirective(<wbr>SourceLocation UndefLoc);<br>
><br>
> Modified: cfe/trunk/lib/Lex/MacroInfo.<wbr>cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Lex/<wbr>MacroInfo.cpp?rev=302966&r1=<wbr>302965&r2=302966&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Lex/MacroInfo.<wbr>cpp (original)<br>
> +++ cfe/trunk/lib/Lex/MacroInfo.<wbr>cpp Fri May 12 18:40:52 2017<br>
> @@ -29,7 +29,6 @@ MacroInfo::MacroInfo(<wbr>SourceLocation DefL<br>
>     IsUsed(false),<br>
>     IsAllowRedefinitionsWithoutWar<wbr>ning(false),<br>
>     IsWarnIfUnused(false),<br>
> -    FromASTFile(false),<br>
>     UsedForHeaderGuard(false) {<br>
> }<br>
><br>
> @@ -137,7 +136,6 @@ LLVM_DUMP_METHOD void MacroInfo::dump()<br>
>   if (<wbr>IsAllowRedefinitionsWithoutWar<wbr>ning)<br>
>     Out << " allow_redefinitions_without_<wbr>warning";<br>
>   if (IsWarnIfUnused) Out << " warn_if_unused";<br>
> -  if (FromASTFile) Out << " imported";<br>
>   if (UsedForHeaderGuard) Out << " header_guard";<br>
><br>
>   Out << "\n    #define <macro>";<br>
><br>
> Modified: cfe/trunk/lib/Lex/<wbr>PPDirectives.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Lex/<wbr>PPDirectives.cpp?rev=302966&<wbr>r1=302965&r2=302966&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Lex/<wbr>PPDirectives.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/<wbr>PPDirectives.cpp Fri May 12 18:40:52 2017<br>
> @@ -54,35 +54,12 @@ using namespace clang;<br>
> // Utility Methods for Preprocessor Directive Handling.<br>
> //===-------------------------<wbr>------------------------------<wbr>---------------===//<br>
><br>
> -MacroInfo *Preprocessor::<wbr>AllocateMacroInfo() {<br>
> -  MacroInfoChain *MIChain = BP.Allocate<MacroInfoChain>();<br>
> -  MIChain->Next = MIChainHead;<br>
> +MacroInfo *Preprocessor::<wbr>AllocateMacroInfo(<wbr>SourceLocation L) {<br>
> +  auto *MIChain = new (BP) MacroInfoChain{L, MIChainHead};<br>
>   MIChainHead = MIChain;<br>
>   return &MIChain->MI;<br>
> }<br>
><br>
> -MacroInfo *Preprocessor::<wbr>AllocateMacroInfo(<wbr>SourceLocation L) {<br>
> -  MacroInfo *MI = AllocateMacroInfo();<br>
> -  new (MI) MacroInfo(L);<br>
> -  return MI;<br>
> -}<br>
> -<br>
> -MacroInfo *Preprocessor::<wbr>AllocateDeserializedMacroInfo(<wbr>SourceLocation L,<br>
> -                                                       unsigned SubModuleID) {<br>
> -  static_assert(alignof(<wbr>MacroInfo) >= sizeof(SubModuleID),<br>
> -                "alignment for MacroInfo is less than the ID");<br>
> -  DeserializedMacroInfoChain *MIChain =<br>
> -      BP.Allocate<<wbr>DeserializedMacroInfoChain>();<br>
> -  MIChain->Next = DeserialMIChainHead;<br>
> -  DeserialMIChainHead = MIChain;<br>
> -<br>
> -  MacroInfo *MI = &MIChain->MI;<br>
> -  new (MI) MacroInfo(L);<br>
> -  MI->FromASTFile = true;<br>
> -  MI->setOwningModuleID(<wbr>SubModuleID);<br>
> -  return MI;<br>
> -}<br>
> -<br>
> DefMacroDirective *Preprocessor::<wbr>AllocateDefMacroDirective(<wbr>MacroInfo *MI,<br>
>                                                            SourceLocation Loc) {<br>
>   return new (BP) DefMacroDirective(MI, Loc);<br>
><br>
> Modified: cfe/trunk/lib/Lex/<wbr>Preprocessor.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/Lex/<wbr>Preprocessor.cpp?rev=302966&<wbr>r1=302965&r2=302966&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Lex/<wbr>Preprocessor.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/<wbr>Preprocessor.cpp Fri May 12 18:40:52 2017<br>
> @@ -88,7 +88,7 @@ Preprocessor::Preprocessor(<wbr>std::shared_p<br>
>       CurDirLookup(nullptr), CurLexerKind(CLK_Lexer),<br>
>       CurLexerSubmodule(nullptr), Callbacks(nullptr),<br>
>       CurSubmoduleState(&<wbr>NullSubmoduleState), MacroArgCache(nullptr),<br>
> -      Record(nullptr), MIChainHead(nullptr), DeserialMIChainHead(nullptr) {<br>
> +      Record(nullptr), MIChainHead(nullptr) {<br>
>   OwnsHeaderSearch = OwnsHeaders;<br>
><br>
>   CounterValue = 0; // __COUNTER__ starts at 0.<br>
> @@ -169,11 +169,6 @@ Preprocessor::~Preprocessor() {<br>
>   std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers, nullptr);<br>
>   CurTokenLexer.reset();<br>
><br>
> -  while (DeserializedMacroInfoChain *I = DeserialMIChainHead) {<br>
> -    DeserialMIChainHead = I->Next;<br>
> -    I->~<wbr>DeserializedMacroInfoChain();<br>
> -  }<br>
> -<br>
>   // Free any cached MacroArgs.<br>
>   for (MacroArgs *ArgList = MacroArgCache; ArgList;)<br>
>     ArgList = ArgList->deallocate();<br>
><br>
> Modified: cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/<wbr>Serialization/ASTReader.cpp?<wbr>rev=302966&r1=302965&r2=<wbr>302966&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp (original)<br>
> +++ cfe/trunk/lib/Serialization/<wbr>ASTReader.cpp Fri May 12 18:40:52 2017<br>
> @@ -1534,9 +1534,8 @@ MacroInfo *ASTReader::ReadMacroRecord(Mo<br>
>         return Macro;<br>
><br>
>       unsigned NextIndex = 1; // Skip identifier ID.<br>
> -      SubmoduleID SubModID = getGlobalSubmoduleID(F, Record[NextIndex++]);<br>
>       SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);<br>
> -      MacroInfo *MI = PP.<wbr>AllocateDeserializedMacroInfo(<wbr>Loc, SubModID);<br>
> +      MacroInfo *MI = PP.AllocateMacroInfo(Loc);<br>
>       MI->setDefinitionEndLoc(<wbr>ReadSourceLocation(F, Record, NextIndex));<br>
>       MI->setIsUsed(Record[<wbr>NextIndex++]);<br>
>       MI->setUsedForHeaderGuard(<wbr>Record[NextIndex++]);<br>
><br>
> Modified: cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=302966&r1=302965&r2=302966&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/<wbr>Serialization/ASTWriter.cpp?<wbr>rev=302966&r1=302965&r2=<wbr>302966&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp (original)<br>
> +++ cfe/trunk/lib/Serialization/<wbr>ASTWriter.cpp Fri May 12 18:40:52 2017<br>
> @@ -2413,7 +2413,6 @@ void ASTWriter::WritePreprocessor(<wbr>const<br>
>     }<br>
><br>
>     AddIdentifierRef(Name, Record);<br>
> -    Record.push_back(<wbr>inferSubmoduleIDFromLocation(<wbr>MI->getDefinitionLoc()));<br>
>     AddSourceLocation(MI-><wbr>getDefinitionLoc(), Record);<br>
>     AddSourceLocation(MI-><wbr>getDefinitionEndLoc(), Record);<br>
>     Record.push_back(MI->isUsed())<wbr>;<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>